mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
Rename PLYReader to TrimeshReader
We're going to repurpose this plug-in to read other file formats as well. Currently it still only registers itself as PLY file reader. But I'm about to change that. Contributes to issue CURA-6739.
This commit is contained in:
parent
6274a58158
commit
6c84f0dbb6
4 changed files with 27 additions and 22 deletions
|
@ -1,7 +0,0 @@
|
||||||
{
|
|
||||||
"name": "PLY Reader",
|
|
||||||
"author": "Ultimaker B.V.",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "Provides support for reading PLY files.",
|
|
||||||
"api": "6.0.0"
|
|
||||||
}
|
|
|
@ -5,19 +5,19 @@
|
||||||
|
|
||||||
import numpy # To create the mesh data.
|
import numpy # To create the mesh data.
|
||||||
import os.path # To create the mesh name for the resulting mesh.
|
import os.path # To create the mesh name for the resulting mesh.
|
||||||
import trimesh # To load the PLY files into a Trimesh.
|
import trimesh # To load the files into a Trimesh.
|
||||||
|
|
||||||
from UM.Mesh.MeshData import MeshData, calculateNormalsFromIndexedVertices
|
from UM.Mesh.MeshData import MeshData, calculateNormalsFromIndexedVertices # To construct meshes from the Trimesh data.
|
||||||
from UM.Mesh.MeshReader import MeshReader
|
from UM.Mesh.MeshReader import MeshReader # The plug-in type we're extending.
|
||||||
from UM.MimeTypeDatabase import MimeTypeDatabase, MimeType
|
from UM.MimeTypeDatabase import MimeTypeDatabase, MimeType # To add file types that we can open.
|
||||||
|
|
||||||
from cura.CuraApplication import CuraApplication
|
from cura.CuraApplication import CuraApplication
|
||||||
from cura.Scene.BuildPlateDecorator import BuildPlateDecorator
|
from cura.Scene.BuildPlateDecorator import BuildPlateDecorator # Added to the resulting scene node.
|
||||||
from cura.Scene.CuraSceneNode import CuraSceneNode
|
from cura.Scene.CuraSceneNode import CuraSceneNode # To create a node in the scene after reading the file.
|
||||||
from cura.Scene.SliceableObjectDecorator import SliceableObjectDecorator
|
from cura.Scene.SliceableObjectDecorator import SliceableObjectDecorator # Added to the resulting scene node.
|
||||||
|
|
||||||
## Class that leverages Trimesh to read PLY files (Stanford Triangle Format).
|
## Class that leverages Trimesh to import files.
|
||||||
class PLYReader(MeshReader):
|
class Trimesh(MeshReader):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
@ -30,10 +30,10 @@ class PLYReader(MeshReader):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
## Reads the PLY file.
|
## Reads a file using Trimesh.
|
||||||
# \param file_name The file path of the PLY file. This is assumed to be a
|
# \param file_name The file path. This is assumed to be one of the file
|
||||||
# PLY file; it's not checked again.
|
# types that Trimesh can read. It will not be checked again.
|
||||||
# \return A scene node that contains the PLY file's contents.
|
# \return A scene node that contains the file's contents.
|
||||||
def _read(self, file_name: str) -> CuraSceneNode:
|
def _read(self, file_name: str) -> CuraSceneNode:
|
||||||
mesh = trimesh.load(file_name)
|
mesh = trimesh.load(file_name)
|
||||||
mesh.merge_vertices()
|
mesh.merge_vertices()
|
||||||
|
@ -50,6 +50,11 @@ class PLYReader(MeshReader):
|
||||||
new_node.addDecorator(SliceableObjectDecorator())
|
new_node.addDecorator(SliceableObjectDecorator())
|
||||||
return new_node
|
return new_node
|
||||||
|
|
||||||
|
## Converts a Trimesh to Uranium's MeshData.
|
||||||
|
# \param tri_node A Trimesh containing the contents of a file that was
|
||||||
|
# just read.
|
||||||
|
# \return Mesh data from the Trimesh in a way that Uranium can understand
|
||||||
|
# it.
|
||||||
def _toMeshData(self, tri_node: trimesh.base.Trimesh) -> MeshData:
|
def _toMeshData(self, tri_node: trimesh.base.Trimesh) -> MeshData:
|
||||||
tri_faces = tri_node.faces
|
tri_faces = tri_node.faces
|
||||||
tri_vertices = tri_node.vertices
|
tri_vertices = tri_node.vertices
|
|
@ -1,7 +1,7 @@
|
||||||
# Copyright (c) 2019 Ultimaker
|
# Copyright (c) 2019 Ultimaker
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
from . import PLYReader
|
from . import TrimeshReader
|
||||||
|
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
i18n_catalog = i18nCatalog("uranium")
|
i18n_catalog = i18nCatalog("uranium")
|
||||||
|
@ -18,4 +18,4 @@ def getMetaData():
|
||||||
}
|
}
|
||||||
|
|
||||||
def register(app):
|
def register(app):
|
||||||
return {"mesh_reader": PLYReader.PLYReader()}
|
return {"mesh_reader": TrimeshReader.TrimeshReader()}
|
7
plugins/TrimeshReader/plugin.json
Normal file
7
plugins/TrimeshReader/plugin.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "Trimesh Reader",
|
||||||
|
"author": "Ultimaker B.V.",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Provides support for reading model files.",
|
||||||
|
"api": "6.0.0"
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue