protected override void CheckScene(FbxScene scene) { base.CheckScene(scene); FbxScene origScene = CreateScene(FbxManager); Assert.IsNotNull(origScene); // Retrieve the mesh from each scene FbxMesh origMesh = origScene.GetRootNode().GetChild(0).GetMesh(); FbxMesh importMesh = scene.GetRootNode().GetChild(0).GetMesh(); // get the layers FbxLayer origLayer = origMesh.GetLayer(0 /* default layer */); FbxLayer importLayer = importMesh.GetLayer(0 /* default layer */); // Check normals CheckFbxElementVector4(origLayer.GetNormals(), importLayer.GetNormals()); // Check binormals CheckFbxElementVector4(origLayer.GetBinormals(), importLayer.GetBinormals()); // Check tangents CheckFbxElementVector4(origLayer.GetTangents(), importLayer.GetTangents()); // Check vertex colors var origVertexColorElement = origLayer.GetVertexColors(); var importVertexColorElement = importLayer.GetVertexColors(); Assert.AreEqual(origVertexColorElement.GetMappingMode(), importVertexColorElement.GetMappingMode()); Assert.AreEqual(origVertexColorElement.GetReferenceMode(), importVertexColorElement.GetReferenceMode()); var origVertexColorElementArray = origVertexColorElement.GetDirectArray(); var importVertexColorElementArray = importVertexColorElement.GetDirectArray(); Assert.AreEqual(origVertexColorElementArray.GetCount(), importVertexColorElementArray.GetCount()); for (int i = 0; i < origVertexColorElementArray.GetCount(); i++) { Assert.AreEqual(origVertexColorElementArray.GetAt(i), importVertexColorElementArray.GetAt(i)); } // Check UVs var origUVElement = origLayer.GetUVs(); var importUVElement = importLayer.GetUVs(); Assert.AreEqual(origUVElement.GetMappingMode(), importUVElement.GetMappingMode()); Assert.AreEqual(origUVElement.GetReferenceMode(), importUVElement.GetReferenceMode()); var origUVElementArray = origUVElement.GetDirectArray(); var importUVElementArray = importUVElement.GetDirectArray(); Assert.AreEqual(origUVElementArray.GetCount(), importUVElementArray.GetCount()); for (int i = 0; i < origUVElementArray.GetCount(); i++) { Assert.AreEqual(origUVElementArray.GetAt(i), importUVElementArray.GetAt(i)); } var origUVElementIndex = origUVElement.GetIndexArray(); var importUVElementIndex = origUVElement.GetIndexArray(); Assert.AreEqual(origUVElementIndex.GetCount(), importUVElementIndex.GetCount()); for (int i = 0; i < origUVElementIndex.GetCount(); i++) { Assert.AreEqual(origUVElementIndex.GetAt(i), importUVElementIndex.GetAt(i)); } }
protected override void CheckScene(FbxScene scene) { base.CheckScene(scene); FbxScene origScene = CreateScene(FbxManager); Assert.IsNotNull(origScene); // Retrieve the mesh from each scene FbxMesh origMesh = origScene.GetRootNode().GetChild(0).GetMesh(); FbxMesh importMesh = scene.GetRootNode().GetChild(0).GetMesh(); // get the layers FbxLayer origLayer = origMesh.GetLayer(0 /* default layer */); FbxLayer importLayer = importMesh.GetLayer(0 /* default layer */); // Check UVs var origUVElement = origLayer.GetUVs(); var importUVElement = importLayer.GetUVs(); Assert.AreEqual(origUVElement.GetMappingMode(), importUVElement.GetMappingMode()); Assert.AreEqual(origUVElement.GetReferenceMode(), importUVElement.GetReferenceMode()); var origUVElementArray = origUVElement.GetDirectArray(); var importUVElementArray = importUVElement.GetDirectArray(); Assert.AreEqual(origUVElementArray.GetCount(), importUVElementArray.GetCount()); for (int i = 0; i < origUVElementArray.GetCount(); i++) { Assert.AreEqual(origUVElementArray.GetAt(i), importUVElementArray.GetAt(i)); } var origUVElementIndex = origUVElement.GetIndexArray(); var importUVElementIndex = origUVElement.GetIndexArray(); Assert.AreEqual(origUVElementIndex.GetCount(), importUVElementIndex.GetCount()); for (int i = 0; i < origUVElementIndex.GetCount(); i++) { Assert.AreEqual(origUVElementIndex.GetAt(i), importUVElementIndex.GetAt(i)); } // Check material and texture var origNode = origScene.GetRootNode().GetChild(0); int origMatIndex = origNode.GetMaterialIndex(m_materialName); Assert.GreaterOrEqual(origMatIndex, 0); var origMaterial = origNode.GetMaterial(origMatIndex); Assert.IsNotNull(origMaterial); var importNode = scene.GetRootNode().GetChild(0); int importMatIndex = importNode.GetMaterialIndex(m_materialName); Assert.GreaterOrEqual(importMatIndex, 0); var importMaterial = importNode.GetMaterial(importMatIndex); Assert.IsNotNull(importMaterial); // TODO: Add ability to Downcast the material to an FbxSurfacePhong. Property[] materialProperties = { new Property(FbxSurfaceMaterial.sDiffuse, PropertyType.Color), new Property(FbxSurfaceMaterial.sEmissive, PropertyType.Color), new Property(FbxSurfaceMaterial.sAmbient, PropertyType.Double3), new Property(FbxSurfaceMaterial.sSpecular, PropertyType.Double3), new Property(FbxSurfaceMaterial.sBumpFactor, PropertyType.Double) }; FbxProperty origMaterialDiffuseProperty = null; FbxProperty importMaterialDiffuseProperty = null; foreach (var prop in materialProperties) { FbxProperty origProp = origMaterial.FindProperty(prop.name); Assert.IsNotNull(origProp); Assert.IsTrue(origProp.IsValid()); FbxProperty importProp = importMaterial.FindProperty(prop.name); Assert.IsNotNull(importProp); Assert.IsTrue(importProp.IsValid()); switch (prop.type) { case PropertyType.Color: Assert.AreEqual(origProp.GetFbxColor(), importProp.GetFbxColor()); break; case PropertyType.Double3: Assert.AreEqual(origProp.GetFbxDouble3(), importProp.GetFbxDouble3()); break; case PropertyType.Double: Assert.AreEqual(origProp.GetDouble(), importProp.GetDouble()); break; default: break; } if (prop.name.Equals(FbxSurfaceMaterial.sDiffuse)) { origMaterialDiffuseProperty = origProp; importMaterialDiffuseProperty = importProp; } } Assert.IsNotNull(origMaterialDiffuseProperty); Assert.IsNotNull(importMaterialDiffuseProperty); var origTexture = origMaterialDiffuseProperty.FindSrcObject(FbxSurfaceMaterial.sDiffuse + "_Texture"); Assert.IsNotNull(origTexture); var importTexture = importMaterialDiffuseProperty.FindSrcObject(FbxSurfaceMaterial.sDiffuse + "_Texture"); Assert.IsNotNull(importTexture); // TODO: Trying to Downcast the texture to an FbxFileTexture returns a null value, // need to figure out how to fix this so we can access the texture properties. /*Assert.AreEqual (origTexture.GetFileName (), importTexture.GetFileName ()); * Assert.AreEqual (origTexture.GetTextureUse (), importTexture.GetTextureUse ()); * Assert.AreEqual (origTexture.GetMappingType (), importTexture.GetMappingType ());*/ }
/// <summary> /// Process UV data and configure the Mesh's UV attributes /// </summary> private void ProcessUVs(FbxMesh fbxMesh, Mesh unityMesh, int maxUVs = 4) { // Import UV sets (maximum defined by maxUVs) int uvsetIndex = 0; // First just try importing diffuse UVs from separate layers // (Maya exports that way) FbxLayerElementUV fbxFirstUVSet = null; FbxLayer fbxFirstUVLayer = null; // NOTE: assuming triangles int polygonIndexCount = fbxMesh.GetPolygonVertexCount(); int vertexCount = fbxMesh.GetControlPointsCount(); int [] polygonVertexIndices = new int [polygonIndexCount]; int j = 0; for (int polyIndex = 0; polyIndex < fbxMesh.GetPolygonCount(); ++polyIndex) { for (int positionInPolygon = 0; positionInPolygon < fbxMesh.GetPolygonSize(polyIndex); ++positionInPolygon) { polygonVertexIndices [j++] = fbxMesh.GetPolygonVertex(polyIndex, positionInPolygon); } } for (int i = 0; i < fbxMesh.GetLayerCount(); i++) { FbxLayer fbxLayer = fbxMesh.GetLayer(i); if (fbxLayer == null) { continue; } FbxLayerElementUV fbxUVSet = fbxLayer.GetUVs(); if (fbxUVSet == null) { continue; } if (fbxFirstUVSet != null) { fbxFirstUVSet = fbxUVSet; fbxFirstUVLayer = fbxLayer; } switch (uvsetIndex) { case 0: unityMesh.uv = ProcessUVSet(fbxUVSet, polygonVertexIndices, vertexCount); break; case 1: unityMesh.uv2 = ProcessUVSet(fbxUVSet, polygonVertexIndices, vertexCount); break; case 2: unityMesh.uv3 = ProcessUVSet(fbxUVSet, polygonVertexIndices, vertexCount); break; case 3: unityMesh.uv4 = ProcessUVSet(fbxUVSet, polygonVertexIndices, vertexCount); break; } uvsetIndex++; if (uvsetIndex == maxUVs) { break; } } // If we have received one UV set, check whether the same layer contains an emissive UV set // that is different from diffuse UV set. // 3dsmax FBX exporters doesn't export UV sets as different layers, instead for lightmapping usually // a material is set up to have lightmap (2nd UV set) as self-illumination slot, and main texture // (1st UV set) as diffuse slot. if (uvsetIndex == 1 && fbxFirstUVSet != null) { FbxLayerElementUV fbxSecondaryUVSet = null; // TODO: check if we've already passed eTextureEmissive layer for (int i = (int)FbxLayerElement.EType.eTextureEmissive; i < (int)FbxLayerElement.EType.eTypeCount; i++) { fbxSecondaryUVSet = fbxFirstUVLayer.GetUVs((FbxLayerElement.EType)i); if (fbxSecondaryUVSet != null) { break; } if (fbxSecondaryUVSet != null) { unityMesh.uv2 = ProcessUVSet(fbxSecondaryUVSet, polygonVertexIndices, vertexCount); uvsetIndex++; } } } }