From 2f12402a03fd88756a4fbb8aafa2322fafaae0df Mon Sep 17 00:00:00 2001 From: dexy Date: Wed, 27 Nov 2019 20:24:02 +1100 Subject: [PATCH] Cutscene viewer hide models partially working --- .../GameFiles/FileTypes/YmapFile.cs | 28 +++++++ .../GameFiles/MetaTypes/Archetype.cs | 2 +- Rendering/Renderer.cs | 13 +++ World/CutsceneForm.cs | 82 ++++++++++--------- 4 files changed, 84 insertions(+), 41 deletions(-) diff --git a/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs b/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs index 3ff74d0..1f72332 100644 --- a/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs +++ b/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs @@ -1312,6 +1312,8 @@ namespace CodeWalker.GameFiles public Vector3 WidgetPosition = Vector3.Zero; public Quaternion WidgetOrientation = Quaternion.Identity; + public uint EntityHash { get; set; } = 0; //used by CW as a unique position+name identifier + public string Name { @@ -1344,6 +1346,7 @@ namespace CodeWalker.GameFiles UpdateWidgetPosition(); UpdateWidgetOrientation(); + UpdateEntityHash(); } public YmapEntityDef(YmapFile ymap, int index, ref CMloInstanceDef mlo) @@ -1456,6 +1459,7 @@ namespace CodeWalker.GameFiles MloInstance.UpdateEntities(); } + UpdateEntityHash(); UpdateWidgetPosition(); } @@ -1478,6 +1482,30 @@ namespace CodeWalker.GameFiles } } + public void UpdateEntityHash() + { + unchecked + { + var ints = new int[4]; + var pv = Position; + ints[0] = (int)pv.X; + ints[1] = (int)pv.Y; + ints[2] = (int)pv.Z; + ints[3] = (int)_CEntityDef.archetypeName.Hash; + var bytes = new byte[16]; + for (int i = 0; i < 4; i++) + { + var ib = i * 4; + var b = BitConverter.GetBytes(ints[i]); + bytes[ib + 0] = b[0]; + bytes[ib + 1] = b[1]; + bytes[ib + 2] = b[2]; + bytes[ib + 3] = b[3]; + } + EntityHash = JenkHash.GenHash(bytes); + } + } + public void SetOrientation(Quaternion ori, bool inverse = false) { if (MloParent != null) diff --git a/CodeWalker.Core/GameFiles/MetaTypes/Archetype.cs b/CodeWalker.Core/GameFiles/MetaTypes/Archetype.cs index e969b9a..470b81d 100644 --- a/CodeWalker.Core/GameFiles/MetaTypes/Archetype.cs +++ b/CodeWalker.Core/GameFiles/MetaTypes/Archetype.cs @@ -603,7 +603,7 @@ namespace CodeWalker.GameFiles e.Orientation = Quaternion.Multiply(owner.Orientation, e.MloRefOrientation); e.UpdateWidgetPosition(); e.UpdateWidgetOrientation(); - + e.UpdateEntityHash(); return e; } diff --git a/Rendering/Renderer.cs b/Rendering/Renderer.cs index 6ebe23b..4a93ac4 100644 --- a/Rendering/Renderer.cs +++ b/Rendering/Renderer.cs @@ -86,6 +86,7 @@ namespace CodeWalker.Rendering private List renderworldentities = new List(); //used when rendering world view. private List renderworldrenderables = new List(); + public Dictionary HideEntities = new Dictionary();//dictionary of entities to hide, for cutscenes to use public bool ShowScriptedYmaps = true; public List VisibleYmaps = new List(); @@ -294,6 +295,8 @@ namespace CodeWalker.Rendering RenderedBoundComps.Clear(); renderskeletonlist.Clear(); + + HideEntities.Clear(); } public void RenderSkyAndClouds() @@ -1641,6 +1644,8 @@ namespace CodeWalker.Rendering var ent = rent.Entity; var arch = ent.Archetype; + if (HideEntities.ContainsKey(ent.EntityHash)) continue; //don't render hidden entities! + RenderArchetype(arch, ent, rent.Renderable, false); } } @@ -2839,6 +2844,14 @@ namespace CodeWalker.Rendering } + public void RenderHideEntity(YmapEntityDef ent) + { + var hash = ent?.EntityHash ?? 0; + if (hash == 0) return; + + HideEntities[hash] = ent; + } + diff --git a/World/CutsceneForm.cs b/World/CutsceneForm.cs index 05d22b4..c0b0d7d 100644 --- a/World/CutsceneForm.cs +++ b/World/CutsceneForm.cs @@ -547,6 +547,15 @@ namespace CodeWalker.World renderer.RenderWeapon(obj.Weapon, obj.AnimClip); } } + foreach (var obj in SceneObjects.Values) + { + if (obj.Enabled == false) continue; + + if (obj.HideEntity != null) + { + renderer.RenderHideEntity(obj.HideEntity); + } + } } } @@ -774,23 +783,23 @@ namespace CodeWalker.World } private void EnableHideObject(CutEvent e) { - var args = e.EventArgs as CutObjectIdEventArgs; - if (args == null) - { return; } - - var obj = args.Object; + var oe = e as CutObjectIdEvent; + if (oe == null) return; + CutsceneObject cso = null; + SceneObjects.TryGetValue(oe.iObjectId, out cso); + if (cso != null) + { + cso.Enabled = true; + } } private void EnableFixupModel(CutEvent e) { } private void EnableBlockBounds(CutEvent e) { - var args = e.EventArgs as CutObjectIdEventArgs; - if (args == null) - { return; } - - var obj = args.Object; + var oe = e as CutObjectIdEvent; + if (oe == null) return; } private void EnableScreenFade(CutEvent e) @@ -798,11 +807,8 @@ namespace CodeWalker.World } private void EnableAnimation(CutEvent e) { - var args = e.EventArgs as CutObjectIdEventArgs; - if (args == null) - { return; } - - var obj = args.Object; + var oe = e as CutObjectIdEvent; + if (oe == null) return; } private void EnableParticleEffect(CutEvent e) @@ -820,11 +826,8 @@ namespace CodeWalker.World } private void EnableCamera(CutEvent e) { - var args = e.EventArgs as CutObjectIdEventArgs; - if (args == null) - { return; } - - var obj = args.Object; + var oe = e as CutObjectIdEvent; + if (oe == null) return; } private void EnableLight(CutEvent e) @@ -832,20 +835,20 @@ namespace CodeWalker.World } private void DisableHideObject(CutEvent e) { - var args = e.EventArgs as CutObjectIdEventArgs; - if (args == null) - { return; } - - var obj = args.Object; + var oe = e as CutObjectIdEvent; + if (oe == null) return; + CutsceneObject cso = null; + SceneObjects.TryGetValue(oe.iObjectId, out cso); + if (cso != null) + { + cso.Enabled = false; + } } private void DisableBlockBounds(CutEvent e) { - var args = e.EventArgs as CutObjectIdEventArgs; - if (args == null) - { return; } - - var obj = args.Object; + var oe = e as CutObjectIdEvent; + if (oe == null) return; } private void DisableScreenFade(CutEvent e) @@ -853,11 +856,8 @@ namespace CodeWalker.World } private void DisableAnimation(CutEvent e) { - var args = e.EventArgs as CutObjectIdEventArgs; - if (args == null) - { return; } - - var obj = args.Object; + var oe = e as CutObjectIdEvent; + if (oe == null) return; } private void DisableParticleEffect(CutEvent e) @@ -875,11 +875,8 @@ namespace CodeWalker.World } private void DisableCamera(CutEvent e) { - var args = e.EventArgs as CutObjectIdEventArgs; - if (args == null) - { return; } - - var obj = args.Object; + var oe = e as CutObjectIdEvent; + if (oe == null) return; } private void DisableLight(CutEvent e) @@ -1064,6 +1061,7 @@ namespace CodeWalker.World public YmapEntityDef Prop { get; set; } public Vehicle Vehicle { get; set; } public Weapon Weapon { get; set; } + public YmapEntityDef HideEntity { get; set; } public MetaHash AnimHash { get; set; } public ClipMapEntry AnimClip { get; set; } @@ -1200,6 +1198,10 @@ namespace CodeWalker.World private void InitHiddenModel(CutHiddenModelObject hid, GameFileCache gfc) { + HideEntity = new YmapEntityDef(); + HideEntity._CEntityDef.archetypeName = hid.cName; + HideEntity.SetPosition(hid.vPosition); + }