示例#1
0
        public static string ExportGameObject(GameObject gameObj, bool copyMaterials, bool copyTextures, string oldPath = null)
        {
            oldPath = RockStudio.defaultPath;

            if (gameObj == null)
            {
                EditorUtility.DisplayDialog("Object is null", "Please select any GameObject to Export to FBX", "Okay");
                return(null);
            }

            string newPath = GetNewPath(gameObj, oldPath);

            if (newPath != null && newPath.Length != 0)
            {
                bool isSuccess = FBXExporter.ExportGameObjToFBX(gameObj, newPath, copyMaterials, copyTextures);

                if (isSuccess)
                {
                    return(newPath);
                }
                else
                {
                    EditorUtility.DisplayDialog("Warning", "The extension probably wasn't an FBX file, could not export.", "Okay");
                }
            }
            return(null);
        }
示例#2
0
    public void ClickSave()
    {
        Action threadAction = () =>
        {
            Debug.Log("Тык");
            GameObject mesh     = null;
            string     meshName = null;
            string     path     = null;

            Execute(() =>   //Будет выполено в мейнтреде
            {
                mesh     = GameObject.Find("Spatial Awareness System");
                meshName = mesh.name;
                path     = Path.Combine(Application.persistentDataPath, "data");
                testThread.Interrupt();
            });

            path = Path.Combine(path, meshName + ".fbx");

            if (!Directory.Exists(Path.GetDirectoryName(path)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(path));
            }

            Execute(() =>
            {
                FBXExporter.ExportGameObjToFBX(mesh, path, false, false);
                testThread.Interrupt();
            });
        };

        testThread = new Thread(new ThreadStart(threadAction));
        testThread.Start();
    }
示例#3
0
    private static void ExportFBXForTheseObjects(GameObject[] objectsToCombine, string folderPathForFBX, string fbxName, bool addObjectInHierarchy, GameObject parentGameobject)
    {
        List <Material> list = new List <Material>();

        list = FBXExporter.GetUniqueMaterials(objectsToCombine);
        GameObject gameObject;

        if (addObjectInHierarchy)
        {
            gameObject = FBXExporter.DuplicateObject(parentGameobject);
        }
        else
        {
            bool flag = objectsToCombine.Length == 1;
            if (flag)
            {
                gameObject = FBXExporter.DuplicateObject(objectsToCombine[0]);
            }
            else
            {
                gameObject = new GameObject(fbxName);
                for (int i = 0; i < objectsToCombine.Length; i++)
                {
                    GameObject gameObject2 = FBXExporter.DuplicateObject(objectsToCombine[i]);
                    gameObject2.transform.parent = gameObject.transform;
                }
            }
        }
        gameObject.name = fbxName;
        FBXExporter.BuildAndSaveFBX(folderPathForFBX, fbxName, gameObject, list.ToArray());
        GameObject.DestroyImmediate(gameObject);
    }
示例#4
0
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.J))
     {
         FBXExporter.ExportGameObjToFBX(_tileModel, _folder, false, false);
         Debug.Log("EXPORT TRIGGERED!!!!!!!!!!");
     }
 }
示例#5
0
 static void ToFbxFile()
 {
     GameObject[] meshObjs = new GameObject[1];
     meshObjs[0] = Selection.activeGameObject;
     //用到动态库WRP_FBXExporter
     FBXExporter.ExportFBX("", "WarehouseScene", meshObjs, false);
     Debug.Log("完成");
 }
示例#6
0
 void Start()
 {
     meshObject = this.gameObject;
     GameObject[] meshObjs = new GameObject[1];
     meshObjs[0] = meshObject;
     //用到动态库WRP_FBXExporter
     // FBXExporter.ExportFBX("", "Wall", meshObjs, true);
     FBXExporter.ExportFBX("/Resources", "Wall", meshObjs, true);
 }
示例#7
0
 public static void ExportSplitObjects(string savePath, TreeNodeCollection nodes, bool isNew = false)
 {
     ThreadPool.QueueUserWorkItem(state =>
     {
         foreach (TreeNode node in nodes)
         {
             //遍历一级子节点
             foreach (TreeNode j in node.Nodes)
             {
                 ProgressBarPerformStep();
                 //收集所有子节点
                 var gameObjects = new List <GameObject>();
                 CollectNode(j, gameObjects);
                 //跳过一些不需要导出的object
                 if (gameObjects.All(x => x.m_SkinnedMeshRenderer == null && x.m_MeshFilter == null))
                 {
                     continue;
                 }
                 //处理非法文件名
                 var filename = FixFileName(j.Text);
                 //每个文件存放在单独的文件夹
                 var targetPath = $"{savePath}{filename}\\";
                 //重名文件处理
                 for (int i = 1; ; i++)
                 {
                     if (Directory.Exists(targetPath))
                     {
                         targetPath = $"{savePath}{filename} ({i})\\";
                     }
                     else
                     {
                         break;
                     }
                 }
                 Directory.CreateDirectory(targetPath);
                 //导出FBX
                 StatusStripUpdate($"Exporting {filename}.fbx");
                 if (isNew)
                 {
                     try
                     {
                         ExportGameObject((GameObject)j, targetPath);
                     }
                     catch (Exception ex)
                     {
                         MessageBox.Show($"{ex.Message}\r\n{ex.StackTrace}");
                     }
                 }
                 else
                 {
                     FBXExporter.WriteFBX($"{targetPath}{filename}.fbx", gameObjects);
                 }
                 StatusStripUpdate($"Finished exporting {filename}.fbx");
             }
         }
     });
 }
