private void ConvertOBJToTOBJ(string filePath) { string fileName = Path.GetFileNameWithoutExtension(filePath); string objString = File.ReadAllText(filePath); ToriiObject tobj = new ToriiObject(objString, TextureFilePathField.Text); ToriiObjectWriter.Write(Path.Combine(OutputFilePathField.Text, fileName + ".tobj"), tobj); }
public static void Write(string location, ToriiObject toriiObject) { using (BinaryWriter writer = new BinaryWriter(File.Open(location, FileMode.Create))) { // FILE HEADER writer.Write(SIGNATURE); writer.Write(0x01); // version // FILE CONTENT writer.Write(toriiObject.ObjectFile); writer.Write(toriiObject.ObjectTexture); writer.Write(toriiObject.NumberOfObjects); writer.Write(0); // max animation ID writer.Write(0); // number of animations } }
// TODO: handle missing files public static DataType Load <DataType>(string filePath, ResourceLifespan lifespan = ResourceLifespan.GLOBAL, bool absolutePath = false) { string normalizedPath = IOUtil.NormalizePath(absolutePath ? filePath : IOUtil.PathCombine(Application.streamingAssetsPath, filePath)); // if the cache contains the resource, return it if (_resources.ContainsKey(normalizedPath)) { return(((GenericResource <DataType>)_resources[normalizedPath]).Resource); } string fileExt = Path.GetExtension(normalizedPath); bool fileNotFound = false; switch (fileExt) { case ".png": { GenericResource <Texture2D> resource = new GenericResource <Texture2D>(); resource.Resource = IOUtil.LoadPNG(normalizedPath); if (resource.Resource == null) { fileNotFound = true; break; } resource.Lifespan = lifespan; _resources.Add(normalizedPath, resource); break; } case ".json": { GenericResource <JSONClass> resource = new GenericResource <JSONClass>(); resource.Resource = IOUtil.ReadJSONFromDisk(normalizedPath); if (resource.Resource == null) { fileNotFound = true; break; } resource.Lifespan = lifespan; _resources.Add(normalizedPath, resource); break; } case ".map": { GenericResource <GameObject> resource = new GenericResource <GameObject>(); if (!File.Exists(normalizedPath)) { Debug.LogError("Could not load resource " + normalizedPath); fileNotFound = true; break; } resource.Resource = MapReader.LoadMap(normalizedPath, IOUtil.PathCombine(Application.streamingAssetsPath, "textures", "wad"), Shader.Find(GameSettings.CurrentSettings.UseClassicShaders ? "LSD/PSX/DiffuseSetNoAffine" : "LSD/DiffuseSet"), Shader.Find(GameSettings.CurrentSettings.UseClassicShaders ? "LSD/PSX/TransparentSetNoAffine" : "LSD/TransparentSet")); resource.Resource.transform.SetParent(_resourceManagerGameObject.transform); resource.Resource.SetActive(false); resource.Lifespan = lifespan; _resources.Add(normalizedPath, resource); break; } case ".tmap": { GenericResource <TMAP> resource = new GenericResource <TMAP>(); if (!File.Exists(normalizedPath)) { Debug.LogError("Could not load resource " + normalizedPath); fileNotFound = true; break; } resource.Resource = ToriiMapReader.ReadFromFile(normalizedPath); resource.Lifespan = lifespan; _resources.Add(normalizedPath, resource); break; } case ".tobj": { GenericResource <GameObject> resource = new GenericResource <GameObject>(); if (!File.Exists(normalizedPath)) { Debug.LogError("Could not load resource " + normalizedPath); fileNotFound = true; break; } TOBJ tobj = new TOBJ(); ToriiObjectReader.Read(normalizedPath, ref tobj); resource.Resource = OBJReader.ReadOBJString(tobj.ObjectFile); resource.Resource.AddComponent <ToriiObject>(); ToriiObject toriiObjScript = resource.Resource.GetComponent <ToriiObject>(); toriiObjScript.ToriiObj = tobj; resource.Resource.transform.SetParent(_resourceManagerGameObject.transform); resource.Resource.SetActive(false); resource.Lifespan = lifespan; _resources.Add(normalizedPath, resource); break; } default: { throw new ResourceLoadException("Did not recognize file type: " + normalizedPath); } } if (fileNotFound) { throw new ResourceLoadException("Could not find resource!"); } return(((GenericResource <DataType>)_resources[normalizedPath]).Resource); }