add weight and joint accessors
This commit is contained in:
parent
ee4deb53fb
commit
9111df6257
61
gltf.hpp
61
gltf.hpp
@ -1,29 +1,37 @@
|
||||
template <typename T>
|
||||
struct Array {
|
||||
T * e;
|
||||
int length;
|
||||
};
|
||||
|
||||
struct Mesh {
|
||||
D3DXVECTOR3 * position;
|
||||
D3DXVECTOR3 * normal;
|
||||
D3DXVECTOR2 * texcoord_0;
|
||||
DWORD * indices;
|
||||
const D3DXVECTOR3 * position;
|
||||
const DWORD position_size;
|
||||
|
||||
const D3DXVECTOR3 * normal;
|
||||
const DWORD normal_size;
|
||||
|
||||
const D3DXVECTOR2 * texcoord_0;
|
||||
const DWORD texcoord_0_size;
|
||||
|
||||
const D3DXVECTOR4 * weights_0;
|
||||
const DWORD weights_0_size;
|
||||
|
||||
const D3DXVECTOR4 * joints_0;
|
||||
const DWORD joints_0_size;
|
||||
|
||||
const DWORD * indices;
|
||||
const DWORD indices_size;
|
||||
};
|
||||
|
||||
struct Skin;
|
||||
|
||||
struct Node {
|
||||
Skin * skin; // skin index (global)
|
||||
Mesh * mesh; // mesh index (global)
|
||||
D3DXVECTOR3 scale;
|
||||
D3DXVECTOR3 translation;
|
||||
D3DXQUATERNION rotation;
|
||||
const Skin * skin; // skin index (global)
|
||||
const Mesh * mesh; // mesh index (global)
|
||||
const D3DXVECTOR3 translation;
|
||||
const D3DXQUATERNION rotation;
|
||||
const D3DXVECTOR3 scale;
|
||||
};
|
||||
|
||||
struct Skin {
|
||||
D3DXMATRIX * inverse_bind_matrices; // accessor
|
||||
Array<Node *> joints;
|
||||
const D3DXMATRIX * inverse_bind_matrices; // accessor
|
||||
const Node ** joints;
|
||||
DWORD joints_length;
|
||||
};
|
||||
|
||||
enum AnimationChannelPath {
|
||||
@ -34,19 +42,20 @@ enum AnimationChannelPath {
|
||||
};
|
||||
|
||||
struct AnimationSampler {
|
||||
float * input; // accessor index, containing keyframe timestamps
|
||||
void * output; // accessor index, containing keyframe values (type depends on channel target path)
|
||||
const float * input; // accessor index, containing keyframe timestamps
|
||||
const void * output; // accessor index, containing keyframe values (type depends on channel target path)
|
||||
const int length;
|
||||
};
|
||||
|
||||
struct AnimationChannel {
|
||||
AnimationSampler * sampler; // sampler index, this animation
|
||||
const AnimationSampler * sampler; // sampler index, this animation
|
||||
struct {
|
||||
Node * node; // node index
|
||||
AnimationChannelPath path; // property to animate
|
||||
const Node * node; // node index
|
||||
const AnimationChannelPath path; // property to animate
|
||||
} target;
|
||||
};
|
||||
|
||||
struct Animation {
|
||||
Array<AnimationChannel> channels;
|
||||
Array<AnimationSampler> samplers;
|
||||
};
|
||||
//struct Animation {
|
||||
// const AnimationChannel * channels;
|
||||
// const AnimationSampler * samplers;
|
||||
//};
|
||||
|
||||
@ -75,12 +75,23 @@ def render_meshes(gltf):
|
||||
position = attributes["POSITION"]
|
||||
normal = attributes.get("NORMAL", None)
|
||||
texcoord_0 = attributes.get("TEXCOORD_0", None)
|
||||
weights_0 = attributes.get("WEIGHTS_0", None)
|
||||
joints_0 = attributes.get("JOINTS_0", None)
|
||||
indices = primitive["indices"]
|
||||
yield f"const Mesh mesh_{mesh_ix} = {{"
|
||||
yield f"accessor_{position}, // position"
|
||||
yield f"accessor_{normal}, // normal" if normal is not None else "NULL,"
|
||||
yield f"accessor_{texcoord_0}, // texcoord_0" if texcoord_0 is not None else "NULL,"
|
||||
yield f"(sizeof (accessor_{position})),"
|
||||
yield f"accessor_{normal}, // normal" if normal is not None else "NULL, // normal"
|
||||
yield f"(sizeof (accessor_{normal}))," if normal is not None else "0,"
|
||||
yield f"accessor_{texcoord_0}, // texcoord_0" if texcoord_0 is not None else "NULL, // texcoord_0"
|
||||
yield f"(sizeof (accessor_{texcoord_0}))," if texcoord_0 is not None else "0,"
|
||||
yield f"accessor_{weights_0}, // weights_0" if weights_0 is not None else "NULL, // weights_0"
|
||||
yield f"(sizeof (accessor_{weights_0}))," if weights_0 is not None else "0,"
|
||||
yield f"accessor_{joints_0}, // joints_0" if joints_0 is not None else "NULL, // joints_0"
|
||||
yield f"(sizeof (accessor_{joints_0}))," if joints_0 is not None else "0,"
|
||||
yield f"accessor_{indices}, // indices"
|
||||
yield f"(sizeof (accessor_{indices})),"
|
||||
|
||||
yield "};"
|
||||
|
||||
def render_nodes(gltf):
|
||||
@ -88,7 +99,7 @@ def render_nodes(gltf):
|
||||
if "skin" not in node:
|
||||
continue
|
||||
skin = node["skin"]
|
||||
yield f"const Skin skin_{skin};"
|
||||
yield f"extern const Skin skin_{skin};"
|
||||
|
||||
for node_ix, node in enumerate(gltf.json["nodes"]):
|
||||
skin = f"&skin_{node['skin']}" if "skin" in node else "NULL"
|
||||
@ -107,9 +118,9 @@ def render_nodes(gltf):
|
||||
yield f"const Node node_{node_ix} = {{"
|
||||
yield f"{skin}, // skin"
|
||||
yield f"{mesh}, // mesh"
|
||||
yield f"{render_value(scale, 'D3DXVECTOR3')}, // scale"
|
||||
yield f"{render_value(translation, 'D3DXVECTOR3')}, // translation"
|
||||
yield f"{render_value(rotation, 'D3DXVECTOR4')}, // rotation"
|
||||
yield f"{render_value(scale, 'D3DXVECTOR3')}, // scale"
|
||||
yield "};"
|
||||
|
||||
def render_skins(gltf):
|
||||
@ -123,7 +134,8 @@ def render_skins(gltf):
|
||||
inverse_bind_matrices = skin["inverseBindMatrices"]
|
||||
yield f"const Skin skin_{skin_ix} = {{"
|
||||
yield f"accessor_{inverse_bind_matrices}, // inverse bind matrices"
|
||||
yield f"{{ skin_{skin_ix}__joints, {len(skin['joints'])} }},"
|
||||
yield f"skin_{skin_ix}__joints, // joints"
|
||||
yield f"{len(skin['joints'])}, // joints length"
|
||||
yield "};"
|
||||
|
||||
def render_animation_samplers(animation_ix, samplers):
|
||||
@ -131,6 +143,7 @@ def render_animation_samplers(animation_ix, samplers):
|
||||
yield f"const AnimationSampler animation_{animation_ix}__sampler_{sampler_ix} = {{"
|
||||
yield f"accessor_{sampler['input']}, // input, keyframe timestamps"
|
||||
yield f"accessor_{sampler['output']}, // output, keyframe values (void *)"
|
||||
yield f"accessor_{sampler['input']}_length, // length"
|
||||
yield "};"
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user