Ejemplo n.º 1
0
        public static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAssetOptions rao)
        {
            if (Path.GetExtension(assetPath.ToLower()) != ".abc")
            {
                return(AssetDeleteResult.DidNotDelete);
            }
            var streamingAssetPath = AlembicImporter.MakeShortAssetPath(assetPath);

            AlembicStream.DisconnectStreamsWithPath(streamingAssetPath);

            try
            {
                var fullStreamingAssetPath = Application.streamingAssetsPath + streamingAssetPath;
                File.SetAttributes(fullStreamingAssetPath, FileAttributes.Normal);
                File.Delete(fullStreamingAssetPath);
                File.SetAttributes(fullStreamingAssetPath + ".meta", FileAttributes.Normal);
                File.Delete(fullStreamingAssetPath + ".meta");
            }
            catch (System.Exception e)
            {
                Debug.LogWarning(e);
            }

            return(AssetDeleteResult.DidNotDelete);
        }
        private void FinalizeImport(AlembicStream stream, GameObject newGo, AlembicStreamDescriptor streamDescr)
        {
            if (m_GeneratePrefab)
            {
                var prefabPath = "Assets/" + newGo.name + ".prefab";

                var prefab = PrefabUtility.CreatePrefab(prefabPath, newGo);
                AssetDatabase.SaveAssets();

                if (m_ImportMode > AlembicImportMode.NoSupportForStreaming)
                {
                    AssetDatabase.AddObjectToAsset(streamDescr, prefabPath);
                    AssetDatabase.SaveAssets();

                    if (m_ImportMode == AlembicImportMode.AutomaticStreamingSetup)
                    {
                        var streamDescrAsset =
                            AssetDatabase.LoadAssetAtPath(prefabPath, typeof(AlembicStreamDescriptor)) as AlembicStreamDescriptor;
                        var player = prefab.GetComponent <AlembicStreamPlayer>();
                        player.m_StreamDescriptor = streamDescrAsset;
                    }
                }
                AssetDatabase.SaveAssets();

                SetDefaultMaterial(prefab, prefab.transform);

                AssetDatabase.SaveAssets();
            }
        }
        void OnEnable()
        {
            // Should not be needed...
            bool newPlayerSettings = false;

            if (m_PlaybackSettings == null)
            {
                m_PlaybackSettings = new AlembicPlaybackSettings();
                newPlayerSettings  = true;
            }

            if (_stream == null)
            {
                if (m_StreamDescriptor == null)
                {
                    return;
                }

                _stream = new AlembicStream(gameObject, m_StreamDescriptor.m_ImportSettings, m_PlaybackSettings, m_Diagnotics);
                Stream.AbcLoad(false);

                // Safety net...
                if (newPlayerSettings)
                {
                    m_PlaybackSettings.m_startTime = Stream.AbcStartTime;
                    m_PlaybackSettings.m_endTime   = Stream.AbcEndTime;
                }
            }

            // Re-importing the asset will create a new import settings asset and the stream will be holding on to an old one...
            if (Stream.ImportSettings != m_StreamDescriptor.m_ImportSettings)
            {
                Stream.ImportSettings = m_StreamDescriptor.m_ImportSettings;
            }
        }
        internal static GameObject Import(AlembicImportMode importMode, AlembicImportSettings importSettings, AlembicDiagnosticSettings diagSettings, Action <AlembicStream, GameObject, AlembicStreamDescriptor> customAction)
        {
            var fileName = System.IO.Path.GetFileNameWithoutExtension(importSettings.m_pathToAbc);
            var go       = new GameObject(fileName);

            using (var abcStream = new AlembicStream(go, importSettings, new AlembicPlaybackSettings(), diagSettings))
            {
                abcStream.AbcLoad(true);

                AlembicStreamDescriptor streamDescr = null;
                if (importMode > AlembicImportMode.NoSupportForStreaming)
                {
                    streamDescr                  = ScriptableObject.CreateInstance <AlembicStreamDescriptor>();
                    streamDescr.name             = "AlembicStream: " + go.name;
                    streamDescr.m_ImportSettings = importSettings;
                    streamDescr.m_importMode     = importMode;
                }

                if (importMode == AlembicImportMode.AutomaticStreamingSetup)
                {
                    var dynStream = go.AddComponent <AlembicStreamPlayer>();
                    dynStream.m_PlaybackSettings = new AlembicPlaybackSettings()
                    {
                        m_startTime = abcStream.AbcStartTime,
                        m_endTime   = abcStream.AbcEndTime
                    };
                    dynStream.m_StreamDescriptor = streamDescr;
                    dynStream.enabled            = true;
                }

                customAction.Invoke(abcStream, go, streamDescr);
            }

            return(go);
        }
