void		LoaderFbxMesh::parseVertexBinormals(FbxMesh* mesh, int controlPointIndex, int vertexId)
{
	for(int i=0; i<mesh->GetElementBinormalCount(); i++)
	{
		FbxVector4 fbxBinormal(0, 0, 0, 0);
		FbxGeometryElementBinormal* binormalElement = mesh->GetElementBinormal(i);
		switch(binormalElement->GetMappingMode())
		{
		case FbxGeometryElement::eByControlPoint:
			fbxBinormal = parseVertexBinormalsByControlPoint(binormalElement, controlPointIndex);
			break;
		case FbxGeometryElement::eByPolygonVertex:
			fbxBinormal = parseVertexBinormalsByPolygonVertex(binormalElement, vertexId);
			break;
		default:
			break;
		}
		Float4 binormal;
		binormal.x = static_cast<float>(fbxBinormal.mData[0]);
		binormal.y = static_cast<float>(fbxBinormal.mData[1]);
		binormal.z = static_cast<float>(fbxBinormal.mData[2]);
		binormal.w = static_cast<float>(fbxBinormal.mData[3]);
		vertexBinormals_.push_back(binormal);
	}
}
Example #2
0
void FBXImporter::ReadBinormals(FBXMeshData* fbxMeshData, int controlPointIndex, int tangentIndex)
{
	FbxMesh* mesh = fbxMeshData->mMesh;

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

	FbxGeometryElementBinormal* binormalElement = mesh->GetElementBinormal(0);

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

			break;

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

			break;
		default:
			break;
		}
	}

	case FbxGeometryElement::eByPolygonVertex:
	{
		switch (binormalElement->GetReferenceMode())
		{
		case FbxGeometryElement::eDirect:
		{
			FbxVector4 fbxBinormal = binormalElement->GetDirectArray().GetAt(tangentIndex);
			XMFLOAT3 binormal;
			binormal.x = static_cast<float>(fbxBinormal[0]);
			binormal.y = static_cast<float>(fbxBinormal[1]);
			binormal.z = static_cast<float>(fbxBinormal[2]);
			fbxMeshData->mBinormals.push_back(binormal);
		}

			break;
		case FbxGeometryElement::eIndexToDirect:
		{
			int id = binormalElement->GetIndexArray().GetAt(tangentIndex);
			FbxVector4 fbxBinormal = binormalElement->GetDirectArray().GetAt(id);
			XMFLOAT3 binormal;
			binormal.x = static_cast<float>(fbxBinormal[0]);
			binormal.y = static_cast<float>(fbxBinormal[1]);
			binormal.z = static_cast<float>(fbxBinormal[2]);
			fbxMeshData->mBinormals.push_back(binormal);
		}

			break;
		default:
			break;
		}
	}

		break;
	default:
		break;
	}
}
Example #3
0
void loadBinormal(FbxMesh* fbxMesh, int vertexIndex, int controlPointIndex, Vertex* vertex)
{
    if (fbxMesh->GetElementBinormalCount() > 0)
    {
        // Get only the first binormal.
        FbxGeometryElementBinormal* binormal = fbxMesh->GetElementBinormal(0);
        FbxGeometryElement::EMappingMode mappingMode = binormal->GetMappingMode();

        if (mappingMode == FbxGeometryElement::eByControlPoint)
        {
            switch (binormal->GetReferenceMode())
            {
            case FbxGeometryElement::eDirect:
                {
                    FbxVector4 vec4 = binormal->GetDirectArray().GetAt(controlPointIndex);
                    vertex->hasBinormal = true;
                    vertex->binormal.x = (float)vec4[0];
                    vertex->binormal.y = (float)vec4[1];
                    vertex->binormal.z = (float)vec4[2];
                }
                break;
            case FbxGeometryElement::eIndexToDirect:
                {
                    int id = binormal->GetIndexArray().GetAt(controlPointIndex);
                    FbxVector4 vec4 = binormal->GetDirectArray().GetAt(id);
                    vertex->hasBinormal = true;
                    vertex->binormal.x = (float)vec4[0];
                    vertex->binormal.y = (float)vec4[1];
                    vertex->binormal.z = (float)vec4[2];
                }
                break;
            default:
                break;
            }
        }
        else if (mappingMode == FbxGeometryElement::eByPolygonVertex)
        {
            switch (binormal->GetReferenceMode())
            {
            case FbxGeometryElement::eDirect:
                {
                    FbxVector4 vec4 = binormal->GetDirectArray().GetAt(vertexIndex);
                    vertex->hasBinormal = true;
                    vertex->binormal.x = (float)vec4[0];
                    vertex->binormal.y = (float)vec4[1];
                    vertex->binormal.z = (float)vec4[2];
                }
                break;
            case FbxGeometryElement::eIndexToDirect:
                {
                    int id = binormal->GetIndexArray().GetAt(vertexIndex);
                    FbxVector4 vec4 = binormal->GetDirectArray().GetAt(id);
                    vertex->hasBinormal = true;
                    vertex->binormal.x = (float)vec4[0];
                    vertex->binormal.y = (float)vec4[1];
                    vertex->binormal.z = (float)vec4[2];
                }
                break;
            default:
                break;
            }
        }
    }
}
Example #4
0
//===============================================================================================================================
bool FBXLoader::LoadVertexBinormal(FbxMesh* mesh, int inCtrlPointIndex, int inVertexCounter, int binormalElement, XMFLOAT3& outBinormal)
{
	if (mesh->GetElementBinormalCount() < 1)
	{
		throw std::exception("Invalid Binormal Number");
	}
	
	int directIndex = -1;
	
	FbxGeometryElementBinormal* vertexBinormal = mesh->GetElementBinormal(binormalElement);
	
	switch (vertexBinormal->GetMappingMode())
	{
		case FbxGeometryElement::eByControlPoint:
		{
			switch (vertexBinormal->GetReferenceMode())
			{
				case FbxGeometryElement::eDirect:
				{
					directIndex = inCtrlPointIndex;
					//outBinormal.x = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(inCtrlPointIndex).mData[0]);
					//outBinormal.y = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(inCtrlPointIndex).mData[1]);
					//outBinormal.z = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(inCtrlPointIndex).mData[2]);
				}
				break;
				case FbxGeometryElement::eIndexToDirect:
				{
					directIndex = vertexBinormal->GetIndexArray().GetAt(inCtrlPointIndex);
					//int index = vertexBinormal->GetIndexArray().GetAt(inCtrlPointIndex);
					//outBinormal.x = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(index).mData[0]);
					//outBinormal.y = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(index).mData[1]);
					//outBinormal.z = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(index).mData[2]);
				}
				break;
				default: throw std::exception("Invalid Reference");
			}
		}
		break;
		case FbxGeometryElement::eByPolygonVertex:
		{
			switch (vertexBinormal->GetReferenceMode())
			{
				case FbxGeometryElement::eDirect:
				{
					directIndex = inVertexCounter;
					//outBinormal.x = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(inVertexCounter).mData[0]);
					//outBinormal.y = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(inVertexCounter).mData[1]);
					//outBinormal.z = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(inVertexCounter).mData[2]);
				}
				break;
				case FbxGeometryElement::eIndexToDirect:
				{
					directIndex = vertexBinormal->GetIndexArray().GetAt(inVertexCounter);
					//int index = vertexBinormal->GetIndexArray().GetAt(inVertexCounter);
					//outBinormal.x = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(index).mData[0]);
					//outBinormal.y = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(index).mData[1]);
					//outBinormal.z = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(index).mData[2]);
				}
				break;
				default: throw std::exception("Invalid Reference");
			}
		}
		break;
	}
	
	if (directIndex != -1)
	{
		FbxVector4 binorm = vertexBinormal->GetDirectArray().GetAt(directIndex);
		
		outBinormal = XMFLOAT3((float)binorm.mData[0], (float)binorm.mData[1], (float)binorm.mData[2]);
		
		return true;
	}
	
	return false;
}