Skip to content

Commit

Permalink
gltf: update morph targets with TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
recp committed Sep 2, 2023
1 parent fe6da3e commit 0aa5440
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions src/io/gltf/imp/core/mesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "../../../../accessor.h"
#include "../../../common/util.h"

#include <ds/rb.h>

/*
glTF meshes -> AkGeometry > AkMesh
glTF primitives -> AkMeshPrimitive
Expand Down Expand Up @@ -162,21 +164,36 @@ gltf_meshes(json_t * __restrict jmesh,
} else if (json_key_eq(jprimVal, _s_gltf_targets)) {
json_array_t *jtargets;
json_t *jtarget, *jattrib;
AkMorph *morph;
AkMorphTarget *target;
AkObject *targetObj;
AkMorphable *morphable;
// AkGeometry *targetGeom;
// AkMesh *targetMesh;
// RBTree *targetsMap;
// int32_t targetIndex;

if (!(jtargets = json_array(jprimVal)))
goto prmv_nxt;

// targetIndex = 0;
// targetsMap = rb_newtree(NULL, ak_cmp_i32, NULL);
morph = ak_heap_calloc(heap, doc, sizeof(*morph));
morph->method = AK_MORPH_METHOD_ADDITIVE;
jtarget = jtargets->base.value;

while (jtarget) {
jattrib = jtarget->value;

target = ak_heap_calloc(heap, morph, sizeof(*target));
/* TODO: Important!!! */
/* target->prim = prim; */

target = ak_heap_calloc(heap, morph, sizeof(*target));
targetObj = ak_objAlloc(heap, target, sizeof(*morphable), AK_MORPHABLE_MORPHABLE, true);
morphable = ak_objGet(targetObj);

/*
TODO: when we want to keep these targets as mesg geometries...:
if (!(targetMesh = rb_find(targetsMap, I2P targetIndex)))
targetMesh = ak_allocMesh(heap, lib, &targetGeom);
*/

while (jattrib) {
AkInput *inp;
Expand Down Expand Up @@ -208,17 +225,19 @@ gltf_meshes(json_t * __restrict jmesh,

if (inp->semantic == AK_INPUT_POSITION)
prim->pos = inp;
inp->next = target->input;
target->input = inp;
target->inputCount++;

inp->next = morphable->input;
morphable->input = inp;
morphable->inputCount++;

jattrib = jattrib->next;
} /* jattrib */

target->next = morph->target;
morph->target = target;
target->target = targetObj;
target->next = morph->target;
morph->target = target;

// targetIndex++;
morph->targetCount++;
jtarget = jtarget->next;
} /* jtarget */
Expand All @@ -227,6 +246,8 @@ gltf_meshes(json_t * __restrict jmesh,
morph->base.next = &doc->lib.morphs->base;

doc->lib.morphs = morph;

rb_insert(gst->meshTargets, geom, morph);
}

prmv_nxt:
Expand Down Expand Up @@ -269,9 +290,6 @@ gltf_meshes(json_t * __restrict jmesh,
geom->base.next = lib->chld;
lib->chld = (void *)geom;

if (morph)
rb_insert(gst->meshTargets, geom, morph);

lib->count++;

jmesh = jmesh->next;
Expand Down

0 comments on commit 0aa5440

Please sign in to comment.