コード例 #1
0
void		LoaderFbxMesh::parseVertexTangents(FbxMesh* mesh, int controlPointIndex, int vertexId)
{
	for(int i=0; i<mesh->GetElementTangentCount(); i++)
	{
		FbxVector4 fbxTangent(0, 0, 0, 0);
		FbxGeometryElementTangent* tangentElement = mesh->GetElementTangent(i);
		switch(tangentElement->GetMappingMode())
		{
		case FbxGeometryElement::eByControlPoint:
			fbxTangent = parseVertexTangentsByControlPoint(tangentElement, controlPointIndex);
			break;
		case FbxGeometryElement::eByPolygonVertex:
			fbxTangent = parseVertexTangentsByPolygonVertex(tangentElement, vertexId);
			break;
		default:
			break;
		}

		Float4 tangent;
		tangent.x = static_cast<float>(fbxTangent.mData[0]);
		tangent.y = static_cast<float>(fbxTangent.mData[1]);
		tangent.z = static_cast<float>(fbxTangent.mData[2]);
		tangent.w = static_cast<float>(fbxTangent.mData[3]);
		vertexTangents_.push_back(tangent);
	}
}
コード例 #2
0
ファイル: FBXSceneImporter.cpp プロジェクト: Muret/Zephyr
void FBXSceneImporter::read_mesh(FbxNode *pNode, FbxMesh* pMesh)
{
	std::vector<Mesh::Vertex> vertices;
	std::vector<int> indices;
	
	//pMesh->GenerateTangentsDataForAllUVSets();

	Mesh *new_mesh = new Mesh();
	
	new_mesh->set_name(pNode->GetName());

	int polygonCount = pMesh->GetPolygonCount();
	FbxVector4* controlPoints = pMesh->GetControlPoints();
	int controlPointCount = pMesh->GetControlPointsCount();

	int vertexID = 0;

	for (int polygon = polygonCount - 1; polygon > -1; polygon--)
	{
		int polyVertCount = pMesh->GetPolygonSize(polygon);
		assert(polyVertCount == 3);

		for (int polyVert = 0; polyVert < polyVertCount; polyVert++)
		{
			Mesh::Vertex vertex;

			int cpIndex = pMesh->GetPolygonVertex(polygon, polyVert);

			// Grab our CP index as well our position information
			//uniqueVert.m_nControlPointIndex = cpIndex;
			vertex.position[0] = controlPoints[cpIndex].mData[0];
			vertex.position[1] = controlPoints[cpIndex].mData[1];
			vertex.position[2] = controlPoints[cpIndex].mData[2];
			vertex.position[3] = 1;

			// Grab UVs
			int uvElementCount = pMesh->GetElementUVCount();
			int ctrlPointIndex = pMesh->GetPolygonVertex(polygon, polyVert);

			for (int uvElement = 0; uvElement < uvElementCount; uvElement++)
			{
				FbxGeometryElementUV* geomElementUV = pMesh->GetElementUV(uvElement);

				FbxLayerElement::EMappingMode mapMode = geomElementUV->GetMappingMode();
				FbxLayerElement::EReferenceMode refMode = geomElementUV->GetReferenceMode();

				if (FbxGeometryElement::eByControlPoint == mapMode)
				{
					switch (geomElementUV->GetReferenceMode())
					{
					case FbxGeometryElement::eDirect:
					{
						vertex.texture_coord.x = static_cast<float>(geomElementUV->GetDirectArray().GetAt(ctrlPointIndex).mData[0]);
						vertex.texture_coord.y = static_cast<float>(geomElementUV->GetDirectArray().GetAt(ctrlPointIndex).mData[1]);
					}
					break;

					case FbxGeometryElement::eIndexToDirect:
					{
						int index = geomElementUV->GetIndexArray().GetAt(ctrlPointIndex);
						vertex.texture_coord.x = static_cast<float>(geomElementUV->GetDirectArray().GetAt(index).mData[0]);
						vertex.texture_coord.y = static_cast<float>(geomElementUV->GetDirectArray().GetAt(index).mData[1]);
					}
					break;

					default:
						throw std::exception("Invalid Reference");
					}
				}
				if (FbxGeometryElement::eByPolygonVertex == mapMode)
				{
					int directIndex = -1;
					if (FbxGeometryElement::eDirect == refMode)
					{
						directIndex = vertexID;
					}
					else if (FbxGeometryElement::eIndexToDirect == refMode)
					{
						directIndex = geomElementUV->GetIndexArray().GetAt(vertexID);
					}

					// If we got an index
					if (directIndex != -1)
					{
						FbxVector4 texture_coord = geomElementUV->GetDirectArray().GetAt(directIndex);

						vertex.texture_coord = D3DXVECTOR4((float)texture_coord.mData[0], (float)texture_coord.mData[1], 0, 0);
					}
				}
			}

			// Grab normals
			int normElementCount = pMesh->GetElementNormalCount();

			for (int normalElement = 0; normalElement < normElementCount; normalElement++)
			{
				FbxGeometryElementNormal* geomElementNormal = pMesh->GetElementNormal(normalElement);

				FbxLayerElement::EMappingMode mapMode = geomElementNormal->GetMappingMode();
				FbxLayerElement::EReferenceMode refMode = geomElementNormal->GetReferenceMode();

				FbxVector4 fbxNormal;
				pMesh->GetPolygonVertexNormal(polygon, polyVert, fbxNormal);
				fbxNormal.Normalize();

				vertex.normal = D3DXVECTOR4(fbxNormal.mData[0], fbxNormal.mData[1], fbxNormal.mData[2], 0);

				//if (FbxGeometryElement::eByControlPoint == mapMode)
				//{ 
				//	switch (geomElementNormal->GetReferenceMode())
				//	{
				//	case FbxGeometryElement::eDirect:
				//	{
				//		vertex.normal.x = static_cast<float>(geomElementNormal->GetDirectArray().GetAt(ctrlPointIndex).mData[0]);
				//		vertex.normal.y = static_cast<float>(geomElementNormal->GetDirectArray().GetAt(ctrlPointIndex).mData[1]);
				//		vertex.normal.z = static_cast<float>(geomElementNormal->GetDirectArray().GetAt(ctrlPointIndex).mData[2]);
				//		D3DXVec4Normalize(&vertex.normal, &vertex.normal);
				//	}
				//	break;
				//
				//	case FbxGeometryElement::eIndexToDirect:
				//	{
				//		int index = geomElementNormal->GetIndexArray().GetAt(ctrlPointIndex);
				//		vertex.normal.x = static_cast<float>(geomElementNormal->GetDirectArray().GetAt(index).mData[0]);
				//		vertex.normal.y = static_cast<float>(geomElementNormal->GetDirectArray().GetAt(index).mData[1]);
				//		vertex.normal.z = static_cast<float>(geomElementNormal->GetDirectArray().GetAt(index).mData[2]);
				//		D3DXVec4Normalize(&vertex.normal, &vertex.normal);
				//	}
				//	break;
				//
				//	default:
				//		throw std::exception("Invalid Reference");
				//	}
				//}
				//if (FbxGeometryElement::eByPolygonVertex == mapMode)
				//{
				//	int directIndex = -1;
				//	if (FbxGeometryElement::eDirect == refMode)
				//	{
				//		directIndex = vertexID;
				//	}
				//	else if (FbxGeometryElement::eIndexToDirect == refMode)
				//	{
				//		directIndex = geomElementNormal->GetIndexArray().GetAt(vertexID);
				//	}
				//
				//	// If we got an index
				//	if (directIndex != -1)
				//	{
				//		FbxVector4 norm = geomElementNormal->GetDirectArray().GetAt(directIndex);
				//
				//		D3DXVECTOR4 normal_final((float)norm.mData[0], (float)norm.mData[1], (float)norm.mData[2], 0);
				//		D3DXVec4Normalize(&vertex.normal, &normal_final);
				//	}
				//}


			}

			// grab tangents
			int tangentElementCount = pMesh->GetElementTangentCount();

			for (int normalElement = 0; normalElement < tangentElementCount; normalElement++)
			{
				FbxGeometryElementTangent* geomElementTangent = pMesh->GetElementTangent(normalElement);

				FbxLayerElement::EMappingMode mapMode = geomElementTangent->GetMappingMode();
				FbxLayerElement::EReferenceMode refMode = geomElementTangent->GetReferenceMode();

				int directIndex = -1;

				if (FbxGeometryElement::eByPolygonVertex == mapMode)
				{
					if (FbxGeometryElement::eDirect == refMode)
					{
						directIndex = vertexID;
					}
					else if (FbxGeometryElement::eIndexToDirect == refMode)
					{
						directIndex = geomElementTangent->GetIndexArray().GetAt(vertexID);
					}
				}

				// If we got an index
				if (directIndex != 1)
				{
					FbxVector4 tangent = geomElementTangent->GetDirectArray().GetAt(directIndex);

					vertex.tangent = D3DXVECTOR4((float)tangent.mData[0], (float)tangent.mData[1], (float)tangent.mData[2], 0);
				}

			}

			size_t size = vertices.size();
			size_t i = size;

			//for (i = 0; i < size; i++)
			//{
			//	if (vertex == vertices[i])
			//	{
			//		break;
			//	}
			//}
			//
			if (i == size)
			{
				vertices.push_back(vertex);
			}

			indices.push_back(i);
			++vertexID;
		}

		//int cur_size = indices.size();
		//int temp = indices[cur_size - 3];
		//indices[cur_size - 3] = indices[cur_size - 1];
		//indices[cur_size - 1] = temp;
	}

	int materialCount = pNode->GetSrcObjectCount<FbxSurfaceMaterial>();

	new_mesh->create_from_buffers(vertices, indices);
	scene_to_fill->add_mesh(new_mesh);

	if (materialCount > 0)
	{
		FbxSurfaceMaterial* material = (FbxSurfaceMaterial*)pNode->GetSrcObject<FbxSurfaceMaterial>(0);
		new_mesh->set_material(read_material(pNode, material));
	}

	get_transformation_matrix(pNode, new_mesh);
	cout << "Read mesh : " << new_mesh->get_name() << "\n";

}
コード例 #3
0
ファイル: FbxUtil.cpp プロジェクト: sunwaylive/fury3d
	std::shared_ptr<Mesh> FbxUtil::CreateMesh(FbxMesh *fbxMesh)
	{
		Mesh::Ptr mesh = Mesh::Create(fbxMesh->GetName());

		// read physical data.

		int polygonCount = fbxMesh->GetPolygonCount();
		int indicesCount = polygonCount * 3;

		mesh->Positions.Data.reserve(indicesCount * 3);
		mesh->Indices.Data.reserve(indicesCount);

		if ((m_Options & Options::UV) && fbxMesh->GetElementUVCount() > 0)
			mesh->UVs.Data.reserve(indicesCount * 2);

		if ((m_Options & Options::NORMAL) && fbxMesh->GetElementNormalCount() > 0)
			mesh->Normals.Data.reserve(indicesCount * 3);

		if ((m_Options & Options::TANGENT) && fbxMesh->GetElementTangent() > 0)
			mesh->Tangents.Data.reserve(indicesCount * 3);

		int normalCounter = 0, uvCounter = 0, tangentCounter = 0;

		for (int i = 0; i < polygonCount; i++)
		{
			for (int j = 0; j < 3; j++)
			{
				int ctrPtrIndex = fbxMesh->GetPolygonVertex(i, j);

				auto position = fbxMesh->GetControlPointAt(ctrPtrIndex);
				mesh->Positions.Data.push_back((float)position.mData[0]);
				mesh->Positions.Data.push_back((float)position.mData[1]);
				mesh->Positions.Data.push_back((float)position.mData[2]);

				// uv
				if ((m_Options & Options::UV) && fbxMesh->GetElementUVCount() > 0)
				{
					int uvIndex = 0;
					FbxGeometryElementUV* vertexUV = fbxMesh->GetElementUV();

					if (vertexUV->GetMappingMode() == FbxGeometryElement::eByControlPoint)
					{
						if (vertexUV->GetReferenceMode() == FbxGeometryElement::eDirect)
							uvIndex = ctrPtrIndex;
						else if (vertexUV->GetReferenceMode() == FbxGeometryElement::eIndexToDirect)
							uvIndex = vertexUV->GetIndexArray().GetAt(ctrPtrIndex);
						else
							ASSERT_MSG(false, "Error: Invalid Reference Mode!");
					}
					else if (vertexUV->GetMappingMode() == FbxGeometryElement::eByPolygonVertex)
					{
						if (vertexUV->GetReferenceMode() == FbxGeometryElement::eDirect)
							uvIndex = uvCounter;
						else if (vertexUV->GetReferenceMode() == FbxGeometryElement::eIndexToDirect)
							uvIndex = vertexUV->GetIndexArray().GetAt(uvCounter);
						else
							ASSERT_MSG(false, "Error: Invalid Reference Mode!");

						uvCounter++;
					}

					auto uv = vertexUV->GetDirectArray().GetAt(uvIndex);
					mesh->UVs.Data.push_back((float)uv.mData[0]);
					mesh->UVs.Data.push_back(1.0f - (float)uv.mData[1]);
				}

				// normal
				if ((m_Options & Options::NORMAL) && fbxMesh->GetElementNormalCount() > 0)
				{
					int normalIndex = 0;
					FbxGeometryElementNormal* vertexNormal = fbxMesh->GetElementNormal();

					if (vertexNormal->GetMappingMode() == FbxGeometryElement::eByControlPoint)
					{
						if (vertexNormal->GetReferenceMode() == FbxGeometryElement::eDirect)
							normalIndex = ctrPtrIndex;
						else if (vertexNormal->GetReferenceMode() == FbxGeometryElement::eIndexToDirect)
							normalIndex = vertexNormal->GetIndexArray().GetAt(ctrPtrIndex);
						else
							ASSERT_MSG(false, "Error: Invalid Reference Mode!");
					}
					else if (vertexNormal->GetMappingMode() == FbxGeometryElement::eByPolygonVertex)
					{
						if (vertexNormal->GetReferenceMode() == FbxGeometryElement::eDirect)
							normalIndex = normalCounter;
						else if (vertexNormal->GetReferenceMode() == FbxGeometryElement::eIndexToDirect)
							normalIndex = vertexNormal->GetIndexArray().GetAt(normalCounter);
						else
							ASSERT_MSG(false, "Error: Invalid Reference Mode!");

						normalCounter++;
					}

					auto normal = vertexNormal->GetDirectArray().GetAt(normalIndex);
					mesh->Normals.Data.push_back((float)normal.mData[0]);
					mesh->Normals.Data.push_back((float)normal.mData[1]);
					mesh->Normals.Data.push_back((float)normal.mData[2]);
				}

				// tangent
				if ((m_Options & Options::TANGENT) && fbxMesh->GetElementNormalCount() > 0)
				{
					int tangentIndex = 0;
					FbxGeometryElementTangent* vertexTangent = fbxMesh->GetElementTangent();

					if (vertexTangent->GetMappingMode() == FbxGeometryElement::eByControlPoint)
					{
						if (vertexTangent->GetReferenceMode() == FbxGeometryElement::eDirect)
							tangentIndex = ctrPtrIndex;
						else if (vertexTangent->GetReferenceMode() == FbxGeometryElement::eIndexToDirect)
							tangentIndex = vertexTangent->GetIndexArray().GetAt(ctrPtrIndex);
						else
							ASSERT_MSG(false, "Error: Invalid Reference Mode!");
					}
					else if (vertexTangent->GetMappingMode() == FbxGeometryElement::eByPolygonVertex)
					{
						if (vertexTangent->GetReferenceMode() == FbxGeometryElement::eDirect)
							tangentIndex = tangentCounter;
						else if (vertexTangent->GetReferenceMode() == FbxGeometryElement::eIndexToDirect)
							tangentIndex = vertexTangent->GetIndexArray().GetAt(tangentCounter);
						else
							ASSERT_MSG(false, "Error: Invalid Reference Mode!");

						tangentCounter++;
					}

					auto tangent = vertexTangent->GetDirectArray().GetAt(tangentIndex);
					mesh->Tangents.Data.push_back((float)tangent.mData[0]);
					mesh->Tangents.Data.push_back((float)tangent.mData[1]);
					mesh->Tangents.Data.push_back((float)tangent.mData[2]);
				}

				mesh->Indices.Data.push_back(i * 3 + j);
			}
		}

		LOGD << mesh->GetName() << " [vtx: " << mesh->Positions.Data.size() / 3 << " tris: " << mesh->Indices.Data.size() / 3 << "]";

		if(m_Options & Options::OPTIMIZE_MESH)
			MeshUtil::Instance()->OptimizeMesh(mesh);

		mesh->CalculateAABB();

		return mesh;
	}
