def clone_tooth(base_shape): clone = gp_Trsf() grouped_shape = base_shape # Find a divisor, between 1 and 8, for the number_of teeth multiplier = 1 max_multiplier = 1 for i in range(0, 8): if num_teeth % multiplier == 0: max_multiplier = i + 1 multiplier = max_multiplier for i in range(1, multiplier): clone.SetRotation(gp_OZ(), -i * tooth_angle) rotated_shape = BRepBuilderAPI_Transform(base_shape, clone, True).Shape() grouped_shape = BRepAlgoAPI_Fuse(grouped_shape, rotated_shape).Shape() # Rotate the basic tooth and fuse together aggregated_shape = grouped_shape for i in range(1, int(num_teeth / multiplier)): clone.SetRotation(gp_OZ(), - i * multiplier * tooth_angle) rotated_shape = BRepBuilderAPI_Transform(grouped_shape, clone, True).Shape() aggregated_shape = BRepAlgoAPI_Fuse(aggregated_shape, rotated_shape).Shape() cylinder = BRepPrimAPI_MakeCylinder(gp_XOY(), top_radius - roller_diameter, thickness) aggregated_shape = BRepAlgoAPI_Fuse(aggregated_shape, cylinder.Shape()).Shape() return aggregated_shape
def boolean_cut(base): # Create a cylinder cylinder_radius = 0.25 cylinder_height = 2.0 cylinder_origin = gp_Ax2(gp_Pnt(0.0, 0.0, -cylinder_height / 2.0), gp_Dir(0.0, 0.0, 1.0)) cylinder = BRepPrimAPI_MakeCylinder(cylinder_origin, cylinder_radius, cylinder_height) # Repeatedly move and subtract it from the input shape move = gp_Trsf() boolean_result = base clone_radius = 1.0 for clone in range(8): angle = clone * pi / 4.0 # Move the cylinder move.SetTranslation( gp_Vec(cos(angle) * clone_radius, sin(angle) * clone_radius, 0.0)) moved_cylinder = BRepBuilderAPI_Transform(cylinder.Shape(), move, True).Shape() # Subtract the moved cylinder from the drilled sphere boolean_result = BRepAlgoAPI_Cut(boolean_result, moved_cylinder).Shape() return boolean_result
def create_shape(self): d = self.declaration args = [coerce_axis(d.axis), d.radius, d.height] if d.angle: args.append(d.angle) cylinder = BRepPrimAPI_MakeCylinder(*args) self.shape = cylinder.Shape()
def TextureRepeat(self, toRepeatU, toRepeatV): self._toRepeatU = toRepeatU self._toRepeatV = toRepeatV def TextureOrigin(self, originU, originV): self._originU = originU self._originV = originV def GetProperties(self): return (self._filename, self._toScaleU, self._toScaleV, self._toRepeatU, self._toRepeatV, self._originU, self._originV) # # First create texture and a material # texture_filename = '../assets/images/ground.bmp' t = Texture(texture_filename) m = Graphic3d_MaterialAspect(Graphic3d_NOM_SILVER) # # Displays a cylinder with a material and a texture # s = BRepPrimAPI_MakeCylinder(60, 200) display.DisplayShape(s.Shape(), material=m, texture=t) # # Display settings # display.View_Iso() display.FitAll() start_display()
anEdgeExplorer.Next() myBody = mkFillet # Create the neck of the bottle neckLocation = gp_Pnt(0, 0, height) neckAxis = gp_DZ() neckAx2 = gp_Ax2(neckLocation, neckAxis) myNeckRadius = thickness / 4.0 myNeckHeight = height / 10.0 mkCylinder = BRepPrimAPI_MakeCylinder(neckAx2, myNeckRadius, myNeckHeight) myBody = BRepAlgoAPI_Fuse(myBody.Shape(), mkCylinder.Shape()) # Our goal is to find the highest Z face and remove it faceToRemove = None zMax = -1 # We have to work our way through all the faces to find the highest Z face so we can remove it for the shell aFaceExplorer = TopExp_Explorer(myBody.Shape(), TopAbs_FACE) while aFaceExplorer.More(): aFace = topods.Face(aFaceExplorer.Current()) if face_is_plane(aFace): aPlane = geom_plane_from_face(aFace) # We want the highest Z face, so compare this to the previous faces aPnt = aPlane.Location()