Esempio n. 1
0
        public FbxLayerElementUV CreateElementUV(string pUVSetName)
        {
            global::System.IntPtr cPtr = FbxWrapperNativePINVOKE.FbxGeometryBase_CreateElementUV__SWIG_1(swigCPtr, pUVSetName);
            FbxLayerElementUV     ret  = (cPtr == global::System.IntPtr.Zero) ? null : new FbxLayerElementUV(cPtr, false);

            return(ret);
        }
Esempio n. 2
0
        public FbxLayerElementUV GetUVs(FbxLayerElement.EType pTypeIdentifier)
        {
            global::System.IntPtr cPtr = fbx_wrapperPINVOKE.FbxLayer_GetUVs__SWIG_0(swigCPtr, (int)pTypeIdentifier);
            FbxLayerElementUV     ret  = (cPtr == global::System.IntPtr.Zero) ? null : new FbxLayerElementUV(cPtr, false);

            return(ret);
        }
Esempio n. 3
0
        public FbxLayerElementUV GetUVs()
        {
            global::System.IntPtr cPtr = fbx_wrapperPINVOKE.FbxLayer_GetUVs__SWIG_1(swigCPtr);
            FbxLayerElementUV     ret  = (cPtr == global::System.IntPtr.Zero) ? null : new FbxLayerElementUV(cPtr, false);

            return(ret);
        }
Esempio n. 4
0
        public FbxLayerElementUV CreateElementUV(string pUVSetName, FbxLayerElement.EType pTypeIdentifier)
        {
            global::System.IntPtr cPtr = fbx_wrapperPINVOKE.FbxGeometryBase_CreateElementUV__SWIG_0(swigCPtr, pUVSetName, (int)pTypeIdentifier);
            FbxLayerElementUV     ret  = (cPtr == global::System.IntPtr.Zero) ? null : new FbxLayerElementUV(cPtr, false);

            return(ret);
        }
Esempio n. 5
0
        public FbxLayerElementUV GetElementUV()
        {
            global::System.IntPtr cPtr = FbxWrapperNativePINVOKE.FbxGeometryBase_GetElementUV__SWIG_2(swigCPtr);
            FbxLayerElementUV     ret  = (cPtr == global::System.IntPtr.Zero) ? null : new FbxLayerElementUV(cPtr, false);

            return(ret);
        }
Esempio n. 6
0
        public FbxLayerElementUV GetElementUV(string pUVSetName)
        {
            global::System.IntPtr cPtr = fbx_wrapperPINVOKE.FbxGeometryBase_GetElementUV__SWIG_6(swigCPtr, pUVSetName);
            FbxLayerElementUV     ret  = (cPtr == global::System.IntPtr.Zero) ? null : new FbxLayerElementUV(cPtr, false);

            return(ret);
        }
Esempio n. 7
0
        public FbxLayerElementUV GetElementUV(int pIndex)
        {
            global::System.IntPtr cPtr = fbx_wrapperPINVOKE.FbxGeometryBase_GetElementUV__SWIG_1(swigCPtr, pIndex);
            FbxLayerElementUV     ret  = (cPtr == global::System.IntPtr.Zero) ? null : new FbxLayerElementUV(cPtr, false);

            return(ret);
        }
Esempio n. 8
0
        public static FbxLayerElementUV Create(FbxLayerContainer pOwner, string pName)
        {
            global::System.IntPtr cPtr = fbx_wrapperPINVOKE.FbxLayerElementUV_Create(FbxLayerContainer.getCPtr(pOwner), pName);
            FbxLayerElementUV     ret  = (cPtr == global::System.IntPtr.Zero) ? null : new FbxLayerElementUV(cPtr, false);

            return(ret);
        }
Esempio n. 9
0
        public FbxLayerElementUV GetElementUV(int pIndex, FbxLayerElement.EType pTypeIdentifier)
        {
            global::System.IntPtr cPtr = FbxWrapperNativePINVOKE.FbxGeometryBase_GetElementUV__SWIG_0(swigCPtr, pIndex, (int)pTypeIdentifier);
            FbxLayerElementUV     ret  = (cPtr == global::System.IntPtr.Zero) ? null : new FbxLayerElementUV(cPtr, false);

            return(ret);
        }
