def _toMeshData(self, tri_node: trimesh.base.Trimesh) -> MeshData:
        # Rotate the part to laydown on the build plate
        # Modification from 5@xes
        tri_node.apply_transform(
            trimesh.transformations.rotation_matrix(math.radians(90),
                                                    [-1, 0, 0]))
        tri_faces = tri_node.faces
        tri_vertices = tri_node.vertices

        # Following Source code from  fieldOfView
        # https://github.com/fieldOfView/Cura-SimpleShapes/blob/bac9133a2ddfbf1ca6a3c27aca1cfdd26e847221/SimpleShapes.py#L45
        indices = []
        vertices = []

        index_count = 0
        face_count = 0
        for tri_face in tri_faces:
            face = []
            for tri_index in tri_face:
                vertices.append(tri_vertices[tri_index])
                face.append(index_count)
                index_count += 1
            indices.append(face)
            face_count += 1

        vertices = numpy.asarray(vertices, dtype=numpy.float32)
        indices = numpy.asarray(indices, dtype=numpy.int32)
        normals = calculateNormalsFromIndexedVertices(vertices, indices,
                                                      face_count)

        mesh_data = MeshData(vertices=vertices,
                             indices=indices,
                             normals=normals)

        return mesh_data
Beispiel #2
0
    def _toMeshData(self,
                    tri_node: trimesh.base.Trimesh,
                    file_name: str = "") -> MeshData:
        tri_faces = tri_node.faces
        tri_vertices = tri_node.vertices

        indices = []
        vertices = []

        index_count = 0
        face_count = 0
        for tri_face in tri_faces:
            face = []
            for tri_index in tri_face:
                vertices.append(tri_vertices[tri_index])
                face.append(index_count)
                index_count += 1
            indices.append(face)
            face_count += 1

        vertices = numpy.asarray(vertices, dtype=numpy.float32)
        indices = numpy.asarray(indices, dtype=numpy.int32)
        normals = calculateNormalsFromIndexedVertices(vertices, indices,
                                                      face_count)

        mesh_data = MeshData(vertices=vertices,
                             indices=indices,
                             normals=normals,
                             file_name=file_name)
        return mesh_data
Beispiel #3
0
    def _toMeshData(self, tri_node: trimesh.base.Trimesh, file_name: str = "") -> MeshData:
        """Converts a Trimesh to Uranium's MeshData.

        :param tri_node: A Trimesh containing the contents of a file that was just read.
        :param file_name: The full original filename used to watch for changes
        :return: Mesh data from the Trimesh in a way that Uranium can understand it.
        """

        tri_faces = tri_node.faces
        tri_vertices = tri_node.vertices

        indices = []
        vertices = []

        index_count = 0
        face_count = 0
        for tri_face in tri_faces:
            face = []
            for tri_index in tri_face:
                vertices.append(tri_vertices[tri_index])
                face.append(index_count)
                index_count += 1
            indices.append(face)
            face_count += 1

        vertices = numpy.asarray(vertices, dtype = numpy.float32)
        indices = numpy.asarray(indices, dtype = numpy.int32)
        normals = calculateNormalsFromIndexedVertices(vertices, indices, face_count)

        mesh_data = MeshData(vertices = vertices, indices = indices, normals = normals, file_name = file_name)
        return mesh_data
    def calculateNormals(self, fast=False):
        if self._vertices is None:
            return

        if self.hasIndices() and not fast:
            self._normals = calculateNormalsFromIndexedVertices(self._vertices, self._indices, self._face_count)
        else:
            self._normals = calculateNormalsFromVertices(self._vertices, self._vertex_count)
Beispiel #5
0
    def calculateNormals(self, fast=False):
        if self._vertices is None:
            return

        if self.hasIndices() and not fast:
            self._normals = calculateNormalsFromIndexedVertices(self._vertices, self._indices, self._face_count)
        else:
            self._normals = calculateNormalsFromVertices(self._vertices, self._vertex_count)
Beispiel #6
0
    def calculateNormals(self, fast=False):
        """Calculate the normals of this mesh, assuming it was created by using addFace (eg; the verts are connected)

        Keyword arguments:
        - fast: A boolean indicating whether or not to use a fast method of normal calculation that assumes each triangle
        is stored as a set of three unique vertices.
        """

        if self._vertices is None:
            return

        if self.hasIndices() and not fast:
            self._normals = calculateNormalsFromIndexedVertices(
                self._vertices, self._indices, self._face_count)
        else:
            self._normals = calculateNormalsFromVertices(
                self._vertices, self._vertex_count)
Beispiel #7
0
    def _toMeshData(self, tri_node: trimesh.base.Trimesh) -> MeshData:
        tri_faces = tri_node.faces
        tri_vertices = tri_node.vertices

        indices = []
        vertices = []

        index_count = 0
        face_count = 0
        for tri_face in tri_faces:
            face = []
            for tri_index in tri_face:
                vertices.append(tri_vertices[tri_index])
                face.append(index_count)
                index_count += 1
            indices.append(face)
            face_count += 1

        vertices = numpy.asarray(vertices, dtype=numpy.float32)
        indices = numpy.asarray(indices, dtype=numpy.int32)
        normals = calculateNormalsFromIndexedVertices(vertices, indices, face_count)

        mesh_data = MeshData(vertices=vertices, indices=indices, normals=normals)
        return mesh_data