Beispiel #1
0
        usdiSchema usdiCreateNode(usdi.Schema schema)
        {
            usdiSchema ret = null;

            if (ret == null)
            {
                var s = usdi.usdiAsPoints(schema);
                if (s)
                {
                    ret = new usdiPoints();
                }
            }
            if (ret == null)
            {
                var s = usdi.usdiAsMesh(schema);
                if (s)
                {
                    ret = new usdiMesh();
                }
            }
            if (ret == null)
            {
                var s = usdi.usdiAsCamera(schema);
                if (s)
                {
                    ret = new usdiCamera();
                }
            }
            if (ret == null)
            {
                // Xform must be latter because some schemas are subclass of Xform
                var s = usdi.usdiAsXform(schema);
                if (s)
                {
                    ret = new usdiXform();
                }
            }
            if (ret == null)
            {
                ret = new usdiSchema();
            }
            ret.nativeSchemaPtr = schema;
            ret.stream          = this;
            return(ret);
        }
Beispiel #2
0
 public void usdiOnLoad(usdiMesh parent, int nth)
 {
     m_stream = parent.stream;
     m_schema = parent.nativeSchemaPtr;
     m_nth    = nth;
 }
Beispiel #3
0
        public void usdiSetupComponents(usdiMesh parent_mesh)
        {
            if (!m_setupRequierd)
            {
                return;
            }
            m_setupRequierd = false;

            GameObject go;

            if (m_nth == 0)
            {
                go = parent_mesh.gameObject;
            }
            else
            {
                string name   = "Submesh[" + m_nth + "]";
                var    parent = parent_mesh.GetComponent <Transform>();
                var    child  = parent.FindChild(name);
                if (child != null)
                {
                    go = child.gameObject;
                }
                else
                {
                    go = new GameObject(name);
                    go.GetComponent <Transform>().SetParent(parent_mesh.GetComponent <Transform>(), false);
                }
            }

            m_trans = go.GetComponent <Transform>();

            var  meshSummary           = parent_mesh.meshSummary;
            var  meshData              = parent_mesh.meshData;
            bool assignDefaultMaterial = false;

            if (meshSummary.num_bones > 0)
            {
                // setup SkinnedMeshRenderer

                var renderer = go.GetComponent <SkinnedMeshRenderer>();
                if (renderer == null)
                {
                    renderer = go.AddComponent <SkinnedMeshRenderer>();
                    assignDefaultMaterial = true;
                }
                {
                    var boneNames = usdi.usdiMeshGetBoneNames(parent_mesh.nativeMeshPtr, ref meshData);
                    m_bones = new Transform[boneNames.Length];
                    for (int i = 0; i < boneNames.Length; ++i)
                    {
                        var schema = m_stream.usdiFindSchema(boneNames[i]);
                        if (schema == null)
                        {
                            Debug.LogError("bone not found: " + boneNames[i]);
                            continue;
                        }
                        if (schema.gameObject == null)
                        {
                            // todo: this will happen on instanced object. need to do something
                            Debug.LogError("bone don't have GameObject: " + boneNames[i]);
                            continue;
                        }
                        m_bones[i] = schema.gameObject.GetComponent <Transform>();
                    }

                    if (meshData.root_bone != IntPtr.Zero)
                    {
                        var rootBone = m_stream.usdiFindSchema(usdi.S(meshData.root_bone));
                        m_rootBone = rootBone.gameObject.GetComponent <Transform>();
                    }
                    else
                    {
                        m_rootBone = m_bones[0]; // maybe incorrect
                    }
                }
                m_renderer = renderer;

                m_umesh = renderer.sharedMesh;
                if (m_umesh == null)
                {
                    m_umesh             = new Mesh();
                    renderer.sharedMesh = m_umesh;
                }
                m_umesh.MarkDynamic();
            }
            else
            {
                // setup MeshFilter and MeshRenderer

                var meshFilter = go.GetComponent <MeshFilter>();
                if (meshFilter == null || meshFilter.sharedMesh == null)
                {
                    m_umesh = new Mesh();
                    if (meshFilter == null)
                    {
                        meshFilter = go.AddComponent <MeshFilter>();
                    }
                    meshFilter.sharedMesh = m_umesh;
                }
                else
                {
                    m_umesh = meshFilter.sharedMesh;
                }
                m_umesh.MarkDynamic();

                m_renderer = go.GetComponent <MeshRenderer>();
                if (m_renderer == null)
                {
                    m_renderer            = go.AddComponent <MeshRenderer>();
                    assignDefaultMaterial = true;
                }
            }

#if UNITY_EDITOR
            if (assignDefaultMaterial)
            {
                Material material = UnityEngine.Object.Instantiate(GetDefaultMaterial());
                material.name             = "Material_0";
                m_renderer.sharedMaterial = material;
            }
#endif
        }
Beispiel #4
0
 public void usdiOnLoad(usdiMesh parent, int nth)
 {
     m_parent = parent;
     m_nth    = nth;
     m_umesh  = usdiAddMeshComponents();
 }