예제 #1
0
        public unsafe bool SetFaces(IMesh maxMesh, MyMesh myMesh)
        {
            bool countChanged = false;

            TriangulateFaces(myMesh);

            if (maxMesh.NumFaces != myMesh.TriangulatedFaces.Length)
            {
                maxMesh.SetNumFaces(myMesh.TriangulatedFaces.Length, false, false);
                maxMesh.SetNumTVFaces(myMesh.TriangulatedFaces.Length, false, 0);
                countChanged = true;
            }

            /* Get the default flags value */

            IFace referenceFace = gi.Face.Create();
            referenceFace.SetEdgeVisFlags(EdgeVisibility.Vis, EdgeVisibility.Vis, EdgeVisibility.Vis);
            Face referenceMaxFace = *(Face*)referenceFace.NativePointer.ToPointer();
            UInt32 referenceFlags = referenceMaxFace.flags;

            /* Create the faces that define the surface of the mesh */

            Face* faces = (Face*)maxMesh.Faces[0].NativePointer.ToPointer();
            TVFace* tvfaces = (TVFace*)maxMesh.TvFace[0].NativePointer.ToPointer();

            for (int i = 0; i < myMesh.TriangulatedFaces.Length; i++)
            {
                MyFace myFace = myMesh.TriangulatedFaces[i];

                faces[i].v.v1 = (UInt32)myFace.PositionVertex1;
                faces[i].v.v2 = (UInt32)myFace.PositionVertex2;
                faces[i].v.v3 = (UInt32)myFace.PositionVertex3;
                faces[i].flags = (UInt32)((ushort)myFace.MaterialId << 16) | (ushort)referenceFlags;

                tvfaces[i].t1 = (UInt32)myFace.TextureVertex1;
                tvfaces[i].t2 = (UInt32)myFace.TextureVertex2;
                tvfaces[i].t3 = (UInt32)myFace.TextureVertex3;

            };

            return countChanged;
        }