コード例 #4
0
ファイル: FBXImporter.cpp プロジェクト: mangosyx/DX11Study
void FBXImporter::ReadTangents(FBXMeshData* fbxMeshData, int controlPointIndex, int tangentIndex)
{
	FbxMesh* mesh = fbxMeshData->mMesh;

	if (mesh->GetElementTangentCount() < 1)
	{
		return;
	}

	FbxGeometryElementTangent* tangentElement = mesh->GetElementTangent(0);

	switch (tangentElement->GetMappingMode())
	{
	case FbxGeometryElement::eByControlPoint:
	{
		switch (tangentElement->GetReferenceMode())
		{
		case FbxGeometryElement::eDirect:
		{
			FbxVector4 fbxTangent = tangentElement->GetDirectArray().GetAt(controlPointIndex);
			XMFLOAT3 tangent;
			tangent.x = static_cast<float>(fbxTangent[0]);
			tangent.y = static_cast<float>(fbxTangent[1]);
			tangent.z = static_cast<float>(fbxTangent[2]);
			fbxMeshData->mTangents.push_back(tangent);
		}

		break;

		case FbxGeometryElement::eIndexToDirect:
		{
			int id = tangentElement->GetIndexArray().GetAt(controlPointIndex);
			FbxVector4 fbxTangent = tangentElement->GetDirectArray().GetAt(id);
			XMFLOAT3 tangent;
			tangent.x = static_cast<float>(fbxTangent[0]);
			tangent.y = static_cast<float>(fbxTangent[1]);
			tangent.z = static_cast<float>(fbxTangent[2]);
			fbxMeshData->mTangents.push_back(tangent);
		}

		break;
		default:

		break;
		}
	}

	case FbxGeometryElement::eByPolygonVertex:
	{
		switch (tangentElement->GetReferenceMode())
		{
		case FbxGeometryElement::eDirect:
		{
			FbxVector4 fbxTangent = tangentElement->GetDirectArray().GetAt(tangentIndex);
			XMFLOAT3 tangent;
			tangent.x = static_cast<float>(fbxTangent[0]);
			tangent.y = static_cast<float>(fbxTangent[1]);
			tangent.z = static_cast<float>(fbxTangent[2]);
			fbxMeshData->mTangents.push_back(tangent);
		}
			
		break;
		case FbxGeometryElement::eIndexToDirect:
		{
			int id = tangentElement->GetIndexArray().GetAt(tangentIndex);
			FbxVector4 fbxTangent = tangentElement->GetDirectArray().GetAt(id);
			XMFLOAT3 tangent;
			tangent.x = static_cast<float>(fbxTangent[0]);
			tangent.y = static_cast<float>(fbxTangent[1]);
			tangent.z = static_cast<float>(fbxTangent[2]);
			fbxMeshData->mTangents.push_back(tangent);
		}
		
		break;
		default:
			break;
		}
	}

		//break;
	default:
		break;
	}
}
コード例 #5
0
ファイル: FBXUtil.cpp プロジェクト: Black-Squirrel/GamePlay
void loadTangent(FbxMesh* fbxMesh, int vertexIndex, int controlPointIndex, Vertex* vertex)
{
    if (fbxMesh->GetElementTangentCount() > 0)
    {
        // Get only the first tangent
        FbxGeometryElementTangent* tangent = fbxMesh->GetElementTangent(0);
        FbxGeometryElement::EMappingMode mappingMode = tangent->GetMappingMode();
        if (mappingMode == FbxGeometryElement::eByControlPoint)
        {
            switch (tangent->GetReferenceMode())
            {
            case FbxGeometryElement::eDirect:
                {
                    FbxVector4 vec4 = tangent->GetDirectArray().GetAt(controlPointIndex);
                    vertex->hasTangent = true;
                    vertex->tangent.x = (float)vec4[0];
                    vertex->tangent.y = (float)vec4[1];
                    vertex->tangent.z = (float)vec4[2];
                }
                break;
            case FbxGeometryElement::eIndexToDirect:
                {
                    int id = tangent->GetIndexArray().GetAt(controlPointIndex);
                    FbxVector4 vec4 = tangent->GetDirectArray().GetAt(id);
                    vertex->hasTangent = true;
                    vertex->tangent.x = (float)vec4[0];
                    vertex->tangent.y = (float)vec4[1];
                    vertex->tangent.z = (float)vec4[2];
                }
                break;
            default:
                break;
            }
        }
        else if (mappingMode == FbxGeometryElement::eByPolygonVertex)
        {
            switch (tangent->GetReferenceMode())
            {
            case FbxGeometryElement::eDirect:
                {
                    FbxVector4 vec4 = tangent->GetDirectArray().GetAt(vertexIndex);
                    vertex->hasTangent = true;
                    vertex->tangent.x = (float)vec4[0];
                    vertex->tangent.y = (float)vec4[1];
                    vertex->tangent.z = (float)vec4[2];
                }
                break;
            case FbxGeometryElement::eIndexToDirect:
                {
                    int id = tangent->GetIndexArray().GetAt(vertexIndex);
                    FbxVector4 vec4 = tangent->GetDirectArray().GetAt(id);
                    vertex->hasTangent = true;
                    vertex->tangent.x = (float)vec4[0];
                    vertex->tangent.y = (float)vec4[1];
                    vertex->tangent.z = (float)vec4[2];
                }
                break;
            default:
                break;
            }
        }
    }
}
コード例 #6
0
void fbxLoader2::readTangent(FbxMesh* mesh, int controlPointIndex, int vertexCounter, D3DXVECTOR3* tangent)
{
	if(mesh->GetElementTangentCount() < 1)
	{
		return;
	}

	FbxGeometryElementTangent* tangentEl = mesh->GetElementTangent(0);

	switch(tangentEl->GetMappingMode())
	{
	case FbxGeometryElement::eByControlPoint:
		{
			switch(tangentEl->GetReferenceMode())
			{
			case FbxGeometryElement::eDirect:
				{
					tangent->x = (float)tangentEl->GetDirectArray().GetAt(controlPointIndex).mData[0];
					tangent->y = (float)tangentEl->GetDirectArray().GetAt(controlPointIndex).mData[1];
					tangent->z = (float)tangentEl->GetDirectArray().GetAt(controlPointIndex).mData[2];
				}
				break;

			case FbxGeometryElement::eIndexToDirect:
				{
					int id = tangentEl->GetIndexArray().GetAt(controlPointIndex);
					tangent->x = (float)tangentEl->GetDirectArray().GetAt(id).mData[0];
					tangent->y = (float)tangentEl->GetDirectArray().GetAt(id).mData[1];
					tangent->z = (float)tangentEl->GetDirectArray().GetAt(id).mData[2];
				}
				break;
			}
		}
		break;

	case FbxGeometryElement::eByPolygonVertex:
		{
			switch(tangentEl->GetReferenceMode())
			{
			case FbxGeometryElement::eDirect:
				{
					tangent->x = (float)tangentEl->GetDirectArray().GetAt(vertexCounter).mData[0];
					tangent->y = (float)tangentEl->GetDirectArray().GetAt(vertexCounter).mData[1];
					tangent->z = (float)tangentEl->GetDirectArray().GetAt(vertexCounter).mData[2];
				}
				break;

			case FbxGeometryElement::eIndexToDirect:
				{
					int id = tangentEl->GetIndexArray().GetAt(vertexCounter);
					tangent->x = (float)tangentEl->GetDirectArray().GetAt(id).mData[0];
					tangent->y = (float)tangentEl->GetDirectArray().GetAt(id).mData[1];
					tangent->z = (float)tangentEl->GetDirectArray().GetAt(id).mData[2];
				}
				break;
			}
		}
		break;
	}
}
コード例 #7
0
ファイル: FBXLoader.cpp プロジェクト: henriyl/ZShadeSandbox
//===============================================================================================================================
bool FBXLoader::LoadVertexTangent(FbxMesh* mesh, int inCtrlPointIndex, int inVertexCounter, int tangentElement, XMFLOAT3& outTangent)
{
	if (mesh->GetElementTangentCount() < 1)
	{
		throw std::exception("Invalid Tangent Number");
	}
	
	int directIndex = -1;
	
	FbxGeometryElementTangent* vertexTangent = mesh->GetElementTangent(tangentElement);
	
	switch (vertexTangent->GetMappingMode())
	{
		case FbxGeometryElement::eByControlPoint:
		{
			switch (vertexTangent->GetReferenceMode())
			{
				case FbxGeometryElement::eDirect:
				{
					directIndex = inCtrlPointIndex;
					//outTangent.x = static_cast<float>(vertexTangent->GetDirectArray().GetAt(inCtrlPointIndex).mData[0]);
					//outTangent.y = static_cast<float>(vertexTangent->GetDirectArray().GetAt(inCtrlPointIndex).mData[1]);
					//outTangent.z = static_cast<float>(vertexTangent->GetDirectArray().GetAt(inCtrlPointIndex).mData[2]);
				}
				break;
				case FbxGeometryElement::eIndexToDirect:
				{
					directIndex = vertexTangent->GetIndexArray().GetAt(inCtrlPointIndex);
					//int index = vertexTangent->GetIndexArray().GetAt(inCtrlPointIndex);
					//outTangent.x = static_cast<float>(vertexTangent->GetDirectArray().GetAt(index).mData[0]);
					//outTangent.y = static_cast<float>(vertexTangent->GetDirectArray().GetAt(index).mData[1]);
					//outTangent.z = static_cast<float>(vertexTangent->GetDirectArray().GetAt(index).mData[2]);
				}
				break;
				default: throw std::exception("Invalid Reference");
			}
		}
		break;
		case FbxGeometryElement::eByPolygonVertex:
		{
			switch (vertexTangent->GetReferenceMode())
			{
				case FbxGeometryElement::eDirect:
				{
					directIndex = inVertexCounter;
					//outTangent.x = static_cast<float>(vertexTangent->GetDirectArray().GetAt(inVertexCounter).mData[0]);
					//outTangent.y = static_cast<float>(vertexTangent->GetDirectArray().GetAt(inVertexCounter).mData[1]);
					//outTangent.z = static_cast<float>(vertexTangent->GetDirectArray().GetAt(inVertexCounter).mData[2]);
				}
				break;
				case FbxGeometryElement::eIndexToDirect:
				{
					directIndex = vertexTangent->GetIndexArray().GetAt(inVertexCounter);
					//int index = vertexTangent->GetIndexArray().GetAt(inVertexCounter);
					//outTangent.x = static_cast<float>(vertexTangent->GetDirectArray().GetAt(index).mData[0]);
					//outTangent.y = static_cast<float>(vertexTangent->GetDirectArray().GetAt(index).mData[1]);
					//outTangent.z = static_cast<float>(vertexTangent->GetDirectArray().GetAt(index).mData[2]);
				}
				break;
				default: throw std::exception("Invalid Reference");
			}
		}
		break;
	}
	
	if (directIndex != -1)
	{
		FbxVector4 tan = vertexTangent->GetDirectArray().GetAt(directIndex);
		
		outTangent = XMFLOAT3((float)tan.mData[0], (float)tan.mData[1], (float)tan.mData[2]);
		
		return true;
	}
	
	return false;
}
コード例 #8
0
ファイル: FbxCommon.cpp プロジェクト: whwayne/otokowantmiku
void ReadTangent(FbxMesh* pMesh , int ctrlPointIndex , int vertecCounter , D3DXVECTOR3* pTangent)  
{  
	if(pMesh->GetElementTangentCount() < 1)  
	{  
		return;  
	}  

	FbxGeometryElementTangent* leTangent = pMesh->GetElementTangent(0);  

	switch(leTangent->GetMappingMode())  
	{  
	case FbxGeometryElement::eByControlPoint:  
		{  
			switch(leTangent->GetReferenceMode())  
			{  
			case FbxGeometryElement::eDirect:  
				{  
					pTangent->x = leTangent->GetDirectArray().GetAt(ctrlPointIndex)[0];  
					pTangent->y = leTangent->GetDirectArray().GetAt(ctrlPointIndex)[1];  
					pTangent->z = leTangent->GetDirectArray().GetAt(ctrlPointIndex)[2];  
				}  
				break;  

			case FbxGeometryElement::eIndexToDirect:  
				{  
					int id = leTangent->GetIndexArray().GetAt(ctrlPointIndex);  
					pTangent->x = leTangent->GetDirectArray().GetAt(id)[0];  
					pTangent->y = leTangent->GetDirectArray().GetAt(id)[1];  
					pTangent->z = leTangent->GetDirectArray().GetAt(id)[2];  
				}  
				break;  

			default:  
				break;  
			}  
		}  
		break;  

	case FbxGeometryElement::eByPolygonVertex:  
		{  
			switch(leTangent->GetReferenceMode())  
			{  
			case FbxGeometryElement::eDirect:  
				{  
					pTangent->x = leTangent->GetDirectArray().GetAt(vertecCounter)[0];  
					pTangent->y = leTangent->GetDirectArray().GetAt(vertecCounter)[1];  
					pTangent->z = leTangent->GetDirectArray().GetAt(vertecCounter)[2];  
				}  
				break;  

			case FbxGeometryElement::eIndexToDirect:  
				{  
					int id = leTangent->GetIndexArray().GetAt(vertecCounter);  
					pTangent->x = leTangent->GetDirectArray().GetAt(id)[0];  
					pTangent->y = leTangent->GetDirectArray().GetAt(id)[1];  
					pTangent->z = leTangent->GetDirectArray().GetAt(id)[2];  
				}  
				break;  

			default:  
				break;  
			}  
		}  
		break;  
	}  
}