Пример #1
0
        private Mesh StripMesh(string propName, string objectName)
        {
            Mesh           mesh = null;
            JurassicReader r    = new JurassicReader();

            if (r.Read(resourcePath + "\\" + propName))
            {
                List <DependencyList> dependencies = (r.reader as PropReader).Dependencies;
                foreach (DependencyList dependencyList in dependencies)
                {
                    foreach (string entry in dependencyList.Objects)
                    {
                        // Only load d3dmeshes, for now :)
                        if (Common.GetExtension(entry).Equals("d3dmesh"))
                        {
                            string meshPath = resourcePath + "\\" + entry;
                            if (!File.Exists(meshPath))
                            {
                                MessageBox.Show("Couldn't find " + entry + "! Please navigate to the JP resource directory.", "ERROR!");
                                AdjustResourcePath();
                                //Console.WriteLine(entry + " does not exist - skipping");
                                continue;
                            }

                            JurassicReader modelReader = new JurassicReader();
                            if (modelReader.Read(meshPath))
                            {
                                Mesh propMesh = modelReader.mesh;
                                if (propMesh == null)
                                {
                                    continue;
                                }

                                if (mesh == null)
                                {
                                    mesh = propMesh;
                                }
                                else
                                {
                                    mesh.Combine(propMesh);
                                }
                            }
                        }
                    }
                }
            }

            return(mesh);
        }
Пример #2
0
        private void OnMassRead(object sender, EventArgs e)
        {
            if (!resourceDialog.Open())
            {
                return;
            }

            string fileName      = resourceDialog.FileName;
            string fileExtension = Common.GetExtension(fileName);
            string fileDirectory = Common.GetPath(fileName);

            foreach (string file in Directory.GetFiles(fileDirectory))
            {
                string extension = Common.GetExtension(file);

                // Only process files with the same extension, for neatness
                if (fileExtension.Equals(extension))
                {
                    JurassicReader r = new JurassicReader();
                    r.Read(file);
                }
            }
        }
Пример #3
0
        private JurassicReader ReadFile(string fileName)
        {
            JurassicReader reader = new JurassicReader();

            if (!reader.Read(resourceDialog.FileName))
            {
                MessageBox.Show(resourceDialog.FileName + "\n\nERROR: File encountered an error while parsing!", "Export failed!");
                return(null);
            }

            string resourceName = resourceDialog.FileName;
            string extension    = Common.GetExtension(resourceName);

            if (reader.reader is IMeshReader)
            {
                Mesh mesh = reader.mesh;

                if (mesh == null)
                {
                    return(reader);
                }

                // Fetch missing textures
                string        texType         = "dds";
                List <string> missingTextures = new List <string>();
                string        path            = Common.GetPath(resourceName);
                foreach (string texture in mesh.GetTextures())
                {
                    if (texture.StartsWith("color_"))
                    {
                        continue;
                    }

                    if (!File.Exists(path + "\\" + texture + "." + texType))
                    {
                        missingTextures.Add(texture);
                    }
                }

                if (missingTextures.Count > 0)
                {
                    MessageBox.Show("Missing " + missingTextures.Count + " texture" + (missingTextures.Count > 1 ? "s" : "") + "! Please specify the texture directory.");
                    string destinationDir = Common.GetPath(resourceDialog.FileName);
                    if (textureDialog.Open())
                    {
                        string texturePath = Common.GetPath(textureDialog.FileName);
                        foreach (string texture in missingTextures)
                        {
                            string textureName = texture + "." + texType;
                            if (!File.Exists(texturePath + "\\" + textureName))
                            {
                                MessageBox.Show("Couldn't locate " + textureName + "!");
                                continue;
                            }
                            File.Copy(texturePath + "\\" + textureName, destinationDir + "\\" + textureName);
                        }
                    }
                }

                // Output the mesh data to a Wavefront OBJ
                String meshOutputName = resourceName.Replace("." + Common.GetExtension(resourceName), ".obj");
                String mtlOutputName  = meshOutputName.Replace(".obj", ".mtl");
                String mtlName        = mtlOutputName.Substring(mtlOutputName.LastIndexOf("\\") + 1);
                File.WriteAllText(meshOutputName, mesh.GetObjData(mtlName));
                File.WriteAllText(mtlOutputName, mesh.GetMtlData());

                // Show the user it worked
                MessageBox.Show(meshOutputName + "\n\nProcessed " + mesh.Chunks.Count + " chunks.\n" + mesh.Vertices.Count + " vertices exported.", "Export successful!");
            }

            return(reader);
        }