Exemple #1
0
        private void treeView_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            DragSource source = (DragSource)e.Node.Tag;

            if (source.Type == typeof(WorkspaceMesh))
            {
                var           srcEditor = (ImportedEditor)Gui.Scripting.Variables[source.Variable];
                ImportedMesh  iMesh     = srcEditor.Imported.MeshList[(int)source.Id];
                WorkspaceMesh wsMesh    = srcEditor.Meshes[(int)source.Id];
                iMesh.Name = wsMesh.Name = e.Label;
            }
        }
Exemple #2
0
        public WorkspaceMesh(ImportedMesh importedMesh) :
            base()
        {
            this.Name        = importedMesh.Name;
            this.SubmeshList = importedMesh.SubmeshList;
            this.BoneList    = importedMesh.BoneList;

            this.SubmeshOptions = new Dictionary <ImportedSubmesh, AdditionalSubmeshOptions>(importedMesh.SubmeshList.Count);
            foreach (ImportedSubmesh submesh in importedMesh.SubmeshList)
            {
                AdditionalSubmeshOptions options = new AdditionalSubmeshOptions();
                this.SubmeshOptions.Add(submesh, options);
            }
        }
Exemple #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);
            }
Exemple #4
0
            public Importer(string path)
            {
                try
                {
                    List <string>    mqoMaterials = new List <string>();
                    List <MqoObject> mqoObjects   = new List <MqoObject>();
                    using (StreamReader reader = new StreamReader(path, Utility.EncodingShiftJIS))
                    {
                        string line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            if (line.Contains("Object"))
                            {
                                MqoObject mqoObject = ParseObject(line, reader);
                                if (mqoObject != null)
                                {
                                    mqoObjects.Add(mqoObject);
                                }
                            }
                            else if (line.Contains("Material"))
                            {
                                string[] sArray       = line.Split(new string[] { "\t", " " }, StringSplitOptions.RemoveEmptyEntries);
                                int      numMaterials = Int32.Parse(sArray[1]);
                                while ((numMaterials > 0) && (line = reader.ReadLine()).Contains("\""))
                                {
                                    int matNameStart = line.IndexOf('\"') + 1;
                                    int matNameEnd   = line.IndexOf('\"', matNameStart);
                                    mqoMaterials.Add(line.Substring(matNameStart, matNameEnd - matNameStart));
                                    numMaterials--;
                                }
                            }
                        }
                    }

                    List <List <MqoObject> > groupedMeshes = new List <List <MqoObject> >();
                    for (int i = 0; i < mqoObjects.Count; i++)
                    {
                        bool found = false;
                        for (int j = 0; j < groupedMeshes.Count; j++)
                        {
                            if (mqoObjects[i].name == groupedMeshes[j][0].name)
                            {
                                groupedMeshes[j].Add(mqoObjects[i]);
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            List <MqoObject> group = new List <MqoObject>();
                            group.Add(mqoObjects[i]);
                            groupedMeshes.Add(group);
                        }
                    }

                    MeshList = new List <ImportedMesh>(groupedMeshes.Count);
                    for (int i = 0; i < groupedMeshes.Count; i++)
                    {
                        ImportedMesh meshList = ImportMeshList(groupedMeshes[i], mqoMaterials);
                        MeshList.Add(meshList);
                    }
                }
                catch (Exception e)
                {
                    Report.ReportLog("Error importing .mqo: " + e.Message);
                }
            }