Exemple #1
0
        protected xxVertex ParseVertex()
        {
            xxVertex vertex;
            if (Format >= 4)
            {
                vertex = new xxVertexUShort();
                vertex.Index = reader.ReadUInt16();
            }
            else
            {
                vertex = new xxVertexInt();
                vertex.Index = reader.ReadInt32();
            }

            vertex.Position = reader.ReadVector3();
            vertex.Weights3 = reader.ReadSingleArray(3);
            vertex.BoneIndices = reader.ReadBytes(4);
            vertex.Normal = reader.ReadVector3();
            vertex.UV = reader.ReadSingleArray(2);

            if (Format >= 4)
            {
                vertex.Unknown1 = reader.ReadBytes(20);
            }
            return vertex;
        }
        public static xxMesh CreateMesh(WorkspaceMesh mesh, int xxFormat, out string[] materialNames, out int[] indices, out bool[] worldCoords, out bool[] replaceSubmeshesOption)
        {
            int numUncheckedSubmeshes = 0;
            foreach (ImportedSubmesh submesh in mesh.SubmeshList)
            {
                if (!mesh.isSubmeshEnabled(submesh))
                    numUncheckedSubmeshes++;
            }
            int numSubmeshes = mesh.SubmeshList.Count - numUncheckedSubmeshes;
            materialNames = new string[numSubmeshes];
            indices = new int[numSubmeshes];
            worldCoords = new bool[numSubmeshes];
            replaceSubmeshesOption = new bool[numSubmeshes];

            xxMesh xxMesh = new xxMesh();
            xxMesh.BoneList = CreateBoneList(mesh.BoneList);

            xxMesh.SubmeshList = new List<xxSubmesh>(mesh.SubmeshList.Count);
            for (int i = 0, submeshIdx = 0; i < numSubmeshes; i++, submeshIdx++)
            {
                while (!mesh.isSubmeshEnabled(mesh.SubmeshList[submeshIdx]))
                    submeshIdx++;

                xxSubmesh xxSubmesh = new xxSubmesh();
                xxMesh.SubmeshList.Add(xxSubmesh);

                xxSubmesh.MaterialIndex = -1;
                materialNames[i] = mesh.SubmeshList[submeshIdx].Material;
                indices[i] = mesh.SubmeshList[submeshIdx].Index;
                worldCoords[i] = mesh.SubmeshList[submeshIdx].WorldCoords;
                replaceSubmeshesOption[i] = mesh.isSubmeshReplacingOriginal(mesh.SubmeshList[submeshIdx]);

                List<ImportedVertex> vertexList = mesh.SubmeshList[submeshIdx].VertexList;
                List<xxVertex> xxVertexList = new List<xxVertex>(vertexList.Count);
                for (int j = 0; j < vertexList.Count; j++)
                {
                    ImportedVertex vert = vertexList[j];
                    xxVertex xxVertex;
                    if (xxFormat >= 4)
                    {
                        xxVertex = new xxVertexUShort();
                        CreateUnknown(xxVertex);
                    }
                    else
                    {
                        xxVertex = new xxVertexInt();
                    }

                    xxVertex.Index = j;
                    xxVertex.Normal = vert.Normal;
                    xxVertex.UV = (float[])vert.UV.Clone();
                    xxVertex.Weights3 = new float[3] { vert.Weights[0], vert.Weights[1], vert.Weights[2] };
                    xxVertex.BoneIndices = (byte[])vert.BoneIndices.Clone();
                    xxVertex.Position = vert.Position;
                    xxVertexList.Add(xxVertex);
                }
                xxSubmesh.VertexList = xxVertexList;

                List<ImportedFace> faceList = mesh.SubmeshList[submeshIdx].FaceList;
                List<xxFace> xxFaceList = new List<xxFace>(faceList.Count);
                for (int j = 0; j < faceList.Count; j++)
                {
                    int[] vertexIndices = faceList[j].VertexIndices;
                    xxFace xxFace = new xxFace();
                    xxFace.VertexIndices = new ushort[3] { (ushort)vertexIndices[0], (ushort)vertexIndices[1], (ushort)vertexIndices[2] };
                    xxFaceList.Add(xxFace);
                }
                xxSubmesh.FaceList = xxFaceList;
            }

            xxMesh.VertexListDuplicate = CreateVertexListDup(xxMesh.SubmeshList);
            return xxMesh;
        }