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); }
public void LoadStream(bool createMissingNodes) { if (streamDescriptor == null) { return; } abcStream = new AlembicStream(gameObject, streamDescriptor); abcStream.AbcLoad(createMissingNodes); forceUpdate = true; }
public void LoadStream() { if (streamDescriptor == null) { return; } abcStream = new AlembicStream(gameObject, streamDescriptor); abcStream.AbcLoad(); forceUpdate = true; }
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 } }
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 } }