示例#1
0
        unsafe private void UpdateMeshPart(MVGraphAPI.MeshData meshData)
        {
            if (!m_meshPart)
            {
                m_meshPart = CreateNewMeshPart();
            }

            UInt32 collectionsCapacity = GetMinimalMeshCollectionsCapacity(meshData);

            MvxUtils.EnsureCollectionMinimalCapacity <Vector3>(ref m_meshPartVertices, collectionsCapacity);

            fixed(Vector3 *verticesPtr = m_meshPartVertices)
            meshData.CopyVerticesRaw((IntPtr)verticesPtr);

            if (!IgnoreNormals())
            {
                MvxUtils.EnsureCollectionMinimalCapacity <Vector3>(ref m_meshPartNormals, collectionsCapacity);

                fixed(Vector3 *normalsPtr = m_meshPartNormals)
                meshData.CopyNormalsRaw((IntPtr)normalsPtr);
            }

            if (!IgnoreColors())
            {
                MvxUtils.EnsureCollectionMinimalCapacity <Color32>(ref m_meshPartColors, collectionsCapacity);

                fixed(Color32 *colorsPtr = m_meshPartColors)
                meshData.CopyColorsRGBARaw((IntPtr)colorsPtr);
            }

            if (!IgnoreUVs())
            {
                MvxUtils.EnsureCollectionMinimalCapacity <Vector2>(ref m_meshPartUVs, collectionsCapacity);

                fixed(Vector2 *uvsPtr = m_meshPartUVs)
                meshData.CopyUVsRaw((IntPtr)uvsPtr);
            }

            UInt32 meshIndicesCount = GetFrameMeshIndicesCount(meshData);

            if (meshIndicesCount == 0)
            {
                m_meshPart.gameObject.SetActive(false);
                return;
            }
            MvxUtils.EnsureCollectionMinimalCapacity <Int32>(ref m_meshPartIndices, meshIndicesCount);
            CopyMeshIndicesToCollection(meshData, m_meshPartIndices);
            MVGraphAPI.MeshIndicesMode meshIndicesMode = GetFrameIndicesMode(meshData);

            // fill the unused trailing of the indices collection with the last used index
            Int32 unusedIndicesValue = m_meshPartIndices[(Int32)meshIndicesCount - 1];

            for (UInt32 unusedIndex = meshIndicesCount; unusedIndex < m_meshPartIndices.Length; unusedIndex++)
            {
                m_meshPartIndices[unusedIndex] = unusedIndicesValue;
            }

            m_meshPart.UpdateMesh(m_meshPartVertices, m_meshPartNormals, m_meshPartColors, m_meshPartUVs, m_meshPartIndices, IndicesModeToMeshTopology(meshIndicesMode));
            m_meshPart.gameObject.SetActive(true);
        }
示例#2
0
        private MeshTopology IndicesModeToMeshTopology(MVGraphAPI.MeshIndicesMode indicesMode)
        {
            switch (indicesMode)
            {
            case MVGraphAPI.MeshIndicesMode.MIM_PointList: return(MeshTopology.Points);

            case MVGraphAPI.MeshIndicesMode.MIM_LineList: return(MeshTopology.Lines);

            case MVGraphAPI.MeshIndicesMode.MIM_TriangleList: return(MeshTopology.Triangles);

            case MVGraphAPI.MeshIndicesMode.MIM_QuadList: return(MeshTopology.Quads);

            default:
                throw new System.ArgumentException("Missing conversion from an indices mode to a mesh topology");
            }
        }