示例#1
0
 void ConvertMesh(UsdMesh mesh, string path)
 {
     if (mesh == null)
     {
         return;
     }
     // todo
 }
示例#2
0
        public static void Open(UsdMesh stream)
        {
            var window = (UsdPrecomputeNormalsWindow)EditorWindow.GetWindow(typeof(UsdPrecomputeNormalsWindow));

            window.titleContent = new GUIContent("Precompute");
            window.m_stream     = null;
            window.m_mesh       = stream;
            window.Show();
        }
示例#3
0
        Mesh usdiShareOrCreateMesh(UsdMesh parent)
        {
            var master = parent.master as UsdMesh;

            if (master != null)
            {
                return(master.submeshes[m_nth].mesh);
            }
            else
            {
                return(new Mesh()
                {
                    name = "<dyn>"
                });
            }
        }
示例#4
0
        UsdSchema usdiCreateNode(usdi.Schema schema)
        {
            UsdSchema ret = null;

            if (ret == null)
            {
                var s = usdi.usdiAsPoints(schema);
                if (s)
                {
                    ret = new UsdPoints();
                }
            }
            if (ret == null)
            {
                var s = usdi.usdiAsMesh(schema);
                if (s)
                {
                    ret = new UsdMesh();
                }
            }
            if (ret == null)
            {
                var s = usdi.usdiAsCamera(schema);
                if (s)
                {
                    ret = new UsdCamera();
                }
            }
            if (ret == null)
            {
                // Xform must be latter because some schemas are subclass of Xform
                var s = usdi.usdiAsXform(schema);
                if (s)
                {
                    ret = new UsdXform();
                }
            }
            if (ret == null)
            {
                ret = new UsdSchema();
            }
            ret.nativeSchemaPtr = schema;
            ret.stream          = this;
            return(ret);
        }
示例#5
0
        public void usdiSetupMesh(UsdMesh parent)
        {
            if (!m_setupRequierd)
            {
                return;
            }
            m_setupRequierd = false;

            if (m_umesh == null)
            {
                m_umesh = new Mesh();
                m_umesh.MarkDynamic();
            }

            var meshData = parent.meshData;

            usdiSetupBones(parent, ref meshData);
        }
示例#6
0
        void usdiSetupBones(UsdMesh parent, ref usdi.MeshData meshData)
        {
            {
                var tmp = usdi.MeshData.default_value;
                m_bindposes   = new Matrix4x4[parent.meshData.num_bones];
                tmp.bindposes = usdi.GetArrayPtr(m_bindposes);
                usdi.usdiMeshReadSample(parent.nativeMeshPtr, ref tmp, usdi.defaultTime, true);
            }

            var renderer = m_renderer as SkinnedMeshRenderer;

            if (renderer == null)
            {
                return;
            }

            if (m_nth > 0)
            {
                m_bindposes = parent.submeshes[0].bindposes;
                m_rootBone  = parent.submeshes[0].rootBone;
                m_bones     = parent.submeshes[0].bones;
            }
            else
            {
                var rootBoneName = usdi.S(meshData.root_bone);
                var boneNames    = usdi.SA(meshData.bones);

                if (parent.isInstance)
                {
                    // remap bone names

                    var root = parent.nativeSchemaPtr;
                    for (;;)
                    {
                        root = usdi.usdiPrimGetParent(root);
                        if (!usdi.usdiPrimGetMaster(root))
                        {
                            break;
                        }
                    }

                    var r = usdi.usdiPrimFindChild(root, Path.GetFileName(rootBoneName), true);
                    if (r)
                    {
                        rootBoneName = usdi.usdiPrimGetPathS(r);
                    }

                    for (int i = 0; i < boneNames.Length; ++i)
                    {
                        var c = usdi.usdiPrimFindChild(root, Path.GetFileName(boneNames[i]), true);
                        if (c)
                        {
                            boneNames[i] = usdi.usdiPrimGetPathS(c);
                        }
                    }
                }

                m_bones = new Transform[boneNames.Length];
                for (int i = 0; i < boneNames.Length; ++i)
                {
                    var schema = parent.stream.usdiFindSchema(boneNames[i]);
                    if (schema == null)
                    {
                        Debug.LogError("bone not found: " + boneNames[i]);
                        continue;
                    }
                    if (schema.gameObject == null)
                    {
                        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 = parent.stream.usdiFindSchema(rootBoneName);
                    m_rootBone = rootBone.gameObject.GetComponent <Transform>();
                }
                else
                {
                    m_rootBone = m_bones[0]; // maybe incorrect
                }
            }

            renderer.bones    = m_bones;
            renderer.rootBone = m_rootBone;
        }
示例#7
0
 public void usdiOnLoad(UsdMesh parent, int nth)
 {
     m_schema = parent.nativeSchemaPtr;
     m_nth    = nth;
 }
示例#8
0
        public void usdiSetupComponents(UsdMesh parent)
        {
            if (!m_setupRequierd)
            {
                return;
            }
            m_setupRequierd = false;

            GameObject go;

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

            m_trans = go.GetComponent <Transform>();

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

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

                var renderer = usdi.GetOrAddComponent <SkinnedMeshRenderer>(go, ref assignDefaultMaterial);
                m_renderer = renderer;
                usdiSetupBones(parent, ref meshData);

                if (renderer.sharedMesh != null && parent.master == null && renderer.sharedMesh.name.IndexOf("<dyn>") == 0)
                {
                    m_umesh = renderer.sharedMesh;
                }
                else
                {
                    m_umesh             = usdiShareOrCreateMesh(parent);
                    renderer.sharedMesh = m_umesh;
                }
                m_umesh.MarkDynamic();
            }
            else
            {
                // setup MeshFilter and MeshRenderer

                var meshFilter = usdi.GetOrAddComponent <MeshFilter>(go);
                if (meshFilter.sharedMesh != null && parent.master == null && meshFilter.sharedMesh.name.IndexOf("<dyn>") == 0)
                {
                    m_umesh = meshFilter.sharedMesh;
                }
                else
                {
                    m_umesh = usdiShareOrCreateMesh(parent);
                    meshFilter.sharedMesh = m_umesh;
                }
                m_umesh.MarkDynamic();

                m_renderer = usdi.GetOrAddComponent <MeshRenderer>(go, ref assignDefaultMaterial);
            }

#if UNITY_EDITOR
            if (assignDefaultMaterial)
            {
                Material[] materials = null;
                if (m_nth != 0)
                {
                    var s = parent.submeshes[0];
                    if (s.renderer != null)
                    {
                        materials = s.renderer.sharedMaterials;
                    }
                }
                if (materials == null)
                {
                    materials         = new Material[] { UnityEngine.Object.Instantiate(GetDefaultMaterial()) };
                    materials[0].name = "Material_0";
                }
                m_renderer.sharedMaterials = materials;
            }
#endif
        }