Ejemplo n.º 1
0
        private void GenerateSubAssets(AssetImportContext ctx, AlembicTreeNode root, AlembicStreamDescriptor streamDescr)
        {
            var material = new Material(Shader.Find("Standard"));

            AddObjectToAsset(ctx, "Default Material", material);

            if (streamDescr.Duration > 0)
            {
                Keyframe[] frames = new Keyframe[2];
                frames[0].value       = 0.0f;
                frames[0].time        = 0.0f;
                frames[0].tangentMode = (int)AnimationUtility.TangentMode.Linear;
                frames[0].outTangent  = 1.0f;
                frames[1].value       = streamDescr.Duration;
                frames[1].time        = streamDescr.Duration;
                frames[1].tangentMode = (int)AnimationUtility.TangentMode.Linear;
                frames[1].inTangent   = 1.0f;
                AnimationCurve curve         = new AnimationCurve(frames);
                var            animationClip = new AnimationClip();
                animationClip.SetCurve("", typeof(AlembicStreamPlayer), "currentTime", curve);
                animationClip.name = root.linkedGameObj.name + "_Clip";

                AddObjectToAsset(ctx, "Default Animation", animationClip);
            }
            varyingTopologyMeshNames = new List <string>();
            splittingMeshNames       = new List <string>();

            CollectSubAssets(ctx, root, material);

            streamDescr.hasVaryingTopology = varyingTopologyMeshNames.Count > 0;
        }
Ejemplo n.º 2
0
        private void CollectSubAssets(AssetImportContext ctx, AlembicTreeNode node, Material mat)
        {
            if (m_ImportSettings.m_importMeshes)
            {
                var meshFilter = node.linkedGameObj.GetComponent <MeshFilter>();
                if (meshFilter != null)
                {
                    var m = meshFilter.sharedMesh;
                    m.name = node.linkedGameObj.name;
                    ctx.AddSubAsset(m.name, m);
                }
            }

            var renderer = node.linkedGameObj.GetComponent <MeshRenderer>();

            if (renderer != null)
            {
                renderer.material = mat;
            }

            foreach (var child in node.children)
            {
                CollectSubAssets(ctx, child, mat);
            }
        }
Ejemplo n.º 3
0
        private void GenerateSubAssets(Subassets subassets, AlembicTreeNode root, AlembicStreamDescriptor streamDescr)
        {
            if (streamDescr.duration > 0)
            {
                var frames = new Keyframe[2];
                frames[0].value      = 0.0f;
                frames[0].time       = 0.0f;
                frames[0].outTangent = 1.0f;
                frames[1].value      = (float)streamDescr.duration;
                frames[1].time       = (float)streamDescr.duration;
                frames[1].inTangent  = 1.0f;

                var curve = new AnimationCurve(frames);
                AnimationUtility.SetKeyLeftTangentMode(curve, 0, AnimationUtility.TangentMode.Linear);
                AnimationUtility.SetKeyRightTangentMode(curve, 1, AnimationUtility.TangentMode.Linear);

                var animationClip = new AnimationClip();
                animationClip.SetCurve("", typeof(AlembicStreamPlayer), "currentTime", curve);
                animationClip.name      = root.gameObject.name + "_Clip";
                animationClip.hideFlags = HideFlags.NotEditable;

                subassets.Add("Default Animation", animationClip);
            }
            varyingTopologyMeshNames = new List <string>();
            splittingMeshNames       = new List <string>();

            CollectSubAssets(subassets, root);

            streamDescr.hasVaryingTopology = varyingTopologyMeshNames.Count > 0;
        }
Ejemplo n.º 4
0
 public AlembicStream(GameObject rootGo, AlembicStreamDescriptor streamDesc)
 {
     m_Config.SetDefaults();
     alembicTreeRoot = new AlembicTreeNode()
     {
         streamDescriptor = streamDesc, linkedGameObj = rootGo
     };
     m_StreamDesc = streamDesc;
 }
