示例#1
0
void MArmature::updateBonesSkinMatrix(void)
{
    M_PROFILE_SCOPE(MArmature::updateBonesSkinMatrix);
	unsigned int i;
	MOBone * bone = NULL;
	for(i=0; i<m_bonesNumber; i++)
	{
		bone = m_bones[i];
		(*bone->getSkinMatrix()) = (*bone->getMatrix()) * (*bone->getInversePoseMatrix());
	}
}
示例#2
0
// skinning
void computeSkinning (
	MArmature * armature, MSkinData * skinData,
	const MVector3 * baseVertices, const MVector3 * baseNormals, const MVector3 * baseTangents,
	MVector3 * vertices, MVector3 * normals, MVector3 * tangents)
{
	MMatrix4x4 matrix;

	unsigned int p;
	unsigned int pSize = skinData->getPointsNumber();
	if(baseTangents && baseNormals)
	{
		for(p = 0; p < pSize; p++)
		{
			MSkinPoint * point = skinData->getPoint(p);
			const unsigned short * bonesIds = point->getBonesIds();
			const float * bonesWeights = point->getBonesWeights();
			
			unsigned int vertexId = point->getVertexId();
			unsigned int b, bSize = point->getBonesNumber();
			
			memset(matrix.entries, 0, sizeof(float)*16);
			
			for(b=0; b<bSize; b++)
			{
				MOBone * bone = armature->getBone(bonesIds[b]);
				blendMatrices(&matrix, bone->getSkinMatrix(), bonesWeights[b]);
			}
			
			vertices[vertexId] = matrix * baseVertices[vertexId];
			normals[vertexId] = matrix.getRotatedVector3(baseNormals[vertexId]);
			tangents[vertexId] = matrix.getRotatedVector3(baseTangents[vertexId]);
		}
	}
	else if(baseNormals)
	{
		for(p = 0; p < pSize; p++)
		{
			MSkinPoint * point = skinData->getPoint(p);
			const unsigned short * bonesIds = point->getBonesIds();
			const float * bonesWeights = point->getBonesWeights();
			
			unsigned int vertexId = point->getVertexId();
			unsigned int b, bSize = point->getBonesNumber();
			
			memset(matrix.entries, 0, sizeof(float)*16);
			
			for(b=0; b<bSize; b++)
			{
				MOBone * bone = armature->getBone(bonesIds[b]);
				blendMatrices(&matrix, bone->getSkinMatrix(), bonesWeights[b]);
			}
			
			vertices[vertexId] = matrix * baseVertices[vertexId];
			normals[vertexId] = matrix.getRotatedVector3(baseNormals[vertexId]);
		}
	}
	else
	{
		for(p = 0; p < pSize; p++)
		{
			MSkinPoint * point = skinData->getPoint(p);
			const unsigned short * bonesIds = point->getBonesIds();
			const float * bonesWeights = point->getBonesWeights();
			
			unsigned int vertexId = point->getVertexId();
			unsigned int b, bSize = point->getBonesNumber();
			
			memset(matrix.entries, 0, sizeof(float)*16);
			
			for(b=0; b<bSize; b++)
			{
				MOBone * bone = armature->getBone(bonesIds[b]);
				blendMatrices(&matrix, bone->getSkinMatrix(), bonesWeights[b]);
			}
			
			vertices[vertexId] = matrix * baseVertices[vertexId];
		}
	}
}
示例#3
0
void computeSkinning(MArmature * armature, MSkinData * skinData, const MVector3 * baseVertices, const MVector3 * baseNormals, const MVector3 * baseTangents, MVector3 * vertices, MVector3 * normals, MVector3 * tangents)
{
    M_PROFILE_SCOPE(computeSkinning);
	unsigned int p;
	unsigned int pSize = skinData->getPointsNumber();
	if (baseTangents && baseNormals)
	{
		for (p = 0; p < pSize; p++)
		{
			MSkinPoint * point = skinData->getPoint(p);
			unsigned short * bonesIds = point->getBonesIds();
			float * bonesWeights = point->getBonesWeights();
			
			unsigned int vertexId = point->getVertexId();
			unsigned int bSize = point->getBonesNumber();
			
			if (bSize > 1) // weighted skin
			{
				MOBone * bone = armature->getBone(bonesIds[0]);
				MMatrix4x4 matrix((*bone->getSkinMatrix()) * bonesWeights[0]);
				
				unsigned int b;
				for(b=1; b<bSize; b++)
				{
					MOBone * bone = armature->getBone(bonesIds[b]);
					matrix += (*bone->getSkinMatrix()) * bonesWeights[b];
				}
				
				vertices[vertexId] = matrix * baseVertices[vertexId];
				normals[vertexId] = matrix.getRotatedVector3(baseNormals[vertexId]);
				tangents[vertexId] = matrix.getRotatedVector3(baseTangents[vertexId]);
			}
			else if (bSize == 1) // simple skin
			{
				MOBone * bone = armature->getBone(bonesIds[0]);
				vertices[vertexId] = (*bone->getSkinMatrix()) * baseVertices[vertexId];
				normals[vertexId] = bone->getSkinMatrix()->getRotatedVector3(baseNormals[vertexId]);
				tangents[vertexId] = bone->getSkinMatrix()->getRotatedVector3(baseTangents[vertexId]);
			}
		}
	}
	else if (baseNormals)
	{
		for (p = 0; p < pSize; p++)
		{
			MSkinPoint * point = skinData->getPoint(p);
			unsigned short * bonesIds = point->getBonesIds();
			float * bonesWeights = point->getBonesWeights();

			unsigned int vertexId = point->getVertexId();
			unsigned int bSize = point->getBonesNumber();
			
			if (bSize > 1) // weighted skin
			{
				MOBone * bone = armature->getBone(bonesIds[0]);
				MMatrix4x4 matrix((*bone->getSkinMatrix()) * bonesWeights[0]);

				unsigned int b;
				for(b=1; b<bSize; b++)
				{
					MOBone * bone = armature->getBone(bonesIds[b]);
					matrix += (*bone->getSkinMatrix()) * bonesWeights[b];
				}

				vertices[vertexId] = matrix * baseVertices[vertexId];
				normals[vertexId] = matrix.getRotatedVector3(baseNormals[vertexId]);
			}
			else if (bSize == 1) // simple skin
			{
				MOBone * bone = armature->getBone(bonesIds[0]);
				vertices[vertexId] = (*bone->getSkinMatrix()) * baseVertices[vertexId];
				normals[vertexId] = bone->getSkinMatrix()->getRotatedVector3(baseNormals[vertexId]);
			}
		}
	}
	else
	{
		for (p = 0; p < pSize; p++)
		{
			MSkinPoint * point = skinData->getPoint(p);
			unsigned short * bonesIds = point->getBonesIds();
			float * bonesWeights = point->getBonesWeights();

			unsigned int vertexId = point->getVertexId();
			unsigned int bSize = point->getBonesNumber();
			
			if (bSize > 1) // weighted skin
			{
				MOBone * bone = armature->getBone(bonesIds[0]);
				MMatrix4x4 matrix((*bone->getSkinMatrix()) * bonesWeights[0]);

				unsigned int b;
				for(b=1; b<bSize; b++)
				{
					MOBone * bone = armature->getBone(bonesIds[b]);
					matrix += (*bone->getSkinMatrix()) * bonesWeights[b];
				}

				vertices[vertexId] = matrix * baseVertices[vertexId];
			}
			else if (bSize == 1) // simple skin
			{
				MOBone * bone = armature->getBone(bonesIds[0]);
				vertices[vertexId] = (*bone->getSkinMatrix()) * baseVertices[vertexId];
			}
		}
	}
}