/// <summary> /// Export the mesh's vertex color using layer 0. /// </summary> /// public void ExportVertexColors(MeshInfo mesh, FbxMesh fbxMesh) { // Set the normals on Layer 0. FbxLayer fbxLayer = fbxMesh.GetLayer(0 /* default layer */); if (fbxLayer == null) { fbxMesh.CreateLayer(); fbxLayer = fbxMesh.GetLayer(0 /* default layer */); } using (var fbxLayerElement = FbxLayerElementVertexColor.Create(fbxMesh, "VertexColors")) { fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); // TODO: normals for each triangle vertex instead of averaged per control point //fbxNormalLayer.SetMappingMode (FbxLayerElement.eByPolygonVertex); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); // Add one normal per each vertex face index (3 per triangle) FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); for (int n = 0; n < mesh.VertexColors.Length; n++) { // Converting to Color from Color32, as Color32 stores the colors // as ints between 0-255, while FbxColor and Color // use doubles between 0-1 Color color = mesh.VertexColors [n]; fbxElementArray.Add(new FbxColor(color.r, color.g, color.b, color.a)); } fbxLayer.SetVertexColors(fbxLayerElement); } }
/// <summary> /// Export the mesh's UVs using layer 0. /// </summary> /// public void ExportUVs(MeshInfo mesh, FbxMesh fbxMesh) { using (var fbxLayerElement = FbxLayerElementUV.Create(fbxMesh, "UVSet")) { fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByPolygonVertex); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eIndexToDirect); // set texture coordinates per vertex FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); for (int n = 0; n < mesh.UV.Length; n++) { fbxElementArray.Add(new FbxVector2(mesh.UV [n] [0], mesh.UV [n] [1])); } // For each face index, point to a texture uv FbxLayerElementArray fbxIndexArray = fbxLayerElement.GetIndexArray(); fbxIndexArray.SetCount(mesh.Indices.Length); for (int vertIndex = 0; vertIndex < mesh.Indices.Length; vertIndex++) { fbxIndexArray.SetAt(vertIndex, mesh.Indices [vertIndex]); } GetBaseLayer(fbxMesh).SetUVs(fbxLayerElement, FbxLayerElement.EType.eTextureDiffuse); } }
public FbxLayerElementArray assign(SWIGTYPE_p_FbxArrayT_FbxColor_t pArrayTemplate) { FbxLayerElementArray ret = new FbxLayerElementArray(FbxWrapperNativePINVOKE.FbxLayerElementArrayTemplateFbxColor_assign__SWIG_0(swigCPtr, SWIGTYPE_p_FbxArrayT_FbxColor_t.getCPtr(pArrayTemplate)), false); if (FbxWrapperNativePINVOKE.SWIGPendingException.Pending) { throw FbxWrapperNativePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public FbxLayerElementArray assign(SWIGTYPE_p_FbxArrayT_bool_t pArrayTemplate) { FbxLayerElementArray ret = new FbxLayerElementArray(fbx_wrapperPINVOKE.DirectArrayFbxBool_assign__SWIG_0(swigCPtr, SWIGTYPE_p_FbxArrayT_bool_t.getCPtr(pArrayTemplate)), false); if (fbx_wrapperPINVOKE.SWIGPendingException.Pending) { throw fbx_wrapperPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public bool IsEqual(FbxLayerElementArray pArray) { bool ret = FbxWrapperNativePINVOKE.FbxLayerElementArray_IsEqual(swigCPtr, FbxLayerElementArray.getCPtr(pArray)); if (FbxWrapperNativePINVOKE.SWIGPendingException.Pending) { throw FbxWrapperNativePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public FbxLayerElementArray assign(FbxArrayFbxVector2 pArrayTemplate) { FbxLayerElementArray ret = new FbxLayerElementArray(FbxWrapperNativePINVOKE.FbxLayerElementArrayTemplateFbxVector2_assign__SWIG_0(swigCPtr, FbxArrayFbxVector2.getCPtr(pArrayTemplate)), false); if (FbxWrapperNativePINVOKE.SWIGPendingException.Pending) { throw FbxWrapperNativePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
/// <summary> /// Export the mesh's UVs using layer 0. /// </summary> public void ExportUVs(MeshInfo mesh, FbxMesh fbxMesh) { // Set the normals on Layer 0. FbxLayer fbxLayer = fbxMesh.GetLayer(0 /* default layer */); if (fbxLayer == null) { fbxMesh.CreateLayer(); fbxLayer = fbxMesh.GetLayer(0 /* default layer */); } using (var fbxLayerElement = FbxLayerElementUV.Create(fbxMesh, "UVSet")) { fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByPolygonVertex); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eIndexToDirect); // set texture coordinates per vertex FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); for (int n = 0; n < mesh.UV.Length; n++) { fbxElementArray.Add(new FbxVector2(mesh.UV [n] [0], mesh.UV [n] [1])); } // For each face index, point to a texture uv var unityTriangles = mesh.Triangles; FbxLayerElementArray fbxIndexArray = fbxLayerElement.GetIndexArray(); fbxIndexArray.SetCount(unityTriangles.Length); for (int i = 0, n = unityTriangles.Length; i < n; ++i) { fbxIndexArray.SetAt(i, unityTriangles[i]); } fbxLayer.SetUVs(fbxLayerElement, FbxLayerElement.EType.eTextureDiffuse); } }
protected override FbxScene CreateScene(FbxManager manager) { FbxScene scene = base.CreateScene(manager); // Set the UVs FbxMesh cubeMesh = scene.GetRootNode().GetChild(0).GetMesh(); FbxLayer fbxLayer = cubeMesh.GetLayer(0 /* default layer */); if (fbxLayer == null) { cubeMesh.CreateLayer(); fbxLayer = cubeMesh.GetLayer(0 /* default layer */); } using (var fbxLayerElement = FbxLayerElementUV.Create(cubeMesh, "UVSet")) { fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByPolygonVertex); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eIndexToDirect); // set texture coordinates per vertex FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); for (int n = 0; n < 8; n++) { fbxElementArray.Add(new FbxVector2(n % 2, 1)); // TODO: switch to correct values } // For each face index, point to a texture uv FbxLayerElementArray fbxIndexArray = fbxLayerElement.GetIndexArray(); fbxIndexArray.SetCount(24); for (int vertIndex = 0; vertIndex < 24; vertIndex++) { fbxIndexArray.SetAt(vertIndex, vertIndex % 8); // TODO: switch to correct values } fbxLayer.SetUVs(fbxLayerElement, FbxLayerElement.EType.eTextureDiffuse); } // Create the material var fbxMaterial = FbxSurfacePhong.Create(scene, m_materialName); fbxMaterial.Diffuse.Set(new FbxColor(1, 1, 1)); fbxMaterial.Emissive.Set(new FbxColor(0.5, 0.1, 0.2)); fbxMaterial.Ambient.Set(new FbxDouble3(0.3, 0.4, 0)); fbxMaterial.BumpFactor.Set(0.6); fbxMaterial.Specular.Set(new FbxDouble3(0.8, 0.7, 0.9)); // Create and add the texture var fbxMaterialProperty = fbxMaterial.FindProperty(FbxSurfaceMaterial.sDiffuse); Assert.IsNotNull(fbxMaterialProperty); Assert.IsTrue(fbxMaterialProperty.IsValid()); var fbxTexture = FbxFileTexture.Create(fbxMaterial, FbxSurfaceMaterial.sDiffuse + "_Texture"); fbxTexture.SetFileName("/path/to/some/texture.jpg"); fbxTexture.SetTextureUse(FbxTexture.ETextureUse.eStandard); fbxTexture.SetMappingType(FbxTexture.EMappingType.eUV); fbxTexture.ConnectDstProperty(fbxMaterialProperty); scene.GetRootNode().GetChild(0).AddMaterial(fbxMaterial); return(scene); }
protected override FbxScene CreateScene(FbxManager manager) { FbxScene scene = base.CreateScene(manager); // Add normals, binormals, UVs, tangents and vertex colors to the cube FbxMesh cubeMesh = scene.GetRootNode().GetChild(0).GetMesh(); // Add normals /// Set the Normals on Layer 0. FbxLayer fbxLayer = cubeMesh.GetLayer(0 /* default layer */); if (fbxLayer == null) { cubeMesh.CreateLayer(); fbxLayer = cubeMesh.GetLayer(0 /* default layer */); } using (var fbxLayerElement = FbxLayerElementNormal.Create(cubeMesh, "Normals")) { fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); // Add one normal per each vertex face index (3 per triangle) FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); // Assign the normal vectors in the same order the control points were defined FbxVector4[] normals = { normalZPos, normalXPos, normalZNeg, normalXNeg, normalYPos, normalYNeg }; for (int n = 0; n < normals.Length; n++) { for (int i = 0; i < 4; i++) { fbxElementArray.Add(normals [n]); } } fbxLayer.SetNormals(fbxLayerElement); } /// Set the binormals on Layer 0. using (var fbxLayerElement = FbxLayerElementBinormal.Create(cubeMesh, "Binormals")) { fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); // Add one normal per each vertex face index (3 per triangle) FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); for (int n = 0; n < cubeMesh.GetControlPointsCount(); n++) { fbxElementArray.Add(new FbxVector4(-1, 0, 1)); // TODO: set to correct values } fbxLayer.SetBinormals(fbxLayerElement); } /// Set the tangents on Layer 0. using (var fbxLayerElement = FbxLayerElementTangent.Create(cubeMesh, "Tangents")) { fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); // Add one normal per each vertex face index (3 per triangle) FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); for (int n = 0; n < cubeMesh.GetControlPointsCount(); n++) { fbxElementArray.Add(new FbxVector4(0, -1, 1)); // TODO: set to correct values } fbxLayer.SetTangents(fbxLayerElement); } // set the vertex colors using (var fbxLayerElement = FbxLayerElementVertexColor.Create(cubeMesh, "VertexColors")) { fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); // Add one normal per each vertex face index (3 per triangle) FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); // make each vertex either black or white for (int n = 0; n < cubeMesh.GetControlPointsCount(); n++) { fbxElementArray.Add(new FbxColor(n % 2, n % 2, n % 2)); } fbxLayer.SetVertexColors(fbxLayerElement); } // set the UVs using (var fbxLayerElement = FbxLayerElementUV.Create(cubeMesh, "UVSet")) { fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByPolygonVertex); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eIndexToDirect); // set texture coordinates per vertex FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); for (int n = 0; n < 8; n++) { fbxElementArray.Add(new FbxVector2(n % 2, 1)); // TODO: switch to correct values } // For each face index, point to a texture uv FbxLayerElementArray fbxIndexArray = fbxLayerElement.GetIndexArray(); fbxIndexArray.SetCount(24); for (int vertIndex = 0; vertIndex < 24; vertIndex++) { fbxIndexArray.SetAt(vertIndex, vertIndex % 8); // TODO: switch to correct values } fbxLayer.SetUVs(fbxLayerElement, FbxLayerElement.EType.eTextureDiffuse); } return(scene); }
public void TestGetPolygonVertexNormal() { using (FbxMesh mesh = CreateObject("mesh")) { mesh.InitControlPoints(4); mesh.SetControlPointAt(new FbxVector4(0, 0, 0), 0); mesh.SetControlPointAt(new FbxVector4(1, 0, 0), 1); mesh.SetControlPointAt(new FbxVector4(1, 0, 1), 2); mesh.SetControlPointAt(new FbxVector4(0, 0, 1), 3); mesh.BeginPolygon(); mesh.AddPolygon(0); mesh.AddPolygon(1); mesh.AddPolygon(2); mesh.AddPolygon(3); mesh.EndPolygon(); // Add normals to the mesh FbxVector4 normal0 = new FbxVector4(0, 0, 1); FbxVector4 normal1 = new FbxVector4(0, 1, 0); FbxVector4 normal2 = new FbxVector4(0, 1, 1); FbxVector4 normal3 = new FbxVector4(0.301511344577764d, 0.904534033733291d, 0.301511344577764d); using (var fbxLayerElement = FbxLayerElementNormal.Create(mesh, "Normals")) { // Set the Normals on the default layer FbxLayer fbxLayer = mesh.GetLayer(0); if (fbxLayer == null) { mesh.CreateLayer(); fbxLayer = mesh.GetLayer(0); } fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); fbxElementArray.Add(normal0); fbxElementArray.Add(normal1); fbxElementArray.Add(normal2); fbxElementArray.Add(normal3); fbxLayer.SetNormals(fbxLayerElement); } FbxVector4 readNormal0; FbxVector4 readNormal1; FbxVector4 readNormal2; FbxVector4 readNormal3; // test if all normals can be read Assert.IsTrue(mesh.GetPolygonVertexNormal(0, 0, out readNormal0)); Assert.IsTrue(mesh.GetPolygonVertexNormal(0, 1, out readNormal1)); Assert.IsTrue(mesh.GetPolygonVertexNormal(0, 2, out readNormal2)); Assert.IsTrue(mesh.GetPolygonVertexNormal(0, 3, out readNormal3)); // test if the normals have the correct values Assert.That(normal0.X, Is.EqualTo(readNormal0.X).Using(FloatEqualityComparer.Instance)); Assert.That(normal0.Y, Is.EqualTo(readNormal0.Y).Using(FloatEqualityComparer.Instance)); Assert.That(normal0.Z, Is.EqualTo(readNormal0.Z).Using(FloatEqualityComparer.Instance)); Assert.That(normal0.W, Is.EqualTo(readNormal0.W).Using(FloatEqualityComparer.Instance)); Assert.That(normal1.X, Is.EqualTo(readNormal1.X).Using(FloatEqualityComparer.Instance)); Assert.That(normal1.Y, Is.EqualTo(readNormal1.Y).Using(FloatEqualityComparer.Instance)); Assert.That(normal1.Z, Is.EqualTo(readNormal1.Z).Using(FloatEqualityComparer.Instance)); Assert.That(normal1.W, Is.EqualTo(readNormal1.W).Using(FloatEqualityComparer.Instance)); Assert.That(normal2.X, Is.EqualTo(readNormal2.X).Using(FloatEqualityComparer.Instance)); Assert.That(normal2.Y, Is.EqualTo(readNormal2.Y).Using(FloatEqualityComparer.Instance)); Assert.That(normal2.Z, Is.EqualTo(readNormal2.Z).Using(FloatEqualityComparer.Instance)); Assert.That(normal2.W, Is.EqualTo(readNormal2.W).Using(FloatEqualityComparer.Instance)); Assert.That(normal3.X, Is.EqualTo(readNormal3.X).Using(FloatEqualityComparer.Instance)); Assert.That(normal3.Y, Is.EqualTo(readNormal3.Y).Using(FloatEqualityComparer.Instance)); Assert.That(normal3.Z, Is.EqualTo(readNormal3.Z).Using(FloatEqualityComparer.Instance)); Assert.That(normal3.W, Is.EqualTo(readNormal3.W).Using(FloatEqualityComparer.Instance)); } }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FbxLayerElementArray obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
/// <summary> /// Export the mesh's normals, binormals and tangents using /// layer 0. /// </summary> /// public void ExportNormalsEtc(MeshInfo mesh, FbxMesh fbxMesh) { /// Set the Normals on Layer 0. FbxLayer fbxLayer = fbxMesh.GetLayer(0 /* default layer */); if (fbxLayer == null) { fbxMesh.CreateLayer(); fbxLayer = fbxMesh.GetLayer(0 /* default layer */); } using (var fbxLayerElement = FbxLayerElementNormal.Create(fbxMesh, "Normals")) { fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); // TODO: normals for each triangle vertex instead of averaged per control point //fbxNormalLayer.SetMappingMode (FbxLayerElement.eByPolygonVertex); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); // Add one normal per each vertex face index (3 per triangle) FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); for (int n = 0; n < mesh.Normals.Length; n++) { fbxElementArray.Add(new FbxVector4(mesh.Normals [n] [0], mesh.Normals [n] [1], mesh.Normals [n] [2])); } fbxLayer.SetNormals(fbxLayerElement); } /// Set the binormals on Layer 0. using (var fbxLayerElement = FbxLayerElementBinormal.Create(fbxMesh, "Binormals")) { fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); // TODO: normals for each triangle vertex instead of averaged per control point //fbxBinormalLayer.SetMappingMode (FbxLayerElement.eByPolygonVertex); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); // Add one normal per each vertex face index (3 per triangle) FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); for (int n = 0; n < mesh.Binormals.Length; n++) { fbxElementArray.Add(new FbxVector4(mesh.Binormals [n] [0], mesh.Binormals [n] [1], mesh.Binormals [n] [2])); } fbxLayer.SetBinormals(fbxLayerElement); } /// Set the tangents on Layer 0. using (var fbxLayerElement = FbxLayerElementTangent.Create(fbxMesh, "Tangents")) { fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); // TODO: normals for each triangle vertex instead of averaged per control point //fbxBinormalLayer.SetMappingMode (FbxLayerElement.eByPolygonVertex); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); // Add one normal per each vertex face index (3 per triangle) FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); for (int n = 0; n < mesh.Normals.Length; n++) { fbxElementArray.Add(new FbxVector4(mesh.Tangents [n] [0], mesh.Tangents [n] [1], mesh.Tangents [n] [2])); } fbxLayer.SetTangents(fbxLayerElement); } }