예제 #1
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;
        }
예제 #2
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;
        }