tree: return linearized traversal order
This commit is contained in:
parent
9c2c7c9ff6
commit
34868d4188
@ -112,7 +112,7 @@ def render_nodes(gltf):
|
||||
skin = node["skin"]
|
||||
yield f"extern const Skin skin_{skin};"
|
||||
|
||||
node_parents = build_tree(gltf)
|
||||
node_parents, traversal_order = build_tree(gltf)
|
||||
|
||||
for node_ix, node in enumerate(gltf.json["nodes"]):
|
||||
if "mesh" in node:
|
||||
@ -223,7 +223,9 @@ def render_gltf_source(gltf, filename_hpp):
|
||||
|
||||
filename = sys.argv[1]
|
||||
filename_cpp = sys.argv[2]
|
||||
assert filename_cpp.endswith(".cpp")
|
||||
filename_hpp = sys.argv[3]
|
||||
assert filename_hpp.endswith(".hpp")
|
||||
gltf = decode_file(filename)
|
||||
|
||||
with open(filename_cpp, "w") as f:
|
||||
|
||||
18
tree.py
18
tree.py
@ -1,5 +1,13 @@
|
||||
from gltf import decode_file
|
||||
|
||||
def linearize_tree(node_ix, nodes):
|
||||
yield node_ix
|
||||
node = nodes[node_ix]
|
||||
if "children" not in node:
|
||||
return
|
||||
for child_ix in node["children"]:
|
||||
yield from linearize_tree(child_ix, nodes)
|
||||
|
||||
def build_tree(gltf):
|
||||
parents = {} # from child to parent
|
||||
|
||||
@ -10,14 +18,10 @@ def build_tree(gltf):
|
||||
assert child_ix not in parents
|
||||
parents[child_ix] = node_ix
|
||||
|
||||
for skin in gltf.json["skins"]:
|
||||
seen = set()
|
||||
for joint in skin["joints"]:
|
||||
parent = parents[joint]
|
||||
assert parent in seen or parent not in skin["joints"], (parent, joint, seen)
|
||||
seen.add(joint)
|
||||
root_node_ix, = [i for i in parents.values() if i not in parents]
|
||||
traversal_order = list(linearize_tree(root_node_ix, gltf.json["nodes"]))
|
||||
|
||||
return parents
|
||||
return parents, traversal_order
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user