当前位置: 首页>>代码示例>>Python>>正文


Python SceneNode.setMeshData方法代码示例

本文整理汇总了Python中UM.Scene.SceneNode.SceneNode.setMeshData方法的典型用法代码示例。如果您正苦于以下问题:Python SceneNode.setMeshData方法的具体用法?Python SceneNode.setMeshData怎么用?Python SceneNode.setMeshData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UM.Scene.SceneNode.SceneNode的用法示例。


在下文中一共展示了SceneNode.setMeshData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read

# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setMeshData [as 别名]
    def read(self, file_name):
        mesh_builder = MeshBuilder()
        scene_node = SceneNode()

        self.load_file(file_name, mesh_builder, _use_numpystl = use_numpystl)

        mesh = mesh_builder.build()

        if use_numpystl:
            verts = mesh.getVertices()
            # In some cases numpy stl reads incorrectly and the result is that the Z values are all 0
            # Add new error cases if you find them.
            if numpy.amin(verts[:, 1]) == numpy.amax(verts[:, 1]):
                # Something may have gone wrong in numpy stl, start over without numpy stl
                Logger.log("w", "All Z coordinates are the same using numpystl, trying again without numpy stl.")
                mesh_builder = MeshBuilder()
                self.load_file(file_name, mesh_builder, _use_numpystl = False)
                mesh = mesh_builder.build()

                verts = mesh.getVertices()
                if numpy.amin(verts[:, 1]) == numpy.amax(verts[:, 1]):
                    Logger.log("e", "All Z coordinates are still the same without numpy stl... let's hope for the best")

        if mesh_builder.getVertexCount() == 0:
            Logger.log("d", "File did not contain valid data, unable to read.")
            return None  # We didn't load anything.
        scene_node.setMeshData(mesh)
        Logger.log("d", "Loaded a mesh with %s vertices", mesh_builder.getVertexCount())

        return scene_node
开发者ID:senttech,项目名称:Uranium,代码行数:32,代码来源:STLReader.py

示例2: read

# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setMeshData [as 别名]
    def read(self, file_name):
        mesh_builder = MeshBuilder()
        scene_node = SceneNode()

        if use_numpystl:
            self._loadWithNumpySTL(file_name, mesh_builder)
        else:
            f = open(file_name, "rb")
            if not self._loadBinary(mesh_builder, f):
                f.close()
                f = open(file_name, "rt")
                try:
                    self._loadAscii(mesh_builder, f)
                except UnicodeDecodeError:
                    return None
                f.close()

            Job.yieldThread() # Yield somewhat to ensure the GUI has time to update a bit.

        mesh_builder.calculateNormals(fast = True)

        mesh = mesh_builder.build()
        Logger.log("d", "Loaded a mesh with %s vertices", mesh_builder.getVertexCount())
        scene_node.setMeshData(mesh)
        return scene_node
开发者ID:TimurAykutYildirim,项目名称:Uranium,代码行数:27,代码来源:STLReader.py

示例3: read

# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setMeshData [as 别名]
    def read(self, file_name):
        self._dxf = DXFObjectReader.DXFObjectReader(open(file_name, "rt"))
        self._mesh = MeshData()
        for obj in self._dxf:
            if obj.getName() == "SECTION":
                if obj.get(2) == "ENTITIES":
                    self._handleEntities()
                elif obj.get(2) == "TABLES":
                    self._handleTables()
                else:
                    Logger.log("d", "DXF: Got unknown section: %s", obj.get(2))
                    for obj in self._dxf:
                        if obj.getName() == "ENDSEC":
                            break
                        else:
                            Logger.log("d", "DXF: %s", obj)
            elif obj.getName() == "EOF":
                pass
            else:
                Logger.log("e", "DXF: Unexpected object: %s", obj)

        #self._mesh.calculateNormals()

        node = SceneNode()
        node.setMeshData(self._mesh)
        return node
开发者ID:daid,项目名称:NinjaKittens2,代码行数:28,代码来源:DXFReader.py

