Example #1
0
        virtual public void Draw(WSceneView view)
        {
            var bbox = GetBoundingBox();

            m_world.DebugDrawBox(bbox.Center, (bbox.Max - bbox.Min) / 2, Transform.Rotation, (Flags & NodeFlags.Selected) == NodeFlags.Selected ? WLinearColor.White : WLinearColor.Black, 0, 0);

            Matrix4 trs = Matrix4.CreateScale(Transform.LocalScale) * Matrix4.CreateFromQuaternion(Transform.Rotation) * Matrix4.CreateTranslation(Transform.Position);

            if (m_actorMesh != null)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (ColorOverrides.ColorsEnabled[i])
                    {
                        m_actorMesh.SetTevColorOverride(i, ColorOverrides.Colors[i]);
                    }

                    if (ColorOverrides.ConstColorsEnabled[i])
                    {
                        m_actorMesh.SetTevkColorOverride(i, ColorOverrides.ConstColors[i]);
                    }
                }

                m_actorMesh.Tick(1 / 60);
                m_actorMesh.Render(view.ViewMatrix, view.ProjMatrix, trs);
            }
            else
            {
                m_objRender.Render(view.ViewMatrix, view.ProjMatrix, trs);
            }
        }
Example #2
0
        public override void Draw(WSceneView view)
        {
            if (HasBrazier() && m_brazierModel != null)
            {
                // Draw the brazier.
                Matrix4 trs = Matrix4.CreateFromQuaternion(Transform.Rotation) * Matrix4.CreateTranslation(Transform.Position);

                for (int i = 0; i < 4; i++)
                {
                    if (ColorOverrides.ColorsEnabled[i])
                    {
                        m_brazierModel.SetTevColorOverride(i, ColorOverrides.Colors[i]);
                    }

                    if (ColorOverrides.ConstColorsEnabled[i])
                    {
                        m_brazierModel.SetTevkColorOverride(i, ColorOverrides.ConstColors[i]);
                    }
                }

                if (IsSelected)
                {
                    m_brazierModel.Tick(1 / (float)60);
                }

                m_brazierModel.Render(view.ViewMatrix, view.ProjMatrix, trs);
            }

            // Draw the region that is lit up.
            base.Draw(view);
        }
Example #3
0
        public void Update(float delta_time)
        {
            m_Model.Tick(delta_time);

            foreach (var j in Children)
            {
                j.Update(delta_time);
            }
        }
Example #4
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 #5
0
        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);

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

            return(model);
        }
Example #6
0
        public override void Tick(float deltaTime)
        {
            base.Tick(deltaTime);

            m_model.Tick(deltaTime);
        }
Example #7
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);
        }
Example #8
0
        public override void Draw(WSceneView view)
        {
            base.Draw(view); // Draw the default editor cube to represent the bridge entity itself so that can still be clicked.

            if (m_plankMesh == null || Path == null)
            {
                return;
            }
            var points = Path.GetPoints();

            if (points.Count < 2)
            {
                return;
            }

            for (int i = 0; i < 4; i++)
            {
                if (ColorOverrides.ColorsEnabled[i])
                {
                    m_plankMesh.SetTevColorOverride(i, ColorOverrides.Colors[i]);
                }

                if (ColorOverrides.ConstColorsEnabled[i])
                {
                    m_plankMesh.SetTevkColorOverride(i, ColorOverrides.ConstColors[i]);
                }
            }

            if (IsSelected)
            {
                m_plankMesh.Tick(1 / (float)60);
            }

            Vector3 p1           = points[0].Transform.Position;
            Vector3 p2           = points[1].Transform.Position;
            Vector3 bridge_delta = p2 - p1;

            float spacing_multiplier = 47f;

            if (bridge_delta.Length > 1300.0)
            {
                spacing_multiplier += 3f;
            }
            int     num_planks  = (int)(bridge_delta.Length / (1.5 * spacing_multiplier));
            Vector3 plank_delta = bridge_delta / (num_planks - 1);

            float      y_rot          = (float)Math.Atan2(bridge_delta.X, bridge_delta.Z);
            Quaternion yRot           = Quaternion.FromAxisAngle(Vector3.UnitY, y_rot);
            Vector3    plank_delta_xz = Vector3.Transform(plank_delta, yRot.Inverted());
            float      x_rot          = (float)-Math.Atan2(plank_delta_xz.Y, plank_delta_xz.Z);
            Quaternion xRot           = Quaternion.FromAxisAngle(Vector3.UnitX, x_rot);
            Quaternion plankRotation  = yRot * xRot;

            Vector3 plankScale = new Vector3(1.0f, 1.0f, 1.5f);

            for (int plank_i = 0; plank_i < num_planks; plank_i++)
            {
                Vector3 plankPosition = p1 + (plank_delta * plank_i);

                Matrix4 trs = Matrix4.CreateScale(plankScale) * Matrix4.CreateFromQuaternion(plankRotation) * Matrix4.CreateTranslation(plankPosition);

                m_plankMesh.Render(view.ViewMatrix, view.ProjMatrix, trs);
            }
        }
        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);
        }