Ejemplo n.º 1
0
        public void SimpleObj_OneMeshPerMaterialGroup()
        {
            CreateTestObj();
            var mesh       = ObjMesh.FromFile("test.obj");
            var dummyScene = new Scene();

            ObjConverter.AddToScene(mesh, dummyScene, null);

            // There should be four meshes in total (one per group, except if there are multiple
            // materials in the same group)
            Assert.Equal(4, dummyScene.Meshes.Count);
        }
Ejemplo n.º 2
0
        static void ExtractBg(string bgPath, string basePath = null)
        {
            if (basePath == null)
            {
                basePath = Path.ChangeExtension(bgPath, null);
            }
            else
            {
                basePath = Path.Combine(basePath, Path.GetFileNameWithoutExtension(bgPath));
            }

            DatReader dat = new DatReader(Utils.CheckDecompress(File.OpenRead(bgPath)));

            using ObjConverter converter = new ObjConverter(dat);
            string mtlPath = basePath + ".mtl";
            string mtlName = Path.GetFileName(mtlPath);

            for (int i = 0; i < 3; ++i)
            {
                using MemoryStream ms = new MemoryStream(dat.GetData(i));
                DatReader innerDat = new DatReader(ms);
                for (int j = 0; j < innerDat.EntriesCount; ++j)
                {
                    using BinaryReader br = new BinaryReader(new MemoryStream(innerDat.GetData(j)));
                    Tdb tdb = new Tdb();
                    tdb.Read(br);

                    // Remap textures (only known for Windows version, PS2 todo when files obtained)
                    if (i == 0)
                    {
                        tdb.Textures[0].DatIndex = 4;
                        tdb.Textures[1].DatIndex = 3;
                    }
                    else
                    {
                        tdb.Textures[0].DatIndex = 5;
                    }

                    using StreamWriter sw = File.CreateText($"{basePath}.{i}_{j}.obj");
                    sw.WriteLine($"mtllib {mtlName}");
                    sw.WriteLine();

                    converter.ConvertObj(tdb, sw);
                }
            }

            using (StreamWriter sw = File.CreateText(mtlPath))
            {
                converter.ExportTextures(sw, basePath + ".", true);
            }
        }
Ejemplo n.º 3
0
        public void SimpleObj_Triangulation()
        {
            CreateTestObj();
            var mesh       = ObjMesh.FromFile("test.obj");
            var dummyScene = new Scene();

            ObjConverter.AddToScene(mesh, dummyScene, null);

            // There should be exactly 7 triangles
            int numTriangles = 0;

            foreach (var m in dummyScene.Meshes)
            {
                numTriangles += m.NumFaces;
            }

            Assert.Equal(7, numTriangles);
        }
Ejemplo n.º 4
0
        static void ExtractTrm(string trmPath, string basePath = null)
        {
            if (basePath == null)
            {
                basePath = Path.ChangeExtension(trmPath, null);
            }
            else
            {
                basePath = Path.Combine(basePath, Path.GetFileNameWithoutExtension(trmPath));
            }

            using DatReader dat = new DatReader(Utils.CheckDecompress(File.OpenRead(trmPath)));
            // First entry is texture DAT
            using DatReader txmDat       = new DatReader(new MemoryStream(dat.GetData(0)));
            using ObjConverter converter = new ObjConverter(txmDat);
            string mtlPath = basePath + ".mtl";
            string mtlName = Path.GetFileName(mtlPath);

            // Subsequent entries are train car DATs
            for (int i = 1; i < dat.EntriesCount; ++i)
            {
                using DatReader innerDat = new DatReader(new MemoryStream(dat.GetData(i)));
                // And within each train car DAT are PDBs
                for (int j = 0; j < innerDat.EntriesCount; ++j)
                {
                    using MemoryStream ms = new MemoryStream(innerDat.GetData(j));
                    BinaryReader br  = new BinaryReader(ms);
                    Pdb          pdb = new Pdb();
                    pdb.Read(br);
                    using StreamWriter sw = File.CreateText($"{basePath}.{i}_{j}.obj");
                    sw.WriteLine($"mtllib {mtlName}");
                    sw.WriteLine();

                    converter.ConvertObj(pdb, sw);
                }
            }

            using (StreamWriter sw = File.CreateText(mtlPath))
            {
                converter.ExportTextures(sw, basePath + ".");
            }
        }
