Exemplo n.º 1
0
void fbxLoader2::computeMesh(FbxNode* pNode, FbxTime& pTime, FbxAnimLayer* pAnimLayer, FbxAMatrix& pGlobalPosition, FbxPose* pPose, int frame)
{
    FbxMesh* lMesh = pNode->GetMesh();
    const int lVertexCount = lMesh->GetControlPointsCount();

    // No vertex to draw.
    if (lVertexCount == 0)
    {
        return;
    }

    // If it has some defomer connection, update the vertices position
    const bool lHasVertexCache = lMesh->GetDeformerCount(FbxDeformer::eVertexCache) &&
        (static_cast<FbxVertexCacheDeformer*>(lMesh->GetDeformer(0, FbxDeformer::eVertexCache)))->IsActive();
    const bool lHasShape = lMesh->GetShapeCount() > 0;
    const bool lHasSkin = lMesh->GetDeformerCount(FbxDeformer::eSkin) > 0;
    const bool lHasDeformation = lHasVertexCache || lHasShape || lHasSkin;

    if (lHasDeformation)
    {
        //we need to get the number of clusters
        const int lSkinCount = lMesh->GetDeformerCount(FbxDeformer::eSkin);
        int lClusterCount = 0;
        for (int lSkinIndex = 0; lSkinIndex < lSkinCount; ++lSkinIndex)
        {
            lClusterCount += ((FbxSkin *)(lMesh->GetDeformer(lSkinIndex, FbxDeformer::eSkin)))->GetClusterCount();
        }
        if (lClusterCount)
        {
            // Deform the vertex array with the skin deformer.
            ComputeSkinDeformation(pGlobalPosition, lMesh, pTime, pPose, frame);
        }
    }
}
void Model::UpdateVertexBuffer( bool pstatic ) {
	


	int total_verts = 0;

	for( u32 mesh_index = 0; mesh_index < MeshNodes.size(); mesh_index++ ) {
		KFbxMesh *mesh = MeshNodes[mesh_index]->GetMesh();
			
		total_verts += mesh->GetPolygonVertexCount();
	}

	nvertices=total_verts;
	Video::generic_vertex *vertices = new Video::generic_vertex[ total_verts ];
	int vert_write = 0;

	for( u32 mesh_index = 0; mesh_index < MeshNodes.size(); mesh_index++ ) {
		KFbxMesh *mesh = MeshNodes[mesh_index]->GetMesh();
		
		int cp_count = mesh->GetControlPointsCount();
        KFbxVector4 *control_points = new KFbxVector4[cp_count];
        memcpy(control_points, mesh->GetControlPoints(), cp_count * sizeof(KFbxVector4));

		const int skin_count = mesh->GetDeformerCount(KFbxDeformer::eSKIN);
		
		// deform mesh with animation
		if( skin_count ) {
			int cluster_count = 0;
			for( int i = 0; i < skin_count; i++ ) {
				cluster_count += ((KFbxSkin*)(mesh->GetDeformer(i, KFbxDeformer::eSKIN)))->GetClusterCount();
			}

			if( cluster_count){
				ComputeSkinDeformation( mesh, AnimationCurrentTime, control_points, NULL );
			}
		}

		// copy vertex data
		int vcount = mesh->GetPolygonVertexCount();
		int *vertex_index = mesh->GetPolygonVertices();
	

		KStringList lUVNames;
		mesh->GetUVSetNames(lUVNames);
		
		for( int i = 0; i < vcount; i++ ) {
			
			vertices[vert_write].x = control_points[ vertex_index[i] ][0];
			vertices[vert_write].y = control_points[ vertex_index[i] ][2];
			vertices[vert_write].z = control_points[ vertex_index[i] ][1];
			

			KFbxVector2 uv;
			mesh->GetPolygonVertexUV( i/3, i%3, lUVNames[0], uv );
			vertices[vert_write].u = uv[0];
			vertices[vert_write].v = -uv[1];
			vertices[vert_write].r = vertices[vert_write].g = vertices[vert_write].b = 255;
			vertices[vert_write].a = 255;
			vert_write++;
		}

		
	}
	
	// reverse vertex order
	for( int i = 0; i < total_verts; i+= 3 ) {
		Video::generic_vertex a;
		a = vertices[i];
		vertices[i] = vertices[i+2];
		vertices[i+2] = a;
	}

	// update VBO
	buffer.BufferData( vertices, total_verts * sizeof( Video::generic_vertex ), pstatic ? GL_STATIC_DRAW_ARB : GL_STREAM_DRAW_ARB );

		
	delete[] vertices;

}
Exemplo n.º 3
0
void fbxLoader2::processMesh(FbxNode* node)
{
	FbxMesh* mesh = node->GetMesh();

	this->readAnimationWeigths(mesh);

	if(mesh!=NULL && mesh->IsTriangleMesh())
	{
		for (int i = 0; i<mesh->GetControlPointsCount(); i++)
		{
			readVertex(mesh, i, &vertex[i]);
			vertexArray[i].position = D3DXVECTOR3(vertex[i]);
		}

		int a = mesh->GetPolygonVertexCount();

		for (int i = 0; i<mesh->GetPolygonVertexCount(); i++)
		{
			readUV(mesh, i, 0, &uv[i]);
			readNormal(mesh, i, &normal[i]);
			indices[i].indice = mesh->GetPolygonVertices()[i];
			indices[i].normal1 = normal[i];
			indices[i].uv1 = uv[i];
			indicesMeshCount++;
		}
	}

	//vertexLists.push_back(vertexArray);
	indiceLists.push_back(indices);

	FbxAnimStack* pAnimStack = FbxCast<FbxAnimStack>(scene->GetSrcObject(FBX_TYPE(FbxAnimStack)));
	int numAnimLayers = pAnimStack->GetMemberCount(FBX_TYPE(FbxAnimLayer));

	this->setBindPoseCluster(node);

	for (int i = 0; i < numAnimLayers; i++)
	{
		FbxAnimLayer* pAnimLayer = pAnimStack->GetMember(FBX_TYPE(FbxAnimLayer), i);
		FbxAnimCurve* animCv = this->findSkeletonRootBone(scene->GetRootNode())->GetChild(0)->LclTranslation.GetCurve(pAnimLayer, FBXSDK_CURVENODE_COMPONENT_X);

		if (animCv)
		{
			FbxTimeSpan animationLength;
			int p = animCv->KeyGetCount();
			animCv->GetTimeInterval(animationLength);

			for(int j = 0; j<animationStructure->GetFramesNumber();j++)
			{
				FbxTime timeKey = animCv->KeyGet(j).mTime;
				//FbxTime interval = (duration/p)*j + animationLength.GetStart();

				//int intervalVal = (duration.GetSecondCount()/p)*j + animationLength.GetStart().GetSecondCount();
				const FbxTime pTime = animCv->KeyGet(j).mTime;


				FbxAMatrix pGlobalPos = GetGlobalPosition(node, pTime, scene->GetPose(j));

				ComputeSkinDeformation(pGlobalPos, mesh, timeKey, scene->GetPose(j), j);
			}
		}
	}

	for(int i = 0; i<node->GetChildCount(); i++)
	{
		processMesh(node->GetChild(i));
	}
}