Esempio n. 10
0
            /// <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);
                }
            }
Esempio n. 11
0
 public void SetUVs(FbxLayerElementUV pUVs, FbxLayerElement.EType pTypeIdentifier)
 {
     NativeMethods.FbxLayer_SetUVs__SWIG_0(swigCPtr, FbxLayerElementUV.getCPtr(pUVs), (int)pTypeIdentifier);
     if (NativeMethods.SWIGPendingException.Pending)
     {
         throw NativeMethods.SWIGPendingException.Retrieve();
     }
 }
Esempio n. 12
0
 public void SetUVs(FbxLayerElementUV pUVs)
 {
     NativeMethods.FbxLayer_SetUVs__SWIG_1(swigCPtr, FbxLayerElementUV.getCPtr(pUVs));
     if (NativeMethods.SWIGPendingException.Pending)
     {
         throw NativeMethods.SWIGPendingException.Retrieve();
     }
 }
Esempio n. 13
0
        public void SetUVs(FbxLayerElementUV pUVs, FbxLayerElement.EType pTypeIdentifier = FbxLayerElement.EType.eTextureDiffuse)
        {
            if (uvs.Get() != null)
            {
                elements.Remove(uvs.Get());
            }

            elements.Add(pUVs);
        }
Esempio n. 14
0
        public static FbxLayerElementUV Create(FbxLayerContainer pOwner, string pName)
        {
            global::System.IntPtr cPtr = NativeMethods.FbxLayerElementUV_Create(FbxLayerContainer.getCPtr(pOwner), pName);
            FbxLayerElementUV     ret  = (cPtr == global::System.IntPtr.Zero) ? null : new FbxLayerElementUV(cPtr, false);

            if (NativeMethods.SWIGPendingException.Pending)
            {
                throw NativeMethods.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Esempio n. 15
0
        public FbxLayerElementUV GetUVs(FbxLayerElement.EType pTypeIdentifier)
        {
            global::System.IntPtr cPtr = NativeMethods.FbxLayer_GetUVs__SWIG_0(swigCPtr, (int)pTypeIdentifier);
            FbxLayerElementUV     ret  = (cPtr == global::System.IntPtr.Zero) ? null : new FbxLayerElementUV(cPtr, false);

            if (NativeMethods.SWIGPendingException.Pending)
            {
                throw NativeMethods.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Esempio n. 16
0
        public void TestSetUVs()
        {
            // make sure nothing crashes

            m_fbxLayer.SetUVs(FbxLayerElementUV.Create(m_fbxMesh, ""));

            // test with type identifier
            m_fbxLayer.SetUVs(FbxLayerElementUV.Create(m_fbxMesh, ""), FbxLayerElement.EType.eEdgeCrease);
            // TODO: why does this return null?
            Assert.IsNull(m_fbxLayer.GetUVs(FbxLayerElement.EType.eEdgeCrease));

            // test null
            m_fbxLayer.SetUVs(null);
            Assert.IsNull(m_fbxLayer.GetUVs());

            // test destroyed
            FbxLayerElementUV uvs = FbxLayerElementUV.Create(m_fbxMesh, "");

            uvs.Dispose();
            m_fbxLayer.SetUVs(uvs);
        }
Esempio n. 17
0
            /// <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);
                }
            }
Esempio n. 18
0
        // For use only by FbxExportGlobals.
        internal static FbxMesh CreateFbxMesh(FbxExportGlobals G, GeometryPool pool, string poolName)
        {
            FbxMesh fbxMesh = FbxMesh.Create(G.m_manager, poolName);

            ExportMesh mesh   = new ExportMesh(pool);
            int        nVerts = mesh.m_pool.m_Vertices.Count;

            fbxMesh.InitControlPoints(nVerts);

            unsafe
            {
                fixed(Vector3 *f = mesh.m_pool.m_Vertices.GetBackingArray())
                {
                    Globals.SetControlPoints(fbxMesh, (IntPtr)f);
                }
            }

            List <int> triangles = mesh.m_pool.m_Tris;

            // Not available in Unity's wrappers
            // fbxMesh.ReservePolygonCount(triangles.Count / 3);
            // fbxMesh.ReservePolygonVertexCount(triangles.Count);
            for (int i = 0; i < triangles.Count; i += 3)
            {
                fbxMesh.BeginPolygon(-1 /* Material */, -1 /* Texture */, -1 /* Group */, false /* Legacy */);
                fbxMesh.AddPolygon(triangles[i]);
                fbxMesh.AddPolygon(triangles[i + 1]);
                fbxMesh.AddPolygon(triangles[i + 2]);
                fbxMesh.EndPolygon();
            }

            FbxLayer layer0 = fbxMesh.GetLayer(0);

            if (layer0 == null)
            {
                fbxMesh.CreateLayer();
                layer0 = fbxMesh.GetLayer(0);
            }

            var layerElementNormal = FbxLayerElementNormal.Create(fbxMesh, "normals");

            layerElementNormal.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint);
            layerElementNormal.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect);
            CopyToFbx(layerElementNormal.GetDirectArray(), mesh.m_pool.m_Normals);
            layer0.SetNormals(layerElementNormal);

            var layerElementColor = FbxLayerElementVertexColor.Create(fbxMesh, "color");

            layerElementColor.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint);
            layerElementColor.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect);
            CopyToFbx(layerElementColor.GetDirectArray(), mesh.m_linearColor);
            layer0.SetVertexColors(layerElementColor);

            var layerElementTangent = FbxLayerElementTangent.Create(fbxMesh, "tangents");

            layerElementTangent.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint);
            layerElementTangent.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect);
            CopyToFbx(layerElementTangent.GetDirectArray(), mesh.m_pool.m_Tangents);
            layer0.SetTangents(layerElementTangent);

            // Compute and export binormals since Unity's FBX importer won't import the tangents without
            // them, even though they're not used.
            var layerElementBinormal = FbxLayerElementBinormal.Create(fbxMesh, "binormals");

            layerElementBinormal.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint);
            layerElementBinormal.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect);
            var binormals = mesh.m_pool.m_Tangents
                            .Select((tan, idx) => {
                var b3 = Vector3.Cross(tan, mesh.m_pool.m_Normals[idx]) * tan.w;
                return(new Vector4(b3.x, b3.y, b3.z, 1));
            })
                            .ToList();

            CopyToFbx(layerElementBinormal.GetDirectArray(), binormals);
            layer0.SetBinormals(layerElementBinormal);

            var layerElementMaterial = FbxLayerElementMaterial.Create(fbxMesh, "materials");

            layerElementMaterial.SetMappingMode(FbxLayerElement.EMappingMode.eAllSame);
            layer0.SetMaterials(layerElementMaterial);

            // Export everything up to the last uvset containing data
            // even if some intermediate uvsets have no data.
            // Otherwise Unity will get the uvset numbering wrong on import

            List <List <Vector2> > uvSets = DemuxTexcoords(mesh.m_pool);

            for (int i = 0; i < uvSets.Count; i++)
            {
                FbxLayer layerN = fbxMesh.GetLayer(i);
                while (layerN == null)
                {
                    fbxMesh.CreateLayer();
                    layerN = fbxMesh.GetLayer(i);
                }
                var layerElementUV = FbxLayerElementUV.Create(fbxMesh, String.Format("uv{0}", i));
                layerElementUV.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint);
                layerElementUV.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect);

                List <Vector2> uvSet = uvSets[i];
                if (uvSet == null)
                {
                    // Do nothing
                    // Replicates what the old fbx export code did; seems to work fine
                }
                else
                {
                    Debug.Assert(uvSet.Count == nVerts);
                    CopyToFbx(layerElementUV.GetDirectArray(), uvSet);
                }

                layerN.SetUVs(layerElementUV, FbxLayerElement.EType.eTextureDiffuse);
            }
            return(fbxMesh);
        }
