Example #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);
        }
Example #2
0
        public void UpdateModel()
        {
            m_brazierModel = null;
            m_objRender    = null;
            m_actorMeshes  = null;
            if (HasBrazier())
            {
                if (IsWooden)
                {
                    m_actorMeshes = WResourceManager.LoadActorResource("Wooden Torch");
                }
                else
                {
                    m_actorMeshes = WResourceManager.LoadActorResource("Golden Torch");
                }
            }
            if (m_actorMeshes == null)
            {
                m_actorMeshes = new List <J3D>();
            }

            if (m_actorMeshes.Count > 0)
            {
                m_brazierModel = m_actorMeshes[0];
            }
            else
            {
                m_objRender = WResourceManager.LoadObjResource("resources/editor/EditorCube.obj", new OpenTK.Vector4(1, 1, 1, 1));
            }
        }
Example #3
0
        public void LoadSkyboxModelsFromFixedModelList(string rootFolder)
        {
            string[] fileNames = new[] { "vr_sky", "vr_kasumi_mae", "vr_uso_umi", "vr_back_cloud" };
            string[] extNames  = new[] { ".bmd", ".bdl" };

            foreach (var model in fileNames)
            {
                foreach (var ext in extNames)
                {
                    string fullPath = Path.Combine(rootFolder, model + ext);
                    if (File.Exists(fullPath))
                    {
                        J3D     j3dModel  = WResourceManager.LoadResource(fullPath);
                        J3DNode modelNode = new J3DNode(j3dModel, m_world, fullPath);

                        switch (model)
                        {
                        case "vr_sky": m_vrSky = modelNode; break;

                        case "vr_kasumi_mae": m_vrKasumiMae = modelNode; break;

                        case "vr_uso_umi": m_vrUsoUmi = modelNode; break;

                        case "vr_back_cloud": m_vrBackCloud = modelNode; break;
                        }
                    }
                }
            }
        }
Example #4
0
        private void LoadRoomModels(string filePath)
        {
            // Search the bmd and bdl folders for valid model names. Then search for a matching brk and btk for those models.
            string[] modelNames  = new[] { "model", "model1", "model2", "model3" };
            string[] folderNames = new[] { "bmd", "bdl" };
            bool[]   validModels = new bool[modelNames.Length];

            CategoryDOMNode col_category = new CategoryDOMNode("Models", m_world);

            col_category.SetParent(this);

            foreach (var subFolder in folderNames)
            {
                string folderPath = Path.Combine(filePath, subFolder);
                foreach (var modelName in modelNames)
                {
                    J3D mesh = LoadModel(folderPath, modelName);
                    if (mesh != null)
                    {
                        J3DNode j3d_node = new J3DNode(mesh, m_world);
                        j3d_node.SetParent(col_category);
                    }
                }
            }
        }
Example #5
0
        public override void PostLoad()
        {
            base.PostLoad();

            m_actorMesh = WResourceManager.LoadActorByName(ToString());
            if (m_actorMesh != null)
            {
                // Create and set up some initial lighting options so character's aren't drawn super brightly
                // until we support actually loading room environment lighting and apply it (see below).
                var lightPos       = new Vector4(250, 200, 250, 0);
                var mainLight      = new JStudio.OpenGL.GXLight(lightPos, -lightPos.Normalized(), new Vector4(1, 0, 1, 1), new Vector4(1.075f, 0, 0, 0), new Vector4(1.075f, 0, 0, 0));
                var secondaryLight = new JStudio.OpenGL.GXLight(lightPos, -lightPos.Normalized(), new Vector4(0, 0, 1, 1), new Vector4(1.075f, 0, 0, 0), new Vector4(1.075f, 0, 0, 0));

                Quaternion lightRot    = Quaternion.FromAxisAngle(Vector3.UnitY, (float)Math.PI / 2f);
                Vector3    newLightPos = Vector3.Transform(new Vector3(-500, 0, 0), lightRot) + new Vector3(0, 50, 0);

                secondaryLight.Position = new Vector4(newLightPos, 0);

                m_actorMesh.SetHardwareLight(0, mainLight);
                m_actorMesh.SetHardwareLight(1, secondaryLight);
                m_actorMesh.SetTextureOverride("ZBtoonEX", "resources/textures/ZBtoonEX.png");
                m_actorMesh.SetTextureOverride("ZAtoon", "resources/textures/ZAtoon.png");

                m_objRender = null;
            }

            if (m_actorMesh == null)
            {
                m_objRender = WResourceManager.LoadObjResource("resources/editor/EditorCube.obj");
            }
        }
