def _read(self, file_name): try: self.defs = {} self.shapes = [] tree = ET.parse(file_name) xml_root = tree.getroot() if xml_root.tag != "X3D": return None scale = 1000 # Default X3D unit it one meter, while Cura's is one millimeters if xml_root[0].tag == "head": for head_node in xml_root[0]: if head_node.tag == "unit" and head_node.attrib.get( "category") == "length": scale *= float(head_node.attrib["conversionFactor"]) break xml_scene = xml_root[1] else: xml_scene = xml_root[0] if xml_scene.tag != "Scene": return None self.transform = Matrix() self.transform.setByScaleFactor(scale) self.index_base = 0 # Traverse the scene tree, populate the shapes list self.processChildNodes(xml_scene) if self.shapes: builder = MeshBuilder() builder.setVertices( numpy.concatenate([shape.verts for shape in self.shapes])) builder.setIndices( numpy.concatenate([shape.faces for shape in self.shapes])) builder.calculateNormals() builder.setFileName(file_name) mesh_data = builder.build() # Manually try and get the extents of the mesh_data. This should prevent nasty NaN issues from # leaving the reader. mesh_data.getExtents() node = SceneNode() node.setMeshData(mesh_data) node.setSelectable(True) node.setName(file_name) else: return None except Exception: Logger.logException("e", "Exception in X3D reader") return None return node
def read(self, file_name): try: self.defs = {} self.shapes = [] tree = ET.parse(file_name) xml_root = tree.getroot() if xml_root.tag != "X3D": return None scale = 1000 # Default X3D unit it one meter, while Cura's is one millimeters if xml_root[0].tag == "head": for head_node in xml_root[0]: if head_node.tag == "unit" and head_node.attrib.get("category") == "length": scale *= float(head_node.attrib["conversionFactor"]) break xml_scene = xml_root[1] else: xml_scene = xml_root[0] if xml_scene.tag != "Scene": return None self.transform = Matrix() self.transform.setByScaleFactor(scale) self.index_base = 0 # Traverse the scene tree, populate the shapes list self.processChildNodes(xml_scene) if self.shapes: builder = MeshBuilder() builder.setVertices(numpy.concatenate([shape.verts for shape in self.shapes])) builder.setIndices(numpy.concatenate([shape.faces for shape in self.shapes])) builder.calculateNormals() builder.setFileName(file_name) mesh_data = builder.build() # Manually try and get the extents of the mesh_data. This should prevent nasty NaN issues from # leaving the reader. mesh_data.getExtents() node = SceneNode() node.setMeshData(mesh_data) node.setSelectable(True) node.setName(file_name) else: return None except Exception: Logger.logException("e", "Exception in X3D reader") return None return node
def _createCube(self, size, maxs, height, dep): mesh = MeshBuilder() # Intial Comment from Ultimaker B.V. I have never try to verify this point # Can't use MeshBuilder.addCube() because that does not get per-vertex normals # Per-vertex normals require duplication of vertices s = size / 2 sm = maxs / 2 l = height s_inf=math.tan(math.radians(dep))*l+s if sm>s and dep!=0: l_max=(sm-s) / math.tan(math.radians(dep)) else : l_max=l # Difference between Cone and Cone + max base size if l_max<l and l_max>0: nbv=40 verts = [ # 10 faces with 4 corners each [-sm, -l_max, sm], [-s, s, s], [ s, s, s], [ sm, -l_max, sm], [-s, s, -s], [-sm, -l_max, -sm], [ sm, -l_max, -sm], [ s, s, -s], [-sm, -l, sm], [-sm, -l_max, sm], [ sm, -l_max, sm], [ sm, -l, sm], [-sm, -l_max, -sm], [-sm, -l, -sm], [ sm, -l, -sm], [ sm, -l_max, -sm], [ sm, -l, -sm], [-sm, -l, -sm], [-sm, -l, sm], [ sm, -l, sm], [-s, s, -s], [ s, s, -s], [ s, s, s], [-s, s, s], [-sm, -l, sm], [-sm, -l, -sm], [-sm, -l_max, -sm], [-sm, -l_max, sm], [ sm, -l, -sm], [ sm, -l, sm], [ sm, -l_max, sm], [ sm, -l_max, -sm], [-sm, -l_max, sm], [-sm, -l_max, -sm], [-s, s, -s], [-s, s, s], [ sm, -l_max, -sm], [ sm, -l_max, sm], [ s, s, s], [ s, s, -s] ] else: nbv=24 verts = [ # 6 faces with 4 corners each [-s_inf, -l, s_inf], [-s, s, s], [ s, s, s], [ s_inf, -l, s_inf], [-s, s, -s], [-s_inf, -l, -s_inf], [ s_inf, -l, -s_inf], [ s, s, -s], [ s_inf, -l, -s_inf], [-s_inf, -l, -s_inf], [-s_inf, -l, s_inf], [ s_inf, -l, s_inf], [-s, s, -s], [ s, s, -s], [ s, s, s], [-s, s, s], [-s_inf, -l, s_inf], [-s_inf, -l, -s_inf], [-s, s, -s], [-s, s, s], [ s_inf, -l, -s_inf], [ s_inf, -l, s_inf], [ s, s, s], [ s, s, -s] ] mesh.setVertices(numpy.asarray(verts, dtype=numpy.float32)) indices = [] for i in range(0, nbv, 4): # All 6 quads (12 triangles) indices.append([i, i+2, i+1]) indices.append([i, i+3, i+2]) mesh.setIndices(numpy.asarray(indices, dtype=numpy.int32)) mesh.calculateNormals() return mesh
def _createPlane(self, size): mesh = MeshBuilder() s = size / 2 verts = [ # 1 face with 4 corners [-s, 0, -s], [s, 0, -s], [s, 0, s], [-s, 0, s], ] mesh.setVertices(numpy.asarray(verts, dtype=numpy.float32)) indices = [] for i in range(0, 4, 4): # All 1 quad (2 triangles) indices.append([i, i + 2, i + 1]) indices.append([i, i + 3, i + 2]) mesh.setIndices(numpy.asarray(indices, dtype=numpy.int32)) mesh.calculateNormals() return mesh
def _createPastille(self, size, nb , lg, He): mesh = MeshBuilder() # Per-vertex normals require duplication of vertices r = size / 2 # First layer length sup = -lg + He l = -lg rng = int(360 / nb) ang = math.radians(nb) verts = [] for i in range(0, rng): # Top verts.append([0, sup, 0]) verts.append([r*math.cos((i+1)*ang), sup, r*math.sin((i+1)*ang)]) verts.append([r*math.cos(i*ang), sup, r*math.sin(i*ang)]) #Side 1a verts.append([r*math.cos(i*ang), sup, r*math.sin(i*ang)]) verts.append([r*math.cos((i+1)*ang), sup, r*math.sin((i+1)*ang)]) verts.append([r*math.cos((i+1)*ang), l, r*math.sin((i+1)*ang)]) #Side 1b verts.append([r*math.cos((i+1)*ang), l, r*math.sin((i+1)*ang)]) verts.append([r*math.cos(i*ang), l, r*math.sin(i*ang)]) verts.append([r*math.cos(i*ang), sup, r*math.sin(i*ang)]) #Bottom verts.append([0, l, 0]) verts.append([r*math.cos(i*ang), l, r*math.sin(i*ang)]) verts.append([r*math.cos((i+1)*ang), l, r*math.sin((i+1)*ang)]) mesh.setVertices(numpy.asarray(verts, dtype=numpy.float32)) indices = [] # for every angle increment 12 Vertices tot = rng * 12 for i in range(0, tot, 3): # indices.append([i, i+1, i+2]) mesh.setIndices(numpy.asarray(indices, dtype=numpy.int32)) mesh.calculateNormals() return mesh
def _createCube(self, size, height): mesh = MeshBuilder() # Can't use MeshBuilder.addCube() because that does not get per-vertex normals # Per-vertex normals require duplication of vertices s = size / 2 l = height #s_inf=math.tan(math.radians(dep))*l+s if self._WiderBase: base_size = self._SupportBaseSize/2 else: base_size = s if self._DropToBuildplate: verts = [ # 6 faces with 4 corners each [-base_size, -l, base_size], [-s, s, s], [ s, s, s], [ base_size, -l, base_size], [-s, s, -s], [-base_size, -l, -base_size], [ base_size, -l, -base_size], [ s, s, -s], [ base_size, -l, -base_size], [-base_size, -l, -base_size], [-base_size, -l, base_size], [ base_size, -l, base_size], [-s, s, -s], [ s, s, -s], [ s, s, s], [-s, s, s], [-base_size, -l, base_size], [-base_size, -l, -base_size], [-s, s, -s], [-s, s, s], [ base_size, -l, -base_size], [ base_size, -l, base_size], [ s, s, s], [ s, s, -s] ] else: verts = [ # 6 faces with 4 corners each [-s, -s, s], [-s, s, s], [ s, s, s], [ s, -s, s], [-s, s, -s], [-s, -s, -s], [ s, -s, -s], [ s, s, -s], [ s, -s, -s], [-s, -s, -s], [-s, -s, s], [ s, -s, s], [-s, s, -s], [ s, s, -s], [ s, s, s], [-s, s, s], [-s, -s, s], [-s, -s, -s], [-s, s, -s], [-s, s, s], [ s, -s, -s], [ s, -s, s], [ s, s, s], [ s, s, -s] ] mesh.setVertices(numpy.asarray(verts, dtype=numpy.float32)) indices = [] for i in range(0, 24, 4): # All 6 quads (12 triangles) indices.append([i, i+2, i+1]) indices.append([i, i+3, i+2]) mesh.setIndices(numpy.asarray(indices, dtype=numpy.int32)) mesh.calculateNormals() return mesh
def _createCube(self, size): mesh = MeshBuilder() # Can't use MeshBuilder.addCube() because that does not get per-vertex normals # Per-vertex normals require duplication of vertices s = size / 2 verts = [ # 6 faces with 4 corners each [-s, -s, s], [-s, s, s], [s, s, s], [s, -s, s], [-s, s, -s], [-s, -s, -s], [s, -s, -s], [s, s, -s], [s, -s, -s], [-s, -s, -s], [-s, -s, s], [s, -s, s], [-s, s, -s], [s, s, -s], [s, s, s], [-s, s, s], [-s, -s, s], [-s, -s, -s], [-s, s, -s], [-s, s, s], [s, -s, -s], [s, -s, s], [s, s, s], [s, s, -s] ] mesh.setVertices(numpy.asarray(verts, dtype=numpy.float32)) indices = [] for i in range(0, 24, 4): # All 6 quads (12 triangles) indices.append([i, i + 2, i + 1]) indices.append([i, i + 3, i + 2]) mesh.setIndices(numpy.asarray(indices, dtype=numpy.int32)) mesh.calculateNormals() return mesh
def _createCube(self, size): mesh = MeshBuilder() # Can't use MeshBuilder.addCube() because that does not get per-vertex normals # Per-vertex normals require duplication of vertices s = size / 2 verts = [ # 6 faces with 4 corners each [-s, -s, s], [-s, s, s], [ s, s, s], [ s, -s, s], [-s, s, -s], [-s, -s, -s], [ s, -s, -s], [ s, s, -s], [ s, -s, -s], [-s, -s, -s], [-s, -s, s], [ s, -s, s], [-s, s, -s], [ s, s, -s], [ s, s, s], [-s, s, s], [-s, -s, s], [-s, -s, -s], [-s, s, -s], [-s, s, s], [ s, -s, -s], [ s, -s, s], [ s, s, s], [ s, s, -s] ] mesh.setVertices(numpy.asarray(verts, dtype=numpy.float32)) indices = [] for i in range(0, 24, 4): # All 6 quads (12 triangles) indices.append([i, i+2, i+1]) indices.append([i, i+3, i+2]) mesh.setIndices(numpy.asarray(indices, dtype=numpy.int32)) mesh.calculateNormals() return mesh
def test_setIndices(): builder = MeshBuilder() builder.setIndices(numpy.zeros(3)) assert builder.getFaceCount() == 1 assert builder.getIndices()[0] == 0
def _createCapsule(self, size, nb , lg, He, lw): mesh = MeshBuilder() # Per-vertex normals require duplication of vertices r = size / 2 # First layer length sup = -lg + He if self._Nb_Layer >1 : sup_c = -lg + (He * 2) else: sup_c = -lg + (He * 3) l = -lg rng = int(360 / nb) ang = math.radians(nb) r_sup=math.tan(math.radians(45))*(He * 3)+r # Top inside radius ri=r_sup-(1.8*lw) # Top radius rit=r-(1.8*lw) verts = [] for i in range(0, rng): # Top verts.append([ri*math.cos(i*ang), sup_c, ri*math.sin(i*ang)]) verts.append([r_sup*math.cos((i+1)*ang), sup_c, r_sup*math.sin((i+1)*ang)]) verts.append([r_sup*math.cos(i*ang), sup_c, r_sup*math.sin(i*ang)]) verts.append([ri*math.cos((i+1)*ang), sup_c, ri*math.sin((i+1)*ang)]) verts.append([r_sup*math.cos((i+1)*ang), sup_c, r_sup*math.sin((i+1)*ang)]) verts.append([ri*math.cos(i*ang), sup_c, ri*math.sin(i*ang)]) #Side 1a verts.append([r_sup*math.cos(i*ang), sup_c, r_sup*math.sin(i*ang)]) verts.append([r_sup*math.cos((i+1)*ang), sup_c, r_sup*math.sin((i+1)*ang)]) verts.append([r*math.cos((i+1)*ang), l, r*math.sin((i+1)*ang)]) #Side 1b verts.append([r*math.cos((i+1)*ang), l, r*math.sin((i+1)*ang)]) verts.append([r*math.cos(i*ang), l, r*math.sin(i*ang)]) verts.append([r_sup*math.cos(i*ang), sup_c, r_sup*math.sin(i*ang)]) #Side 2a verts.append([rit*math.cos((i+1)*ang), sup, rit*math.sin((i+1)*ang)]) verts.append([ri*math.cos((i+1)*ang), sup_c, ri*math.sin((i+1)*ang)]) verts.append([ri*math.cos(i*ang), sup_c, ri*math.sin(i*ang)]) #Side 2b verts.append([ri*math.cos(i*ang), sup_c, ri*math.sin(i*ang)]) verts.append([rit*math.cos(i*ang), sup, rit*math.sin(i*ang)]) verts.append([rit*math.cos((i+1)*ang), sup, rit*math.sin((i+1)*ang)]) #Bottom Top verts.append([0, sup, 0]) verts.append([rit*math.cos((i+1)*ang), sup, rit*math.sin((i+1)*ang)]) verts.append([rit*math.cos(i*ang), sup, rit*math.sin(i*ang)]) #Bottom verts.append([0, l, 0]) verts.append([r*math.cos(i*ang), l, r*math.sin(i*ang)]) verts.append([r*math.cos((i+1)*ang), l, r*math.sin((i+1)*ang)]) mesh.setVertices(numpy.asarray(verts, dtype=numpy.float32)) indices = [] # for every angle increment 24 Vertices tot = rng * 24 for i in range(0, tot, 3): # indices.append([i, i+1, i+2]) mesh.setIndices(numpy.asarray(indices, dtype=numpy.int32)) mesh.calculateNormals() return mesh
def updateSceneFromOptimizationResult( self, analysis: pywim.smartslice.result.Analysis): type_map = { 'int': int, 'float': float, 'str': str, 'enum': str, 'bool': bool } our_only_node = getPrintableNodes()[0] active_extruder = getNodeActiveExtruder(our_only_node) # TODO - Move this into a common class or function to apply an am.Config to GlobalStack/ExtruderStack if analysis.print_config.infill: infill_density = analysis.print_config.infill.density infill_pattern = analysis.print_config.infill.pattern if infill_pattern is None or infill_pattern == pywim.am.InfillType.unknown: infill_pattern = pywim.am.InfillType.grid infill_pattern_name = SmartSliceJobHandler.INFILL_SMARTSLICE_CURA[ infill_pattern] extruder_dict = { "wall_line_count": analysis.print_config.walls, "top_layers": analysis.print_config.top_layers, "bottom_layers": analysis.print_config.bottom_layers, "infill_sparse_density": analysis.print_config.infill.density, "infill_pattern": infill_pattern_name } Logger.log("d", "Optimized extruder settings: {}".format(extruder_dict)) for key, value in extruder_dict.items(): if value is not None: property_type = type_map.get( active_extruder.getProperty(key, "type")) if property_type: active_extruder.setProperty(key, "value", property_type(value), set_from_cache=True) active_extruder.setProperty(key, "state", InstanceState.User, set_from_cache=True) Application.getInstance().getMachineManager( ).forceUpdateAllSettings() self.optimizationResultAppliedToScene.emit() # Remove any modifier meshes which are present from a previous result mod_meshes = getModifierMeshes() if len(mod_meshes) > 0: for node in mod_meshes: node.addDecorator(SmartSliceRemovedDecorator()) our_only_node.removeChild(node) Application.getInstance().getController().getScene( ).sceneChanged.emit(node) # Add in the new modifier meshes for modifier_mesh in analysis.modifier_meshes: # Building the scene node modifier_mesh_node = CuraSceneNode() modifier_mesh_node.setName("SmartSliceMeshModifier") modifier_mesh_node.setSelectable(True) modifier_mesh_node.setCalculateBoundingBox(True) # Use the data from the SmartSlice engine to translate / rotate / scale the mod mesh modifier_mesh_node.setTransformation( Matrix(modifier_mesh.transform)) # Building the mesh # # Preparing the data from pywim for MeshBuilder modifier_mesh_vertices = [[v.x, v.y, v.z] for v in modifier_mesh.vertices] modifier_mesh_indices = [[triangle.v1, triangle.v2, triangle.v3] for triangle in modifier_mesh.triangles] # Doing the actual build modifier_mesh_data = MeshBuilder() modifier_mesh_data.setVertices( numpy.asarray(modifier_mesh_vertices, dtype=numpy.float32)) modifier_mesh_data.setIndices( numpy.asarray(modifier_mesh_indices, dtype=numpy.int32)) modifier_mesh_data.calculateNormals() modifier_mesh_node.setMeshData(modifier_mesh_data.build()) modifier_mesh_node.calculateBoundingBoxMesh() active_build_plate = Application.getInstance( ).getMultiBuildPlateModel().activeBuildPlate modifier_mesh_node.addDecorator( BuildPlateDecorator(active_build_plate)) modifier_mesh_node.addDecorator(SliceableObjectDecorator()) modifier_mesh_node.addDecorator(SmartSliceAddedDecorator()) bottom = modifier_mesh_node.getBoundingBox().bottom z_offset_decorator = ZOffsetDecorator() z_offset_decorator.setZOffset(bottom) modifier_mesh_node.addDecorator(z_offset_decorator) stack = modifier_mesh_node.callDecoration("getStack") settings = stack.getTop() modifier_mesh_node_infill_pattern = SmartSliceJobHandler.INFILL_SMARTSLICE_CURA[ modifier_mesh.print_config.infill.pattern] definition_dict = { "infill_mesh": True, "infill_pattern": modifier_mesh_node_infill_pattern, "infill_sparse_density": modifier_mesh.print_config.infill.density, "wall_line_count": modifier_mesh.print_config.walls, "top_layers": modifier_mesh.print_config.top_layers, "bottom_layers": modifier_mesh.print_config.bottom_layers, } Logger.log( "d", "Optimized modifier mesh settings: {}".format(definition_dict)) for key, value in definition_dict.items(): if value is not None: definition = stack.getSettingDefinition(key) property_type = type_map.get(stack.getProperty( key, "type")) if property_type: new_instance = SettingInstance(definition, settings) new_instance.setProperty("value", property_type(value)) new_instance.resetState( ) # Ensure that the state is not seen as a user state. settings.addInstance(new_instance) our_only_node.addChild(modifier_mesh_node) # emit changes and connect error tracker Application.getInstance().getController().getScene( ).sceneChanged.emit(modifier_mesh_node)
def _createCylinder(self, size, nb , height): mesh = MeshBuilder() # Per-vertex normals require duplication of vertices r = size / 2 # additionale length sup = size * 0.1 l = -height rng = int(360 / nb) ang = math.radians(nb) verts = [] if self._WiderBase: r_base = self._SupportBaseSize/2 else: r_base = r if self._DropToBuildplate: for i in range(0, rng): # Top verts.append([0, sup, 0]) verts.append([r*math.cos((i+1)*ang), sup, r*math.sin((i+1)*ang)]) verts.append([r*math.cos(i*ang), sup, r*math.sin(i*ang)]) #Side 1a verts.append([r*math.cos(i*ang), sup, r*math.sin(i*ang)]) verts.append([r*math.cos((i+1)*ang), sup, r*math.sin((i+1)*ang)]) verts.append([r_base*math.cos((i+1)*ang), l, r_base*math.sin((i+1)*ang)]) #Side 1b verts.append([r_base*math.cos((i+1)*ang), l, r_base*math.sin((i+1)*ang)]) verts.append([r_base*math.cos(i*ang), l, r_base*math.sin(i*ang)]) verts.append([r*math.cos(i*ang), sup, r*math.sin(i*ang)]) #Bottom verts.append([0, l, 0]) verts.append([r_base*math.cos((i+1)*ang), l, r_base*math.sin((i+1)*ang)]) verts.append([r_base*math.cos(i*ang), l, r_base*math.sin(i*ang)]) else: for i in range(0, rng): # Top verts.append([0, sup, 0]) verts.append([r*math.cos((i+1)*ang), sup, r*math.sin((i+1)*ang)]) verts.append([r*math.cos(i*ang), sup, r*math.sin(i*ang)]) #Side 1a verts.append([r*math.cos(i*ang), sup, r*math.sin(i*ang)]) verts.append([r*math.cos((i+1)*ang), sup, r*math.sin((i+1)*ang)]) verts.append([r*math.cos((i+1)*ang), -size, r*math.sin((i+1)*ang)]) #Side 1b verts.append([r*math.cos((i+1)*ang), -size, r*math.sin((i+1)*ang)]) verts.append([r*math.cos(i*ang), -size, r*math.sin(i*ang)]) verts.append([r*math.cos(i*ang), sup, r*math.sin(i*ang)]) #Bottom verts.append([0, -size, 0]) verts.append([r*math.cos((i+1)*ang), -size, r*math.sin((i+1)*ang)]) verts.append([r*math.cos(i*ang), -size, r*math.sin(i*ang)]) mesh.setVertices(numpy.asarray(verts, dtype=numpy.float32)) indices = [] # for every angle increment 12 Vertices tot = rng * 12 for i in range(0, tot, 3): # indices.append([i, i+1, i+2]) mesh.setIndices(numpy.asarray(indices, dtype=numpy.int32)) mesh.calculateNormals() return mesh
def _createCustom(self, size, maxs, pos1 , pos2, dep, ztop): mesh = MeshBuilder() # Init point Pt1 = Vector(pos1.x,pos1.z,pos1.y) Pt2 = Vector(pos2.x,pos2.z,pos2.y) V_Dir = Pt2 - Pt1 # Calcul vecteur s = size / 2 sm = maxs / 2 l_a = pos1.y s_infa=math.tan(math.radians(dep))*l_a+s l_b = pos2.y s_infb=math.tan(math.radians(dep))*l_b+s if sm>s and dep!=0: l_max_a=(sm-s) / math.tan(math.radians(dep)) l_max_b=(sm-s) / math.tan(math.radians(dep)) else : l_max_a=l_a l_max_b=l_b Vtop = Vector(0,0,ztop) VZ = Vector(0,0,s) VZa = Vector(0,0,-l_a) VZb = Vector(0,0,-l_b) Norm=Vector.cross(V_Dir,VZ).normalized() Dec = Vector(Norm.x*s,Norm.y*s,Norm.z*s) if l_max_a<l_a and l_max_b<l_b and l_max_a>0 and l_max_b>0: nbv=40 Deca = Vector(Norm.x*sm,Norm.y*sm,Norm.z*sm) Decb = Vector(Norm.x*sm,Norm.y*sm,Norm.z*sm) VZam = Vector(0,0,-l_max_a) VZbm = Vector(0,0,-l_max_b) # X Z Y P_1t = Vtop+Dec P_2t = Vtop-Dec P_3t = V_Dir+Vtop+Dec P_4t = V_Dir+Vtop-Dec P_1m = VZam+Deca P_2m = VZam-Deca P_3m = VZbm+V_Dir+Decb P_4m = VZbm+V_Dir-Decb P_1i = VZa+Deca P_2i = VZa-Deca P_3i = VZb+V_Dir+Decb P_4i = VZb+V_Dir-Decb """ 1) Top 2) Front 3) Left 4) Right 5) Back 6) Front inf 7) Left inf 8) Right inf 9) Back inf 10) Bottom """ verts = [ # 10 faces with 4 corners each [P_1t.x, P_1t.z, P_1t.y], [P_2t.x, P_2t.z, P_2t.y], [P_4t.x, P_4t.z, P_4t.y], [P_3t.x, P_3t.z, P_3t.y], [P_1t.x, P_1t.z, P_1t.y], [P_3t.x, P_3t.z, P_3t.y], [P_3m.x, P_3m.z, P_3m.y], [P_1m.x, P_1m.z, P_1m.y], [P_2t.x, P_2t.z, P_2t.y], [P_1t.x, P_1t.z, P_1t.y], [P_1m.x, P_1m.z, P_1m.y], [P_2m.x, P_2m.z, P_2m.y], [P_3t.x, P_3t.z, P_3t.y], [P_4t.x, P_4t.z, P_4t.y], [P_4m.x, P_4m.z, P_4m.y], [P_3m.x, P_3m.z, P_3m.y], [P_4t.x, P_4t.z, P_4t.y], [P_2t.x, P_2t.z, P_2t.y], [P_2m.x, P_2m.z, P_2m.y], [P_4m.x, P_4m.z, P_4m.y], [P_1m.x, P_1m.z, P_1m.y], [P_3m.x, P_3m.z, P_3m.y], [P_3i.x, P_3i.z, P_3i.y], [P_1i.x, P_1i.z, P_1i.y], [P_2m.x, P_2m.z, P_2m.y], [P_1m.x, P_1m.z, P_1m.y], [P_1i.x, P_1i.z, P_1i.y], [P_2i.x, P_2i.z, P_2i.y], [P_3m.x, P_3m.z, P_3m.y], [P_4m.x, P_4m.z, P_4m.y], [P_4i.x, P_4i.z, P_4i.y], [P_3i.x, P_3i.z, P_3i.y], [P_4m.x, P_4m.z, P_4m.y], [P_2m.x, P_2m.z, P_2m.y], [P_2i.x, P_2i.z, P_2i.y], [P_4i.x, P_4i.z, P_4i.y], [P_1i.x, P_1i.z, P_1i.y], [P_2i.x, P_2i.z, P_2i.y], [P_4i.x, P_4i.z, P_4i.y], [P_3i.x, P_3i.z, P_3i.y] ] else: nbv=24 Deca = Vector(Norm.x*s_infa,Norm.y*s_infa,Norm.z*s_infa) Decb = Vector(Norm.x*s_infb,Norm.y*s_infb,Norm.z*s_infb) # X Z Y P_1t = Vtop+Dec P_2t = Vtop-Dec P_3t = V_Dir+Vtop+Dec P_4t = V_Dir+Vtop-Dec P_1i = VZa+Deca P_2i = VZa-Deca P_3i = VZb+V_Dir+Decb P_4i = VZb+V_Dir-Decb """ 1) Top 2) Front 3) Left 4) Right 5) Back 6) Bottom """ verts = [ # 6 faces with 4 corners each [P_1t.x, P_1t.z, P_1t.y], [P_2t.x, P_2t.z, P_2t.y], [P_4t.x, P_4t.z, P_4t.y], [P_3t.x, P_3t.z, P_3t.y], [P_1t.x, P_1t.z, P_1t.y], [P_3t.x, P_3t.z, P_3t.y], [P_3i.x, P_3i.z, P_3i.y], [P_1i.x, P_1i.z, P_1i.y], [P_2t.x, P_2t.z, P_2t.y], [P_1t.x, P_1t.z, P_1t.y], [P_1i.x, P_1i.z, P_1i.y], [P_2i.x, P_2i.z, P_2i.y], [P_3t.x, P_3t.z, P_3t.y], [P_4t.x, P_4t.z, P_4t.y], [P_4i.x, P_4i.z, P_4i.y], [P_3i.x, P_3i.z, P_3i.y], [P_4t.x, P_4t.z, P_4t.y], [P_2t.x, P_2t.z, P_2t.y], [P_2i.x, P_2i.z, P_2i.y], [P_4i.x, P_4i.z, P_4i.y], [P_1i.x, P_1i.z, P_1i.y], [P_2i.x, P_2i.z, P_2i.y], [P_4i.x, P_4i.z, P_4i.y], [P_3i.x, P_3i.z, P_3i.y] ] mesh.setVertices(numpy.asarray(verts, dtype=numpy.float32)) indices = [] for i in range(0, nbv, 4): # All 6 quads (12 triangles) indices.append([i, i+2, i+1]) indices.append([i, i+3, i+2]) mesh.setIndices(numpy.asarray(indices, dtype=numpy.int32)) mesh.calculateNormals() return mesh
def _createTube(self, size, maxs, isize, nb , lg ,dep): # Logger.log('d', 'isize : ' + str(isize)) mesh = MeshBuilder() # Per-vertex normals require duplication of vertices r = size / 2 ri = isize / 2 rm = maxs / 2 # additionale length sup = size * 0.1 l = -lg rng = int(360 / nb) ang = math.radians(nb) r_inf=math.tan(math.radians(dep))*lg+r if rm>r and dep!=0: l_max=(rm-r) / math.tan(math.radians(dep)) else : l_max=l verts = [] if l_max<lg and l_max>0: nbv=30 for i in range(0, rng): # Top verts.append([ri*math.cos(i*ang), sup, ri*math.sin(i*ang)]) verts.append([r*math.cos((i+1)*ang), sup, r*math.sin((i+1)*ang)]) verts.append([r*math.cos(i*ang), sup, r*math.sin(i*ang)]) verts.append([ri*math.cos((i+1)*ang), sup, ri*math.sin((i+1)*ang)]) verts.append([r*math.cos((i+1)*ang), sup, r*math.sin((i+1)*ang)]) verts.append([ri*math.cos(i*ang), sup, ri*math.sin(i*ang)]) #Side 1a verts.append([r*math.cos(i*ang), sup, r*math.sin(i*ang)]) verts.append([r*math.cos((i+1)*ang), sup, r*math.sin((i+1)*ang)]) verts.append([rm*math.cos((i+1)*ang), -l_max, rm*math.sin((i+1)*ang)]) #Side 1b verts.append([rm*math.cos((i+1)*ang), -l_max, rm*math.sin((i+1)*ang)]) verts.append([rm*math.cos(i*ang), -l_max, rm*math.sin(i*ang)]) verts.append([r*math.cos(i*ang), sup, r*math.sin(i*ang)]) #Side 2a verts.append([rm*math.cos(i*ang), -l_max, rm*math.sin(i*ang)]) verts.append([rm*math.cos((i+1)*ang), -l_max, rm*math.sin((i+1)*ang)]) verts.append([rm*math.cos((i+1)*ang), l, rm*math.sin((i+1)*ang)]) #Side 2b verts.append([rm*math.cos((i+1)*ang), l, rm*math.sin((i+1)*ang)]) verts.append([rm*math.cos(i*ang), l, rm*math.sin(i*ang)]) verts.append([rm*math.cos(i*ang), -l_max, rm*math.sin(i*ang)]) #Bottom verts.append([ri*math.cos(i*ang), l, ri*math.sin(i*ang)]) verts.append([rm*math.cos(i*ang), l, rm*math.sin(i*ang)]) verts.append([rm*math.cos((i+1)*ang), l, rm*math.sin((i+1)*ang)]) verts.append([ri*math.cos((i+1)*ang), l, ri*math.sin((i+1)*ang)]) verts.append([ri*math.cos(i*ang), l, ri*math.sin(i*ang)]) verts.append([rm*math.cos((i+1)*ang), l, rm*math.sin((i+1)*ang)]) #Side Inta verts.append([ri*math.cos(i*ang), sup, ri*math.sin(i*ang)]) verts.append([ri*math.cos((i+1)*ang), l, ri*math.sin((i+1)*ang)]) verts.append([ri*math.cos((i+1)*ang), sup, ri*math.sin((i+1)*ang)]) #Side Intb verts.append([ri*math.cos((i+1)*ang), l, ri*math.sin((i+1)*ang)]) verts.append([ri*math.cos(i*ang), sup, ri*math.sin(i*ang)]) verts.append([ri*math.cos(i*ang), l, ri*math.sin(i*ang)]) else: nbv=24 for i in range(0, rng): # Top verts.append([ri*math.cos(i*ang), sup, ri*math.sin(i*ang)]) verts.append([r*math.cos((i+1)*ang), sup, r*math.sin((i+1)*ang)]) verts.append([r*math.cos(i*ang), sup, r*math.sin(i*ang)]) verts.append([ri*math.cos((i+1)*ang), sup, ri*math.sin((i+1)*ang)]) verts.append([r*math.cos((i+1)*ang), sup, r*math.sin((i+1)*ang)]) verts.append([ri*math.cos(i*ang), sup, ri*math.sin(i*ang)]) #Side 1a verts.append([r*math.cos(i*ang), sup, r*math.sin(i*ang)]) verts.append([r*math.cos((i+1)*ang), sup, r*math.sin((i+1)*ang)]) verts.append([r_inf*math.cos((i+1)*ang), l, r_inf*math.sin((i+1)*ang)]) #Side 1b verts.append([r_inf*math.cos((i+1)*ang), l, r_inf*math.sin((i+1)*ang)]) verts.append([r_inf*math.cos(i*ang), l, r_inf*math.sin(i*ang)]) verts.append([r*math.cos(i*ang), sup, r*math.sin(i*ang)]) #Bottom verts.append([ri*math.cos(i*ang), l, ri*math.sin(i*ang)]) verts.append([r_inf*math.cos(i*ang), l, r_inf*math.sin(i*ang)]) verts.append([r_inf*math.cos((i+1)*ang), l, r_inf*math.sin((i+1)*ang)]) verts.append([ri*math.cos((i+1)*ang), l, ri*math.sin((i+1)*ang)]) verts.append([ri*math.cos(i*ang), l, ri*math.sin(i*ang)]) verts.append([r_inf*math.cos((i+1)*ang), l, r_inf*math.sin((i+1)*ang)]) #Side Inta verts.append([ri*math.cos(i*ang), sup, ri*math.sin(i*ang)]) verts.append([ri*math.cos((i+1)*ang), l, ri*math.sin((i+1)*ang)]) verts.append([ri*math.cos((i+1)*ang), sup, ri*math.sin((i+1)*ang)]) #Side Intb verts.append([ri*math.cos((i+1)*ang), l, ri*math.sin((i+1)*ang)]) verts.append([ri*math.cos(i*ang), sup, ri*math.sin(i*ang)]) verts.append([ri*math.cos(i*ang), l, ri*math.sin(i*ang)]) mesh.setVertices(numpy.asarray(verts, dtype=numpy.float32)) indices = [] # for every angle increment ( 24 or 30 ) Vertices tot = rng * nbv for i in range(0, tot, 3): # indices.append([i, i+1, i+2]) mesh.setIndices(numpy.asarray(indices, dtype=numpy.int32)) mesh.calculateNormals() return mesh
def _createAbutment(self, size, maxs, height, top, dep, ydir): # Logger.log('d', 'Ydir : ' + str(ydir)) mesh = MeshBuilder() s = size / 2 sm = maxs / 2 l = height s_inf=math.tan(math.radians(dep))*(l+top)+(2*s) if sm>s and dep!=0: l_max=(sm-s) / math.tan(math.radians(dep)) else : l_max=l # Difference between Standart Abutment and Abutment + max base size if l_max<l and l_max>0: nbv=40 if ydir == False : verts = [ # 10 faces with 4 corners each [-s, -l_max, sm], [-s, top, 2*s], [ s, top, 2*s], [ s, -l_max, sm], [-s, top, -2*s], [-s, -l_max, -sm], [ s, -l_max, -sm], [ s, top, -2*s], [-s, -l, sm], [-s, -l_max, sm], [ s, -l_max, sm], [ s, -l, sm], [-s, -l_max, -sm], [-s, -l, -sm], [ s, -l, -sm], [ s, -l_max, -sm], [ s, -l, -sm], [-s, -l, -sm], [-s, -l, sm], [ s, -l, sm], [-s, top, -2*s], [ s, top, -2*s], [ s, top, 2*s], [-s, top, 2*s], [-s, -l_max, sm], [-s, -l_max, -sm], [-s, top, -2*s], [-s, top, 2*s], [ s, -l_max, -sm], [ s, -l_max, sm], [ s, top, 2*s], [ s, top, -2*s], [-s, -l, sm], [-s, -l, -sm], [-s, -l_max, -sm], [-s, -l_max, sm], [ s, -l, -sm], [ s, -l, sm], [ s, -l_max, sm], [ s, -l_max, -sm] ] else: verts = [ # 10 faces with 4 corners each [-sm, -l_max, s], [-2*s, top, s], [ 2*s, top, s], [ sm, -l_max, s], [-2*s, top, -s], [-sm, -l_max, -s], [ sm, -l_max, -s], [ 2*s, top, -s], [-sm, -l, s], [-sm, -l_max, s], [ sm, -l_max, s], [ sm, -l, s], [-sm, -l_max, -s], [-sm, -l, -s], [ sm, -l, -s], [ sm, -l_max, -s], [ sm, -l, -s], [-sm, -l, -s], [-sm, -l, s], [ sm, -l, s], [-2*s, top, -s], [ 2*s, top, -s], [ 2*s, top, s], [-2*s, top, s], [-sm, -l_max, s], [-sm, -l_max, -s], [-2*s, top, -s], [-2*s, top, s], [ sm, -l_max, -s], [ sm, -l_max, s], [ 2*s, top, s], [ 2*s, top, -s], [-sm, -l, s], [-sm, -l, -s], [-sm, -l_max, -s], [-sm, -l_max, s], [ sm, -l, -s], [ sm, -l, s], [ sm, -l_max, s], [ sm, -l_max, -s] ] else: nbv=24 if ydir == False : verts = [ # 6 faces with 4 corners each [-s, -l, s_inf], [-s, top, 2*s], [ s, top, 2*s], [ s, -l, s_inf], [-s, top, -2*s], [-s, -l, -s_inf], [ s, -l, -s_inf], [ s, top, -2*s], [ s, -l, -s_inf], [-s, -l, -s_inf], [-s, -l, s_inf], [ s, -l, s_inf], [-s, top, -2*s], [ s, top, -2*s], [ s, top, 2*s], [-s, top, 2*s], [-s, -l, s_inf], [-s, -l, -s_inf], [-s, top, -2*s], [-s, top, 2*s], [ s, -l, -s_inf], [ s, -l, s_inf], [ s, top, 2*s], [ s, top, -2*s] ] else: verts = [ # 6 faces with 4 corners each [-s_inf, -l, s], [-2*s, top, s], [ 2*s, top, s], [ s_inf, -l, s], [-2*s, top, -s], [-s_inf, -l, -s], [ s_inf, -l, -s], [ 2*s, top, -s], [ s_inf, -l, -s], [-s_inf, -l, -s], [-s_inf, -l, s], [ s_inf, -l, s], [-2*s, top, -s], [ 2*s, top, -s], [ 2*s, top, s], [-2*s, top, s], [-s_inf, -l, s], [-s_inf, -l, -s], [-2*s, top, -s], [-2*s, top, s], [ s_inf, -l, -s], [ s_inf, -l, s], [ 2*s, top, s], [ 2*s, top, -s] ] mesh.setVertices(numpy.asarray(verts, dtype=numpy.float32)) indices = [] for i in range(0, nbv, 4): # All 6 quads (12 triangles) indices.append([i, i+2, i+1]) indices.append([i, i+3, i+2]) mesh.setIndices(numpy.asarray(indices, dtype=numpy.int32)) mesh.calculateNormals() return mesh