Ejemplo n.º 1
0
void CModelConverter::ReadDAESceneTree(FCDSceneNode* pNode, CConversionSceneNode* pScene)
{
	size_t iTransforms = pNode->GetTransformCount();

	Matrix4x4 mTransformations;

	for (size_t t = 0; t < iTransforms; t++)
	{
		FCDTransform* pTransform = pNode->GetTransform(t);
		FMMatrix44 m = pTransform->ToMatrix();
		mTransformations *= Matrix4x4(m);
	}

	pScene->SetTransformations(mTransformations);

	size_t iInstances = pNode->GetInstanceCount();

	for (size_t i = 0; i < iInstances; i++)
	{
		FCDEntityInstance* pInstance = pNode->GetInstance(i);

		switch (pInstance->GetType())
		{
		case FCDEntityInstance::GEOMETRY:
		{
			FCDGeometryInstance* pGeometryInstance = dynamic_cast<FCDGeometryInstance*>(pInstance);
			FCDEntity* pEntity = pGeometryInstance->GetEntity();
			size_t iMesh = pScene->m_pScene->FindMesh(convert_from_fstring(pEntity->GetName()));
			size_t iMeshInstance = pScene->AddMeshInstance(iMesh);

			size_t iMaterialInstances = pGeometryInstance->GetMaterialInstanceCount();
			for (size_t m = 0; m < iMaterialInstances; m++)
			{
				FCDMaterialInstance* pMaterialInstance = pGeometryInstance->GetMaterialInstance(m);
				FCDMaterial* pMaterial = pMaterialInstance->GetMaterial();
				tstring sMaterial = pMaterial?convert_from_fstring(pMaterialInstance->GetMaterial()->GetName()):"";
				tstring sMaterialStub = convert_from_fstring(pMaterialInstance->GetSemantic());

				size_t iMaterial = pScene->m_pScene->FindMaterial(sMaterial);
				size_t iMaterialStub = pScene->m_pScene->GetMesh(iMesh)->FindMaterialStub(sMaterialStub);

				pScene->GetMeshInstance(iMeshInstance)->AddMappedMaterial(iMaterialStub, iMaterial);
			}
		}
		}
	}

	size_t iChildren = pNode->GetChildrenCount();
	for (size_t j = 0; j < iChildren; j++)
	{
		FCDSceneNode* pChildNode = pNode->GetChild(j);
		size_t iNode = pScene->AddChild(convert_from_fstring(pChildNode->GetName()));
		ReadDAESceneTree(pChildNode, pScene->GetChild(iNode));
	}
}
Ejemplo n.º 2
0
FMMatrix44 ColladaSceneNode::CalculateTransformForTime(FCDSceneNode * originalNode, float32 time)
{
	FMMatrix44 colladaLocalMatrix;
	colladaLocalMatrix = FMMatrix44::Identity;// = FMMatrix44::Identity(); 
	
	for (int t = 0; t < (int)originalNode->GetTransformCount(); ++t)
	{
		FCDTransform * transform = originalNode->GetTransform(t);
		if (transform->IsAnimated()) // process all animations to make CalculateWorldTransform work
		{
			FCDAnimated * animated = transform->GetAnimated();
			animated->Evaluate(time);
		}
		
		if (transform->GetType() == FCDTransform::TRANSLATION)
		{
			FCDTTranslation * translation = dynamic_cast<FCDTTranslation*>(transform);
			FMVector3 point = FMVector3(0.0f, 0.0f, 0.0f);
			point = translation->GetTranslation();
			if (transform->IsAnimated()) 
			{
				FCDAnimationCurve* curve;
				
				// look for x animation
				curve = transform->GetAnimated()->FindCurve(".X");
				if (curve != 0) 
					point.x = curve->Evaluate(time);
					
				// look for y animation
				curve = transform->GetAnimated()->FindCurve(".Y");
				if (curve != 0) 
					point.y = curve->Evaluate(time);
						
				// look for z animation
				curve = transform->GetAnimated()->FindCurve(".Z");
				if (curve != 0) 
					point.z = curve->Evaluate(time);
			}
			colladaLocalMatrix = colladaLocalMatrix * FMMatrix44::TranslationMatrix(point);
		}else if (transform->GetType() == FCDTransform::ROTATION)
		{
			FCDTRotation * rotation = dynamic_cast<FCDTRotation*>(transform);
			FMVector3 axis = FMVector3(0.0f, 0.0f, 0.0f);
			float angle = 0;
			axis = rotation->GetAxis();
			angle = rotation->GetAngle();
			
			if (rotation->IsAnimated()) 
			{
				FCDAnimationCurve* curve;
				
				// look for x animation
				curve = rotation->GetAnimated()->FindCurve(".X");
				if (curve != 0) 
					axis.x = curve->Evaluate(time);
					
				// look for y animation
				curve = rotation->GetAnimated()->FindCurve(".Y");
				if (curve != 0) 
					axis.y = curve->Evaluate(time);
						
				// look for z animation
				curve = rotation->GetAnimated()->FindCurve(".Z");
				if (curve != 0) 
					axis.z = curve->Evaluate(time);
							
							// look for z animation
				curve = rotation->GetAnimated()->FindCurve(".ANGLE");
				if (curve != 0) 
					angle = curve->Evaluate(time);
			}
			colladaLocalMatrix = colladaLocalMatrix * FMMatrix44::AxisRotationMatrix(axis, angle * PI / 180.0f);
		}else
		{
			colladaLocalMatrix = colladaLocalMatrix * transform->ToMatrix();
		}
		
	}
	return colladaLocalMatrix;
}