Exemple #1
0
spSkeleton* spSkeleton_create (spSkeletonData* data) {
	int i, ii;

	_spSkeleton* internal = NEW(_spSkeleton);
	spSkeleton* self = SUPER(internal);
	CONST_CAST(spSkeletonData*, self->data) = data;

	self->bonesCount = self->data->bonesCount;
	self->bones = MALLOC(spBone*, self->bonesCount);

	for (i = 0; i < self->bonesCount; ++i) {
		spBoneData* boneData = self->data->bones[i];
		spBone* parent = 0;
		if (boneData->parent) {
			/* Find parent bone. */
			for (ii = 0; ii < self->bonesCount; ++ii) {
				if (data->bones[ii] == boneData->parent) {
					parent = self->bones[ii];
					break;
				}
			}
		}
		self->bones[i] = spBone_create(boneData, self, parent);
	}
	CONST_CAST(spBone*, self->root) = self->bones[0];

	self->slotsCount = data->slotsCount;
	self->slots = MALLOC(spSlot*, self->slotsCount);
	for (i = 0; i < self->slotsCount; ++i) {
		spSlotData *slotData = data->slots[i];

		/* Find bone for the slotData's boneData. */
		spBone* bone = 0;
		for (ii = 0; ii < self->bonesCount; ++ii) {
			if (data->bones[ii] == slotData->boneData) {
				bone = self->bones[ii];
				break;
			}
		}
		self->slots[i] = spSlot_create(slotData, bone);
	}

	self->drawOrder = MALLOC(spSlot*, self->slotsCount);
	memcpy(self->drawOrder, self->slots, sizeof(spSlot*) * self->slotsCount);

	self->r = 1;
	self->g = 1;
	self->b = 1;
	self->a = 1;

	self->ikConstraintsCount = data->ikConstraintsCount;
	self->ikConstraints = MALLOC(spIkConstraint*, self->ikConstraintsCount);
	for (i = 0; i < self->data->ikConstraintsCount; ++i)
		self->ikConstraints[i] = spIkConstraint_create(self->data->ikConstraints[i], self);

	spSkeleton_updateCache(self);

	return self;
}
Exemple #2
0
spSkeleton* spSkeleton_create (spSkeletonData* data) {
    int i;
    int* childrenCounts;

    _spSkeleton* internal = NEW(_spSkeleton);
    spSkeleton* self = SUPER(internal);
    CONST_CAST(spSkeletonData*, self->data) = data;

    self->bonesCount = self->data->bonesCount;
    self->bones = MALLOC(spBone*, self->bonesCount);
    childrenCounts = CALLOC(int, self->bonesCount);

    for (i = 0; i < self->bonesCount; ++i) {
        spBoneData* boneData = self->data->bones[i];
        spBone* bone;
        if (!boneData->parent)
            bone = spBone_create(boneData, self, 0);
        else {
            spBone* parent = self->bones[boneData->parent->index];
            bone = spBone_create(boneData, self, parent);
            ++childrenCounts[boneData->parent->index];
        }
        self->bones[i] = bone;
    }
    for (i = 0; i < self->bonesCount; ++i) {
        spBoneData* boneData = self->data->bones[i];
        spBone* bone = self->bones[i];
        CONST_CAST(spBone**, bone->children) = MALLOC(spBone*, childrenCounts[boneData->index]);
    }
    for (i = 0; i < self->bonesCount; ++i) {
        spBone* bone = self->bones[i];
        spBone* parent = bone->parent;
        if (parent)
            parent->children[parent->childrenCount++] = bone;
    }
    CONST_CAST(spBone*, self->root) = self->bones[0];

    self->slotsCount = data->slotsCount;
    self->slots = MALLOC(spSlot*, self->slotsCount);
    for (i = 0; i < self->slotsCount; ++i) {
        spSlotData *slotData = data->slots[i];
        spBone* bone = self->bones[slotData->boneData->index];
        self->slots[i] = spSlot_create(slotData, bone);
    }

    self->drawOrder = MALLOC(spSlot*, self->slotsCount);
    memcpy(self->drawOrder, self->slots, sizeof(spSlot*) * self->slotsCount);

    self->ikConstraintsCount = data->ikConstraintsCount;
    self->ikConstraints = MALLOC(spIkConstraint*, self->ikConstraintsCount);
    self->ikConstraintsSorted = MALLOC(spIkConstraint*, self->ikConstraintsCount);
    for (i = 0; i < self->data->ikConstraintsCount; ++i)
        self->ikConstraints[i] = spIkConstraint_create(self->data->ikConstraints[i], self);

    self->transformConstraintsCount = data->transformConstraintsCount;
    self->transformConstraints = MALLOC(spTransformConstraint*, self->transformConstraintsCount);
    for (i = 0; i < self->data->transformConstraintsCount; ++i)
        self->transformConstraints[i] = spTransformConstraint_create(self->data->transformConstraints[i], self);

    self->pathConstraintsCount = data->pathConstraintsCount;
    self->pathConstraints = MALLOC(spPathConstraint*, self->pathConstraintsCount);
    for (i = 0; i < self->data->pathConstraintsCount; i++)
        self->pathConstraints[i] = spPathConstraint_create(self->data->pathConstraints[i], self);

    self->r = 1;
    self->g = 1;
    self->b = 1;
    self->a = 1;

    spSkeleton_updateCache(self);

    FREE(childrenCounts);

    return self;
}