Ejemplo n.º 5
0
        public void Update()
        {
            if (abcStream == null || streamDescriptor == null)
            {
                return;
            }

            ClampTime();
            if (lastUpdateTime != currentTime || forceUpdate)
            {
                abcStream.vertexMotionScale = vertexMotionScale;
                abcStream.asyncLoad         = asyncLoad;
                if (abcStream.AbcUpdateBegin(startTime + currentTime))
                {
                    lastUpdateTime = currentTime;
                    forceUpdate    = false;
                    updateStarted  = true;
                }
                else
                {
                    abcStream.Dispose();
                    abcStream = null;
                    LoadStream(false);
                }
            }
        }
Ejemplo n.º 6
0
 public void LoadStream(bool createMissingNodes)
 {
     if (streamDescriptor == null)
     {
         return;
     }
     abcStream = new AlembicStream(gameObject, streamDescriptor);
     abcStream.AbcLoad(createMissingNodes);
     forceUpdate = true;
 }
Ejemplo n.º 7
0
 public void LoadStream()
 {
     if (streamDescriptor == null)
     {
         return;
     }
     abcStream = new AlembicStream(gameObject, streamDescriptor);
     abcStream.AbcLoad();
     forceUpdate = true;
 }
Ejemplo n.º 8
0
        private void GenerateSubAssets(AssetImportContext ctx, GameObject go, AlembicStream stream)
        {
            var material = new Material(Shader.Find("Standard"))
            {
            };

            ctx.AddSubAsset("Default Material", material);

            CollectSubAssets(ctx, stream.AlembicTreeRoot, material);
        }
        private void GenerateSubAssets(ImportAssetEventArgs args, GameObject go, AlembicStream stream)
        {
            var material = new Material(Shader.Find("Standard"))
            {
            };

            args.AddSubAsset("Default Material", material);

            CollectSubAssets(stream.AlembicTreeRoot, args, material);
        }
Ejemplo n.º 10
0
        private void GenerateSubAssets(GameObject go, AlembicStream stream)
        {
            var material = new Material(Shader.Find("Standard"))
            {
            };

            AddSubAsset("Default Material", material);

            CollectSubAssets(stream.AlembicTreeRoot, material);
        }