Ejemplo n.º 5
0
 public AlembicStream(GameObject rootGo, AlembicStreamDescriptor streamDesc)
 {
     m_config.SetDefaults();
     m_abcTreeRoot = new AlembicTreeNode()
     {
         stream = this, gameObject = rootGo
     };
     m_streamDesc = streamDesc;
 }
Ejemplo n.º 6
0
        void CollectSubAssets(Subassets subassets, AlembicTreeNode node)
        {
            var mesh = node.GetAlembicObj <AlembicMesh>();

            if (mesh != null)
            {
                var sum = mesh.summary;
                if (mesh.summary.topologyVariance == aiTopologyVariance.Heterogeneous)
                {
                    varyingTopologyMeshNames.Add(node.gameObject.name);
                }
                else if (mesh.sampleSummary.splitCount > 1)
                {
                    splittingMeshNames.Add(node.gameObject.name);
                }
            }

            int submeshCount = 0;
            var meshFilter   = node.gameObject.GetComponent <MeshFilter>();

            if (meshFilter != null)
            {
                var m = meshFilter.sharedMesh;
                submeshCount = m.subMeshCount;
                m.name       = node.gameObject.name;
                subassets.Add(node.abcObject.abcObject.fullname, m);
            }

            var renderer = node.gameObject.GetComponent <MeshRenderer>();

            if (renderer != null)
            {
                var mats = new Material[submeshCount];
                for (int i = 0; i < submeshCount; ++i)
                {
                    mats[i] = subassets.defaultMaterial;
                }
                renderer.sharedMaterials = mats;
            }

            var apr = node.gameObject.GetComponent <AlembicPointsRenderer>();

            if (apr != null)
            {
                var cubeGO = GameObject.CreatePrimitive(PrimitiveType.Cube);
                apr.sharedMesh = cubeGO.GetComponent <MeshFilter>().sharedMesh;
                DestroyImmediate(cubeGO);

                apr.sharedMaterials      = new Material[] { subassets.pointsMaterial };
                apr.motionVectorMaterial = subassets.pointsMotionVectorMaterial;
            }

            foreach (var child in node.children)
            {
                CollectSubAssets(subassets, child);
            }
        }
Ejemplo n.º 7
0
 void AbcBeforeUpdateSamples(AlembicTreeNode node)
 {
     if (node.abcObject != null && node.gameObject != null)
     {
         node.abcObject.AbcPrepareSample();
     }
     foreach (var child in node.children)
     {
         AbcBeforeUpdateSamples(child);
     }
 }
Ejemplo n.º 8
0
 void AbcBeginSyncData(AlembicTreeNode node)
 {
     foreach (var obj in node.alembicObjects)
     {
         obj.Value.AbcSyncDataBegin();
     }
     foreach (var child in node.children)
     {
         AbcBeginSyncData(child);
     }
 }
Ejemplo n.º 9
0
 void AbcBeforeUpdateSamples(AlembicTreeNode node)
 {
     foreach (var obj in node.alembicObjects)
     {
         obj.Value.AbcPrepareSample();
     }
     foreach (var child in node.children)
     {
         AbcBeforeUpdateSamples(child);
     }
 }
Ejemplo n.º 10
0
 void AbcEndSyncData(AlembicTreeNode node)
 {
     if (node.abcObject != null && node.gameObject != null)
     {
         node.abcObject.AbcSyncDataEnd();
     }
     foreach (var child in node.children)
     {
         AbcEndSyncData(child);
     }
 }
Ejemplo n.º 11
0
        public AlembicStream(GameObject rootGo, AlembicImportSettings importSettings, AlembicPlaybackSettings playSettings, AlembicDiagnosticSettings diagSettings)
        {
            _alembicTreeRoot = new AlembicTreeNode()
            {
                stream = this, linkedGameObj = rootGo
            };
            ImportSettings     = importSettings;
            m_playbackSettings = playSettings;
            m_diagSettings     = diagSettings ?? new AlembicDiagnosticSettings();

            AbcAPI.aiEnableFileLog(m_diagSettings.m_logToFile, m_diagSettings.m_logPath);
        }