示例#8
0
    public static void ExportFBX(string folderPathForFBX, string fbxName, GameObject[] selectedObjects, bool addObjectInHierarchy)
    {
        fbxName = FBXExporter.GetUniqueName(fbxName, folderPathForFBX, ".fbx");
        bool flag = FBXExporter.ErrorCheckings(selectedObjects, addObjectInHierarchy) != 0;

        if (!flag)
        {
            GameObject[] objectsToCombine = FBXExporter.GetObjectsToCombine(selectedObjects, addObjectInHierarchy);
            FBXExporter.SetDirectories(folderPathForFBX);
            FBXExporter.ExportFBXForTheseObjects(objectsToCombine, folderPathForFBX, fbxName, addObjectInHierarchy, selectedObjects[0]);
        }
    }
示例#9
0
    void OnGUI()
    {
        EditorGUILayout.Separator();
        GUILayout.Label("Select options and hit apply...");
        EditorGUILayout.Separator();

        addObjectsInHierarchy = EditorGUILayout.Toggle("Add Objects in heirarchy", addObjectsInHierarchy);

        EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator();

        GameObject[] objectsToCombine = FBXExporter.GetObjectsToCombine(Selection.gameObjects, addObjectsInHierarchy);

        if (nameSetByUser == false)
        {
            SetNameAndPath(objectsToCombine);
        }

        string objectsToString = "";

        for (int i = 0; i < objectsToCombine.Length; i++)
        {
            objectsToString += objectsToCombine[i].name;
            if (i < objectsToCombine.Length - 1)
            {
                objectsToString += "\n";
            }
        }
        EditorGUILayout.LabelField("Selected Objects : " + objectsToCombine.Length);
        scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(200), GUILayout.Height(80));

        EditorGUILayout.TextArea(objectsToString);

        EditorGUILayout.EndScrollView();

        EditorGUILayout.Separator();

        EditorGUILayout.BeginHorizontal();
        pathForFBX = EditorGUILayout.TextArea(pathForFBX, GUILayout.MaxWidth(250));
        if (GUILayout.Button("Browse"))
        {
            pathForFBX = GetFilePath();
        }
        EditorGUILayout.EndHorizontal();

        if (GUILayout.Button("Export"))
        {
            folderPathForFBX = pathForFBX.Replace("Assets", "");
            folderPathForFBX = folderPathForFBX.Replace("/" + fbxName + ".fbx", "");

            FBXExporter.ExportFBX(folderPathForFBX, fbxName, Selection.gameObjects, addObjectsInHierarchy);
        }
    }
示例#10
0
    private static void Export(string filename, string folder, TrackBuildR data, Mesh exportMesh, ExportMaterial[] exportTextures)
    {
        switch (data.fileType)
        {
        case TrackBuildR.fileTypes.Obj:
            OBJExporter.Export(folder, filename, exportMesh, exportTextures, data.copyTexturesIntoExportFolder);
            break;

        case TrackBuildR.fileTypes.Fbx:
            FBXExporter.Export(folder, filename, exportMesh, exportTextures, data.copyTexturesIntoExportFolder);
            break;
        }
    }
示例#11
0
    void ExportMesh(GameObject obj)
    {
        if (fileFormatSelector.value == 0)
        {
            FBXExporter.ExportGameObjToFBX(obj, _path, false, false);
        }

        if (fileFormatSelector.value == 1)
        {
            ObjExporter.MeshToFile(obj.GetComponent <MeshFilter>(), _path);
        }
        Debug.Log("exported");
    }
示例#12
0
    private static void Export(string filename, string folder, BuildrData data, Mesh exportMesh, ExportMaterial[] exportTextures)
    {
        switch (data.filetype)
        {
        case BuildrData.filetypes.obj:
            OBJExporter.Export(folder, filename, exportMesh, exportTextures, data.copyTexturesIntoExportFolder);
            break;

        case BuildrData.filetypes.fbx:
            FBXExporter.Export(folder, filename, exportMesh, exportTextures, data.copyTexturesIntoExportFolder);
            break;
        }
    }
