diff options
author | Seva Alekseyev <sevaa@nih.gov> | 2016-08-08 21:11:30 +0300 |
---|---|---|
committer | Ghostkeeper <rubend@tutanota.com> | 2016-08-24 18:28:30 +0300 |
commit | 87bff34eb62e236a11ed48898dc7b96ca72e179c (patch) | |
tree | 0d60076ecb1fa272ed4bc97b87ce3295eb9d6b7a /plugins/X3DReader | |
parent | e4049296d97458ba2e3e4b168d3cb6b4acb92820 (diff) |
Support for explicit length unit override in X3D header
Diffstat (limited to 'plugins/X3DReader')
-rw-r--r-- | plugins/X3DReader/X3DReader.py | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/plugins/X3DReader/X3DReader.py b/plugins/X3DReader/X3DReader.py index 3b5af06d6e..43f528fb82 100644 --- a/plugins/X3DReader/X3DReader.py +++ b/plugins/X3DReader/X3DReader.py @@ -32,11 +32,31 @@ class X3DReader(MeshReader): try: self.sceneNodes = [] self.fileName = file_name - self.transform = Matrix() - self.transform.setByScaleVector(Vector(1000, 1000, 1000)) tree = ET.parse(file_name) - self.processNode(tree.getroot()) + root = tree.getroot() + + if root.tag != "X3D": + return None + + scale = 1000 # Default X3D unit it one meter, while Cura's is one mm + if root[0].tag == "head": + for headNode in root[0]: + if headNode.tag == "unit" and headNode.attrib.get("category") == "length": + scale *= float.parse(headNode.attrib["conversionFactor"]) + break + scene = root[1] + else: + scene = root[0] + + if scene.tag != "Scene": + return None + + self.transform = Matrix() + self.transform.setByScaleVector(Vector(scale, scale, scale)) + + # This will populate the sceneNodes array + self.processChildNodes(scene) if len(self.sceneNodes) > 1: theScene = SceneNode() @@ -68,7 +88,7 @@ class X3DReader(MeshReader): return tag = xmlNode.tag - if tag in ("X3D", "Scene", "Group", "StaticGroup", "CADAssembly", "CADFace", "CADLayer", "CADPart", "Collision"): + if tag in ("Group", "StaticGroup", "CADAssembly", "CADFace", "CADLayer", "CADPart", "Collision"): self.processChildNodes(xmlNode) elif tag == "LOD": self.processNode(xmlNode[0]) |