Ejemplo n.º 12
0
        void GenerateSubAssets(Subassets subassets, AlembicTreeNode root, AlembicStreamDescriptor streamDescr)
        {
            if (streamDescr.duration > 0)
            {
                // AnimationClip for time
                {
                    var frames = new Keyframe[2];
                    frames[0].value      = 0.0f;
                    frames[0].time       = 0.0f;
                    frames[0].outTangent = 1.0f;
                    frames[1].value      = (float)streamDescr.duration;
                    frames[1].time       = (float)streamDescr.duration;
                    frames[1].inTangent  = 1.0f;

                    var curve = new AnimationCurve(frames);
                    AnimationUtility.SetKeyLeftTangentMode(curve, 0, AnimationUtility.TangentMode.Linear);
                    AnimationUtility.SetKeyRightTangentMode(curve, 1, AnimationUtility.TangentMode.Linear);

                    var clip = new AnimationClip();
                    clip.SetCurve("", typeof(AlembicStreamPlayer), "currentTime", curve);
                    clip.name      = root.gameObject.name + "_Time";
                    clip.hideFlags = HideFlags.NotEditable;

                    subassets.Add("Default Animation", clip);
                }

                // AnimationClip for frame events
                {
                    var abc = root.stream.abcContext;
                    var n   = abc.timeSamplingCount;
                    for (int i = 1; i < n; ++i)
                    {
                        var clip = new AnimationClip();
                        if (AddFrameEvents(clip, abc.GetTimeSampling(i)))
                        {
                            var name = root.gameObject.name + "_Frames";
                            if (n > 2)
                            {
                                name += i.ToString();
                            }
                            clip.name = name;
                            subassets.Add(clip.name, clip);
                        }
                    }
                }
            }
            varyingTopologyMeshNames = new List <string>();
            splittingMeshNames       = new List <string>();

            CollectSubAssets(subassets, root);

            streamDescr.hasVaryingTopology = varyingTopologyMeshNames.Count > 0;
        }
Ejemplo n.º 13
0
        public void Dispose()
        {
            AlembicStream.s_streams.Remove(this);
            if (m_abcTreeRoot != null)
            {
                m_abcTreeRoot.Dispose();
                m_abcTreeRoot = null;
            }

            if (abcIsValid)
            {
                m_context.Destroy();
            }
        }
Ejemplo n.º 14
0
        public void Dispose()
        {
            AlembicStream.s_Streams.Remove(this);
            if (alembicTreeRoot != null)
            {
                alembicTreeRoot.Dispose();
                alembicTreeRoot = null;
            }

            if (AbcIsValid())
            {
                AbcAPI.aiDestroyContext(m_Context);
                m_Context = default(AbcAPI.aiContext);
            }
        }
Ejemplo n.º 15
0
        public void AbcUpdateElements(AlembicTreeNode node = null)
        {
            if (node == null)
            {
                node = _alembicTreeRoot;
            }

            foreach (var o in node.alembicObjects)
            {
                o.Value.AbcUpdate();
            }

            foreach (var c in node.children)
            {
                AbcUpdateElements(c);
            }
        }
Ejemplo n.º 16
0
        void UpdateAbcTree(aiContext ctx, AlembicTreeNode node, double time, bool createMissingNodes)
        {
            var top = ctx.topObject;

            if (!top)
            {
                return;
            }

            m_importContext = new ImportContext
            {
                alembicTreeNode = node,
                ss = AbcAPI.aiTimeToSampleSelector(time),
                createMissingNodes = createMissingNodes,
            };
            top.EachChild(ImportCallback);
            m_importContext = null;
        }
