Example #1
0
        public bool SetPositionVertices(IMesh maxMesh, MyMesh myMesh)
        {
            bool countChanged = false;

            if (maxMesh.NumVerts != myMesh.NumVertices)
            {
                maxMesh.SetNumVerts(myMesh.NumVertices, false, false);
                countChanged = true;
            }

            IPoint3 p3 = maxMesh.GetVertPtr(0);
            Marshal.Copy(myMesh.Vertices.ToArray(), 0, p3.NativePointer, myMesh.NumVertices * 3);

            return countChanged;
        }
Example #2
0
        protected unsafe TriMeshFacesAndPositions GetTriMeshFacesAndPositions(IMesh mesh)
        {
            VertexChannel channel = new VertexChannel();
            channel.m_type = VertexChannelType.Positions;

            channel.m_vertices = new Point3[mesh.NumVerts];
            fixed (Point3* vertexData = channel.m_vertices)
            {
                CopyMemory((IntPtr)vertexData, mesh.GetVertPtr(0).Handle, (uint)(sizeof(Point3) * mesh.NumVerts));
            }

            var faces = new Face[mesh.NumFaces];
            fixed (Face* faceData = faces)
            {
                CopyMemory((IntPtr)faceData, mesh.Faces[0].Handle, (uint)(sizeof(Face) * mesh.NumFaces));
            }

            /* Split the face data into seperate arrays. Put the face indices in one with the channel, the others to one side to filter into groups later if the user wants */

            TriMeshFacesAndPositions faces_data = new TriMeshFacesAndPositions();

            faces_data.face_flags = new short[faces.Length];
            faces_data.face_materialIds = new short[faces.Length];

            channel.m_faces = new Indices3[faces.Length];

            for (int i = 0; i < faces.Length; i++)
            {
                short materialid = (short)((faces[i].flags & 0xFFFF0000) >> 16); //in Max the high word of the flags member contains the material id.
                short flags = (short)(faces[i].flags & 0x0000FFFF);

                faces_data.face_flags[i] = flags;
                faces_data.face_materialIds[i] = materialid;

                channel.m_faces[i] = faces[i].v;
            }

            faces_data.positions_channel = channel;

            return faces_data;
        }