Beispiel #1
0
        private IEnumerator StoreMesh()
        {
            yield return(new WaitForSeconds(duration));

            yield return(new WaitForEndOfFrame());

            /// Why the Zig-zag
            /// Please Refer to TrailBase.cs in which all trails are generated in the world space.
            /// Hence we need to convert the generated mesh or it will have a strange pivot :)
            /// No Performance Consideration on this Part because it is Editor Only.
            Matrix4x4 mat      = transform.worldToLocalMatrix;
            Mesh      toBake   = new Mesh();
            Mesh      original = trailToBake.GetTrailMesh();

            Vector3[] verts = new Vector3[original.vertices.Length];
            if (toBake != null)
            {
                for (int i = 0; i < original.vertices.Length; i++)
                {
                    verts[i] = mat.MultiplyPoint3x4(original.vertices[i]);
                }
                toBake.vertices = verts;
                toBake.uv       = original.uv;
                toBake.normals  = original.normals;
                Debug.Log(original.GetIndices(0).Length);
                toBake.SetIndices(original.GetIndices(0), MeshTopology.Triangles, 0);
                FBXManager.SaveMeshAsFBX(toBake, trailName);
            }
        }
Beispiel #2
0
        public static void InitializeSdkObjects(string sceneName, out FBXManager pManager, out FBXScene pScene)
        {
            // The first thing to do is to create the FBX Manager which is the object allocator for almost all the classes in the SDK
            pManager = FBXManager.Create();
            if (pManager == null)
            {
                Debug.WriteLine("Error: Unable to create FBX Manager!");
                Environment.Exit(1);
            }
            else
            {
                Debug.WriteLine("Autodesk FBX SDK version {0}", FBXManager.GetVersion(true));
            }

            // Create an IOSettings object. This object holds all import/export settings.
            FBXIOSettings ios = FBXIOSettings.Create(pManager, "IOSRoot");

            pManager.SetIOSettings(ios);

            // Load plugins from the executable directory (optional)
            pManager.LoadPluginsDirectory(Environment.CurrentDirectory, string.Empty);

            // Create an FBX scene. This object holds most objects imported/exported from/to files.
            pScene = FBXScene.Create(pManager, sceneName);
            if (pScene == null)
            {
                Debug.WriteLine("Error: Unable to create FBX scene!\n");
                Environment.Exit(1);
            }
        }