Esempio n. 19
0
        protected override FbxMesh GenerateFbx()
        {
            string meshName = (Souls.meshRoot != null ? Souls.meshRoot.Name : "") + "_Mesh";

            FbxMesh mesh = FbxMesh.Create(Scene, meshName);

            mesh.InitControlPoints(Souls.mesh.Vertices.Count);

            int layerIndex = mesh.CreateLayer();

            FbxLayer layer = mesh.GetLayer(layerIndex);

            FbxLayerContainer layerContainer = FbxLayerContainer.Create(Scene, meshName + "_LayerContainer");

            FbxLayerElementUV uv = FbxLayerElementUV.Create(layerContainer, "Diffuse");

            layer.SetUVs(uv);

            FbxLayerElementNormal normal = FbxLayerElementNormal.Create(layerContainer, "Normal");

            layer.SetNormals(normal);
            normal.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect);
            normal.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint);

            FbxLayerElementBinormal binormal = FbxLayerElementBinormal.Create(layerContainer, "Binormal");

            layer.SetBinormals(binormal);

            FbxLayerElementTangent tangent = FbxLayerElementTangent.Create(layerContainer, "Tangent");

            layer.SetTangents(tangent);
            tangent.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect);
            tangent.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint);

            for (int vertexIndex = 0; vertexIndex < Souls.mesh.Vertices.Count; ++vertexIndex)
            {
                FLVER.Vertex vertex = Souls.mesh.Vertices[vertexIndex];

                Vector3 position = vertex.Position;

                // this fixes vertex positions since otherwise the model is turned inside out
                // and it appears like it holds weapons in the left hand
                position.Z = -position.Z;

                normal.GetDirectArray().Add(vertex.Normal.ToFbxVector4());

                tangent.GetDirectArray().Add(new FbxVector4(vertex.Tangents[0].X, vertex.Tangents[0].Y, vertex.Tangents[0].Z));

                Vector2 uvValue = new Vector2(0);

                if (vertex.UVs.Count > 0)
                {
                    uvValue.X = vertex.UVs[0].X;
                    uvValue.Y = vertex.UVs[0].Y;
                }

                uv.GetDirectArray().Add(uvValue.ToFbxVector2());

                mesh.SetControlPointAt(position.ToFbxVector4(), vertexIndex);
            }

            for (int faceSetIndex = 0; faceSetIndex < Souls.mesh.FaceSets.Count; ++faceSetIndex)
            {
                FLVER2.FaceSet faceSet = Souls.mesh.FaceSets[faceSetIndex];

                if (faceSet.Flags != FLVER2.FaceSet.FSFlags.None)
                {
                    continue;
                }

                for (int faceStartIndex = 0; faceStartIndex < faceSet.Indices.Count; faceStartIndex += 3)
                {
                    mesh.AddCompletePolygon(
                        faceSet.Indices[faceStartIndex],
                        faceSet.Indices[faceStartIndex + 1],
                        faceSet.Indices[faceStartIndex + 2]
                        );
                    //mesh.AddCompletePolygon(
                    //    faceSet.Indices[faceStartIndex + 2],
                    //    faceSet.Indices[faceStartIndex + 1],
                    //    faceSet.Indices[faceStartIndex]
                    //);
                }
            }

            mesh.BuildMeshEdgeArray();

            FbxGeometryConverter converter = new FbxGeometryConverter(Scene.GetFbxManager());

            converter.ComputeEdgeSmoothingFromNormals(mesh);
            converter.ComputePolygonSmoothingFromEdgeSmoothing(mesh);

            return(mesh);
        }
