Esempio n. 1
0
void animateArmature(MArmature * armature, MArmatureAnim * armatureAnim, float t)
{
	MObject3dAnim * bonesAnim = armatureAnim->getBonesAnim();

	MVector3 position;
	MVector3 scale;
	MQuaternion rotation;

	unsigned int b;
	unsigned int bSize = armatureAnim->getBonesAnimNumber();
	for (b = 0; b < bSize; b++)
	{
		MOBone * bone = armature->getBone(b);
		
		// position
		if(animateVector3(bonesAnim->getPositionKeys(), bonesAnim->getPositionKeysNumber(), t, &position))
			bone->setPosition(position);

		// scale
		if(animateVector3(bonesAnim->getScaleKeys(), bonesAnim->getScaleKeysNumber(), t, &scale))
			bone->setScale(scale);

		// rotation
		if(animateQuaternion(bonesAnim->getRotationKeys(), bonesAnim->getRotationKeysNumber(), t, &rotation))
			bone->setRotation(rotation);

		bonesAnim++;
	}

	armature->processBonesLinking();
	armature->updateBonesSkinMatrix();
}
Esempio n. 2
0
// Armature anim bin export
bool exportArmatureAnimBin(const char * filename, MArmatureAnim * anim)
{
	int version = 1;
	
	
	// create file
	MFile * file = M_fopen(filename, "wb");
	if(! file)
	{
		printf("Error : can't create file %s\n", filename);
		return false;
	}
	
	
	// header
	M_fwrite(M_AA_HEADER, sizeof(char), 8, file);
	
	// version
	M_fwrite(&version, sizeof(int), 1, file);
	
	
	// bones
	unsigned int b, bonesAnimNumber = anim->getBonesAnimNumber();
	MObject3dAnim * bonesAnim = anim->getBonesAnim();
	
	M_fwrite(&bonesAnimNumber, sizeof(int), 1, file);
	for(b=0; b<bonesAnimNumber; b++)
	{
		MObject3dAnim * objAnim = &(bonesAnim[b]);
	
		unsigned int positionKeysNumber = objAnim->getPositionKeysNumber();
		unsigned int scaleKeysNumber = objAnim->getScaleKeysNumber();
		unsigned int rotationKeysNumber = objAnim->getRotationKeysNumber();
		
		MKey * positionKeys = objAnim->getPositionKeys();
		MKey * scaleKeys = objAnim->getScaleKeys();
		MKey * rotationKeys = objAnim->getRotationKeys();
	
		writeKeys(file, positionKeys, M_VARIABLE_VEC3, positionKeysNumber);
		writeKeys(file, scaleKeys, M_VARIABLE_VEC3, scaleKeysNumber);
		writeKeys(file, rotationKeys, M_VARIABLE_QUAT, rotationKeysNumber);
	}
	
	
	M_fclose(file);
	return true;
}