示例#13
0
        private void menuExportClick(object sender, EventArgs e)
        {
            ToolStripMenuItem mi = (ToolStripMenuItem)sender;

            switch (mi.Text)
            {
            case "Autodesk FBX File...":
                sfdBrowse.Filter = "Autodesk FBX files (*.fbx)|*.fbx";
                if (sfdBrowse.ShowDialog() == DialogResult.OK)
                {
                    FBXExporter fx = new FBXExporter();
                    fx.ExportSettings.AddSetting("NeedsFlipping", SceneManager.Current.CoordinateSystem == CoordinateSystem.LeftHanded);
                    fx.ExportSettings.AddSetting("Version", FlummeryApplication.Version);
                    fx.Export(SceneManager.Current.Models[0], sfdBrowse.FileName);

                    SceneManager.Current.UpdateProgress($"Saved {Path.GetFileName(sfdBrowse.FileName)}");
                }
                break;
            }
        }
示例#14
0
        private static void ExportMesh(Mesh mesh, string path, ExportMeshFormat format, object data, bool switchUv)
        {
            string formatName = GetMeshFormat(format);
            string finalPath  = path + formatName;

            if (File.Exists(finalPath))
            {
                File.Delete(finalPath);
            }

            switch (format)
            {
            case ExportMeshFormat.FBX:
                FBXExporter.ExportMesh(mesh, finalPath, switchUv);
                break;

            case ExportMeshFormat.OBJ_NotWorking:
                break;
            }
        }
示例#15
0
    /// <summary>
    /// 保存
    /// </summary>
    /// <param name="meshObject"></param>
    public void Btn_SaveScene(GameObject meshObject)
    {
#if UNITY_EDITOR
        //GameObject  go = (GameObject) AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Resources/Wall.fbx");


        //if (null != go )
        //{
        //    Debug.Log(AssetDatabase.GetAssetPath(go));
        //    EditorGUIUtility.PingObject(go);//显示黄色的框
        //    AssetDatabase.Refresh();
        //}
#endif
        meshObject = GameObject.Find("Ground");
        GameObject[] meshObjs = new GameObject[1];
        meshObjs[0] = meshObject;
        print("保存");

        FBXExporter.ExportFBX("/Resources", "Wall", meshObjs, true);
    }
示例#16
0
        static IEnumerator SaveUniqueHLODAssetOfFbx(Transform hlodRoot, string savePath)
        {
            if (!string.IsNullOrEmpty(savePath))
            {
                var directory = Path.Combine(savePath, s_DirectoryName);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                var path = Path.Combine(directory, hlodRoot.name);
                path = Path.ChangeExtension(path, "fbx");
                path = path.Replace("/", "\\");
                FBXExporter.ExportGameObjToFBX(hlodRoot.gameObject, path, false, false);
                yield return(null);

                var assetImporter = AssetImporter.GetAtPath(path);
                var modelImporter = assetImporter as ModelImporter;
                if (modelImporter && !modelImporter.isReadable)
                {
                    modelImporter.isReadable = true;
                }
                modelImporter.importBlendShapes = false;
                modelImporter.importVisibility  = false;
                modelImporter.importCameras     = false;
                modelImporter.importLights      = false;
                modelImporter.meshCompression   = ModelImporterMeshCompression.High;
                modelImporter.indexFormat       = ModelImporterIndexFormat.Auto;
                modelImporter.animationType     = ModelImporterAnimationType.None;
                modelImporter.importAnimation   = false;
                //modelImporter.materialImportMode = ModelImporterMaterialImportMode.None;
                modelImporter.SaveAndReimport();
                yield return(null);

                var        fbx = AssetDatabase.LoadAssetAtPath <GameObject>(path);
                MeshFilter m   = fbx.GetComponent <MeshFilter>();
                MeshFilter mh  = hlodRoot.GetComponent <MeshFilter>();
                hlodRoot.GetComponent <MeshFilter>().sharedMesh = m.sharedMesh;
            }
        }
示例#17
0
 public static void ExportSplitObjects(string savePath, TreeNodeCollection nodes)
 {
     foreach (TreeNode node in nodes)
     {
         //遍历一级子节点
         foreach (TreeNode j in node.Nodes)
         {
             //收集所有子节点
             var gameObjects = new List <GameObject>();
             CollectNode(j, gameObjects);
             //跳过一些不需要导出的object
             if (gameObjects.All(x => x.m_SkinnedMeshRenderer == null && x.m_MeshFilter == null))
             {
                 continue;
             }
             //处理非法文件名
             var filename = FixFileName(j.Text);
             //每个文件存放在单独的文件夹
             var targetPath = $"{savePath}{filename}\\";
             //重名文件处理
             for (int i = 1; ; i++)
             {
                 if (Directory.Exists(targetPath))
                 {
                     targetPath = $"{savePath}{filename} ({i})\\";
                 }
                 else
                 {
                     break;
                 }
             }
             Directory.CreateDirectory(targetPath);
             //导出FBX
             StatusStripUpdate($"Exporting {filename}.fbx");
             FBXExporter.WriteFBX($"{targetPath}{filename}.fbx", gameObjects);
             StatusStripUpdate($"Finished exporting {filename}.fbx");
         }
         ProgressBarPerformStep();
     }
 }
示例#18
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);
        }