Esempio n. 20
0
 public void SetUVs(FbxLayerElementUV pUVs)
 {
     FbxWrapperNativePINVOKE.FbxLayer_SetUVs__SWIG_1(swigCPtr, FbxLayerElementUV.getCPtr(pUVs));
 }
        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);
        }
Esempio n. 23
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FbxLayerElementUV obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Esempio n. 24
0
        public bool RemoveElementUV(FbxLayerElementUV pElementUV)
        {
            bool ret = fbx_wrapperPINVOKE.FbxGeometryBase_RemoveElementUV(swigCPtr, FbxLayerElementUV.getCPtr(pElementUV));

            return(ret);
        }
Esempio n. 25
0
 public void SetUVs(FbxLayerElementUV pUVs, FbxLayerElement.EType pTypeIdentifier)
 {
     fbx_wrapperPINVOKE.FbxLayer_SetUVs__SWIG_0(swigCPtr, FbxLayerElementUV.getCPtr(pUVs), (int)pTypeIdentifier);
 }
Esempio n. 26
0
            /// <summary>
            /// Process a single UV dataset and return data for configuring a Mesh UV attribute
            /// </summary>
            private Vector2 [] ProcessUVSet(FbxLayerElementUV element,
                                            int [] polygonVertexIndices,
                                            int vertexCount)
            {
                Vector2 [] result = new Vector2 [polygonVertexIndices.Length];

                FbxLayerElement.EReferenceMode referenceMode = element.GetReferenceMode();
                FbxLayerElement.EMappingMode   mappingMode   = element.GetMappingMode();

                // direct or via-index
                bool isDirect = referenceMode == FbxLayerElement.EReferenceMode.eDirect;

                var fbxElementArray = element.GetDirectArray();
                var fbxIndexArray   = isDirect ? null : element.GetIndexArray();

                if (mappingMode == FbxLayerElement.EMappingMode.eByControlPoint)
                {
                    if (fbxElementArray.GetCount() != vertexCount)
                    {
                        Debug.LogError(string.Format("UVSet size ({0}) does not match vertex count {1}",
                                                     fbxElementArray.GetCount(), vertexCount));
                        return(null);
                    }

                    for (int i = 0; i < polygonVertexIndices.Length; i++)
                    {
                        int index = i;
                        if (!isDirect)
                        {
                            index = fbxIndexArray.GetAt(i);
                        }

                        FbxVector2 fbxVector2 = fbxElementArray.GetAt(polygonVertexIndices [index]);
                        Debug.Assert(fbxVector2.X >= float.MinValue && fbxVector2.X <= float.MaxValue);
                        Debug.Assert(fbxVector2.Y >= float.MinValue && fbxVector2.Y <= float.MaxValue);

                        result [i] = new Vector2((float)fbxVector2.X, (float)fbxVector2.Y);

                        // UVs in FBX can contain NaNs, so we set these vertices to (0,0)
                        if (float.IsNaN(result [i] [0]) || float.IsNaN(result [i] [1]))
                        {
                            Debug.LogWarning(string.Format("invalid UV detected at {0}", i));
                            result [i] = Vector2.zero;
                        }
                    }
                }
                else if (mappingMode == FbxLayerElement.EMappingMode.eAllSame)
                {
                    FbxVector2 fbxVector2 = fbxElementArray.GetAt(0);
                    Debug.Assert(fbxVector2.X >= float.MinValue && fbxVector2.X <= float.MaxValue);
                    Debug.Assert(fbxVector2.Y >= float.MinValue && fbxVector2.Y <= float.MaxValue);

                    Vector2 value = new Vector2((float)fbxVector2.X, (float)fbxVector2.Y);
                    for (int i = 0; i < polygonVertexIndices.Length; i++)
                    {
                        result [i] = value;
                    }
                }
                else
                {
                    Debug.LogError("unsupported UV-to-Component mapping mode");
                }

                return(result);
            }
Esempio n. 27
0
            /// <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++;
                        }
                    }
                }
            }
Esempio n. 28
0
 public void SetUVs(FbxLayerElementUV pUVs)
 {
     fbx_wrapperPINVOKE.FbxLayer_SetUVs__SWIG_1(swigCPtr, FbxLayerElementUV.getCPtr(pUVs));
 }