protected override bool Export()
        {
            if (string.IsNullOrEmpty(ExportFileName))
            {
                Debug.LogError("FbxExporter: Please specify an fbx filename");
                return(false);
            }
            var folderPath = ExportSettings.GetAbsoluteSavePath(FbxSavePaths[SelectedFbxPath]);
            var filePath   = System.IO.Path.Combine(folderPath, ExportFileName + ".fbx");

            if (!OverwriteExistingFile(filePath))
            {
                return(false);
            }

            string exportResult;

            if (IsTimelineAnim)
            {
                exportResult = ModelExporter.ExportTimelineClip(filePath, TimelineClipToExport, PlayableDirector, SettingsObject);
            }
            else
            {
                exportResult = ModelExporter.ExportObjects(filePath, ToExport, SettingsObject);
            }

            if (!string.IsNullOrEmpty(exportResult))
            {
                // refresh the asset database so that the file appears in the
                // asset folder view.
                AssetDatabase.Refresh();
            }
            return(true);
        }
Exemplo n.º 2
0
        // Export GameObjects sample function
        public static void ExportGameObjects(Object[] objects)
        {
            string filePath = Path.Combine(Application.dataPath, "MyGame.fbx");

            ModelExporter.ExportObjects(filePath, objects);

            // ModelExporter.ExportObject can be used instead of
            // ModelExporter.ExportObjects to export a single game object
        }
Exemplo n.º 3
0
    public static void ExportGameObjects(Object[] objects, string path)
    {
        //Its working. Disable for build
        path = "Exported/" + path + ".fbx";
        string filePath = Path.Combine(Application.dataPath, path);

        ModelExporter.ExportObjects(filePath, objects);
        Debug.Log("Exported to: " + Application.dataPath + path);
    }
Exemplo n.º 4
0
        protected override void EndRecording(RecordingSession session)
        {
            if (session == null)
            {
                throw new System.ArgumentNullException("session");
            }

            var settings = (FbxRecorderSettings)session.settings;

            foreach (var input in m_Inputs)
            {
                var aInput = (AnimationInput)input;

                if (aInput.GameObjectRecorder == null)
                {
                    continue;
                }

                var clip = new AnimationClip();

                settings.FileNameGenerator.CreateDirectory(session);

                var absolutePath = FileNameGenerator.SanitizePath(settings.FileNameGenerator.BuildAbsolutePath(session));
                var clipName     = absolutePath.Replace(FileNameGenerator.SanitizePath(Application.dataPath), "Assets");

#if UNITY_2019_3_OR_NEWER
                var options = new Animations.CurveFilterOptions();
                options.keyframeReduction = false;
                aInput.GameObjectRecorder.SaveToClip(clip, settings.FrameRate, options);
#else
                aInput.GameObjectRecorder.SaveToClip(clip, settings.FrameRate);
#endif
                var root = ((AnimationInputSettings)aInput.settings).gameObject;
                clip.name = "recorded_clip";

                var exportSettings = new ExportModelSettingsSerialize();
                exportSettings.SetAnimationSource(settings.TransferAnimationSource);
                exportSettings.SetAnimationDest(settings.TransferAnimationDest);
                exportSettings.SetObjectPosition(ExportSettings.ObjectPosition.WorldAbsolute);
                var toInclude = ExportSettings.Include.ModelAndAnim;
                if (!settings.ExportGeometry)
                {
                    toInclude = ExportSettings.Include.Anim;
                }
                exportSettings.SetModelAnimIncludeOption(toInclude);

                var exportData = new AnimationOnlyExportData();
                exportData.CollectDependencies(clip, root, exportSettings);
                var exportDataContainer = new Dictionary <GameObject, IExportData>();
                exportDataContainer.Add(root, exportData);

                ModelExporter.ExportObjects(clipName, new UnityEngine.Object[] { root }, exportSettings, exportDataContainer);

                aInput.GameObjectRecorder.ResetRecording();
            }
            base.EndRecording(session);
        }
        public void TestExportOutsideProject()
        {
            Assert.IsNotNull(m_toExport);
            Assert.Greater(m_toExport.Length, 1);
            var filename = GetTempOutsideFilePath();

            var fbxFileName = ModelExporter.ExportObjects(filename, m_toExport);

            Assert.IsNotNull(fbxFileName);
            Assert.AreEqual(fbxFileName, filename);
        }