Ejemplo n.º 11
0
        public override void OnImportAsset(AssetImportContext ctx)
        {
            var shortAssetPath = MakeShortAssetPath(ctx.assetPath);

            AlembicStream.DisconnectStreamsWithPath(shortAssetPath);
            var sourcePath    = Application.dataPath + shortAssetPath;
            var destPath      = Application.streamingAssetsPath + shortAssetPath;
            var directoryPath = Path.GetDirectoryName(destPath);

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }
            if (File.Exists(destPath))
            {
                File.SetAttributes(destPath, FileAttributes.Normal);
            }
            File.Copy(sourcePath, destPath, true);

            var fileName = Path.GetFileNameWithoutExtension(destPath);
            var go       = new GameObject(fileName);

            var streamDescriptor = ScriptableObject.CreateInstance <AlembicStreamDescriptor>();

            streamDescriptor.name      = go.name + "_ABCDesc";
            streamDescriptor.pathToAbc = shortAssetPath;
            streamDescriptor.settings  = streamSettings;

            using (var abcStream = new AlembicStream(go, streamDescriptor))
            {
                abcStream.AbcLoad(true);

                abcStream.GetTimeRange(ref startTime, ref endTime);
                streamDescriptor.abcStartTime = abcStartTime = startTime;
                streamDescriptor.abcEndTime   = abcEndTime = endTime;

                var streamPlayer = go.AddComponent <AlembicStreamPlayer>();
                streamPlayer.streamDescriptor = streamDescriptor;
                streamPlayer.startTime        = startTime;
                streamPlayer.endTime          = endTime;

                var subassets = new Subassets(ctx);
                subassets.Add(streamDescriptor.name, streamDescriptor);
                GenerateSubAssets(subassets, abcStream.abcTreeRoot, streamDescriptor);

                AlembicStream.ReconnectStreamsWithPath(shortAssetPath);

#if UNITY_2017_3_OR_NEWER
                ctx.AddObjectToAsset(go.name, go);
                ctx.SetMainObject(go);
#else
                ctx.SetMainAsset(go.name, go);
#endif
            }
        }
Ejemplo n.º 12
0
        public static AssetMoveResult OnWillMoveAsset(string from, string to)
        {
            if (Path.GetExtension(from.ToLower()) != ".abc")
            {
                return(AssetMoveResult.DidNotMove);
            }
            var streamDstPath = AlembicImporter.MakeShortAssetPath(to);
            var streamSrcPath = AlembicImporter.MakeShortAssetPath(from);

            AlembicStream.DisconnectStreamsWithPath(streamSrcPath);
            AlembicStream.RemapStreamsWithPath(streamSrcPath, streamDstPath);

            var dstPath = Application.streamingAssetsPath + streamDstPath;
            var srcPath = Application.streamingAssetsPath + streamSrcPath;

            try
            {
                var directoryPath = Path.GetDirectoryName(dstPath);
                if (File.Exists(dstPath))
                {
                    File.SetAttributes(dstPath + ".meta", FileAttributes.Normal);
                    File.Delete(dstPath);
                }
                else if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }
                if (File.Exists(dstPath))
                {
                    File.SetAttributes(dstPath, FileAttributes.Normal);
                }
                File.Move(srcPath, dstPath);
                if (File.Exists(dstPath + ".meta"))
                {
                    File.SetAttributes(dstPath + ".meta", FileAttributes.Normal);
                    File.Move(srcPath + ".meta", dstPath + ".meta");
                }

                AssetDatabase.Refresh(ImportAssetOptions.Default);
                AlembicStream.ReconnectStreamsWithPath(streamDstPath);
            }
            catch (System.Exception e)
            {
                Debug.LogWarning(e);
            }
            return(AssetMoveResult.DidNotMove);
        }
Ejemplo n.º 13
0
        public static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAssetOptions rao)
        {
            if (Path.GetExtension(assetPath.ToLower()) != ".abc")
            {
                return(AssetDeleteResult.DidNotDelete);
            }
            var streamingAssetPath = assetPath.Replace("Assets", "");

            AlembicStream.DisconnectStreamsWithPath(streamingAssetPath);

            var fullStreamingAssetPath = Application.streamingAssetsPath + streamingAssetPath;

            File.SetAttributes(fullStreamingAssetPath, FileAttributes.Normal);
            File.Delete(fullStreamingAssetPath);
            File.SetAttributes(fullStreamingAssetPath + ".meta", FileAttributes.Normal);
            File.Delete(fullStreamingAssetPath + ".meta");

            return(AssetDeleteResult.DidNotDelete);
        }
