Skip to content

Commit

Permalink
FIX: issue 125: Export node order should be deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
ziriax committed Jun 2, 2020
1 parent 5a3b24b commit b673d7b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/ExportableAsset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,14 @@ ExportableAsset::ExportableAsset(const Arguments &args)
trs.scale[0] = trs.scale[1] = trs.scale[2] = rootScaleFactor;
}

for (auto *node : m_scene.orphans()) {
m_glRootNode.children.push_back(&node->glSecondaryNode());
for (auto &&pair : m_scene.orphans()) {
GLTF::Node *secondary_node = &pair.second->glSecondaryNode();
m_glRootNode.children.push_back(secondary_node);
}
} else {
for (auto *node : m_scene.orphans()) {
m_scene.glScene.nodes.push_back(&node->glSecondaryNode());
for (auto &&pair : m_scene.orphans()) {
GLTF::Node *secondary_node = &pair.second->glSecondaryNode();
m_scene.glScene.nodes.push_back(secondary_node);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/ExportableScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ void ExportableScene::getAllAccessors(AccessorsPerDagPath &accessors) {
}
}

void ExportableScene::registerOrphanNode(ExportableNode *node) {
m_orphans[node->dagPath] = node;
}

int ExportableScene::distanceToRoot(MDagPath dagPath) {
int distance;

Expand Down
7 changes: 5 additions & 2 deletions src/ExportableScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
class ExportableNode;

typedef std::map<std::string, std::unique_ptr<ExportableNode>> NodeTable;
typedef std::set<ExportableNode *> OrphanNodes;

// OrphanNodes = nodes without a parent. We use the MDagPath as a key to make
// sure we get a deterministic output (pointers change)
typedef std::map<MDagPath, ExportableNode *, MDagPathComparer> OrphanNodes;

typedef std::map<MDagPath, std::vector<GLTF::Accessor *>, MDagPathComparer>
AccessorsPerDagPath;
Expand Down Expand Up @@ -40,7 +43,7 @@ class ExportableScene {
void getAllAccessors(AccessorsPerDagPath &accessors);

// Register a node without parent
void registerOrphanNode(ExportableNode *node) { m_orphans.insert(node); }
void registerOrphanNode(ExportableNode *node);

static int distanceToRoot(MDagPath dagPath);

Expand Down

0 comments on commit b673d7b

Please sign in to comment.