Beispiel #1
0
void Model::processMesh(FbxMesh *mesh, int level)
{
	int numVerts = mesh->GetControlPointsCount();
	int numInds = mesh->GetPolygonVertexCount();

	Vertex *pVerts = new Vertex[numVerts];
	int *pIndices = mesh->GetPolygonVertices();

	for (int i = 0; i < numVerts; i++)
	{
		FbxVector4 vert = mesh->GetControlPointAt(i);
		pVerts[i].pos = vec3(vert[0], vert[1], vert[2]);
		pVerts[i].color = vec4(1, 1, 1, 1);
		pVerts[i].texture = vec2(0, 0);
		//pVerts[i].tangent = processMeshTangent(mesh, i);
		//pVerts[i].binormal = processMeshBinormal(mesh, i);
	}

	processMeshTextCoords(mesh, pVerts, numVerts);
	processMeshNormals(mesh, pVerts, numVerts);
	
	uint initVertCount = vertices->size();
	for (int i = 0; i < numVerts; i++)
		vertices->push_back(pVerts[i]);

	for (int i = 0; i < numInds; i++)
		indices->push_back(initVertCount + pIndices[i]);

	//PrintTabs(level);
	//printf("Vertices %d Indices %d\n", numVerts, numInds);

	delete[] pVerts;
}
Beispiel #2
0
void Model::processMesh(FbxMesh *mesh, Data &model) {
  int numVerts = mesh->GetControlPointsCount();
  int numIndices = mesh->GetPolygonVertexCount();

  Vertex * pVerts = new Vertex[numVerts];
  int *pIndices = mesh->GetPolygonVertices();

  for (int i = 0; i < numVerts; i++) {
    FbxVector4 currentVert = mesh->GetControlPointAt(i);
    pVerts[i].position = glm::vec3(currentVert[0], currentVert[1], currentVert[2]);
    pVerts[i].colour = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f);
    pVerts[i].texCoords = glm::vec2(0.0f, 0.0f);
    pVerts[i].binormal = glm::vec3(0.0f, 0.0f, 0.0f);
    pVerts[i].tangentNormal = glm::vec3(0.0f, 0.0f, 0.0f);
  }

  //read normal
  processMeshNormals(mesh, pVerts, numVerts);
  processMeshTextureCoords(mesh, pVerts, numVerts);

  //read texture coordinates
  LOG(INFO) << "Vertices " << numVerts << " Indices " << numIndices;

  calculateTagentAndBinormals(pVerts, numVerts, pIndices, numIndices);

  for (int i = 0; i < numVerts; ++i)
    model.model.back()->vertices.push_back(pVerts[i]);

  for (int i = 0; i < numIndices; ++i)
    model.model.back()->indices.push_back(pIndices[i]);

  if (pVerts) {
    delete [] pVerts;
    pVerts = NULL;
  }
}
void processMesh(FbxMesh * mesh, GameObject *go)
{
	Mesh * meshComponent = new Mesh();
	meshComponent->init();

	int numVerts = mesh->GetControlPointsCount();
	int numIndices = mesh->GetPolygonVertexCount();

	Vertex * pVerts = new Vertex[numVerts];
	int *pIndices = mesh->GetPolygonVertices();

	for (int i = 0; i < numVerts; i++)
	{
		FbxVector4 currentVert = mesh->GetControlPointAt(i);
		pVerts[i].position = vec3(currentVert[0], currentVert[1], currentVert[2]);
		pVerts[i].colours = vec4(1.0f, 1.0f, 1.0f, 1.0f);
		pVerts[i].texCoords = vec2(0.0f, 0.0f);
	}

	//read normal
	processMeshNormals(mesh, pVerts, numVerts);
	processMeshTextureCoords(mesh, pVerts, numVerts);

	//read texture coordinates
	std::cout << "Vertices " << numVerts << " Indices " << numIndices << std::endl;

	meshComponent->copyIndexData(numIndices, sizeof(int), (void**)pIndices);
	meshComponent->copyVertexData(numVerts, sizeof(Vertex), (void**)pVerts);

	go->setMesh(meshComponent);
	if (pVerts)
	{
		delete[] pVerts;
		pVerts = NULL;
	}
}