public static J3D LoadResource(string filePath) { var existRef = m_j3dList.Find(x => string.Compare(x.FilePath, filePath, StringComparison.InvariantCultureIgnoreCase) == 0); if (existRef == null) { J3D j3d = new J3D(Path.GetFileNameWithoutExtension(filePath)); using (EndianBinaryReader reader = new EndianBinaryReader(File.ReadAllBytes(filePath), Endian.Big)) j3d.LoadFromStream(reader, WSettingsManager.GetSettings().DumpTextures, WSettingsManager.GetSettings().DumpShaders); j3d.SetHardwareLight(0, m_mainLight); j3d.SetHardwareLight(1, m_secondaryLight); // Apply patches for Wind Waker by default, since they don't seem to break anything else. j3d.SetTextureOverride("ZBtoonEX", "resources/textures/ZBtoonEX.png"); j3d.SetTextureOverride("ZAtoon", "resources/textures/ZAtoon.png"); j3d.SetColorWriteOverride("eyeLdamA", false); j3d.SetColorWriteOverride("eyeLdamB", false); j3d.SetColorWriteOverride("mayuLdamA", false); j3d.SetColorWriteOverride("mayuLdamB", false); j3d.SetColorWriteOverride("eyeRdamA", false); j3d.SetColorWriteOverride("eyeRdamB", false); j3d.SetColorWriteOverride("mayuRdamA", false); j3d.SetColorWriteOverride("mayuRdamB", false); existRef = new TSharedRef <J3D>(); existRef.FilePath = filePath; existRef.Asset = j3d; m_j3dList.Add(existRef); } existRef.ReferenceCount++; return(existRef.Asset); }
public static SimpleObjRenderer LoadObjResource(string filePath) { var existRef = m_objList.Find(x => string.Compare(x.FilePath, filePath, StringComparison.InvariantCultureIgnoreCase) == 0); if (existRef == null) { Obj obj = new Obj(); obj.Load(filePath); existRef = new TSharedRef <SimpleObjRenderer>(); existRef.FilePath = filePath; existRef.Asset = new SimpleObjRenderer(obj); m_objList.Add(existRef); } existRef.ReferenceCount++; return(existRef.Asset); }
public static SimpleObjRenderer LoadObjResource(string filePath, Vector4 tint_color, bool enable_blending = false) { var existRef = m_objList.Find(x => string.Compare(x.FilePath, filePath, StringComparison.InvariantCultureIgnoreCase) == 0 && x.Asset.BlendingEnabled == enable_blending && x.Asset.TintColor == tint_color); if (existRef == null) { Obj obj = new Obj(); obj.Load(filePath); existRef = new TSharedRef <SimpleObjRenderer>(); existRef.FilePath = filePath; existRef.Asset = new SimpleObjRenderer(obj, tint_color, enable_blending); m_objList.Add(existRef); } existRef.ReferenceCount++; return(existRef.Asset); }
public static J3D LoadModelFromVFS(VirtualFilesystemDirectory fs, string path) { TSharedRef <J3D> existRef = null;//m_j3dList.Find(x => string.Compare(x.FilePath, arc_and_file_path, StringComparison.InvariantCultureIgnoreCase) == 0); J3D model = new J3D(path); VirtualFilesystemFile file = fs.GetFileAtPath(path); using (EndianBinaryReader reader = new EndianBinaryReader(file.Data, Endian.Big)) model.LoadFromStream(reader); existRef = new TSharedRef <J3D>(); existRef.FilePath = fs.Name + '/' + path; existRef.Asset = model; existRef.ReferenceCount++; m_j3dList.Add(existRef); return(model); }
public static J3D LoadModelFromVFS(VirtualFilesystemDirectory fs, string path = null, ushort?fileID = null) { if (path == null && fileID == null) { throw new ArgumentException("Must specify either file path or file ID when loading a model from an archive.", "path"); } TSharedRef <J3D> existRef = null;//m_j3dList.Find(x => string.Compare(x.FilePath, arc_and_file_path, StringComparison.InvariantCultureIgnoreCase) == 0); VirtualFilesystemFile file; if (fileID != null) { file = fs.FindByID((ushort)fileID); } else { file = fs.GetFileAtPath(path); } // This isn't actually a relative path, just the flat filename. // Shouldn't actually matter though, filenames in RARCs must be unique even in completely different foldes. string fileRelativePath = file.NameWithExtension; J3D model = new J3D(fileRelativePath); using (EndianBinaryReader reader = new EndianBinaryReader(file.Data, Endian.Big)) model.LoadFromStream(reader); existRef = new TSharedRef <J3D>(); existRef.FilePath = fs.Name + '/' + fileRelativePath; existRef.Asset = model; existRef.ReferenceCount++; m_j3dList.Add(existRef); model.Tick(1 / (float)60); return(model); }
public static List <J3D> LoadActorResource(string name) { List <J3D> models = new List <J3D>(); if (!m_actorResources.ContainsKey(name)) { return(null); } WActorResource res = m_actorResources[name]; foreach (var model in res.Models) { string model_arc_name = res.ArchiveName; if (!string.IsNullOrEmpty(model.ArchiveName)) { model_arc_name = model.ArchiveName; string model_arc_path = Path.Combine(WSettingsManager.GetSettings().RootDirectoryPath, "files", "res/Object/", model_arc_name + ".arc"); if (!File.Exists(model_arc_path)) { continue; } } string arc_and_file_path = Path.Combine(model_arc_name, model.Path); TSharedRef <J3D> existRef = null;//m_j3dList.Find(x => string.Compare(x.FilePath, arc_and_file_path, StringComparison.InvariantCultureIgnoreCase) == 0); if (existRef != null) { existRef.ReferenceCount++; models.Add(existRef.Asset); continue; } J3D loaded_model = LoadModelFromResource(model, model_arc_name); if (loaded_model == null) { continue; } existRef = new TSharedRef <J3D>(); existRef.FilePath = arc_and_file_path; existRef.Asset = loaded_model; existRef.ReferenceCount++; m_j3dList.Add(existRef); models.Add(loaded_model); } if (models.Count > 0 && (name == "Link" || name == "Tetra" || name == "Zelda")) { models[0].SetColorWriteOverride("eyeLdamA", false); models[0].SetColorWriteOverride("eyeLdamB", false); models[0].SetColorWriteOverride("mayuLdamA", false); models[0].SetColorWriteOverride("mayuLdamB", false); models[0].SetColorWriteOverride("eyeRdamA", false); models[0].SetColorWriteOverride("eyeRdamB", false); models[0].SetColorWriteOverride("mayuRdamA", false); models[0].SetColorWriteOverride("mayuRdamB", false); models[0].SetColorWriteOverride("m_pz_eyeLdamA", false); models[0].SetColorWriteOverride("m_pz_eyeLdamB", false); models[0].SetColorWriteOverride("m_pz_eyeRdamA", false); models[0].SetColorWriteOverride("m_pz_eyeRdamB", false); models[0].SetColorWriteOverride("m_pz_mayuLdamA", false); models[0].SetColorWriteOverride("m_pz_mayuLdamB", false); models[0].SetColorWriteOverride("m_pz_mayuRdamA", false); models[0].SetColorWriteOverride("m_pz_mayuRdamB", false); foreach (var material in models[0].MAT3Tag.MaterialList) { if (material.BlendModeIndex.SourceFactor == GXBlendModeControl.DstAlpha && material.BlendModeIndex.DestinationFactor == GXBlendModeControl.InverseDstAlpha) { material.BlendModeIndex.SourceFactor = GXBlendModeControl.SrcAlpha; material.BlendModeIndex.DestinationFactor = GXBlendModeControl.InverseSrcAlpha; } } } if (models.Count > 0 && (name == "Wizzrobe")) { foreach (var material in models[0].MAT3Tag.MaterialList) { material.ZModeIndex.UpdateEnable = true; } } return(models); }
public static J3D LoadActorByName(string actorName) { // Stop to check if we've already loaded this model. var existRef = m_j3dList.Find(x => string.Compare(x.FilePath, actorName, StringComparison.InvariantCultureIgnoreCase) == 0); if (existRef != null) { existRef.ReferenceCount++; return(existRef.Asset); } if (actorName == null) { return(null); } // Check to see if we have an Actor Descriptor for this actor. if (!m_actorDescriptors.ContainsKey(actorName)) { return(null); } WActorDescriptor descriptor = m_actorDescriptors[actorName]; // Check to see that this actor descriptor specifies a model path. if (string.IsNullOrEmpty(descriptor.ModelPath) || string.IsNullOrEmpty(descriptor.ArchiveName)) { return(null); } string archivePath = Path.Combine(Properties.Settings.Default.RootDirectory, "res/Object/", descriptor.ArchiveName + ".arc"); // Check to see that the archive exists if (!File.Exists(archivePath)) { return(null); } // Finally, open the archive so we can look insdie of it to see if it exists. VirtualFilesystemDirectory archive = ArchiveUtilities.LoadArchive(archivePath); VirtualFilesystemFile archiveFile = archive.GetFileAtPath(descriptor.ModelPath); if (archiveFile == null) { Console.WriteLine("LoadActorByName failed because the specified path \"{0}\" does not exist in archive \"{1}\"!", descriptor.ModelPath, descriptor.ArchiveName); return(null); } // Now that we finally have the file, we can try to load a J3D from it. byte[] j3dData = archiveFile.Data; J3D j3d = new J3D(archiveFile.Name); using (EndianBinaryReader reader = new EndianBinaryReader(j3dData, Endian.Big)) j3d.LoadFromStream(reader, Properties.Settings.Default.DumpTexturesToDisk, Properties.Settings.Default.DumpShadersToDisk); j3d.SetHardwareLight(0, m_mainLight); j3d.SetHardwareLight(1, m_secondaryLight); // Apply patches for Wind Waker by default, since they don't seem to break anything else. j3d.SetTextureOverride("ZBtoonEX", "resources/textures/ZBtoonEX.png"); j3d.SetTextureOverride("ZAtoon", "resources/textures/ZAtoon.png"); j3d.SetColorWriteOverride("eyeLdamA", false); j3d.SetColorWriteOverride("eyeLdamB", false); j3d.SetColorWriteOverride("mayuLdamA", false); j3d.SetColorWriteOverride("mayuLdamB", false); j3d.SetColorWriteOverride("eyeRdamA", false); j3d.SetColorWriteOverride("eyeRdamB", false); j3d.SetColorWriteOverride("mayuRdamA", false); j3d.SetColorWriteOverride("mayuRdamB", false); existRef = new TSharedRef <J3D>(); existRef.FilePath = actorName; existRef.Asset = j3d; existRef.ReferenceCount++; m_j3dList.Add(existRef); return(j3d); }
public static List <J3D> LoadActorResource(string name) { List <J3D> models = new List <J3D>(); if (!m_actorResources.ContainsKey(name)) { return(null); } WActorResource res = m_actorResources[name]; foreach (var model in res.Models) { string arc_and_file_path = Path.Combine(res.ArchiveName, model.Path); TSharedRef <J3D> existRef = null;//m_j3dList.Find(x => string.Compare(x.FilePath, arc_and_file_path, StringComparison.InvariantCultureIgnoreCase) == 0); if (existRef != null) { existRef.ReferenceCount++; models.Add(existRef.Asset); continue; } J3D loaded_model = LoadModelFromResource(model, res.ArchiveName); if (loaded_model == null) { continue; } loaded_model.SetHardwareLight(0, m_mainLight); loaded_model.SetHardwareLight(1, m_secondaryLight); loaded_model.SetTextureOverride("ZBtoonEX", "resources/textures/ZBtoonEX.png"); loaded_model.SetTextureOverride("ZAtoon", "resources/textures/ZAtoon.png"); existRef = new TSharedRef <J3D>(); existRef.FilePath = arc_and_file_path; existRef.Asset = loaded_model; existRef.ReferenceCount++; m_j3dList.Add(existRef); loaded_model.Tick(1 / (float)60); models.Add(loaded_model); } if (models.Count > 0 && (name == "Link" || name == "Tetra" || name == "Zelda")) { models[0].SetColorWriteOverride("eyeLdamA", false); models[0].SetColorWriteOverride("eyeLdamB", false); models[0].SetColorWriteOverride("mayuLdamA", false); models[0].SetColorWriteOverride("mayuLdamB", false); models[0].SetColorWriteOverride("eyeRdamA", false); models[0].SetColorWriteOverride("eyeRdamB", false); models[0].SetColorWriteOverride("mayuRdamA", false); models[0].SetColorWriteOverride("mayuRdamB", false); } return(models); }