Ejemplo n.º 17
0
 public void AbcUpdateElements(AlembicTreeNode node = null)
 {
     if (node == null)
     {
         node = alembicTreeRoot;
     }
     using (var o = node.alembicObjects.GetEnumerator())
     {
         while (o.MoveNext())
         {
             o.Current.Value.AbcUpdate();
         }
     }
     using (var c = node.children.GetEnumerator())
     {
         while (c.MoveNext())
         {
             AbcUpdateElements(c.Current);
         }
     }
 }
Ejemplo n.º 18
0
        private void CollectSubAssets(AssetImportContext ctx, AlembicTreeNode node, Material mat)
        {
            AlembicMesh mesh = node.GetAlembicObj <AlembicMesh>();

            if (mesh != null)
            {
                if ((streamSettings.shareVertices || streamSettings.treatVertexExtraDataAsStatics) &&
                    mesh.summary.topologyVariance == AbcAPI.aiTopologyVariance.Heterogeneous)
                {
                    varyingTopologyMeshNames.Add(node.linkedGameObj.name);
                }
                else if (streamSettings.shareVertices && mesh.sampleSummary.splitCount > 1)
                {
                    splittingMeshNames.Add(node.linkedGameObj.name);
                }
            }

            var meshFilter = node.linkedGameObj.GetComponent <MeshFilter>();

            if (meshFilter != null)
            {
                var m = meshFilter.sharedMesh;
                m.name = node.linkedGameObj.name;
                AddObjectToAsset(ctx, m.name, m);
            }

            var renderer = node.linkedGameObj.GetComponent <MeshRenderer>();

            if (renderer != null)
            {
                renderer.sharedMaterial = mat;
            }

            foreach (var child in node.children)
            {
                CollectSubAssets(ctx, child, mat);
            }
        }
Ejemplo n.º 19
0
        // --- method overrides ---

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_alembicTreeRoot != null)
                {
                    _alembicTreeRoot.Dispose();
                    _alembicTreeRoot = null;
                }
            }

            if (AbcIsValid())
            {
                if (m_updateBegan)
                {
                    AbcAPI.aiUpdateSamplesEnd(m_abc);
                }
                AbcAPI.aiDestroyContext(m_abc);
                m_abc = default(AbcAPI.aiContext);
            }

            base.Dispose(disposing);
        }
Ejemplo n.º 20
0
        /*
         *  public static GameObject ImportAbc(string path)
         *  {
         *      var relPath = MakeRelativePath(path);
         *      ImportParams p = new ImportParams();
         *      return ImportImpl(relPath, p);
         *  }
         *
         *  private static GameObject ImportImpl(string path, ImportParams p)
         *  {
         *      if (path == null || path == "")
         *      {
         *          return null;
         *      }
         *
         *      string baseName = System.IO.Path.GetFileNameWithoutExtension(path);
         *      string name = baseName;
         *      int index = 1;
         *
         *      while (GameObject.Find("/" + name) != null)
         *      {
         *          name = baseName + index;
         ++index;
         *      }
         *
         *      var root = new GameObject {name = name};
         *      var abcStream = new AlembicStream( root )
         *      {
         *          m_pathToAbc = path,
         *          m_swapHandedness = p.swapHandedness,
         *          m_swapFaceWinding = p.swapFaceWinding
         *      };
         *      abcStream.AbcLoad(true);
         *
         *      return root;
         *  }
         */
    #endif

        public static void UpdateAbcTree(aiContext ctx, AlembicTreeNode node, float time, bool createMissingNodes = false)
        {
            var ic = new ImportContext
            {
                alembicTreeNode = node,
                ss = aiTimeToSampleSelector(time),
                createMissingNodes = createMissingNodes,
                objectsToDelete    = new List <aiObject>()
            };

            GCHandle hdl = GCHandle.Alloc(ic);

            aiObject top = aiGetTopObject(ctx);

            if (top.ptr != (IntPtr)0)
            {
                aiEnumerateChild(top, ImportEnumerator, GCHandle.ToIntPtr(hdl));

                foreach (aiObject obj in ic.objectsToDelete)
                {
                    aiDestroyObject(ctx, obj);
                }
            }
        }
Ejemplo n.º 21
0
        void ImportCallback(aiObject obj)
        {
            var             ic            = m_importContext;
            AlembicTreeNode treeNode      = ic.alembicTreeNode;
            AlembicTreeNode childTreeNode = null;

            aiSchema schema = obj.AsXform();

            if (!schema)
            {
                schema = obj.AsPolyMesh();
            }
            if (!schema)
            {
                schema = obj.AsCamera();
            }
            if (!schema)
            {
                schema = obj.AsPoints();
            }

            if (schema)
            {
                // Get child. create if needed and allowed.
                string childName = obj.name;

                // Find targetted child GameObj
                GameObject childGO = null;

                var childTransf = treeNode.linkedGameObj == null ? null : treeNode.linkedGameObj.transform.Find(childName);
                if (childTransf == null)
                {
                    if (!ic.createMissingNodes)
                    {
                        obj.enabled = false;
                        return;
                    }

                    childGO = new GameObject {
                        name = childName
                    };
                    var trans = childGO.GetComponent <Transform>();
                    trans.parent           = treeNode.linkedGameObj.transform;
                    trans.localPosition    = Vector3.zero;
                    trans.localEulerAngles = Vector3.zero;
                    trans.localScale       = Vector3.one;
                }
                else
                {
                    childGO = childTransf.gameObject;
                }

                childTreeNode = new AlembicTreeNode()
                {
                    linkedGameObj = childGO, streamDescriptor = treeNode.streamDescriptor
                };
                treeNode.children.Add(childTreeNode);

                // Update
                AlembicElement elem = null;

                if (obj.AsXform())
                {
                    elem = childTreeNode.GetOrAddAlembicObj <AlembicXform>();
                }
                else if (obj.AsPolyMesh())
                {
                    elem = childTreeNode.GetOrAddAlembicObj <AlembicMesh>();
                }
                else if (obj.AsCamera())
                {
                    elem = childTreeNode.GetOrAddAlembicObj <AlembicCamera>();
                }
                else if (obj.AsPoints())
                {
                    elem = childTreeNode.GetOrAddAlembicObj <AlembicPoints>();
                }

                if (elem != null)
                {
                    elem.AbcSetup(obj, schema);
                    elem.AbcPrepareSample();
                    schema.UpdateSample(ref ic.ss);
                    elem.AbcSyncDataBegin();
                    elem.AbcSyncDataEnd();
                }
            }
            else
            {
                obj.enabled = false;
            }

            ic.alembicTreeNode = childTreeNode;
            obj.EachChild(ImportCallback);
            ic.alembicTreeNode = treeNode;
        }