Beispiel #3
0
        public void ExportSkeletalMeshToFbx(MESkeletalMesh mesh, string meshName, string targetdir)
        {
            FBXManager lSdkManager = new FBXManager();
            FBXScene   lScene      = new FBXScene();

            FBXHelper.InitializeSdkObjects(lSdkManager, lScene);
            FBXNode SceneRoot     = lScene.GetRootNode();
            FBXNode lSkeletonRoot = CreateFbxSkeleton(mesh.Bones, lScene);

            SceneRoot.AddChild(lSkeletonRoot);
            try
            {
                FBXNode fbxMesh = CreateFbxMesh(mesh, meshName, lScene);
                CreateMeshSkinning(mesh, 0, fbxMesh, lSkeletonRoot, lScene);
                SceneRoot.AddChild(fbxMesh);
                //StoreRestPose(lScene, lSkeletonRoot, skeleton);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            bool lResult = FBXHelper.SaveScene(lSdkManager, lScene, targetdir);

            FBXHelper.DestroySdkObjects(lSdkManager, lResult);
        }
Beispiel #4
0
        public bool ExportSkinnedMeshToFBX(SkeletonAsset skeleton, MeshAsset mesh, int lodIndex, String targetdir, bool asOne)
        {
            FBXManager lSdkManager = new FBXManager();
            FBXScene   lScene      = new FBXScene();

            FBXHelper.InitializeSdkObjects(lSdkManager, lScene);
            FBXNode SceneRoot     = lScene.GetRootNode();
            FBXNode lSkeletonRoot = CreateFbxSkeleton(skeleton, lScene);

            SceneRoot.AddChild(lSkeletonRoot);
            if (asOne)
            {
                FBXNode fbxMesh = CreateFbxMesh(mesh.lods[lodIndex], lScene);
                CreateMeshSkinning(skeleton, mesh.lods[lodIndex], fbxMesh, lSkeletonRoot, lScene);
                SceneRoot.AddChild(fbxMesh);
                StoreRestPose(lScene, lSkeletonRoot, skeleton);
            }
            else
            {
                for (int i = 0; i < mesh.lods[lodIndex].sections.Count; i++)
                {
                    FBXNode CurrentSectionMesh = CreateFbxMesh(mesh.lods[lodIndex].sections[i], lScene);
                    CreateMeshSkinning(skeleton, mesh.lods[lodIndex].sections[i], CurrentSectionMesh, lSkeletonRoot, lScene);
                    SceneRoot.AddChild(CurrentSectionMesh);
                    StoreBindPose(lScene, CurrentSectionMesh);
                }
            }
            return(SaveScene(targetdir, lSdkManager, lScene));
        }
Beispiel #5
0
        private bool SaveScene(String targetdir, FBXManager pSdkManager, FBXScene pScene)
        {
            bool lResult = FBXHelper.SaveScene(pSdkManager, pScene, targetdir);

            FBXHelper.DestroySdkObjects(pSdkManager, lResult);
            return(lResult);
        }
Beispiel #6
0
        public void Load()
        {
            LogMessage("Instantiating the FBX Manager...");
            FBXManager managerInstance = ArcManagedFBX.FBXManager.Create();

            if (string.IsNullOrEmpty(Filename))
            {
                throw new FileNotFoundException("The file that is being loaded in does not exist!");
            }

            if (!File.Exists(Filename))
            {
                throw new FileNotFoundException("The file that is being loaded was not found on disk.");
            }

            LogMessage("Instantiating the FBX Settings...");
            FBXIOSettings settings = FBXIOSettings.Create(managerInstance, "IOSRoot");

            managerInstance.SetIOSettings(settings);

            LogMessage("Loading plugins directory...");
            managerInstance.LoadPluginsDirectory(Environment.CurrentDirectory, "");

            int fileMajorNumber = 0, fileMinorNumber = 0, fileRevisionNumber = 0;

            LogMessage("Instantiating the Scene...");

            FBXScene    scene    = FBXScene.Create(managerInstance, "My Scene");
            FBXImporter importer = FBXImporter.Create(managerInstance, "");

            // Instantiate the framework for the scene as required.
            m_SceneFramework = new SceneFramework(scene);

            LogMessage("Load the importer for the file '{0}'", Filename);
            bool initializeResult = importer.Initialize(Filename, -1, managerInstance.GetIOSettings());

            FBXManager.GetFileFormatVersion(ref fileMajorNumber, ref fileMinorNumber, ref fileRevisionNumber);

            bool importResult = importer.Import(scene);

            m_SceneFramework.Operation();

            if (importResult)
            {
                PerformTests(scene);
            }
            else
            {
                LogError("Import failed. Nothing to do!");
            }
        }
Beispiel #7
0
        public bool ExportMeshWithMorph(SkeletonAsset Skeleton, MeshAsset mesh, int lodIndex, List <Vector> morphVertex, List <Vector> morphBones, String targetdir)
        {
            FBXManager lSdkManager = new FBXManager();
            FBXScene   lScene      = new FBXScene();

            FBXHelper.InitializeSdkObjects(lSdkManager, lScene);
            FBXNode SceneRoot = lScene.GetRootNode();
            FBXNode fbxMesh   = CreateFbxMesh(mesh.lods[lodIndex], lScene);

            AddMorphToMesh(lScene, fbxMesh, morphVertex);
            SceneRoot.AddChild(fbxMesh);
            if (Skeleton != null)
            {
                FBXNode lSkeletonRoot = CreateFbxSkeleton(Skeleton, lScene);
                CreateMeshSkinning(Skeleton, mesh.lods[lodIndex], fbxMesh, lSkeletonRoot, lScene);
                UpdateSkeletonWithMorph(Skeleton, lSkeletonRoot, morphBones);
                SceneRoot.AddChild(lSkeletonRoot);
                StoreBindPose(lScene, fbxMesh);
            }
            return(SaveScene(targetdir, lSdkManager, lScene));
        }
Beispiel #8
0
        public void ExportMeshWithMorph(Unreal.BioMorphFace morph, int lodIndex, String targetdir)
        {
            FBXManager lSdkManager = new FBXManager();
            FBXScene   lScene      = new FBXScene();

            FBXHelper.InitializeSdkObjects(lSdkManager, lScene);
            FBXNode        SceneRoot = lScene.GetRootNode();
            MESkeletalMesh mesh      = morph.Apply();
            FBXNode        fbxMesh   = CreateFbxMesh(mesh, morph.Name, lScene);

            SceneRoot.AddChild(fbxMesh);
            if (mesh.Bones != null)
            {
                FBXNode lSkeletonRoot = CreateFbxSkeleton(mesh.Bones, lScene);
                CreateMeshSkinning(mesh, lodIndex, fbxMesh, lSkeletonRoot, lScene);
                UpdateSkeletonWithMorph(morph, lSkeletonRoot);
                SceneRoot.AddChild(lSkeletonRoot);
                //StoreBindPose(lScene, fbxMesh);
            }
            bool lResult = FBXHelper.SaveScene(lSdkManager, lScene, targetdir);

            FBXHelper.DestroySdkObjects(lSdkManager, lResult);
        }
Beispiel #9
0
        public bool ExportStaticMeshToFBX(MeshAsset mesh, int lodIndex, String targetdir, bool asOne)
        {
            FBXManager lSdkManager = new FBXManager();
            FBXScene   lScene      = new FBXScene();

            FBXHelper.InitializeSdkObjects(lSdkManager, lScene);
            FBXNode SceneRoot = lScene.GetRootNode();

            if (asOne)
            {
                FBXNode fbxMesh = CreateFbxMesh(mesh.lods[lodIndex], lScene);
                SceneRoot.AddChild(fbxMesh);
            }
            else
            {
                for (int i = 0; i < mesh.lods[lodIndex].sections.Count; i++)
                {
                    FBXNode CurrentSectionMesh = CreateFbxMesh(mesh.lods[lodIndex].sections[i], lScene);
                    SceneRoot.AddChild(CurrentSectionMesh);
                }
            }
            return(SaveScene(targetdir, lSdkManager, lScene));
        }
Beispiel #10
0
        private void ImportFBX(string path)
        {
            FBXManager    man = FBXManager.Create();
            FBXIOSettings io  = FBXIOSettings.Create(man, "IOSRoot");

            man.SetIOSettings(io);

            FBXImporter fbx = FBXImporter.Create(man, "");

            fbx.Initialize(path, -1, man.GetIOSettings());

            FBXScene scene = FBXScene.Create(man, "importScene");

            fbx.Import(scene);
            fbx.Destroy();

            var root = scene.GetRootNode();

            for (int i = 0; i < root.GetChildCount(); i++)
            {
                var child = root.GetChild(i);

                if (child.GetName() == "Root")
                {
                    ParseNode(child, true);
                    break;
                }
            }

            List <VMeshDataFile> lst_vmesh_data    = new List <VMeshDataFile>();
            VMeshDataFile        cur_meshdata_file = null;

            for (int i = 0; i < cmpndData.Count; i++)
            {
                var cmpnd = cmpndData[i];

                for (uint lod = 0; lod < cmpnd.object_data.lods; lod++)
                {
                    if (cur_meshdata_file == null || cmpnd.object_data.data[lod].vmeshref.NumIndex + cur_meshdata_file.ref_vertices > 0xFFFF)
                    {
                        cur_meshdata_file              = new VMeshDataFile();
                        cur_meshdata_file.filename     = UniqueName + lst_vmesh_data.Count + ".vms";
                        cur_meshdata_file.ref_vertices = 0;
                        cur_meshdata_file.vertices     = 0;
                        cur_meshdata_file.meshes       = 0;
                        lst_vmesh_data.Add(cur_meshdata_file);
                    }

                    cur_meshdata_file.ref_vertices += cmpnd.object_data.data[lod].vmeshref.NumIndex;
                    cur_meshdata_file.vertices     += cmpnd.object_data.data[lod].vmeshref.NumVert;
                    cur_meshdata_file.meshes       += cmpnd.object_data.data[lod].vmeshref.NumMeshes;

                    cmpnd.object_data.data[lod].vmeshref.VMeshLibId = Utilities.FLModelCRC(cur_meshdata_file.filename);
                    cmpnd.object_data.data[lod].vmeshdata           = cur_meshdata_file;
                }

                cmpnd.object_data.file_name = UniqueName + "." + cmpnd.object_name + ".3db";

                cmpndData.RemoveAt(i);
                cmpndData.Insert(i, cmpnd);
            }

            foreach (var vmesh in lst_vmesh_data)
            {
                /*VMeshData vmeshdata = new VMeshData();
                 *
                 * switch (VertexType)
                 * {
                 *  case ModelImportVertexType.Normals:
                 *      vmeshdata.FlexibleVertexFormat = (ushort)(VMeshData.D3DFVF_XYZ | VMeshData.D3DFVF_NORMAL | VMeshData.D3DFVF_TEX1);
                 *      break;
                 *  case ModelImportVertexType.VertexColors:
                 *      vmeshdata.FlexibleVertexFormat = (ushort)(VMeshData.D3DFVF_XYZ | VMeshData.D3DFVF_DIFFUSE | VMeshData.D3DFVF_TEX1);
                 *      break;
                 *  case ModelImportVertexType.VertexColorsNormals:
                 *      vmeshdata.FlexibleVertexFormat = (ushort)(VMeshData.D3DFVF_XYZ | VMeshData.D3DFVF_DIFFUSE | VMeshData.D3DFVF_NORMAL | VMeshData.D3DFVF_DIFFUSE);
                 *      break;
                 *  case ModelImportVertexType.ExtraUVs:
                 *      vmeshdata.FlexibleVertexFormat = (ushort)(VMeshData.D3DFVF_XYZ | VMeshData.D3DFVF_NORMAL | VMeshData.D3DFVF_TEX2);
                 *      break;
                 *  case ModelImportVertexType.TangentsBinormals:
                 *      vmeshdata.FlexibleVertexFormat = (ushort)(VMeshData.D3DFVF_XYZ | VMeshData.D3DFVF_NORMAL | VMeshData.D3DFVF_TEX4);
                 *      break;
                 *  case ModelImportVertexType.ExtraUVsTangentsBinormals:
                 *      vmeshdata.FlexibleVertexFormat = (ushort)(VMeshData.D3DFVF_XYZ | VMeshData.D3DFVF_NORMAL | VMeshData.D3DFVF_TEX5);
                 *      break;
                 * }*/

                const uint HEADER_SIZE      = 2 * 4 + 4 * 2;
                const uint MESH_HEADER_SIZE = 4 + 3 * 2 + 2;
                const uint INDEX_SIZE       = 2;
                uint       VERTEX_SIZE      = 0;
                switch (VertexType)
                {
                case ModelImportVertexType.Normals:
                    VERTEX_SIZE = 3 * 4 + 3 * 4 + 2 * 4;
                    break;

                case ModelImportVertexType.VertexColors:
                    VERTEX_SIZE = 3 * 4 + 1 * 4 + 2 * 4;
                    break;

                case ModelImportVertexType.VertexColorsNormals:
                    VERTEX_SIZE = 3 * 4 + 3 * 4 + 1 * 4 + 2 * 4;
                    break;

                case ModelImportVertexType.ExtraUVs:
                    VERTEX_SIZE = 3 * 4 + 3 * 4 + 2 * 4 + 2 * 4;
                    break;

                case ModelImportVertexType.TangentsBinormals:
                    VERTEX_SIZE = 3 * 4 + 3 * 4 + 2 * 4 + 3 * 4 + 3 * 4;
                    break;

                case ModelImportVertexType.ExtraUVsTangentsBinormals:
                    VERTEX_SIZE = 3 * 4 + 3 * 4 + 2 * 4 + 2 * 4 + 3 * 4 + 3 * 4;
                    break;
                }

                int meshCount     = 0;
                int indicesCount  = 0;
                int verticesCount = 0;
                foreach (var cmpnd in cmpndData)
                {
                    for (int lod = 0; lod < cmpnd.object_data.lods; lod++)
                    {
                        if (cmpnd.object_data.data[lod].vmeshdata == vmesh)
                        {
                            meshCount += cmpnd.object_data.data[lod].meshes.Count;
                            foreach (var m in cmpnd.object_data.data[lod].meshes)
                            {
                                indicesCount  += m.t.Length * 3;
                                verticesCount += m.v.Length;
                            }
                        }
                    }
                }

                byte[] data = new byte[HEADER_SIZE + MESH_HEADER_SIZE * meshCount + INDEX_SIZE * indicesCount + VERTEX_SIZE * verticesCount];
                int    pos  = 0;

                // write header
                Utilities.WriteInt(data, 1, ref pos);
                Utilities.WriteInt(data, 4, ref pos);
                Utilities.WriteWord(data, (ushort)vmesh.meshes, ref pos);
                Utilities.WriteWord(data, (ushort)vmesh.ref_vertices, ref pos);

                ushort fvf = 0;
                switch (VertexType)
                {
                case ModelImportVertexType.Normals:
                    fvf = 0x112;
                    break;

                case ModelImportVertexType.VertexColors:
                    fvf = 0x142;
                    break;

                case ModelImportVertexType.VertexColorsNormals:
                    fvf = 0x152;
                    break;

                case ModelImportVertexType.ExtraUVs:
                    fvf = 0x212;
                    break;

                case ModelImportVertexType.TangentsBinormals:
                    fvf = 0x412;
                    break;

                case ModelImportVertexType.ExtraUVsTangentsBinormals:
                    fvf = 0x512;
                    break;
                }
                Utilities.WriteWord(data, fvf, ref pos);
                Utilities.WriteWord(data, (ushort)vmesh.vertices, ref pos);

                uint iMesh = 0;
                uint iGlobalStartVertex = 0;
                uint iGlobalStartIndex  = 0;

                // save mesh header data
                foreach (var cmpnd in cmpndData)
                {
                    for (int lod = 0; lod < cmpnd.object_data.lods; lod++)
                    {
                        if (cmpnd.object_data.data[lod].vmeshdata == vmesh)
                        {
                            cmpnd.object_data.data[lod].vmeshref.StartMesh  = (ushort)iMesh;
                            cmpnd.object_data.data[lod].vmeshref.StartVert  = (ushort)iGlobalStartVertex;
                            cmpnd.object_data.data[lod].vmeshref.StartIndex = (ushort)iGlobalStartIndex;

                            uint iStartVert = 0;

                            foreach (var m in cmpnd.object_data.data[lod].meshes)
                            {
                                Utilities.WriteDWord(data, Utilities.FLModelCRC(m.material_name), ref pos);
                                Utilities.WriteWord(data, (ushort)iStartVert, ref pos);
                                Utilities.WriteWord(data, (ushort)(iStartVert + m.nVerts - 1), ref pos);
                                Utilities.WriteWord(data, (ushort)(m.nTris * 3), ref pos);
                                Utilities.WriteWord(data, 0xCC, ref pos);

                                iStartVert         += (uint)m.nVerts;
                                iGlobalStartIndex  += (uint)m.nTris * 3;
                                iGlobalStartVertex += (uint)m.nVerts;
                                iMesh++;
                            }
                        }
                    }
                }

                // save indices
                foreach (var cmpnd in cmpndData)
                {
                    for (int lod = 0; lod < cmpnd.object_data.lods; lod++)
                    {
                        if (cmpnd.object_data.data[lod].vmeshdata == vmesh)
                        {
                            foreach (var m in cmpnd.object_data.data[lod].meshes)
                            {
                                foreach (var t in m.t)
                                {
                                    Utilities.WriteWord(data, t.vertices[0], ref pos);
                                    Utilities.WriteWord(data, t.vertices[1], ref pos);
                                    Utilities.WriteWord(data, t.vertices[2], ref pos);
                                }
                            }
                        }
                    }
                }

                // save vertices
                foreach (var cmpnd in cmpndData)
                {
                    for (int lod = 0; lod < cmpnd.object_data.lods; lod++)
                    {
                        if (cmpnd.object_data.data[lod].vmeshdata == vmesh)
                        {
                            foreach (var m in cmpnd.object_data.data[lod].meshes)
                            {
                                foreach (var v in m.v)
                                {
                                    Utilities.WriteFloat(data, v.vert.X, ref pos);
                                    Utilities.WriteFloat(data, v.vert.Y, ref pos);
                                    Utilities.WriteFloat(data, v.vert.Z, ref pos);

                                    if (VertexType != ModelImportVertexType.VertexColors)
                                    {
                                        Utilities.WriteFloat(data, v.normal.X, ref pos);
                                        Utilities.WriteFloat(data, v.normal.Y, ref pos);
                                        Utilities.WriteFloat(data, v.normal.Z, ref pos);
                                    }

                                    if (VertexType == ModelImportVertexType.VertexColors || VertexType == ModelImportVertexType.VertexColorsNormals)
                                    {
                                        Utilities.WriteDWord(data, v.diffuse, ref pos);
                                    }

                                    Utilities.WriteFloat(data, v.uv.X, ref pos);
                                    Utilities.WriteFloat(data, v.uv.Y, ref pos);

                                    if (VertexType == ModelImportVertexType.ExtraUVs || VertexType == ModelImportVertexType.ExtraUVsTangentsBinormals)
                                    {
                                        Utilities.WriteFloat(data, v.uv2.X, ref pos);
                                        Utilities.WriteFloat(data, v.uv2.Y, ref pos);
                                    }

                                    if (VertexType == ModelImportVertexType.ExtraUVsTangentsBinormals || VertexType == ModelImportVertexType.TangentsBinormals)
                                    {
                                        Utilities.WriteFloat(data, v.tangent.X, ref pos);
                                        Utilities.WriteFloat(data, v.tangent.Y, ref pos);
                                        Utilities.WriteFloat(data, v.tangent.Z, ref pos);

                                        Utilities.WriteFloat(data, v.binormal.X, ref pos);
                                        Utilities.WriteFloat(data, v.binormal.Y, ref pos);
                                        Utilities.WriteFloat(data, v.binormal.Z, ref pos);
                                    }
                                }
                            }
                        }
                    }
                }

                TreeNode vmeshnode = CreateNode(vmesh.filename);
                vmeshlib.Nodes.Add(vmeshnode);

                TreeNode vmeshdatanode = CreateNode("VMeshData", data);
                vmeshnode.Nodes.Add(vmeshdatanode);
            }

            uint iTotalVWireIndices = 0;

            if (Wireframe)
            {
            }

            TreeNode consnode = CreateNode("Cons");

            cmpnd.Nodes.Add(consnode);

            if (rev.Parts.Count > 0)
            {
                TreeNode revnode = CreateNode("Rev", rev.GetBytes());
                consnode.Nodes.Add(revnode);
            }

            if (pris.Parts.Count > 0)
            {
                TreeNode prisnode = CreateNode("Pris", pris.GetBytes());
                consnode.Nodes.Add(prisnode);
            }

            if (fix.Parts.Count > 0)
            {
                TreeNode fixnode = CreateNode("Fix", fix.GetBytes());
                consnode.Nodes.Add(fixnode);
            }

            foreach (var cmpnd in cmpndData)
            {
                // Cmpnd child node
                {
                    TreeNode cmpndnode = CreateNode(cmpnd.name);
                    this.cmpnd.Nodes.Add(cmpndnode);

                    TreeNode file_name   = CreateNode("File name", Encoding.ASCII.GetBytes(cmpnd.object_data.file_name + "\u0000"));
                    TreeNode index       = CreateNode("Index", BitConverter.GetBytes(cmpnd.index));
                    TreeNode object_name = CreateNode("Object name", Encoding.ASCII.GetBytes(cmpnd.object_name + "\u0000"));

                    cmpndnode.Nodes.Add(file_name);
                    cmpndnode.Nodes.Add(index);
                    cmpndnode.Nodes.Add(object_name);
                }

                // Root child node
                {
                    TreeNode threedbnode = CreateNode(cmpnd.object_data.file_name);
                    rootCMP.Nodes.Add(threedbnode);

                    if (Wireframe)
                    {
                    }

                    TreeNode multilevel = CreateNode("MultiLevel");
                    threedbnode.Nodes.Add(multilevel);

                    if (cmpnd.object_data.lods > 1)
                    {
                        byte[] data = new byte[4 * cmpnd.object_data.lods];
                        int    pos  = 0;
                        Utilities.WriteFloat(data, 0.0f, ref pos);

                        for (int lod = 1; lod < cmpnd.object_data.lods; lod++)
                        {
                            Utilities.WriteFloat(data, (float)Math.Pow(10.0f, (float)(lod + 1)), ref pos);
                        }
                        Utilities.WriteFloat(data, 1000000.0f, ref pos);

                        TreeNode switch2 = CreateNode("Switch2", data);
                        multilevel.Nodes.Add(switch2);
                    }

                    for (int lod = 0; lod < cmpnd.object_data.lods; lod++)
                    {
                        TreeNode levelnode = CreateNode("Level" + lod);
                        multilevel.Nodes.Add(levelnode);

                        TreeNode vmeshpart = CreateNode("VMeshPart");
                        levelnode.Nodes.Add(vmeshpart);

                        TreeNode vmeshref = CreateNode("VMeshRef", cmpnd.object_data.data[lod].vmeshref.GetBytes());
                        vmeshpart.Nodes.Add(vmeshref);
                    }
                }
            }
        }
Beispiel #11
0
        public static bool LoadScene(FBXManager pManager, FBXDocument pScene, string pFilename)
        {
            int sdkMajor    = 0;
            int sdkMinor    = 0;
            int sdkRevision = 0;

            // int lFileFormat = -1;
            string lPassword = new string(new char[1024]);

            // Get the file version number generate by the FBX SDK.
            FBXManager.GetFileFormatVersion(ref sdkMajor, ref sdkMinor, ref sdkRevision);

            // Create an importer.
            FBXImporter lImporter = FBXImporter.Create(pManager, string.Empty);

            // Initialize the importer by providing a filename.
            bool lImportStatus = lImporter.Initialize(pFilename, -1, pManager.GetIOSettings());

            // lImporter.GetFileVersion(ref lFileMajor, ref lFileMinor, ref lFileRevision);
            if (!lImportStatus)
            {
                var error = lImporter.GetStatus().GetErrorString();
                Debug.WriteLine("Call to FBXImporter::Initialize() failed");
                Debug.WriteLine("Error returned: {0}", error);

                // if (lImporter.GetStatus().GetCode() == FBXStatus.eInvalidFileVersion)
                // {
                // Debug.WriteLine("FBX file format version for this FBX SDK is %d.%d.%d\n", lSDKMajor, lSDKMinor, lSDKRevision);
                // Debug.WriteLine("FBX file format version for file '%s' is %d.%d.%d\n\n", pFilename, lFileMajor, lFileMinor, lFileRevision);
                // }
                return(false);
            }

            Debug.WriteLine("FBX file format version for this FBX SDK is {0}.{1}.{2}", sdkMajor, sdkMinor, sdkRevision);

            if (lImporter.IsFBX())
            {
                // Debug.WriteLine("FBX file format version for file '%s' is %d.%d.%d\n\n", pFilename, lFileMajor, lFileMinor, lFileRevision);

                // From this point, it is possible to access animation stack information without
                // the expense of loading the entire file.
                Debug.WriteLine("Animation Stack Information");

                var lAnimStackCount = lImporter.GetAnimStackCount();

                Debug.WriteLine("    Number of Animation Stacks: {0}", lAnimStackCount);
                Debug.WriteLine("    Current Animation Stack: {0}", lImporter.GetActiveAnimStackName());

                int i;
                for (i = 0; i < lAnimStackCount; i++)
                {
                    // FbxTakeInfo lTakeInfo = lImporter.GetTakeInfo(i);

                    // Debug.WriteLine("    Animation Stack %d\n", i);
                    // Debug.WriteLine("         Name: \"%s\"\n", lTakeInfo.mName.Buffer());
                    // Debug.WriteLine("         Description: \"%s\"\n", lTakeInfo.mDescription.Buffer());

                    //// Change the value of the import name if the animation stack should be imported
                    //// under a different name.
                    // Debug.WriteLine("         Import Name: \"%s\"\n", lTakeInfo.mImportName.Buffer());

                    //// Set the value of the import state to false if the animation stack should be not
                    //// be imported.
                    // Debug.WriteLine("         Import State: %s\n", lTakeInfo.mSelect ? "true" : "false");
                    // Debug.WriteLine("\n");
                }

                //// Set the import states. By default, the import states are always set to
                //// true. The code below shows how to change these states.
                // (*(pManager.GetIOSettings())).SetBoolProp(IMP_FBX_MATERIAL, true);
                // (*(pManager.GetIOSettings())).SetBoolProp(IMP_FBX_TEXTURE, true);
                // (*(pManager.GetIOSettings())).SetBoolProp(IMP_FBX_LINK, true);
                // (*(pManager.GetIOSettings())).SetBoolProp(IMP_FBX_SHAPE, true);
                // (*(pManager.GetIOSettings())).SetBoolProp(IMP_FBX_GOBO, true);
                // (*(pManager.GetIOSettings())).SetBoolProp(IMP_FBX_ANIMATION, true);
                // (*(pManager.GetIOSettings())).SetBoolProp(IMP_FBX_GLOBAL_SETTINGS, true);
            }

            // Import the scene.
            var lStatus = lImporter.Import(pScene);

            // if (lStatus == false && lImporter.GetStatus().GetCode() == FbxStatus.ePasswordError)
            // {
            // Debug.WriteLine("Please enter password: "******"%s", lPassword);
            // FBXSDK_CRT_SECURE_NO_WARNING_END FbxString lString(lPassword);

            // (*(pManager.GetIOSettings())).SetStringProp(IMP_FBX_PASSWORD, lString);
            // (*(pManager.GetIOSettings())).SetBoolProp(IMP_FBX_PASSWORD_ENABLE, true);

            // lStatus = lImporter.Import(pScene);

            // if (lStatus == false && lImporter.GetStatus().GetCode() == FbxStatus.ePasswordError)
            // {
            // Debug.WriteLine("\nPassword is wrong, import aborted.\n");
            // }
            // }
            return(lStatus);
        }
Beispiel #12
0
        public static bool SaveScene(FBXManager pManager, FBXDocument pScene, string pFilename, int pFileFormat = -1, bool pEmbedMedia = false)
        {
            int  lMajor    = 0;
            int  lMinor    = 0;
            int  lRevision = 0;
            bool lStatus   = true;

            // Create an exporter.
            FBXExporter lExporter  = FBXExporter.Create(pManager, string.Empty);
            var         ioSettings = lExporter.GetIOSettings();

            // if (pFileFormat < 0 || pFileFormat >= pManager.GetIOPluginRegistry().GetWriterFormatCount())
            // {
            // // Write in fall back format in less no ASCII format found
            // pFileFormat = pManager.GetIOPluginRegistry().GetNativeWriterFormat();

            // //Try to export in ASCII if possible
            // int lFormatIndex;
            // int lFormatCount = pManager.GetIOPluginRegistry().GetWriterFormatCount();

            // for (lFormatIndex = 0; lFormatIndex < lFormatCount; lFormatIndex++)
            // {
            // if (pManager.GetIOPluginRegistry().WriterIsFBX(lFormatIndex))
            // {
            // FbxString lDesc = pManager.GetIOPluginRegistry().GetWriterFormatDescription(lFormatIndex);
            // string lASCII = "ascii";
            // if (lDesc.Find(lASCII) >= 0)
            // {
            // pFileFormat = lFormatIndex;
            // break;
            // }
            // }
            // }
            // }

            //// Set the export states. By default, the export states are always set to
            //// true except for the option eEXPORT_TEXTURE_AS_EMBEDDED. The code below
            //// shows how to change these states.
            // (*(pManager.GetIOSettings())).SetBoolProp(EXP_FBX_MATERIAL, true);
            // (*(pManager.GetIOSettings())).SetBoolProp(EXP_FBX_TEXTURE, true);
            // (*(pManager.GetIOSettings())).SetBoolProp(EXP_FBX_EMBEDDED, pEmbedMedia);
            // (*(pManager.GetIOSettings())).SetBoolProp(EXP_FBX_SHAPE, true);
            // (*(pManager.GetIOSettings())).SetBoolProp(EXP_FBX_GOBO, true);
            // (*(pManager.GetIOSettings())).SetBoolProp(EXP_FBX_ANIMATION, true);
            // (*(pManager.GetIOSettings())).SetBoolProp(EXP_FBX_GLOBAL_SETTINGS, true);

            // Initialize the exporter by providing a filename.
            if (lExporter.Initialize(pFilename, pFileFormat, pManager.GetIOSettings()) == false)
            {
                Debug.WriteLine("Call to FBXExporter::Initialize() failed.");

                // Debug.WriteLine("Error returned: {0}", lExporter.GetStatus().GetErrorString());
                return(false);
            }

            FBXManager.GetFileFormatVersion(ref lMajor, ref lMinor, ref lRevision);
            Debug.WriteLine("FBX file format version {0}.{1}.{2}", lMajor, lMinor, lRevision);

            // Export the scene.
            Directory.SetCurrentDirectory(Path.GetDirectoryName(pFilename));
            lStatus = lExporter.Export(pScene, false);

            // Destroy the exporter.
            lExporter.Destroy();
            return(lStatus);
        }