Skip to content

Commit

Permalink
new design to load skinners and morphers
Browse files Browse the repository at this point in the history
* drop instance controllerr
  • Loading branch information
recp committed May 17, 2020
1 parent 91e7aec commit f896ba3
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 172 deletions.
16 changes: 10 additions & 6 deletions include/ak/assetkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,11 @@ typedef struct AkBindMaterial {
} AkBindMaterial;

typedef struct AkInstanceGeometry {
AkInstanceBase base;
AkBindMaterial *bindMaterial;
AkInstanceBase base;

AkBindMaterial *bindMaterial;
struct AkInstanceMorph *morpher;
struct AkInstanceSkin *skinner;
} AkInstanceGeometry;

typedef struct AkInstanceNode {
Expand Down Expand Up @@ -440,6 +443,7 @@ typedef struct AkScene {
} AkScene;

struct AkMorph;
struct AkSkin;

typedef struct AkLibraries {
struct AkLibrary *cameras;
Expand All @@ -458,8 +462,8 @@ typedef struct AkLibraries {
struct FListItem *textures;
struct FListItem *samplers;
struct FListItem *images;
struct FListItem *skins;
struct AkMorph *morphs;
struct AkSkin *skins;
} AkLibraries;

typedef const char* (*AkFetchFromURLHandler)(const char * __restrict url);
Expand Down Expand Up @@ -492,7 +496,7 @@ typedef struct AkDoc {

AK_EXPORT
AkResult
ak_load(AkDoc ** __restrict dest,
ak_load(AkDoc ** __restrict dest,
const char * __restrict url,
.../* options */);

Expand All @@ -502,7 +506,7 @@ ak_getId(void * __restrict objptr);

AK_EXPORT
AkResult
ak_setId(void * __restrict objptr,
ak_setId(void * __restrict objptr,
const char * __restrict objectId);

AK_EXPORT
Expand All @@ -512,7 +516,7 @@ ak_moveId(void * __restrict objptrOld,

AK_EXPORT
void *
ak_getObjectById(AkDoc * __restrict doc,
ak_getObjectById(AkDoc * __restrict doc,
const char * __restrict objectId);

AK_EXPORT
Expand Down
40 changes: 19 additions & 21 deletions include/ak/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,29 @@ typedef struct AkBoneWeights {
uint32_t *counts; /* joint count per vertex */
size_t *indexes; /* offset of weight at buffer by index */
AkBoneWeight *weights;
// AkAccessor *joints;
// AkAccessor *weights;
AkTree *extra;
size_t nWeights; /* cache: count of weights */
size_t nVertex; /* cache: count of pJointsCount/pWeightsIndex */

/* TODO: Will be removed */
AkTree *extra;
} AkBoneWeights;

typedef struct AkSkin {
struct AkNode **joints; /* global joints, check instanceController */
AkFloat4x4 *invBindPoses;
// AkAccessor *invBindPosesAcc;
AkBoneWeights **weights; /* per primitive */
AkOneWayIterBase base;
struct AkNode **joints; /* global joints, check instanceController */
AkFloat4x4 *invBindPoses;
AkBoneWeights **weights; /* per primitive */
AkURL baseGeom;
size_t nJoints; /* cache: joint count */
uint32_t nPrims; /* cache: primitive count */
uint32_t nMaxJoints;
AkFloat4x4 bindShapeMatrix;

/* TODO: Will be removed */
AkSource *source;
AkTree *extra;
void *reserved[5];
uint32_t reserved2;
AkURL baseGeom;
size_t nJoints; /* cache: joint count */
uint32_t nPrims; /* cache: primitive count */
uint32_t nMaxJoints;
AkFloat4x4 bindShapeMatrix;
} AkSkin;

typedef struct AkMorphTarget {
Expand All @@ -76,11 +78,15 @@ typedef struct AkMorph {
} AkMorph;

typedef struct AkInstanceMorph {
AkGeometry *baseGeometry;
AkMorph *morph;
AkFloatArray *overrideWeights; /* override default weights or NULL */
} AkInstanceMorph;

typedef struct AkInstanceSkin {
AkSkin *skin;
struct AkNode **overrideJoints;
} AkInstanceSkin;

typedef struct AkController {
/* const char * id; */
const char *name;
Expand All @@ -89,14 +95,6 @@ typedef struct AkController {
struct AkController *next;
} AkController;

typedef struct AkInstanceController {
AkInstanceBase base;
AkURL geometry;
struct AkNode **joints;
AkBindMaterial *bindMaterial;
struct FListItem *reserved;
} AkInstanceController;

/*!
* @brief fill a buffer with JointID and JointWeight to feed GPU buffer
* you can send this buffer to GPU buffer (e.g. OpenGL) directly
Expand Down
7 changes: 2 additions & 5 deletions include/ak/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,9 @@ typedef struct AkNode {
struct AkMatrix *matrix;
struct AkMatrix *matrixWorld;
struct AkBoundingBox *bbox;

AkInstanceBase *camera;
struct AkInstanceController *controller;
struct AkInstanceMorph *morpher;
void *skinner;

AkInstanceGeometry *geometry;
AkInstanceBase *camera;
AkInstanceBase *light;
AkInstanceNode *node;

Expand Down
17 changes: 1 addition & 16 deletions src/collada/core/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,7 @@ dae_node(DAEState * __restrict dst,
}

instctl->base.node = node;

if (node->controller) {
node->controller->base.next = &instctl->base;
instctl->base.prev = &node->controller->base;
}

flist_sp_insert(&dst->instCtlrs, instctl);

node->controller = instctl;
flist_sp_insert(&dst->instCtlrs, instctl);;
} else if (xml_tag_eq(xml, _s_dae_instance_geometry)) {
AkInstanceGeometry *instgeo;
xml_t *xinstgeo;
Expand All @@ -235,13 +227,6 @@ dae_node(DAEState * __restrict dst,

instgeo->base.next = (void *)node->geometry;
node->geometry = instgeo;

if (node->controller) {
instgeo->base.prev = &node->controller->base;
node->controller->base.prev = &instgeo->base;

flist_sp_insert(&dst->instCtlrs, instgeo);
}
} else if (xml_tag_eq(xml, _s_dae_instance_light)) {
AkInstanceBase *instlight;

Expand Down
3 changes: 1 addition & 2 deletions src/collada/fixup/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ dae_nodeFixupFixedCoord(AkHeap * __restrict heap,
&& !node->light)
return;

if (!node->controller
&& !node->geometry
if (!node->geometry
&& !node->chld
&& !node->node) {
node->flags |= AK_NODEF_FIXED_COORD;
Expand Down
44 changes: 32 additions & 12 deletions src/collada/postscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,26 +366,33 @@ dae_fixup_instctlr(DAEState * __restrict dst) {
FListItem *item;
AkInstanceController *instCtlr;
AkController *ctlr;
AkNode *node;
AkInstanceGeometry *instGeom;
AkContext ctx = { .doc = dst->doc };

item = dst->instCtlrs;
while (item) {
instCtlr = item->data;
ctlr = ak_instanceObject(&instCtlr->base);
node = instCtlr->base.node;

ctlr = ak_instanceObject(&instCtlr->base);
instGeom = ak_heap_calloc(dst->heap, node, sizeof(*instGeom));

switch (ctlr->data->type) {
case AK_CONTROLLER_SKIN: {
AkSkin *skin;
AkNode **joints;
AkInput *jointsInp, *matrixInp;
AkAccessor *jointsAcc, *matrixAcc;
AkBuffer *jointsBuff, *matrixBuff;
FListItem *skel;
const char *sid, **it;
AkFloat *mit;
AkFloat4x4 *invm;
size_t count, i;
AkInstanceSkin *instSkin;
AkSkin *skin;
AkNode **joints;
AkInput *jointsInp, *matrixInp;
AkAccessor *jointsAcc, *matrixAcc;
AkBuffer *jointsBuff, *matrixBuff;
FListItem *skel;
const char *sid, **it;
AkFloat *mit;
AkFloat4x4 *invm;
size_t count, i;

instSkin = ak_heap_calloc(dst->heap, node, sizeof(*instSkin));

skin = ak_objGet(ctlr->data);
jointsInp = skin->reserved[0];
Expand Down Expand Up @@ -430,9 +437,22 @@ dae_fixup_instctlr(DAEState * __restrict dst) {
glm_mat4_transpose(invm[i]);
}

instCtlr->joints = joints;
skin->nJoints = count;
skin->invBindPoses = invm;

instSkin->skin = skin;
instSkin->overrideJoints = joints;

/* create instance geometry for skin */
instGeom->skinner = instSkin;
instGeom->bindMaterial = instCtlr->bindMaterial;
instGeom->base.object = skin->baseGeom.ptr;
ak_heap_setpm(instCtlr->bindMaterial, instGeom);

instGeom->base.next = (AkInstanceBase *)node->geometry;
if (node->geometry)
node->geometry->base.prev = (AkInstanceBase *)instGeom;
node->geometry = instGeom;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/coord/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ ak_fixNodeCoordSys(AkNode * __restrict node) {
AkInstanceBase *inst;
AkInstanceBase *instArray[] = {(AkInstanceBase *)node->geometry,
(AkInstanceBase *)node->node,
(AkInstanceBase *)node->controller,
node->camera,
node->light};
int i, instArrayLen, instTransCount;
Expand Down
6 changes: 4 additions & 2 deletions src/gltf/core/anim.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,12 @@ gltf_animations(json_t * __restrict janim,
ch->targetType = AK_TARGET_SCALE;
ch->resolvedTarget = ak_getTransformTRS(node, AKT_SCALE);
} else if (strncasecmp(path, _s_gltf_weights, pathLen) == 0) {
AkInstanceMorph *morpher;
AkInstanceMorph *morpher;
AkInstanceGeometry *instGeom;

ch->targetType = AK_TARGET_WEIGHTS;
if ((morpher = node->morpher))
if ((instGeom = node->geometry)
&& (morpher = instGeom->morpher))
ch->resolvedTarget = morpher->overrideWeights;
}
}
Expand Down
27 changes: 0 additions & 27 deletions src/gltf/core/morph.c

This file was deleted.

16 changes: 0 additions & 16 deletions src/gltf/core/morph.h

This file was deleted.

Loading

0 comments on commit f896ba3

Please sign in to comment.