示例4: _reloadJobFinished

# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setMeshData [as 别名]
 def _reloadJobFinished(self, replaced_node: SceneNode, job: ReadMeshJob) -> None:
     for node in job.getResult():
         mesh_data = node.getMeshData()
         if mesh_data:
             replaced_node.setMeshData(mesh_data)
         else:
             Logger.log("w", "Could not find a mesh in reloaded node.")
开发者ID:Ultimaker,项目名称:Uranium,代码行数:9,代码来源:Scene.py

示例5: read

# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setMeshData [as 别名]
    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
开发者ID:cederom,项目名称:Cura,代码行数:58,代码来源:X3DReader.py

示例6: read

# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setMeshData [as 别名]
    def read(self, file_name):
        extension = os.path.splitext(file_name)[1]
        if extension.lower() == self._supported_extension:
            layer_data = LayerData()
            with open (file_name,"rt") as f:
                layer = ""
                current_path_type = ""

                current_layer_nr = 0
                poly_list = []
                old_position = [0,0,0]
                current_z = 0
                for line in f:
                    if line.startswith(';TYPE:'):
                        current_path_type = line[6:].strip()
                        #layer_data.addPolygon(current_layer_nr,3 ,None ,5 )
                    elif line.startswith(';LAYER:'):
                        current_layer_nr = int(line[7:].strip())
                        layer_data.addLayer(int(line[7:].strip()))
                    elif line.startswith(';'):
                        pass # Ignore comments
                    else:
                        command_type = self.getCodeInt(line, 'G')
                        if command_type == 0 or command_type == 1: #Move command
                            x = self.getCodeFloat(line, 'X')
                            y = self.getCodeFloat(line, 'Y')
                            z = self.getCodeFloat(line, 'Z')
                            if z:
                                current_z = z
                            if x and y:
                                polygon_data = numpy.zeros((4,3)) #Square :)
                                polygon_data[0,:] = old_position
                                polygon_data[1,:] = old_position
                                polygon_data[2,:] = [x,current_z,y]
                                polygon_data[3,:] = [x,current_z,y]
                                old_position = [x,current_z,y]
                                if current_path_type == "SKIRT":
                                    layer_data.addPolygon(current_layer_nr,5 ,polygon_data ,5 )
                                elif current_path_type == "WALL-INNER":
                                    layer_data.addPolygon(current_layer_nr,3 ,polygon_data ,5 )
                                elif current_path_type == "WALL-OUTER":
                                    layer_data.addPolygon(current_layer_nr,1 ,polygon_data ,5 )
                                else:
                                    layer_data.addPolygon(current_layer_nr,2 ,polygon_data ,5 )
                            #e = self.getCodeFloat(line, 'E')
                            #print(x , " ", y , " ", z, " " , e)
                        pass
            layer_data.build()
            decorator = LayerDataDecorator()
            decorator.setLayerData(layer_data)
            new_node = SceneNode()
            new_node.setMeshData(MeshData())
            new_node.addDecorator(decorator)
            new_node.setParent(self._scene.getRoot())
开发者ID:faisalomar,项目名称:Cura,代码行数:56,代码来源:GCodeReader.py

示例7: _onFileLoaded

# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setMeshData [as 别名]
    def _onFileLoaded(self, job):
        mesh = job.getResult()
        if mesh != None:
            node = SceneNode()

            node.setSelectable(True)
            node.setMeshData(mesh)
            node.setName(os.path.basename(job.getFileName()))

            op = AddSceneNodeOperation(node, self.getController().getScene().getRoot())
            op.push()
开发者ID:stef735,项目名称:Cura,代码行数:13,代码来源:CuraApplication.py

示例8: test_compute2DConvexHullMeshData

# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setMeshData [as 别名]
def test_compute2DConvexHullMeshData(convex_hull_decorator):
    node = SceneNode()
    mb = MeshBuilder()
    mb.addCube(10,10,10)
    node.setMeshData(mb.build())

    convex_hull_decorator._getSettingProperty = MagicMock(return_value = 0)

    with patch("UM.Application.Application.getInstance", MagicMock(return_value=mocked_application)):
        convex_hull_decorator.setNode(node)

    assert convex_hull_decorator._compute2DConvexHull() == Polygon([[5.0,-5.0], [-5.0,-5.0], [-5.0,5.0], [5.0,5.0]])
开发者ID:Ultimaker,项目名称:Cura,代码行数:14,代码来源:TestConvexHullDecorator.py

示例9: multiplyObject

# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setMeshData [as 别名]
    def multiplyObject(self, object_id, count):
        node = self.getController().getScene().findObject(object_id)

        if node:
            op = GroupedOperation()
            for i in range(count):
                new_node = SceneNode()
                new_node.setMeshData(node.getMeshData())
                new_node.setScale(node.getScale())
                new_node.translate(Vector((i + 1) * node.getBoundingBox().width, 0, 0))
                new_node.setSelectable(True)
                op.addOperation(AddSceneNodeOperation(new_node, node.getParent()))
            op.push()
开发者ID:lotuspaperboy,项目名称:Cura,代码行数:15,代码来源:CuraApplication.py

示例10: run

# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setMeshData [as 别名]
    def run(self):
        objectIdMap = {}
        new_node = SceneNode()
        ## Put all nodes in a dict identified by ID
        for node in DepthFirstIterator(self._scene.getRoot()):
            if type(node) is SceneNode and node.getMeshData():
                if hasattr(node.getMeshData(), "layerData"):
                    self._scene.getRoot().removeChild(node)
                else:
                    objectIdMap[id(node)] = node

        settings = Application.getInstance().getActiveMachine()
        layerHeight = settings.getSettingValueByKey("layer_height")

        for object in self._message.objects:
            try:        
                node = objectIdMap[object.id]
            except KeyError:
                continue
            
            mesh = MeshData()

            layerData = LayerData.LayerData()
            for layer in object.layers:
                for polygon in layer.polygons:
                    points = numpy.fromstring(polygon.points, dtype="i8") # Convert bytearray to numpy array
                    points = points.reshape((-1,2)) # We get a linear list of pairs that make up the points, so make numpy interpret them correctly.
                    points = numpy.asarray(points, dtype=numpy.float32)
                    points /= 1000
                    points = numpy.insert(points, 1, layer.id * layerHeight, axis = 1)

                    points[:,2] *= -1

                    if not settings.getSettingValueByKey("machine_center_is_zero"):
                        center = [settings.getSettingValueByKey("machine_width") / 2, 0.0, -settings.getSettingValueByKey("machine_depth") / 2]
                        points -= numpy.array(center)

                    #points = numpy.pad(points, ((0,0), (0,1)), "constant", constant_values=(0.0, 1.0))
                    #inverse = node.getWorldTransformation().getInverse().getData()
                    #points = points.dot(inverse)
                    #points = points[:,0:3]

                    layerData.addPolygon(layer.id, polygon.type, points)

            # We are done processing all the layers we got from the engine, now create a mesh out of the data
            layerData.build()
            mesh.layerData = layerData
            
        new_node.setMeshData(mesh)
        new_node.setParent(self._scene.getRoot())
开发者ID:derekhe,项目名称:Cura,代码行数:52,代码来源:ProcessSlicedObjectListJob.py

示例11: test_deepCopy

# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setMeshData [as 别名]
    def test_deepCopy(self):
        node_1 = SceneNode()
        node_2 = SceneNode()
        node_1.translate(Vector(1, 2, 3))
        node_1.scale(Vector(1.5, 1., 1.))
        node_1.setMeshData(MeshData())
        node_1.addChild(node_2)
        node_1.addDecorator(GroupDecorator())
        copied_node = deepcopy(node_1)

        assert copied_node.getScale() == Vector(1.5, 1, 1)
        assert copied_node.getPosition() == Vector(1, 2, 3)
        assert len(copied_node.getChildren()) == 1
        # Ensure that the decorator also got copied
        assert copied_node.callDecoration("isGroup")