Ejemplo n.º 5
0
        static void ExtractMapAnim(string mapAnimPath, string basePath = null)
        {
            if (basePath == null)
            {
                basePath = Path.ChangeExtension(mapAnimPath, null);
            }
            else
            {
                basePath = Path.Combine(basePath, Path.GetFileNameWithoutExtension(mapAnimPath));
            }

            using DatReader dat = new DatReader(Utils.CheckDecompress(File.OpenRead(mapAnimPath)));
            // Second entry is texture DAT
            using DatReader txmDat       = new DatReader(new MemoryStream(dat.GetData(1)));
            using ObjConverter converter = new ObjConverter(txmDat);
            string mtlPath = basePath + ".mtl";
            string mtlName = Path.GetFileName(mtlPath);

            // First entry is a collection of weird PDBs
            using DatReader pdbDat = new DatReader(new MemoryStream(dat.GetData(0)));
            for (int i = 0; i < pdbDat.EntriesCount; ++i)
            {
                using MemoryStream ms = new MemoryStream(pdbDat.GetData(i));
                // This is a DAT, but we're going to pretend it's a normal PDB
                BinaryReader br  = new BinaryReader(ms);
                Pdb          pdb = new Pdb();
                pdb.Read(br);
                using StreamWriter sw = File.CreateText($"{basePath}.{i}.obj");
                sw.WriteLine($"mtllib {mtlName}");
                sw.WriteLine();

                converter.ConvertObj(pdb, sw);
            }

            using (StreamWriter sw = File.CreateText(mtlPath))
            {
                converter.ExportTextures(sw, basePath + ".");
            }
        }
Ejemplo n.º 6
0
        public void SimpleObj_ShouldBeRead()
        {
            CreateTestObj();
            var mesh       = ObjMesh.FromFile("test.obj");
            var dummyScene = new Scene();

            ObjConverter.AddToScene(mesh, dummyScene, null);

            Assert.Empty(mesh.Errors);

            // There should be some meshes
            Assert.NotEmpty(dummyScene.Meshes);

            // Every mesh should have a material assigned
            foreach (var m in dummyScene.Meshes)
            {
                Assert.NotNull(m.Material);
            }

            // There should be an emitter
            Assert.NotEmpty(dummyScene.Emitters);
        }
Ejemplo n.º 7
0
        static void ExtractPdb(string pdbPath, string txmPath, string basePath = null, bool forceDirect = false)
        {
            if (basePath == null)
            {
                basePath = Path.ChangeExtension(pdbPath, null);
            }
            else
            {
                basePath = Path.Combine(basePath, Path.GetFileNameWithoutExtension(pdbPath));
            }

            DatReader dat = new DatReader(Utils.CheckDecompress(File.OpenRead(pdbPath)));

            using DatReader txmDat       = new DatReader(Utils.CheckDecompress(File.OpenRead(txmPath)));
            using ObjConverter converter = new ObjConverter(txmDat);
            string mtlPath = basePath + ".mtl";
            string mtlName = Path.GetFileName(mtlPath);

            for (int i = 0; i < dat.EntriesCount; ++i)
            {
                using MemoryStream ms = new MemoryStream(dat.GetData(i));
                BinaryReader br  = new BinaryReader(ms);
                Pdb          pdb = new Pdb();
                pdb.Read(br);
                using StreamWriter sw = File.CreateText($"{basePath}.{i}.obj");
                sw.WriteLine($"mtllib {mtlName}");
                sw.WriteLine();

                converter.ConvertObj(pdb, sw);
            }

            using (StreamWriter sw = File.CreateText(mtlPath))
            {
                converter.ExportTextures(sw, basePath + ".", forceDirect);
            }
        }
Ejemplo n.º 8
0
        public static SearchObject WordCountMatch(SearchObject searchObj)
        {
            // iterate through each entry in the listtosearch
            for (int it = 0; it < searchObj.listToSearch.Count; it++)
            {
                // sanitse
                string searchOrig = ObjConverter.StripSymbols(searchObj.searchString).ToLower();
                string searchDest = ObjConverter.StripSymbols(searchObj.listToSearch[it].name).ToLower();

                double matchingWords = 0;

                // get total substrings in search string
                string[] arr          = ObjConverter.StringToArray(searchOrig, ObjConverter.ConversationCase.None);
                int      searchLength = arr.Length;

                // get total substrings in result string
                string[] rArr         = ObjConverter.StringToArray(searchDest, ObjConverter.ConversationCase.None);
                int      resultLength = rArr.Length;

                // find matching words
                foreach (string s in arr)
                {
                    double i = 0;
                    while (i < resultLength)
                    {
                        if (ObjConverter.StripSymbols(s) == ObjConverter.StripSymbols(rArr[Convert.ToInt32(i)].ToLower()))
                        {
                            // reduce score to 0.5 for common works like and, of, the, a
                            if (ObjConverter.StripSymbols(s).ToLower() == "a" ||
                                ObjConverter.StripSymbols(s).ToLower() == "of" ||
                                ObjConverter.StripSymbols(s).ToLower() == "the" ||
                                ObjConverter.StripSymbols(s).ToLower() == "and")
                            {
                                matchingWords = matchingWords + 0.3;
                            }
                            else
                            {
                                matchingWords = matchingWords + 1;
                            }
                            matchingWords++;
                            break;
                        }
                        i++;
                    }
                }

                // create new searchresult object and add to list
                SearchResult sr = new SearchResult();
                sr.resultId     = searchObj.listToSearch[it].id;
                sr.resultString = searchObj.listToSearch[it].name;
                sr.score        = (Convert.ToDouble(matchingWords) / Convert.ToDouble(arr.Length)) * 100;

                if (sr.score > 0)
                {
                    searchObj.searchResults.Add(sr);
                    continue;
                }
            }
            // order list
            searchObj.searchResults.OrderByDescending(a => a.score);

            return(searchObj);
        }