mirror of https://github.com/bjornbytes/lovr.git
gltf: Support partially-keyed animation properties;
This commit is contained in:
parent
8d1b335da4
commit
79ba7a7ad5
|
@ -162,6 +162,9 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
float transform[16];
|
||||
float translation[3];
|
||||
float rotation[4];
|
||||
float scale[3];
|
||||
uint32_t* children;
|
||||
uint32_t childCount;
|
||||
uint32_t primitiveIndex;
|
||||
|
|
|
@ -743,9 +743,9 @@ ModelData* lovrModelDataInitGltf(ModelData* model, Blob* source) {
|
|||
jsmntok_t* token = info.nodes;
|
||||
ModelNode* node = model->nodes;
|
||||
for (int i = (token++)->size; i > 0; i--, node++) {
|
||||
float translation[3] = { 0, 0, 0 };
|
||||
float rotation[4] = { 0, 0, 0, 0 };
|
||||
float scale[3] = { 1, 1, 1 };
|
||||
vec3 translation = vec3_set(node->translation, 0.f, 0.f, 0.f);
|
||||
quat rotation = quat_set(node->rotation, 0.f, 0.f, 0.f, 1.f);
|
||||
vec3 scale = vec3_set(node->scale, 1.f, 1.f, 1.f);
|
||||
bool matrix = false;
|
||||
node->primitiveCount = 0;
|
||||
node->skin = -1;
|
||||
|
|
|
@ -68,7 +68,11 @@ void lovrAnimatorUpdate(Animator* animator, float dt) {
|
|||
}
|
||||
|
||||
bool lovrAnimatorEvaluate(Animator* animator, int nodeIndex, mat4 transform) {
|
||||
float properties[3][4] = { { 0, 0, 0 }, { 0, 0, 0, 1 }, { 1, 1, 1 } };
|
||||
float properties[3][4];
|
||||
ModelNode* node = &animator->data->nodes[nodeIndex];
|
||||
vec3_init(properties[PROP_TRANSLATION], node->translation);
|
||||
quat_init(properties[PROP_ROTATION], node->rotation);
|
||||
vec3_init(properties[PROP_SCALE], node->scale);
|
||||
bool touched = false;
|
||||
|
||||
for (int i = 0; i < animator->data->animationCount; i++) {
|
||||
|
@ -138,6 +142,8 @@ bool lovrAnimatorEvaluate(Animator* animator, int nodeIndex, mat4 transform) {
|
|||
mat4_translate(transform, T[0], T[1], T[2]);
|
||||
mat4_rotateQuat(transform, R);
|
||||
mat4_scale(transform, S[0], S[1], S[2]);
|
||||
} else {
|
||||
mat4_multiply(transform, node->transform);
|
||||
}
|
||||
|
||||
return touched;
|
||||
|
|
|
@ -13,8 +13,8 @@ static void updateGlobalNodeTransform(Model* model, uint32_t nodeIndex, mat4 tra
|
|||
mat4 globalTransform = model->globalNodeTransforms + 16 * nodeIndex;
|
||||
mat4_set(globalTransform, transform);
|
||||
|
||||
if (!model->animator || !lovrAnimatorEvaluate(model->animator, nodeIndex, globalTransform)) {
|
||||
mat4_multiply(globalTransform, node->transform);
|
||||
if (model->animator) {
|
||||
lovrAnimatorEvaluate(model->animator, nodeIndex, globalTransform);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < node->childCount; i++) {
|
||||
|
|
Loading…
Reference in New Issue