restore support for non-animated meshes
This commit is contained in:
parent
34868d4188
commit
a94b3044b0
@ -119,7 +119,7 @@ def render_nodes(gltf):
|
|||||||
print(f"mesh node {node_ix}", file=sys.stderr)
|
print(f"mesh node {node_ix}", file=sys.stderr)
|
||||||
|
|
||||||
skin = f"&skin_{node['skin']}" if "skin" in node else "NULL"
|
skin = f"&skin_{node['skin']}" if "skin" in node else "NULL"
|
||||||
mesh = f"&mesh_{node['skin']}" if "mesh" in node else "NULL"
|
mesh = f"&mesh_{node['mesh']}" if "mesh" in node else "NULL"
|
||||||
|
|
||||||
scale = (1, 1, 1)
|
scale = (1, 1, 1)
|
||||||
translation = (0, 0, 0)
|
translation = (0, 0, 0)
|
||||||
@ -154,6 +154,9 @@ def render_nodes_extern(gltf):
|
|||||||
yield f'const int nodes__length = {len(gltf.json["nodes"])};'
|
yield f'const int nodes__length = {len(gltf.json["nodes"])};'
|
||||||
|
|
||||||
def render_skins(gltf):
|
def render_skins(gltf):
|
||||||
|
if "skins" not in gltf.json:
|
||||||
|
return
|
||||||
|
|
||||||
for skin_ix, skin in enumerate(gltf.json["skins"]):
|
for skin_ix, skin in enumerate(gltf.json["skins"]):
|
||||||
yield f"const int skin_{skin_ix}__joints[] = {{"
|
yield f"const int skin_{skin_ix}__joints[] = {{"
|
||||||
for joint in skin["joints"]:
|
for joint in skin["joints"]:
|
||||||
@ -169,6 +172,8 @@ def render_skins(gltf):
|
|||||||
yield "};"
|
yield "};"
|
||||||
|
|
||||||
def render_skins_extern(gltf):
|
def render_skins_extern(gltf):
|
||||||
|
if "skins" not in gltf.json:
|
||||||
|
return
|
||||||
for skin_ix, skin in enumerate(gltf.json["skins"]):
|
for skin_ix, skin in enumerate(gltf.json["skins"]):
|
||||||
yield f"const int skin_{skin_ix}__joints__length = {len(skin['joints'])};"
|
yield f"const int skin_{skin_ix}__joints__length = {len(skin['joints'])};"
|
||||||
|
|
||||||
@ -194,12 +199,16 @@ def render_animation_channels(animation_ix, channels):
|
|||||||
yield "};"
|
yield "};"
|
||||||
|
|
||||||
def render_animations_extern(animation_ix):
|
def render_animations_extern(animation_ix):
|
||||||
|
if "animations" not in gltf.json:
|
||||||
|
return
|
||||||
for animation_ix, animation in enumerate(gltf.json["animations"]):
|
for animation_ix, animation in enumerate(gltf.json["animations"]):
|
||||||
yield f"extern const AnimationChannel animation_{animation_ix}__channels[];"
|
yield f"extern const AnimationChannel animation_{animation_ix}__channels[];"
|
||||||
length = len(animation["channels"])
|
length = len(animation["channels"])
|
||||||
yield f"const int animation_{animation_ix}__channels__length = {length};"
|
yield f"const int animation_{animation_ix}__channels__length = {length};"
|
||||||
|
|
||||||
def render_animations(gltf):
|
def render_animations(gltf):
|
||||||
|
if "animations" not in gltf.json:
|
||||||
|
return
|
||||||
for animation_ix, animation in enumerate(gltf.json["animations"]):
|
for animation_ix, animation in enumerate(gltf.json["animations"]):
|
||||||
yield from render_animation_samplers(animation_ix, animation["samplers"])
|
yield from render_animation_samplers(animation_ix, animation["samplers"])
|
||||||
yield from render_animation_channels(animation_ix, animation["channels"])
|
yield from render_animation_channels(animation_ix, animation["channels"])
|
||||||
|
|||||||
7
tree.py
7
tree.py
@ -11,6 +11,10 @@ def linearize_tree(node_ix, nodes):
|
|||||||
def build_tree(gltf):
|
def build_tree(gltf):
|
||||||
parents = {} # from child to parent
|
parents = {} # from child to parent
|
||||||
|
|
||||||
|
# fixme: hack
|
||||||
|
if len(gltf.json["nodes"]) == 1:
|
||||||
|
return {}, [0]
|
||||||
|
|
||||||
for node_ix, node in enumerate(gltf.json["nodes"]):
|
for node_ix, node in enumerate(gltf.json["nodes"]):
|
||||||
if "children" not in node:
|
if "children" not in node:
|
||||||
continue
|
continue
|
||||||
@ -18,7 +22,8 @@ def build_tree(gltf):
|
|||||||
assert child_ix not in parents
|
assert child_ix not in parents
|
||||||
parents[child_ix] = node_ix
|
parents[child_ix] = node_ix
|
||||||
|
|
||||||
root_node_ix, = [i for i in parents.values() if i not in parents]
|
root_node_ix, = set(i for i in parents.values() if i not in parents)
|
||||||
|
print(root_node_ix)
|
||||||
traversal_order = list(linearize_tree(root_node_ix, gltf.json["nodes"]))
|
traversal_order = list(linearize_tree(root_node_ix, gltf.json["nodes"]))
|
||||||
|
|
||||||
return parents, traversal_order
|
return parents, traversal_order
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user