Ejemplo n.º 22
0
        static void ImportEnumerator(aiObject obj, IntPtr userData)
        {
            var             ic       = GCHandle.FromIntPtr(userData).Target as ImportContext;
            AlembicTreeNode treeNode = ic.alembicTreeNode;

            // Get child. create if needed and allowed.
            string childName = aiGetName(obj);

            // Find targetted child GameObj
            AlembicTreeNode childTreeNode = null;
            GameObject      childGO       = null;
            var             childTransf   = treeNode.linkedGameObj.transform.Find(childName);

            if (childTransf == null)
            {
                if (!ic.createMissingNodes)
                {
                    ic.objectsToDelete.Add(obj);
                    return;
                }

                childGO = new GameObject {
                    name = childName
                };
                var trans = childGO.GetComponent <Transform>();
                trans.parent           = treeNode.linkedGameObj.transform;
                trans.localPosition    = Vector3.zero;
                trans.localEulerAngles = Vector3.zero;
                trans.localScale       = Vector3.one;
            }
            else
            {
                childGO = childTransf.gameObject;
            }

            if (childTreeNode == null)
            {
                childTreeNode = new AlembicTreeNode()
                {
                    linkedGameObj = childGO, stream = treeNode.stream
                };
                treeNode.children.Add(childTreeNode);
            }

            // Update
            AlembicElement elem   = null;
            aiSchema       schema = default(aiSchema);

            if (aiGetXForm(obj))
            {
                elem   = childTreeNode.GetOrAddAlembicObj <AlembicXForm>();
                schema = aiGetXForm(obj);
            }
            else if (aiGetPolyMesh(obj))
            {
                elem   = childTreeNode.GetOrAddAlembicObj <AlembicMesh>();
                schema = aiGetPolyMesh(obj);
            }
            else if (aiGetCamera(obj))
            {
                elem   = childTreeNode.GetOrAddAlembicObj <AlembicCamera>();
                schema = aiGetCamera(obj);
            }
            else if (aiGetPoints(obj))
            {
                elem   = childTreeNode.GetOrAddAlembicObj <AlembicPoints>();
                schema = aiGetPoints(obj);
            }

            if (elem != null)
            {
                elem.AbcSetup(obj, schema);
                elem.AbcUpdateConfig();
                aiSchemaUpdateSample(schema, ref ic.ss);
                elem.AbcUpdate();
            }

            ic.alembicTreeNode = childTreeNode;
            aiEnumerateChild(obj, ImportEnumerator, userData);
            ic.alembicTreeNode = treeNode;
        }
Ejemplo n.º 23
0
        void ImportCallback(aiObject obj)
        {
            var             ic            = m_importContext;
            AlembicTreeNode treeNode      = ic.alembicTreeNode;
            AlembicTreeNode childTreeNode = null;

            aiSchema schema = obj.AsXform();

            if (!schema)
            {
                schema = obj.AsPolyMesh();
            }
            if (!schema)
            {
                schema = obj.AsCamera();
            }
            if (!schema)
            {
                schema = obj.AsPoints();
            }

            if (schema)
            {
                // Get child. create if needed and allowed.
                string childName = obj.name;

                // Find targetted child GameObj
                GameObject childGO = null;

                var childTransf = treeNode.gameObject == null ? null : treeNode.gameObject.transform.Find(childName);
                if (childTransf == null)
                {
                    if (!ic.createMissingNodes)
                    {
                        obj.enabled = false;
                        return;
                    }
                    else
                    {
                        obj.enabled = true;
                    }

                    childGO = new GameObject {
                        name = childName
                    };
                    childGO.GetComponent <Transform>().SetParent(treeNode.gameObject.transform, false);
                }
                else
                {
                    childGO = childTransf.gameObject;
                }

                childTreeNode = new AlembicTreeNode()
                {
                    stream = this, gameObject = childGO
                };
                treeNode.children.Add(childTreeNode);

                // Update
                AlembicElement elem = null;

                if (obj.AsXform() && m_streamDesc.settings.importXform)
                {
                    elem = childTreeNode.GetOrAddAlembicObj <AlembicXform>();
                }
                else if (obj.AsCamera() && m_streamDesc.settings.importCameras)
                {
                    elem = childTreeNode.GetOrAddAlembicObj <AlembicCamera>();
                }
                else if (obj.AsPolyMesh() && m_streamDesc.settings.importMeshes)
                {
                    elem = childTreeNode.GetOrAddAlembicObj <AlembicMesh>();
                }
                else if (obj.AsPoints() && m_streamDesc.settings.importPoints)
                {
                    elem = childTreeNode.GetOrAddAlembicObj <AlembicPoints>();
                }

                if (elem != null)
                {
                    elem.AbcSetup(obj, schema);
                    elem.AbcPrepareSample();
                    schema.UpdateSample(ref ic.ss);
                    elem.AbcSyncDataBegin();
                    elem.AbcSyncDataEnd();
                }
            }
            else
            {
                obj.enabled = false;
            }

            ic.alembicTreeNode = childTreeNode;
            obj.EachChild(ImportCallback);
            ic.alembicTreeNode = treeNode;
        }