Beispiel #1
0
        // async
        void usdiAllocateMeshData(double t)
        {
            usdi.MeshData md = usdi.MeshData.default_value;
            usdi.usdiMeshReadSample(m_mesh, ref md, t, true);

            m_meshData = md;
            if (m_meshData.num_submeshes == 0)
            {
                m_submeshes[0].usdiAllocateMeshData(ref m_meshSummary, ref m_meshData);
            }
            else
            {
                m_submeshData        = new usdi.SubmeshData[m_meshData.num_submeshes];
                m_meshData.submeshes = usdi.GetArrayPtr(m_submeshData);
                usdi.usdiMeshReadSample(m_mesh, ref m_meshData, t, true);

                while (m_submeshes.Count < m_meshData.num_submeshes)
                {
                    usdiAddSubmesh();
                }
                for (int i = 0; i < m_meshData.num_submeshes; ++i)
                {
                    m_submeshes[i].usdiAllocateMeshData(ref m_meshSummary, ref m_submeshData);
                }
            }
        }
Beispiel #2
0
 public static void CaptureMesh(usdi.Mesh usd, ref usdi.MeshData data, MeshBuffer dst_buf)
 {
     data = usdi.MeshData.default_value;
     if (dst_buf.vertices != null)
     {
         data.points     = usdi.GetArrayPtr(dst_buf.vertices);
         data.num_points = dst_buf.vertices.Length;
     }
     if (dst_buf.indices != null)
     {
         data.indices     = usdi.GetArrayPtr(dst_buf.indices);
         data.num_indices = dst_buf.indices.Length;
     }
     if (dst_buf.normals != null)
     {
         data.normals = usdi.GetArrayPtr(dst_buf.normals);
     }
     if (dst_buf.tangents != null)
     {
         data.tangents = usdi.GetArrayPtr(dst_buf.tangents);
     }
     if (dst_buf.uvs != null)
     {
         data.uvs = usdi.GetArrayPtr(dst_buf.uvs);
     }
     if (dst_buf.weights != null && dst_buf.bones != null)
     {
         data.weights          = usdi.GetArrayPtr(dst_buf.weights);
         data.bindposes        = usdi.GetArrayPtr(dst_buf.bindposes);
         data.num_bones        = dst_buf.bones.Length;
         data.max_bone_weights = 4;
         usdi.usdiMeshAssignBones(usd, ref data, dst_buf.bones, dst_buf.bones.Length);
         usdi.usdiMeshAssignRootBone(usd, ref data, dst_buf.rootBone);
     }
 }
Beispiel #3
0
 public static void CaptureMesh(
     usdi.Mesh usd, ref usdi.MeshData data, MeshBuffer buf,
     Mesh mesh, MeshCaptureFlags flags)
 {
     buf.vertices = flags.points ? mesh.vertices : null;
     buf.normals  = flags.normals ? mesh.normals : null;
     buf.tangents = flags.tangents ? mesh.tangents : null;
     buf.indices  = flags.indices ? mesh.triangles : null;
     buf.uvs      = flags.uvs ? mesh.uv : null;
     CaptureMesh(usd, ref data, buf);
 }
Beispiel #4
0
        public void usdiKickVBUpdateTask(ref usdi.MeshData data, bool updateIndices)
        {
            bool active = m_renderer.isVisible;

            if (active)
            {
                if (m_vuCmd == null)
                {
                    m_vuCmd = new usdi.VertexUpdateCommand(usdi.usdiPrimGetNameS(m_schema));
                }
                m_vuCmd.Update(ref data, m_VB, updateIndices ? m_IB : IntPtr.Zero);
            }
        }
