示例#1
0
            public static void WriteMeshObject(StreamWriter writer, List <ImportedVertex> vertexList, List <ImportedFace> faceList, int mqoMatIdx, bool[] colorVertex)
            {
                writer.WriteLine("\tvertex " + vertexList.Count + " {");
                for (int i = 0; i < vertexList.Count; i++)
                {
                    ImportedVertex vertex = vertexList[i];
                    Vector3        pos    = vertex.Position * 10f;
                    writer.WriteLine("\t\t" + pos.X.ToFloatString() + " " + pos.Y.ToFloatString() + " " + pos.Z.ToFloatString());
                }
                writer.WriteLine("\t}");

                writer.WriteLine("\tface " + faceList.Count + " {");
                for (int i = 0; i < faceList.Count; i++)
                {
                    ImportedFace face        = faceList[i];
                    int[]        vertIndices = new int[] { face.VertexIndices[0], face.VertexIndices[2], face.VertexIndices[1] };
                    float[]      uv1         = vertexList[vertIndices[0]].UV;
                    float[]      uv2         = vertexList[vertIndices[1]].UV;
                    float[]      uv3         = vertexList[vertIndices[2]].UV;

                    writer.Write("\t\t3 V(" + vertIndices[0] + " " + vertIndices[1] + " " + vertIndices[2] + ")");
                    if (mqoMatIdx >= 0)
                    {
                        writer.Write(" M(" + mqoMatIdx + ")");
                    }
                    writer.Write(" UV("
                                 + uv1[0].ToFloatString() + " " + uv1[1].ToFloatString() + " "
                                 + uv2[0].ToFloatString() + " " + uv2[1].ToFloatString() + " "
                                 + uv3[0].ToFloatString() + " " + uv3[1].ToFloatString() + ")");
                    if ((colorVertex != null) && (colorVertex[vertIndices[0]] || colorVertex[vertIndices[1]] || colorVertex[vertIndices[2]]))
                    {
                        string s = " COL(";
                        for (int j = 0; j < vertIndices.Length; j++)
                        {
                            if (colorVertex[vertIndices[j]])
                            {
                                s += 0xFFFF0000 + " ";
                            }
                            else
                            {
                                s += 0xFF000000 + " ";
                            }
                        }
                        s = s.Substring(0, s.Length - 1) + ")";
                        writer.Write(s);
                    }
                    writer.WriteLine();
                }
                writer.WriteLine("\t}");
            }
示例#2
0
        public static List <ImportedFace> ImportedFaceList(List <xxFace> faceList)
        {
            List <ImportedFace> importedList = new List <ImportedFace>(faceList.Count);

            for (int i = 0; i < faceList.Count; i++)
            {
                ImportedFace importedFace = new ImportedFace();
                importedList.Add(importedFace);
                importedFace.VertexIndices = new int[3];
                for (int j = 0; j < 3; j++)
                {
                    importedFace.VertexIndices[j] = faceList[i].VertexIndices[j];
                }
            }
            return(importedList);
        }
