diff --git a/dist/occt-import-js.wasm b/dist/occt-import-js.wasm index 4b3396a..b99a192 100644 Binary files a/dist/occt-import-js.wasm and b/dist/occt-import-js.wasm differ diff --git a/occt-import-js/example/main.cpp b/occt-import-js/example/main.cpp index 28d4c28..bcfe2c4 100644 --- a/occt-import-js/example/main.cpp +++ b/occt-import-js/example/main.cpp @@ -71,6 +71,34 @@ static void WriteNode (const NodePtr& node, ObjWriter& writer) } } +static void DumpNode (const NodePtr& node, int level) +{ + auto writeIndent = [](int indentLevel) { + for (int i = 0; i < indentLevel; i++) { + std::cout << " "; + } + }; + + writeIndent (level); + std::cout << "-> Node: " << node->GetName (); + std::cout << std::endl; + + node->EnumerateMeshes ([&](const Mesh& mesh) { + writeIndent (level); + std::cout << " Mesh: " << mesh.GetName (); + Color color; + if (mesh.GetColor (color)) { + std::cout << " (" << color.r << ", " << color.g << ", " << color.b << ")"; + } + std::cout << std::endl; + }); + + std::vector children = node->GetChildren (); + for (const NodePtr& child : children) { + DumpNode (child, level + 1); + } +} + int main (int argc, const char* argv[]) { if (argc < 2) { @@ -104,8 +132,11 @@ int main (int argc, const char* argv[]) return 1; } - ObjWriter writer; - WriteNode (importer->GetRootNode (), writer); + //ObjWriter writer; + //WriteNode (importer->GetRootNode (), writer); + + DumpNode (importer->GetRootNode (), 0); + system ("PAUSE"); return 0; } diff --git a/occt-import-js/src/importer-xcaf.cpp b/occt-import-js/src/importer-xcaf.cpp index b1a58eb..7b53b1e 100644 --- a/occt-import-js/src/importer-xcaf.cpp +++ b/occt-import-js/src/importer-xcaf.cpp @@ -25,6 +25,16 @@ static std::string GetLabelName (const TDF_Label& label) return name; } +static std::string GetLabelName (const Handle (XCAFDoc_ShapeTool)& shapeTool, const TDF_Label& label) +{ + if (XCAFDoc_ShapeTool::IsReference (label)) { + TDF_Label referredShape; + shapeTool->GetReferredShape (label, referredShape); + return GetLabelName (shapeTool, referredShape); + } + return GetLabelName (label); +} + static bool IsFreeShape (const TDF_Label& label, const Handle (XCAFDoc_ShapeTool)& shapeTool) { TopoDS_Shape tmpShape; @@ -37,7 +47,7 @@ static std::string GetShapeName (const TopoDS_Shape& shape, const Handle (XCAFDo if (!shapeTool->Search (shape, shapeLabel)) { return std::string (); } - return GetLabelName (shapeLabel); + return GetLabelName (shapeTool, shapeLabel); } static bool GetShapeColor (const TopoDS_Shape& shape, const Handle (XCAFDoc_ColorTool)& colorTool, Color& color) @@ -168,7 +178,7 @@ class XcafNode : public Node virtual std::string GetName () const override { - return GetLabelName (label); + return GetLabelName (shapeTool, label); } virtual std::vector GetChildren () const override diff --git a/test/test.js b/test/test.js index 0cc0040..906c1db 100644 --- a/test/test.js +++ b/test/test.js @@ -97,17 +97,17 @@ it ('as1_pe_203', function () { children : [] }, { - name : "L_BRACKET_ASSEMBLY", + name : "L_BRACKET_ASSEMBLY_ASM", meshes : [1, 2, 3, 4, 5, 6, 7], children : [] }, { - name : "L_BRACKET_ASSEMBLY", + name : "L_BRACKET_ASSEMBLY_ASM", meshes : [8, 9, 10, 11, 12, 13, 14], children : [] }, { - name : "ROD", + name : "ROD_ASM", meshes : [15, 16, 17], children : [] }