Example #6
0
        protected virtual J3D LoadModel(string rootFolder, string modelName)
        {
            string[] extNames = new[] { ".bmd", ".bdl" };
            foreach (var ext in extNames)
            {
                string fullPath = Path.Combine(rootFolder, modelName + ext);
                if (File.Exists(fullPath))
                {
                    J3D j3dMesh = WResourceManager.LoadResource(fullPath);

                    // Now that we've loaded a j3dMesh, we're going to try loading btk anims too.
                    string btkFolder = rootFolder + "\\..\\btk\\";
                    string btkFile   = btkFolder + modelName + ".btk";

                    if (File.Exists(btkFile))
                    {
                        j3dMesh.LoadMaterialAnim(btkFile);
                        j3dMesh.SetMaterialAnimation(modelName);
                    }

                    return(j3dMesh);
                }
            }

            return(null);
        }
Example #7
0
        public J3DNode(J3D model, WWorld world, string filename = "") : base(world)
        {
            m_model  = model;
            Name     = model.Name;
            Filename = filename;

            IsRendered = true;
        }
Example #8
0
        public J3DRenderable(J3D model_ref, J3DRenderable parent, LightingType light_type = LightingType.Actor, string socket = "")
        {
            Children = new List <J3DRenderable>();

            m_Parent     = parent;
            m_Model      = model_ref;
            m_LightType  = light_type;
            m_SocketName = socket;
        }
Example #9
0
        public override void PostLoad()
        {
            m_stairMesh = null;
            var meshes = WResourceManager.LoadActorResource("Earth Temple Stair");

            if (meshes != null && meshes.Count > 0)
            {
                m_stairMesh = meshes[0];
            }

            base.PostLoad();
        }
Example #10
0
        public override void PostLoad()
        {
            m_actorMeshes     = WResourceManager.LoadActorResource("Pulley Lift");
            m_liftControlMesh = null;
            var meshes = WResourceManager.LoadActorResource("Pulley Lift Control");

            if (meshes != null && meshes.Count > 0)
            {
                m_liftControlMesh = meshes[0];
            }

            base.PostLoad();
        }
Example #11
0
        private void UpdateModel()
        {
            List <J3D> meshes = null;

            if (PlankType == PlankTypeEnum.Reinforced_Wood || Ropeless)
            {
                meshes = WResourceManager.LoadActorResource("Reinforced Bridge Plank");
            }
            else
            {
                meshes = WResourceManager.LoadActorResource("Plain Bridge Plank");
            }

            if (meshes != null && meshes.Count > 0)
            {
                m_plankMesh = meshes[0];
            }
        }
Example #12
0
        private void LoadRoomModels(string filePath)
        {
            // Search the bmd and bdl folders for valid model names. Then search for a matching brk and btk for those models.
            string[] modelNames  = new[] { "model", "model1", "model2", "model3" };
            string[] folderNames = new[] { "bmd", "bdl" };
            bool[]   validModels = new bool[modelNames.Length];

            foreach (var subFolder in folderNames)
            {
                string folderPath = Path.Combine(filePath, subFolder);
                foreach (var modelName in modelNames)
                {
                    J3D mesh = LoadModel(folderPath, modelName);
                    if (mesh != null)
                    {
                        m_roomModels.Add(mesh);
                    }
                }
            }
        }
        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);
        }
Example #14
0
        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);
        }
Example #15
0
        private void LoadStageModels(string filepath)
        {
            m_skybox = new WSkyboxNode(m_world);
            m_skybox.LoadSkyboxModelsFromFixedModelList(filepath);
            m_skybox.SetParent(this);

            CategoryDOMNode meshCategory = new CategoryDOMNode("Models", m_world);

            meshCategory.SetParent(this);

            string[] files = Directory.GetFiles(filepath, "*.bdl");

            foreach (string str in files)
            {
                J3D mesh = LoadModel(filepath, Path.GetFileNameWithoutExtension(str));
                if (mesh != null)
                {
                    J3DNode j3d_node = new J3DNode(mesh, m_world, str);
                    j3d_node.IsRendered = false;
                    j3d_node.SetParent(meshCategory);
                }
            }
        }
