Exemple #1
0
        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);
        }
        private void LoadAssetFromFilepath(string filePath, bool unloadExisting)
        {
            if (!File.Exists(filePath))
            {
                Console.WriteLine("Cannot load: \"{0}\", not a file!", filePath);
            }

            string fileName      = Path.GetFileNameWithoutExtension(filePath);
            string fileExtension = Path.GetExtension(filePath).ToLowerInvariant();

            switch (fileExtension)
            {
            case ".bdl":
            case ".bmd":
            {
                if (unloadExisting)
                {
                    foreach (var model in m_loadedModels)
                    {
                        model.Dispose();
                    }
                    m_loadedModels.Clear();
                    m_sceneGraphs.Clear();
                }

                var newModel = new J3D(fileName);
                using (EndianBinaryReader reader = new EndianBinaryReader(new FileStream(filePath, FileMode.Open, FileAccess.Read), Endian.Big))
                    newModel.LoadFromStream(reader, true, true);

                newModel.SetHardwareLight(0, m_mainLight);
                newModel.SetHardwareLight(1, m_secondaryLight);

                // Apply patches for Wind Waker by default, since they don't seem to break anything else.
                newModel.SetTextureOverride("ZBtoonEX", "resources/textures/ZBtoonEX.png");
                newModel.SetTextureOverride("ZAtoon", "resources/textures/ZAtoon.png");
                newModel.SetColorWriteOverride("eyeLdamA", false);
                newModel.SetColorWriteOverride("eyeLdamB", false);
                newModel.SetColorWriteOverride("mayuLdamA", false);
                newModel.SetColorWriteOverride("mayuLdamB", false);
                newModel.SetColorWriteOverride("eyeRdamA", false);
                newModel.SetColorWriteOverride("eyeRdamB", false);
                newModel.SetColorWriteOverride("mayuRdamA", false);
                newModel.SetColorWriteOverride("mayuRdamB", false);

                m_loadedModels.Add(newModel);
                m_sceneGraphs.Add(new SceneGraphViewModel(newModel, newModel.INF1Tag.HierarchyRoot, ""));
            }
            break;

            case ".bck":
            {
                if (MainModel != null)
                {
                    if (unloadExisting)
                    {
                        MainModel.UnloadBoneAnimations();
                    }
                    MainModel.LoadBoneAnimation(filePath);

                    // Automatically play the latest animation loaded.
                    MainModel.SetBoneAnimation(fileName);
                }
            }
            break;

            case ".btk":
            {
                if (MainModel != null)
                {
                    if (unloadExisting)
                    {
                        MainModel.UnloadMaterialAnimations();
                    }
                    MainModel.LoadMaterialAnim(filePath);

                    // Automatically play the latest animation loaded.
                    MainModel.SetMaterialAnimation(fileName);
                }
            }
            break;

            case ".brk":
            {
                if (MainModel != null)
                {
                    if (unloadExisting)
                    {
                        MainModel.UnloadRegisterAnimations();
                    }
                    MainModel.LoadRegisterAnim(filePath);

                    MainModel.SetRegisterAnimation(fileName);
                }
            }
            break;

            case ".bmt":
            {
                if (MainModel != null)
                {
                    if (unloadExisting)
                    {
                        MainModel.UnloadExternalMaterials();
                    }
                    MainModel.LoadExternalMaterial(filePath);

                    // Automatically set the latest external material loaded.
                    MainModel.SetExternalMaterial(fileName);
                }
            }
            break;
            }

            // m_loadedModels.Sort((x,y) => x.Name.CompareTo(y.Name));

            if (PropertyChanged != null)
            {
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs("MainModel"));
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs("MainScenegraph"));
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs("HasLoadedModel"));
            }
        }
Exemple #3
0
        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);
        }