Beispiel #5
0
        public static void CaptureMesh(
            usdi.Mesh usd, ref usdi.MeshData data, MeshBuffer buf,
            SkinnedMeshRenderer smr, MeshCaptureFlags flags, bool captureBones)
        {
            Cloth cloth = smr.GetComponent <Cloth>();

            if (cloth != null)
            {
                var mesh = buf.bakedMesh;
                smr.BakeMesh(mesh);

                buf.vertices = flags.points ? cloth.vertices : null;
                buf.normals  = flags.normals ? cloth.normals : null;
                buf.tangents = flags.tangents ? mesh.tangents : null;
                buf.indices  = flags.indices ? mesh.triangles : null;
                buf.uvs      = flags.uvs ? mesh.uv : null;
            }
            else if (captureBones && buf.bones != null)
            {
                var mesh = smr.sharedMesh;

                buf.vertices = flags.points ? mesh.vertices : null;
                buf.normals  = flags.normals ? mesh.normals : null;
                buf.tangents = flags.tangents ? mesh.tangents : null;
                buf.indices  = flags.indices ? mesh.triangles : null;
                buf.uvs      = flags.uvs ? mesh.uv : null;

                buf.weights   = mesh.boneWeights;
                buf.bindposes = mesh.bindposes;
            }
            else
            {
                var mesh = buf.bakedMesh;
                smr.BakeMesh(mesh);

                buf.vertices = flags.points ? mesh.vertices : null;
                buf.normals  = flags.normals ? mesh.normals : null;
                buf.tangents = flags.tangents ? mesh.tangents : null;
                buf.indices  = flags.indices ? mesh.triangles : null;
                buf.uvs      = flags.uvs ? mesh.uv : null;
            }

            CaptureMesh(usd, ref data, buf);
        }
Beispiel #6
0
 public void usdiAllocateMeshData(ref usdi.MeshSummary summary, ref usdi.MeshData meshData)
 {
     {
         m_points        = new Vector3[meshData.num_points];
         meshData.points = usdi.GetArrayPtr(m_points);
     }
     {
         m_normals        = new Vector3[meshData.num_points];
         meshData.normals = usdi.GetArrayPtr(m_normals);
     }
     if (summary.has_colors)
     {
         m_colors        = new Color[meshData.num_points];
         meshData.colors = usdi.GetArrayPtr(m_colors);
     }
     if (summary.has_tangents)
     {
         m_tangents        = new Vector4[meshData.num_points];
         meshData.tangents = usdi.GetArrayPtr(m_tangents);
     }
     if (summary.has_uvs)
     {
         m_uvs        = new Vector2[meshData.num_points];
         meshData.uvs = usdi.GetArrayPtr(m_uvs);
         if (summary.has_tangents)
         {
             m_tangents        = new Vector4[meshData.num_points];
             meshData.tangents = usdi.GetArrayPtr(m_tangents);
         }
     }
     if (summary.num_bones > 0)
     {
         m_weights        = new BoneWeight[meshData.num_points];
         meshData.weights = usdi.GetArrayPtr(m_weights);
     }
     {
         m_indices = new int[meshData.num_indices_triangulated];
         meshData.indices_triangulated = usdi.GetArrayPtr(m_indices);
     }
 }
Beispiel #7
0
        public override void usdiOnUnload()
        {
            base.usdiOnUnload();

            int c = m_submeshes.Count;

            for (int i = 0; i < c; ++i)
            {
                m_submeshes[i].usdiOnUnload();
            }

            m_meshData    = usdi.MeshData.default_value;
            m_submeshData = null;
            m_meshSummary = usdi.MeshSummary.default_value;

            m_allocateMeshDataRequired = false;
            m_updateIndicesRequired    = false;
            m_updateVerticesRequired   = false;
            m_updateSkinningRequired   = false;
            m_timeRead = 0.0;

            m_asyncRead = null;
        }
Beispiel #8
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;
        }
Beispiel #9
0
 public void usdiUpdateBounds(ref usdi.MeshData data)
 {
     usdi.MeshAssignBounds(m_umesh, ref data.center, ref data.extents);
 }