From a94b3044b0e1606873b335db2b4c75b52f59d830 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Thu, 8 Jan 2026 19:18:50 -0600 Subject: [PATCH] restore support for non-animated meshes --- render_cpp.py | 11 ++++++++++- tree.py | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/render_cpp.py b/render_cpp.py index 35c35cf..81e4326 100644 --- a/render_cpp.py +++ b/render_cpp.py @@ -119,7 +119,7 @@ def render_nodes(gltf): print(f"mesh node {node_ix}", file=sys.stderr) 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) translation = (0, 0, 0) @@ -154,6 +154,9 @@ def render_nodes_extern(gltf): yield f'const int nodes__length = {len(gltf.json["nodes"])};' def render_skins(gltf): + if "skins" not in gltf.json: + return + for skin_ix, skin in enumerate(gltf.json["skins"]): yield f"const int skin_{skin_ix}__joints[] = {{" for joint in skin["joints"]: @@ -169,6 +172,8 @@ def render_skins(gltf): yield "};" def render_skins_extern(gltf): + if "skins" not in gltf.json: + return for skin_ix, skin in enumerate(gltf.json["skins"]): yield f"const int skin_{skin_ix}__joints__length = {len(skin['joints'])};" @@ -194,12 +199,16 @@ def render_animation_channels(animation_ix, channels): yield "};" def render_animations_extern(animation_ix): + if "animations" not in gltf.json: + return for animation_ix, animation in enumerate(gltf.json["animations"]): yield f"extern const AnimationChannel animation_{animation_ix}__channels[];" length = len(animation["channels"]) yield f"const int animation_{animation_ix}__channels__length = {length};" def render_animations(gltf): + if "animations" not in gltf.json: + return for animation_ix, animation in enumerate(gltf.json["animations"]): yield from render_animation_samplers(animation_ix, animation["samplers"]) yield from render_animation_channels(animation_ix, animation["channels"]) diff --git a/tree.py b/tree.py index 0d8bee3..3076ea7 100644 --- a/tree.py +++ b/tree.py @@ -11,6 +11,10 @@ def linearize_tree(node_ix, nodes): def build_tree(gltf): parents = {} # from child to parent + # fixme: hack + if len(gltf.json["nodes"]) == 1: + return {}, [0] + for node_ix, node in enumerate(gltf.json["nodes"]): if "children" not in node: continue @@ -18,7 +22,8 @@ def build_tree(gltf): assert child_ix not in parents 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"])) return parents, traversal_order