Exemplo n.º 6
0
        protected void Export()
        {
            var validatedObjects = RecordedObjectEntity.latestEntities.Where(t => t.target != null).ToArray();

            if (validatedObjects.Length == 0)
            {
                Debug.LogError("Please set the export objects.");
                return;
            }

            var animatorControllerBackup = new Dictionary <Animator, RuntimeAnimatorController> ();

            try {
                // 出力用のAnimator.runtimeAnimatorController を作成
                foreach (var obj in validatedObjects)
                {
                    var target = obj.target;

                    animatorControllerBackup[target] = target.runtimeAnimatorController;


                    var controller = CreateAnimatorControllerWithClip(obj.clip);
                    target.runtimeAnimatorController = controller;
                }

                // 単数の場合はクリップ名なければ、オブジェクト名で複数ある場合はシーン名で出力する。
                string filename = SceneManager.GetActiveScene().name;
                if (validatedObjects.Length == 1)
                {
                    if (validatedObjects[0].clip == null)
                    {
                        filename = validatedObjects[0].target.name;
                    }
                    else
                    {
                        filename = validatedObjects[0].clip.name;
                    }
                }

                string filePath = Path.Combine(exportFolder, filename + ".fbx");
                ModelExporter.ExportObjects(filePath, validatedObjects.Select(t => t.target).ToArray());
            }
            finally {
                // Animator.runtimeAnimatorController をもとに戻す
                foreach (var obj in validatedObjects)
                {
                    Object.DestroyImmediate(obj.target.runtimeAnimatorController);
                    obj.target.runtimeAnimatorController = animatorControllerBackup[obj.target];
                }
            }
        }
        public void TestPerformance()
        {
            Assert.IsNotNull(m_toExport);

            var filename = GetRandomFbxFilePath();

            UnityEngine.Debug.unityLogger.logEnabled = false;

            m_stopwatch.Reset();
            m_stopwatch.Start();
            var fbxFileName = ModelExporter.ExportObjects(filename, new Object[] { m_toExport }) as string;

            m_stopwatch.Stop();

            UnityEngine.Debug.unityLogger.logEnabled = true;

            Assert.IsNotNull(fbxFileName);
            Assert.LessOrEqual(m_stopwatch.ElapsedMilliseconds, PerformanceThresholdMilliseconds);
        }
        public void TestExportObjects()
        {
            Assert.IsNotNull(m_toExport);
            Assert.Greater(m_toExport.Length, 1);
            var filename = GetRandomFbxFilePath();

            var fbxFileName = ModelExporter.ExportObjects(filename, m_toExport);

            Assert.IsNotNull(fbxFileName);
            Assert.AreEqual(fbxFileName, filename);

            Object[] loaded       = AssetDatabase.LoadAllAssetsAtPath(filename);
            var      loadedMeshes = (from loadedObj in loaded where loadedObj as Mesh != null select loadedObj as Mesh).ToArray();

            Assert.AreEqual(2, loadedMeshes.Length);
            foreach (var mesh in loadedMeshes)
            {
                Assert.Greater(mesh.triangles.Length, 0);
            }
        }
Exemplo n.º 9
0
        public void ExportSingleTimelineClipFromExportDataTest()
        {
            string cubeSpecialPath = FindPathInUnitTests("Scene/CubeSpecial.prefab");

            GameObject myCube     = AddAssetToScene(cubeSpecialPath);
            string     folderPath = GetRandomFileNamePath(extName: "");
            string     filePath   = null;
            var        exportData = new Dictionary <GameObject, IExportData>();

            PlayableDirector pd = myCube.GetComponent <PlayableDirector>();

            if (pd != null)
            {
                foreach (PlayableBinding output in pd.playableAsset.outputs)
                {
                    AnimationTrack at = output.sourceObject as AnimationTrack;

                    var atComponent = pd.GetGenericBinding(at) as Component;
                    Assert.That(atComponent, Is.Not.Null);

                    var atObject = atComponent.gameObject;

                    // One file by animation clip
                    foreach (TimelineClip timeLineClip in at.GetClips())
                    {
                        Assert.That(timeLineClip.animationClip, Is.Not.Null);

                        filePath             = $"{folderPath}/{atObject.name}@Recorded.fbx";
                        exportData[atObject] = ModelExporter.GetExportData(atObject, timeLineClip.animationClip);
                        break;
                    }
                }
            }
            Assert.That(filePath, Is.Not.Null);
            Assert.That(exportData, Is.Not.Null);
            ModelExporter.ExportObjects(filePath, new UnityEngine.Object[1] {
                myCube
            }, null, exportData);
            FileAssert.Exists(filePath);
        }
        protected override bool Export()
        {
            if (string.IsNullOrEmpty(ExportFileName))
            {
                Debug.LogError("FbxExporter: Please specify an fbx filename");
                return(false);
            }
            var folderPath = ExportSettings.GetAbsoluteSavePath(FbxSavePaths[SelectedFbxPath]);
            var filePath   = System.IO.Path.Combine(folderPath, ExportFileName + ".fbx");

            if (!OverwriteExistingFile(filePath))
            {
                return(false);
            }

            if (ModelExporter.ExportObjects(filePath, GetToExport(), SettingsObject) != null)
            {
                // refresh the asset database so that the file appears in the
                // asset folder view.
                AssetDatabase.Refresh();
            }
            return(true);
        }
Exemplo n.º 11
0
        internal virtual GameObject ExportSelection(string filename, Object[] selected, IExportOptions exportOptions = null)
        {
            Debug.unityLogger.logEnabled = false;
            var fbxFileName = ModelExporter.ExportObjects(filename, selected, exportOptions) as string;

            Debug.unityLogger.logEnabled = true;

            Assert.IsNotNull(fbxFileName);

            // make filepath relative to project folder
            if (fbxFileName.StartsWith(Application.dataPath, System.StringComparison.CurrentCulture))
            {
                fbxFileName = "Assets" + fbxFileName.Substring(Application.dataPath.Length);
            }
            // refresh the assetdata base so that we can query for the model
            AssetDatabase.Refresh();

            Object unityMainAsset = AssetDatabase.LoadMainAssetAtPath(fbxFileName);
            var    fbxRoot        = unityMainAsset as GameObject;

            Assert.IsNotNull(fbxRoot);
            return(fbxRoot);
        }