Example #16
0
        private void UpdateActorMeshFromNameProperty()
        {
            TStringPropertyValue stringProperty = m_namePropertyValueCache as TStringPropertyValue;

            if (stringProperty != null)
            {
                m_actorMesh = WResourceManager.LoadActorByName((string)stringProperty.GetValue());
                if (m_actorMesh != null)
                {
                    m_actorMesh.SetHardwareLight(0, new JStudio.OpenGL.GXLight(Vector4.Zero, Vector4.UnitX, new Vector4(1, 1, 1, 1), new Vector4(1.875f, 0, 0, 0), new Vector4(1.875f, 0, 0, 0)));
                    m_actorMesh.SetHardwareLight(1, new JStudio.OpenGL.GXLight(Vector4.Zero, Vector4.UnitX, new Vector4(1, 1, 1, 1), new Vector4(1.875f, 0, 0, 0), new Vector4(1.875f, 0, 0, 0)));
                    m_actorMesh.SetTextureOverride("ZBtoonEX", "resources/textures/ZBtoonEX.png");
                    m_actorMesh.SetTextureOverride("ZAtoon", "resources/textures/ZAtoon.png");

                    m_objRender = null;
                }
            }

            if (m_actorMesh == null)
            {
                m_objRender = WResourceManager.LoadObjResource("resources/editor/EditorCube.obj");
            }
        }
        public SceneGraphViewModel(J3D model, HierarchyNode parent, string nodeName)
        {
            Name     = nodeName;
            Node     = parent;
            Children = new ObservableCollection <SceneGraphViewModel>();

            foreach (var childNode in Node.Children)
            {
                string childNodeName = "";
                if (childNode.Type == HierarchyDataType.Joint)
                {
                    var jnt1 = model.JNT1Tag;
                    childNodeName = jnt1.BindJoints[jnt1.JointRemapTable[childNode.Value]].ToString();
                }
                if (childNode.Type == HierarchyDataType.Material)
                {
                    var mat3 = model.MAT3Tag;
                    childNodeName = mat3.MaterialList[mat3.MaterialRemapTable[childNode.Value]].Name;
                }

                SceneGraphViewModel child = new SceneGraphViewModel(model, childNode, childNodeName);
                Children.Add(child);
            }
        }
Example #18
0
        public override void SetTimeOfDay(float timeOfDay)
        {
            base.SetTimeOfDay(timeOfDay);

            List <J3DNode> m_roomModelNodes = GetChildrenOfType <J3DNode>();

            if (EnvironmentLighting != null)
            {
                var curLight = EnvironmentLighting.Lerp(EnvironmentLightingConditions.WeatherPreset.Default, true, timeOfDay);
                foreach (J3DNode node in m_roomModelNodes)
                {
                    J3D model = node.Model;
                    if (model.Name == "model")
                    {
                        model.SetTevColorOverride(0, curLight.RoomLightColor);
                        model.SetTevkColorOverride(0, curLight.RoomAmbientColor);
                    }
                    else if (model.Name == "model1")
                    {
                        model.SetTevColorOverride(0, curLight.WaveColor);
                        model.SetTevkColorOverride(0, curLight.OceanColor);
                    }
                    else if (model.Name == "model3")
                    {
                        model.SetTevColorOverride(0, curLight.DoorBackfill);
                    }
                }

                var childActors = GetChildrenOfType <VisibleDOMNode>();
                foreach (var child in childActors)
                {
                    child.ColorOverrides.SetTevColorOverride(0, curLight.ShadowColor);
                    child.ColorOverrides.SetTevkColorOverride(0, curLight.ActorAmbientColor);
                }
            }
        }
