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

            // skip if already allocated
            if (m_prevVertexCount == md.num_points &&
                m_prevIndexCount == md.num_indices_triangulated)
            {
                return;
            }

            m_meshData = md;
            if (m_meshData.num_splits != 0)
            {
                m_splitedData     = new usdi.SubmeshData[m_meshData.num_splits];
                m_meshData.splits = usdi.GetArrayPtr(m_splitedData);
                usdi.usdiMeshReadSample(m_mesh, ref m_meshData, t, true);

                while (m_children.Count < m_meshData.num_splits)
                {
                    usdiAddSplit();
                }

                for (int i = 0; i < m_children.Count; ++i)
                {
                    m_children[i].usdiAllocateMeshData(ref m_splitedData[i]);
                }
            }
            else
            {
                m_buf.Allocate(ref m_meshSummary, ref m_meshData);
            }
        }
Exemple #2
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_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);
     }
 }
        // async
        void usdiAllocateMeshData(double t)
        {
            usdi.MeshData md = default(usdi.MeshData);
            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);
                }
            }
        }
Exemple #4
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);
     }
 }
Exemple #5
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);
 }
Exemple #6
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);
            }
        }
Exemple #7
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);
        }
Exemple #8
0
 public void Allocate(ref usdi.MeshSummary summary, ref usdi.MeshData md)
 {
     {
         positions = new Vector3[md.num_points];
         md.points = usdi.GetArrayPtr(positions);
     }
     if (summary.has_normals)
     {
         normals    = new Vector3[md.num_points];
         md.normals = usdi.GetArrayPtr(normals);
     }
     if (summary.has_uvs)
     {
         uvs    = new Vector2[md.num_points];
         md.uvs = usdi.GetArrayPtr(uvs);
     }
     {
         indices = new int[md.num_indices_triangulated];
         md.indices_triangulated = usdi.GetArrayPtr(indices);
     }
 }
        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_timeRead = 0.0;

            m_asyncRead = null;
        }
Exemple #10
0
        public static void CaptureMesh(
            Mesh mesh, Cloth cloth, MeshBuffer dst_buf, ref usdi.MeshData data, double t,
            bool capture_normals, bool capture_uvs, bool capture_indices)
        {
            dst_buf.indices = capture_indices ? mesh.triangles : null;
            dst_buf.uvs     = capture_uvs ? mesh.uv : null;
            if (cloth == null)
            {
                dst_buf.vertices = mesh.vertices;
                dst_buf.normals  = capture_normals ? mesh.normals : null;
            }
            else
            {
                dst_buf.vertices = cloth.vertices;
                dst_buf.normals  = capture_normals ? cloth.normals : null;
            }

            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.uvs != null)
            {
                data.uvs = usdi.GetArrayPtr(dst_buf.uvs);
            }
        }
Exemple #11
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;
        }
Exemple #12
0
 public void usdiUpdateBounds(ref usdi.MeshData data)
 {
     usdi.MeshAssignBounds(m_umesh, ref data.center, ref data.extents);
 }