Skip to content

Commit

Permalink
Names don't work in case of reference shapes #24
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacsv committed Apr 12, 2023
1 parent 60057e4 commit d881053
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
Binary file modified dist/occt-import-js.wasm
Binary file not shown.
35 changes: 33 additions & 2 deletions occt-import-js/example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodePtr> children = node->GetChildren ();
for (const NodePtr& child : children) {
DumpNode (child, level + 1);
}
}

int main (int argc, const char* argv[])
{
if (argc < 2) {
Expand Down Expand Up @@ -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;
}
14 changes: 12 additions & 2 deletions occt-import-js/src/importer-xcaf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -168,7 +178,7 @@ class XcafNode : public Node

virtual std::string GetName () const override
{
return GetLabelName (label);
return GetLabelName (shapeTool, label);
}

virtual std::vector<NodePtr> GetChildren () const override
Expand Down
6 changes: 3 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 : []
}
Expand Down

0 comments on commit d881053

Please sign in to comment.