Example #19
0
        private static J3D LoadModelFromResource(WActorResource.ModelResource res, string archive)
        {
            J3D j3d = null;

            if (string.IsNullOrEmpty(res.Path) || string.IsNullOrEmpty(archive))
            {
                return(null);
            }

            string archivePath = Path.Combine(WSettingsManager.GetSettings().RootDirectoryPath, "files", "res/Object/", archive + ".arc");

            if (!File.Exists(archivePath))
            {
                return(null);
            }

            VirtualFilesystemDirectory model_arc   = ArchiveUtilities.LoadArchive(archivePath);
            VirtualFilesystemFile      archiveFile = model_arc.GetFileAtPath(res.Path);

            if (archiveFile == null)
            {
                Console.WriteLine("LoadActorByName failed because the specified path \"{0}\" does not exist in archive \"{1}\"!", res.Path, archive);
                return(null);
            }

            byte[] j3dData = archiveFile.Data;

            j3d = new J3D(archiveFile.Name);
            using (EndianBinaryReader reader = new EndianBinaryReader(j3dData, Endian.Big))
                j3d.LoadFromStream(reader, WSettingsManager.GetSettings().DumpTextures, WSettingsManager.GetSettings().DumpShaders);

            if (res.Position != null)
            {
                j3d.SetOffsetTranslation((Vector3)res.Position);
            }
            if (res.Rotation != null)
            {
                j3d.SetOffsetRotation((Vector3)res.Rotation);
            }
            if (res.Scale != null)
            {
                j3d.SetOffsetScale((Vector3)res.Scale);
            }

            j3d.SetHardwareLight(0, m_mainLight);
            j3d.SetHardwareLight(1, m_secondaryLight);
            j3d.SetTextureOverride("ZBtoonEX", "resources/textures/ZBtoonEX.png");
            j3d.SetTextureOverride("ZAtoon", "resources/textures/ZAtoon.png");

            if (res.Animations == null)
            {
                res.Animations = new WActorResource.AnimationResource[0];
            }

            foreach (var anim in res.Animations)
            {
                VirtualFilesystemDirectory anim_arc = model_arc;

                if (!string.IsNullOrEmpty(anim.ArchiveName))
                {
                    string anim_arc_path = Path.Combine(WSettingsManager.GetSettings().RootDirectoryPath, "files", "res/Object/", anim.ArchiveName + ".arc");

                    if (!File.Exists(anim_arc_path))
                    {
                        return(null);
                    }

                    anim_arc = ArchiveUtilities.LoadArchive(anim_arc_path);
                }

                VirtualFilesystemFile anim_file = anim_arc.GetFileAtPath(anim.Path);

                if (anim_file == null)
                {
                    continue;
                }

                byte[] anim_data = anim_file.Data;

                // Decompress the file if necessary
                if (anim_data[0] == 'Y')
                {
                    MemoryStream decompressed_data = null;

                    using (EndianBinaryReader decompressor = new EndianBinaryReader(anim_data, Endian.Big))
                    {
                        decompressed_data = Yaz0.Decode(decompressor);
                    }

                    anim_data = decompressed_data.ToArray();
                }

                switch (anim.Type)
                {
                case "bck":
                    BCK loaded_bck = new BCK(anim_file.Name);
                    using (EndianBinaryReader reader = new EndianBinaryReader(anim_data, Endian.Big))
                        loaded_bck.LoadFromStream(reader);

                    j3d.BoneAnimations.Add(loaded_bck);
                    j3d.SetBoneAnimation(anim_file.Name);

                    loaded_bck.Tick(anim.StartTime);

                    if (anim.PausedOnLoad)
                    {
                        loaded_bck.Pause();
                    }
                    break;

                case "btk":
                    BTK loaded_btk = new BTK(anim_file.Name);
                    using (EndianBinaryReader reader = new EndianBinaryReader(anim_data, Endian.Big))
                        loaded_btk.LoadFromStream(reader);

                    j3d.MaterialAnimations.Add(loaded_btk);
                    j3d.SetMaterialAnimation(anim_file.Name);

                    loaded_btk.Tick(anim.StartTime);

                    if (anim.PausedOnLoad)
                    {
                        loaded_btk.Pause();
                    }
                    break;

                case "brk":
                    BRK loaded_brk = new BRK(anim_file.Name);
                    using (EndianBinaryReader reader = new EndianBinaryReader(anim_data, Endian.Big))
                        loaded_brk.LoadFromStream(reader);

                    j3d.RegisterAnimations.Add(loaded_brk);
                    j3d.SetRegisterAnimation(anim_file.Name);

                    loaded_brk.Tick(anim.StartTime);

                    if (anim.PausedOnLoad)
                    {
                        loaded_brk.Pause();
                    }
                    break;

                case "bmt":
                    BMT loaded_bmt = new BMT(anim_file.Name);
                    using (EndianBinaryReader reader = new EndianBinaryReader(anim_data, Endian.Big))
                        loaded_bmt.LoadFromStream(reader);

                    j3d.ExternalMaterials.Add(loaded_bmt);
                    j3d.SetExternalMaterial(anim_file.Name);

                    if (loaded_bmt.MAT3 != null)
                    {
                        // a hack to get bmts working
                        Material dummyMat = null;
                        j3d.AssignVertexAttributesToMaterialsRecursive(j3d.INF1Tag.HierarchyRoot, ref dummyMat, loaded_bmt.MAT3);
                        j3d.GenerateShadersForMaterials(loaded_bmt.MAT3);
                    }

                    break;

                default:
                    break;
                }
            }

            j3d.Tick(1 / (float)60);

            if (res.ChildModels == null)
            {
                res.ChildModels = new WActorResource.ModelResource[0];
            }

            foreach (var childRes in res.ChildModels)
            {
                var childJ3d = LoadModelFromResource(childRes, archive);
                j3d.AddChildModel(childJ3d, childRes.ParentJointName);
            }

            return(j3d);
        }
        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"));
            }
        }
        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);
        }
Example #22
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);
        }
Example #23
0
        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);
        }
Example #24
0
 public J3DNode(J3D model, WWorld world) : base(world)
 {
     m_model = model;
 }
Example #25
0
 public J3DNode(J3D model, WWorld world) : base(world)
 {
     m_model    = model;
     Name       = model.Name;
     IsRendered = true;
 }