Skip to content

Commit

Permalink
Minor code clean-up.
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacsv committed Apr 15, 2023
1 parent 3c918ac commit 10303ad
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions occt-import-js/src/js-interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class HierarchyWriter
{
public:
HierarchyWriter (emscripten::val& meshesArr) :
meshesArr (meshesArr),
meshCount (0)
mMeshesArr (meshesArr),
mMeshCount (0)
{
}

Expand All @@ -34,6 +34,7 @@ class HierarchyWriter
nodeObj.set ("children", childrenArr);
}

private:
void WriteMeshes (const NodePtr& node, emscripten::val& nodeMeshesArr)
{
if (!node->IsMeshNode ()) {
Expand All @@ -42,15 +43,18 @@ class HierarchyWriter

int nodeMeshCount = 0;
node->EnumerateMeshes ([&](const Mesh& mesh) {
emscripten::val meshObj (emscripten::val::object ());
meshObj.set ("name", mesh.GetName ());

int vertexCount = 0;
int normalCount = 0;
int triangleCount = 0;
int brepFacesCount = 0;
int brepFaceCount = 0;

emscripten::val positionArr (emscripten::val::array ());
emscripten::val normalArr (emscripten::val::array ());
emscripten::val indexArr (emscripten::val::array ());
emscripten::val brepFacesArr (emscripten::val::array ());
emscripten::val brepFaceArr (emscripten::val::array ());

mesh.EnumerateFaces ([&](const Face& face) {
int triangleOffset = triangleCount;
Expand Down Expand Up @@ -86,23 +90,10 @@ class HierarchyWriter
} else {
brepFaceObj.set ("color", emscripten::val::null ());
}
brepFacesArr.set (brepFacesCount, brepFaceObj);
brepFacesCount += 1;
brepFaceArr.set (brepFaceCount, brepFaceObj);
brepFaceCount += 1;
});

emscripten::val meshObj (emscripten::val::object ());
meshObj.set ("name", mesh.GetName ());
Color meshColor;
if (mesh.GetColor (meshColor)) {
emscripten::val colorArr (emscripten::val::array ());
colorArr.set (0, meshColor.r);
colorArr.set (1, meshColor.g);
colorArr.set (2, meshColor.b);
meshObj.set ("color", colorArr);
}

meshObj.set ("brep_faces", brepFacesArr);

emscripten::val attributesObj (emscripten::val::object ());

emscripten::val positionObj (emscripten::val::object ());
Expand All @@ -121,15 +112,26 @@ class HierarchyWriter
meshObj.set ("attributes", attributesObj);
meshObj.set ("index", indexObj);

meshesArr.set (meshCount, meshObj);
nodeMeshesArr.set (nodeMeshCount, meshCount);
meshCount += 1;
Color meshColor;
if (mesh.GetColor (meshColor)) {
emscripten::val colorArr (emscripten::val::array ());
colorArr.set (0, meshColor.r);
colorArr.set (1, meshColor.g);
colorArr.set (2, meshColor.b);
meshObj.set ("color", colorArr);
}

meshObj.set ("brep_faces", brepFaceArr);

mMeshesArr.set (mMeshCount, meshObj);
nodeMeshesArr.set (nodeMeshCount, mMeshCount);
mMeshCount += 1;
nodeMeshCount += 1;
});
}

emscripten::val& meshesArr;
int meshCount;
emscripten::val& mMeshesArr;
int mMeshCount;
};

static void EnumerateNodeMeshes (const NodePtr& node, const std::function<void (const Mesh&)>& onMesh)
Expand Down

0 comments on commit 10303ad

Please sign in to comment.