Exemplo n.º 1
0
        public static DMesh3 ReadMeshFromMM(RemoteControl rc, int nObjectId, bool bWantColors = false)
        {
            Debug.Assert(bWantColors == false); // haven't implemented yet

            DMesh3 mesh = new DMesh3(MeshComponents.FaceGroups);

            int NV           = rc.GetVertexCount(nObjectId);
            int nBatchSize   = 750;
            int nFullBatches = NV / nBatchSize;

            for (int i = 0; i < nFullBatches; ++i)
            {
                Vector3f[] vPositions = rc.GetVertexPositionInRange(nObjectId, i * nBatchSize, nBatchSize);
                for (int j = 0; j < vPositions.Length; ++j)
                {
                    int vid = mesh.AppendVertex((Vector3d)vPositions[j]);
                    Debug.Assert(vid == i * nBatchSize + j);
                }
            }
            int nLeft = NV - nFullBatches * nBatchSize;

            if (nLeft > 0)
            {
                Vector3f[] vPositions = rc.GetVertexPositionInRange(nObjectId, nFullBatches * nBatchSize, nLeft);
                for (int j = 0; j < nLeft; ++j)
                {
                    int vid = mesh.AppendVertex((Vector3d)vPositions[j]);
                }
            }

            int NT = rc.GetTriangleCount(nObjectId);

            nBatchSize   = 750;
            nFullBatches = NT / nBatchSize;
            for (int i = 0; i < nFullBatches; ++i)
            {
                Index3i[] vTriangles = rc.GetTrianglesInRange(nObjectId, i * nBatchSize, nBatchSize);
                int[]     vGroups    = rc.GetFaceGroupsInRange(nObjectId, i * nBatchSize, nBatchSize);
                for (int j = 0; j < vTriangles.Length; ++j)
                {
                    int vid = mesh.AppendTriangle(vTriangles[j], vGroups[j]);
                    Debug.Assert(vid == i * nBatchSize + j);
                }
            }
            nLeft = NT - nFullBatches * nBatchSize;
            if (nLeft > 0)
            {
                Index3i[] vTriangles = rc.GetTrianglesInRange(nObjectId, nFullBatches * nBatchSize, nLeft);
                int[]     vGroups    = rc.GetFaceGroupsInRange(nObjectId, nFullBatches * nBatchSize, nLeft);
                for (int j = 0; j < nLeft; ++j)
                {
                    int vid = mesh.AppendTriangle(vTriangles[j], vGroups[j]);
                }
            }

            return(mesh);
        }