示例#3
0
            private static ImportedMesh ImportMeshList(List <MqoObject> mqoObjects, List <string> mqoMaterials)
            {
                ImportedMesh meshList = new ImportedMesh();

                meshList.Name = mqoObjects[0].name;
                float scale = 1f;

                if (!mqoObjects[0].worldCoords)
                {
                    int startPos = meshList.Name.IndexOf("(Scale=");
                    if (startPos > 0)
                    {
                        int endPos = meshList.Name.IndexOf(')');
                        scale = 1f / Single.Parse(meshList.Name.Substring(startPos + 7, endPos - startPos - 7));
                    }
                }
                meshList.BoneList    = new List <ImportedBone>(0);
                meshList.SubmeshList = new List <ImportedSubmesh>(mqoObjects.Count);

                int vertIdx = 0;

                foreach (MqoObject mqoObject in mqoObjects)
                {
                    List <VertexMap>[]            vertexMapList = new List <VertexMap> [mqoMaterials.Count + 1];
                    Dictionary <int, VertexMap>[] vertexMapDic  = new Dictionary <int, VertexMap> [mqoMaterials.Count + 1];
                    List <VertexMap[]>[]          faceMap       = new List <VertexMap[]> [mqoMaterials.Count + 1];
                    foreach (MqoFace mqoFace in mqoObject.faces)
                    {
                        int mqoFaceMatIdxOffset = mqoFace.materialIndex + 1;
                        if (vertexMapList[mqoFaceMatIdxOffset] == null)
                        {
                            vertexMapList[mqoFaceMatIdxOffset] = new List <VertexMap>(mqoObject.vertices.Length);
                            vertexMapDic[mqoFaceMatIdxOffset]  = new Dictionary <int, VertexMap>();
                            faceMap[mqoFaceMatIdxOffset]       = new List <VertexMap[]>(mqoObject.faces.Length);
                        }

                        VertexMap[] faceMapArray = new VertexMap[mqoFace.vertexIndices.Length];
                        faceMap[mqoFaceMatIdxOffset].Add(faceMapArray);
                        for (int i = 0; i < mqoFace.vertexIndices.Length; i++)
                        {
                            VertexMap vertMap;
                            if (!vertexMapDic[mqoFaceMatIdxOffset].TryGetValue(mqoFace.vertexIndices[i], out vertMap))
                            {
                                ImportedVertex vert;
                                MqoVertex      mqoVert = mqoObject.vertices[mqoFace.vertexIndices[i]];
                                if (mqoVert is MqoVertexWithColour)
                                {
                                    vert = new ImportedVertexWithColour();
                                    ((ImportedVertexWithColour)vert).Colour = ((MqoVertexWithColour)mqoVert).colour;
                                }
                                else
                                {
                                    vert = new ImportedVertex();
                                }
                                vert.BoneIndices = new byte[4];
                                vert.Weights     = new float[4];
                                vert.Normal      = new Vector3();
                                vert.UV          = mqoFace.UVs[i];
                                vert.Position    = mqoVert.coords * scale;

                                vertMap = new VertexMap {
                                    mqoIdx = mqoFace.vertexIndices[i], vert = vert
                                };
                                vertexMapDic[mqoFaceMatIdxOffset].Add(mqoFace.vertexIndices[i], vertMap);
                                vertMap.uvDic.Add(mqoFace.UVs[i], vertMap);
                                vertexMapList[mqoFaceMatIdxOffset].Add(vertMap);
                            }

                            VertexMap uvVertMap;
                            if (!vertMap.uvDic.TryGetValue(mqoFace.UVs[i], out uvVertMap))
                            {
                                ImportedVertex vert = new ImportedVertex();
                                vert.BoneIndices = new byte[4];
                                vert.Weights     = new float[4];
                                vert.Normal      = new Vector3();
                                vert.UV          = mqoFace.UVs[i];
                                vert.Position    = mqoObject.vertices[mqoFace.vertexIndices[i]].coords;

                                uvVertMap = new VertexMap {
                                    mqoIdx = Int32.MaxValue, vert = vert
                                };
                                vertMap.uvDic.Add(mqoFace.UVs[i], uvVertMap);
                                vertexMapList[mqoFaceMatIdxOffset].Add(uvVertMap);
                            }

                            faceMapArray[i] = uvVertMap;
                        }
                    }

                    for (int i = 0; i < vertexMapList.Length; i++)
                    {
                        if (vertexMapList[i] != null)
                        {
                            ImportedSubmesh mesh = new ImportedSubmesh();
                            mesh.VertexList  = new List <ImportedVertex>(vertexMapList[i].Count);
                            mesh.FaceList    = new List <ImportedFace>(faceMap[i].Count);
                            mesh.Index       = mqoObject.baseIdx;
                            mesh.WorldCoords = mqoObject.worldCoords;
                            mesh.Visible     = mqoObject.visible;
                            int matIdx = i - 1;
                            if ((matIdx >= 0) && (matIdx < mqoMaterials.Count))
                            {
                                mesh.Material = mqoMaterials[matIdx];
                            }
                            meshList.SubmeshList.Add(mesh);

                            vertexMapList[i].Sort();
                            for (int j = 0; j < vertexMapList[i].Count; j++)
                            {
                                vertexMapList[i][j].wsMeshIdx = j;
                                mesh.VertexList.Add(vertexMapList[i][j].vert);
                                vertIdx++;
                            }

                            for (int j = 0; j < faceMap[i].Count; j++)
                            {
                                ImportedFace face = new ImportedFace();
                                face.VertexIndices = new int[] { faceMap[i][j][0].wsMeshIdx, faceMap[i][j][2].wsMeshIdx, faceMap[i][j][1].wsMeshIdx };
                                mesh.FaceList.Add(face);
                            }
                        }
                    }
                }

                return(meshList);
            }