开发者ID:Ultimaker,项目名称:Uranium,代码行数:17,代码来源:TestSceneNode.py

示例12: multiplyObject

# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setMeshData [as 别名]
    def multiplyObject(self, object_id, count):
        node = self.getController().getScene().findObject(object_id)

        if not node and object_id != 0: #Workaround for tool handles overlapping the selected object
            node = Selection.getSelectedObject(0)

        if node:
            op = GroupedOperation()
            for i in range(count):
                new_node = SceneNode()
                new_node.setMeshData(node.getMeshData())

                new_node.translate(Vector((i + 1) * node.getBoundingBox().width, node.getPosition().y, 0))
                new_node.setOrientation(node.getOrientation())
                new_node.setScale(node.getScale())
                new_node.setSelectable(True)
                op.addOperation(AddSceneNodeOperation(new_node, node.getParent()))
            op.push()
开发者ID:kelvinfang,项目名称:Cura,代码行数:20,代码来源:CuraApplication.py

示例13: test_compute2DConvexHullMeshDataGrouped

# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setMeshData [as 别名]
def test_compute2DConvexHullMeshDataGrouped(convex_hull_decorator):
    parent_node = SceneNode()
    parent_node.addDecorator(GroupDecorator())
    node = SceneNode()
    parent_node.addChild(node)

    mb = MeshBuilder()
    mb.addCube(10, 10, 10)
    node.setMeshData(mb.build())

    convex_hull_decorator._getSettingProperty = MagicMock(return_value=0)

    with patch("UM.Application.Application.getInstance", MagicMock(return_value=mocked_application)):
        convex_hull_decorator.setNode(parent_node)
        with patch("cura.Settings.ExtruderManager.ExtruderManager.getInstance"):
            copied_decorator = copy.deepcopy(convex_hull_decorator)
            copied_decorator._getSettingProperty = MagicMock(return_value=0)
        node.addDecorator(copied_decorator)
    assert convex_hull_decorator._compute2DConvexHull() == Polygon([[-5.0,5.0], [5.0,5.0], [5.0,-5.0], [-5.0,-5.0]])
开发者ID:Ultimaker,项目名称:Cura,代码行数:21,代码来源:TestConvexHullDecorator.py

示例14: read

# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setMeshData [as 别名]
    def read(self, file_name):
        mesh = None
        scene_node = None

        mesh = MeshData()
        scene_node = SceneNode()
        f = open(file_name, "rb")
        if not self._loadBinary(mesh, f):
            f.close()
            f = open(file_name, "rt")
            try:
                self._loadAscii(mesh, f)
            except UnicodeDecodeError:
                pass
            f.close()

        f.close()
        time.sleep(0.1) #Yield somewhat to ensure the GUI has time to update a bit.
        mesh.calculateNormals(fast = True)

        Logger.log("d", "Loaded a mesh with %s vertices", mesh.getVertexCount())
        scene_node.setMeshData(mesh)
        return scene_node
开发者ID:dakshsingh,项目名称:Uranium,代码行数:25,代码来源:STLReader.py

示例15: read

# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setMeshData [as 别名]
    def read(self, file_name):
        mesh = None
        scene_node = None
        extension = os.path.splitext(file_name)[1]
        if extension.lower() == self._supported_extension:
            mesh = MeshData()
            scene_node = SceneNode()
            f = open(file_name, "rb")
            if not self._loadBinary(mesh, f):
                f.close()
                f = open(file_name, "rt")
                try:
                    self._loadAscii(mesh, f)
                except UnicodeDecodeError:
                    pass
                f.close()

            f.close()

            mesh.calculateNormals(fast = True)

            Logger.log("d", "Loaded a mesh with %s vertices", mesh.getVertexCount())
            scene_node.setMeshData(mesh)
        return scene_node
开发者ID:kelvinfang,项目名称:Uranium,代码行数:26,代码来源:STLReader.py


注:本文中的UM.Scene.SceneNode.SceneNode.setMeshData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。