Ejemplo n.º 14
0
        public static AssetMoveResult OnWillMoveAsset(string from, string to)
        {
            if (Path.GetExtension(from.ToLower()) != ".abc")
            {
                return(AssetMoveResult.DidNotMove);
            }
            var streamDestPath   = to.Replace("Assets", "");
            var streamSourcePath = from.Replace("Assets", "");

            AlembicStream.DisconnectStreamsWithPath(streamSourcePath);
            AlembicStream.RemapStreamsWithPath(streamSourcePath, streamDestPath);

            var destPath   = Application.streamingAssetsPath + streamDestPath;
            var sourcePath = Application.streamingAssetsPath + streamSourcePath;

            var directoryPath = Path.GetDirectoryName(destPath);

            if (File.Exists(destPath))
            {
                File.SetAttributes(destPath + ".meta", FileAttributes.Normal);
                File.Delete(destPath);
            }
            else if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }
            if (File.Exists(destPath))
            {
                File.SetAttributes(destPath, FileAttributes.Normal);
            }
            File.Move(sourcePath, destPath);
            if (File.Exists(destPath + ".meta"))
            {
                File.SetAttributes(destPath + ".meta", FileAttributes.Normal);
                File.Move(sourcePath + ".meta", destPath + ".meta");
            }
            AssetDatabase.Refresh(ImportAssetOptions.Default);
            AlembicStream.ReconnectStreamsWithPath(streamDestPath);

            return(AssetMoveResult.DidNotMove);
        }
Ejemplo n.º 15
0
        public override void OnImportAsset(AssetImportContext ctx)
        {
            var shortAssetPath = ctx.assetPath.Replace("Assets", "");

            AlembicStream.DisconnectStreamsWithPath(shortAssetPath);
            var sourcePath    = Application.dataPath + shortAssetPath;
            var destPath      = Application.streamingAssetsPath + shortAssetPath;
            var directoryPath = Path.GetDirectoryName(destPath);

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }
            if (File.Exists(destPath))
            {
                File.SetAttributes(destPath, FileAttributes.Normal);
            }
            File.Copy(sourcePath, destPath, true);

            var fileName = Path.GetFileNameWithoutExtension(destPath);
            var go       = new GameObject(fileName);

            go.transform.localScale *= scaleFactor;

            AlembicStreamDescriptor streamDescriptor = ScriptableObject.CreateInstance <AlembicStreamDescriptor>();

            streamDescriptor.name      = go.name + "_ABCDesc";
            streamDescriptor.pathToAbc = shortAssetPath;
            streamDescriptor.settings  = streamSettings;

            using (var abcStream = new AlembicStream(go, streamDescriptor))
            {
                abcStream.AbcLoad();
                AbcStartTime  = abcStream.AbcStartTime;
                AbcEndTime    = abcStream.AbcEndTime;
                AbcFrameCount = abcStream.AbcFrameCount;

                startFrame = startFrame < 0 ? 0 : startFrame;
                endFrame   = endFrame > AbcFrameCount - 1 ? AbcFrameCount - 1 : endFrame;

                streamDescriptor.minFrame      = startFrame;
                streamDescriptor.maxFrame      = endFrame;
                streamDescriptor.abcFrameCount = AbcFrameCount;
                streamDescriptor.abcDuration   = AbcEndTime - AbcStartTime;
                streamDescriptor.abcStartTime  = AbcStartTime;

                var streamPlayer = go.AddComponent <AlembicStreamPlayer>();
                streamPlayer.streamDescriptor = streamDescriptor;
                streamPlayer.startFrame       = startFrame;
                streamPlayer.endFrame         = endFrame;

                AddObjectToAsset(ctx, streamDescriptor.name, streamDescriptor);
                GenerateSubAssets(ctx, abcStream.alembicTreeRoot, streamDescriptor);

                AlembicStream.ReconnectStreamsWithPath(shortAssetPath);

#if UNITY_2017_3_OR_NEWER
                ctx.AddObjectToAsset(go.name, go);
                ctx.SetMainObject(go);
#else
                ctx.SetMainAsset(go.name, go);
#endif
            }
        }