From eab1526df51f2b6264f797d5966272c48a501049 Mon Sep 17 00:00:00 2001 From: dexyfex Date: Mon, 2 Oct 2017 01:06:12 +1100 Subject: [PATCH] Selected scenario vehicle nodes display car model --- GameFiles/MetaTypes/MetaTypes.cs | 1 + ProjectForm.cs | 4 ++ World/Scenarios.cs | 15 ++++++ World/Space.cs | 2 +- WorldForm.cs | 79 +++++++++++++++++++++----------- 5 files changed, 74 insertions(+), 27 deletions(-) diff --git a/GameFiles/MetaTypes/MetaTypes.cs b/GameFiles/MetaTypes/MetaTypes.cs index d07e6f8..6895f01 100644 --- a/GameFiles/MetaTypes/MetaTypes.cs +++ b/GameFiles/MetaTypes/MetaTypes.cs @@ -4371,6 +4371,7 @@ namespace CodeWalker.GameFiles { [TC(typeof(EXP))] public MUnk_4023740759 Parent { get; set; } public MCScenarioPointRegion Region { get; set; } + public ScenarioNode ScenarioNode { get; set; } public CScenarioChainingNode _Data; public CScenarioChainingNode Data { get { return _Data; } set { _Data = value; } } diff --git a/ProjectForm.cs b/ProjectForm.cs index 8ce9320..10dbeb7 100644 --- a/ProjectForm.cs +++ b/ProjectForm.cs @@ -4789,6 +4789,9 @@ namespace CodeWalker n1.ChainingNode.NotLast = true; n2.ChainingNode.NotFirst = true; + n1.ChainingNode.ScenarioNode = n1; + n2.ChainingNode.ScenarioNode = n2; + paths.AddNode(n1.ChainingNode); paths.AddNode(n2.ChainingNode); @@ -5621,6 +5624,7 @@ namespace CodeWalker thisnode.MyPoint.Type = stype; thisnode.ChainingNode = new MCScenarioChainingNode(); + thisnode.ChainingNode.ScenarioNode = thisnode; thisnode.ChainingNode.Chain = chain; thisnode.ChainingNode.Type = stype; thisnode.ChainingNode.TypeHash = stype?.NameHash ?? 0; diff --git a/World/Scenarios.cs b/World/Scenarios.cs index 9e7bf71..d8018df 100644 --- a/World/Scenarios.cs +++ b/World/Scenarios.cs @@ -576,6 +576,7 @@ namespace CodeWalker.World NodeDict[cnode.Position] = exnode; Nodes.Add(exnode); } + cnode.ScenarioNode = exnode; return exnode; } private ScenarioNode EnsureNode(MCScenarioPoint point) @@ -745,6 +746,7 @@ namespace CodeWalker.World if (copy.ChainingNode != null) { n.ChainingNode = new MCScenarioChainingNode(rgn, copy.ChainingNode); + n.ChainingNode.ScenarioNode = n; } } else @@ -1755,6 +1757,9 @@ namespace CodeWalker.World public string NameLower { get; set; } public MetaHash NameHash { get; set; } public bool IsVehicle { get; set; } + public string VehicleModelSet { get; set; } + public MetaHash VehicleModelSetHash { get; set; } + public virtual void Load(XmlNode node) { @@ -1762,6 +1767,16 @@ namespace CodeWalker.World Name = Xml.GetChildInnerText(node, "Name"); NameLower = Name.ToLowerInvariant(); NameHash = JenkHash.GenHash(NameLower); + + + if (IsVehicle) + { + VehicleModelSet = Xml.GetChildStringAttribute(node, "VehicleModelSet", "ref"); + if (!string.IsNullOrEmpty(VehicleModelSet) && (VehicleModelSet != "NULL")) + { + VehicleModelSetHash = JenkHash.GenHash(VehicleModelSet.ToLowerInvariant()); + } + } } public override string ToString() diff --git a/World/Space.cs b/World/Space.cs index ce7f0a9..0ebe523 100644 --- a/World/Space.cs +++ b/World/Space.cs @@ -263,7 +263,7 @@ namespace CodeWalker.World MapDataStoreNode dsn = new MapDataStoreNode(ymap); if (dsn.Name != 0) { - nodedict[dsn.Name] = dsn; + nodedict[dsn.Name] = dsn;//perhaps should add as entry.ShortNameHash? } else { } diff --git a/WorldForm.cs b/WorldForm.cs index 5f47b44..46355da 100644 --- a/WorldForm.cs +++ b/WorldForm.cs @@ -2734,6 +2734,38 @@ namespace CodeWalker + private void RenderCar(Vector3 pos, Quaternion ori, MetaHash modelHash, MetaHash modelSetHash) + { + SelectedCarGenEntity.SetPosition(pos); + SelectedCarGenEntity.SetOrientation(ori); + + uint carhash = modelHash; + if ((carhash == 0) && (modelSetHash != 0)) + { + //find the pop group... and choose a vehicle.. + var stypes = Scenarios.ScenarioTypes; + if (stypes != null) + { + var modelset = stypes.GetVehicleModelSet(modelSetHash); + if ((modelset != null) && (modelset.Models != null) && (modelset.Models.Length > 0)) + { + carhash = JenkHash.GenHash(modelset.Models[0].NameLower); + } + } + } + if (carhash == 0) carhash = 418536135; //"infernus" + + YftFile caryft = gameFileCache.GetYft(carhash); + if ((caryft != null) && (caryft.Loaded) && (caryft.Fragment != null)) + { + RenderFragment(null, SelectedCarGenEntity, caryft.Fragment, carhash); + } + } + + + + + private void RenderWorldCollisionMeshes() { //enqueue collision meshes for rendering - from the world grid @@ -3155,32 +3187,9 @@ namespace CodeWalker RenderSelectionArrowOutline(cg.Position, Vector3.UnitX, Vector3.UnitY, ori, arrowlen, arrowrad, cgrn); Quaternion cgtrn = Quaternion.RotationAxis(Vector3.UnitZ, (float)Math.PI * -0.5f); //car fragments currently need to be rotated 90 deg right... - Quaternion cgori = Quaternion.Multiply(cg.Orientation, cgtrn); + Quaternion cgori = Quaternion.Multiply(ori, cgtrn); - SelectedCarGenEntity.SetPosition(cg.Position); - SelectedCarGenEntity.SetOrientation(cgori); - - uint carhash = cg._CCarGen.carModel; - if ((carhash == 0) && (cg._CCarGen.popGroup != 0)) - { - //find the pop group... and choose a vehicle.. - var stypes = Scenarios.ScenarioTypes; - if (stypes != null) - { - var modelset = stypes.GetVehicleModelSet(cg._CCarGen.popGroup); - if ((modelset != null) && (modelset.Models != null) && (modelset.Models.Length > 0)) - { - carhash = JenkHash.GenHash(modelset.Models[0].NameLower); - } - } - } - if (carhash == 0) carhash = 418536135; //"infernus" - - YftFile caryft = gameFileCache.GetYft(carhash); - if ((caryft != null) && (caryft.Loaded) && (caryft.Fragment != null)) - { - RenderFragment(null, SelectedCarGenEntity, caryft.Fragment, carhash); - } + RenderCar(cg.Position, cgori, cg._CCarGen.carModel, cg._CCarGen.popGroup); } if (selectionItem.PathNode != null) { @@ -3202,6 +3211,24 @@ namespace CodeWalker float arrowrad = 0.25f; RenderSelectionArrowOutline(sn.Position, Vector3.UnitY, Vector3.UnitZ, ori, arrowlen, arrowrad, cgrn); + MCScenarioPoint vpoint = sn.MyPoint ?? sn.ClusterMyPoint; + if ((vpoint != null) && (vpoint?.Type?.IsVehicle ?? false)) + { + var vhash = vpoint.ModelSet?.NameHash ?? vpoint.Type?.VehicleModelSetHash ?? 0; + if ((vhash == 0) && (sn.ChainingNode?.Chain?.Edges != null) && (sn.ChainingNode.Chain.Edges.Length > 0)) + { + var fedge = sn.ChainingNode.Chain.Edges[0]; //for chain nodes, show the first node's model... + var fnode = fedge?.NodeFrom?.ScenarioNode; + if (fnode != null) + { + vpoint = fnode.MyPoint ?? fnode.ClusterMyPoint; + vhash = vpoint.ModelSet?.NameHash ?? vpoint.Type?.VehicleModelSetHash ?? 0; + } + } + + RenderCar(sn.Position, sn.Orientation, 0, vhash); + } + } if (selectionItem.ScenarioEdge != null) { @@ -4230,7 +4257,7 @@ namespace CodeWalker { bool nearer = (hitdist < CurMouseHit.HitDist); //closer than the last.. bool radsm = true; - if ((CurMouseHit.Archetype != null)) //compare hit archetype sizes... + if ((CurMouseHit.Archetype != null) && (arche != null)) //compare hit archetype sizes... { //var b1 = (arche.BBMax - arche.BBMin) * scale; //var b2 = (mousehit.Archetype.BBMax - mousehit.Archetype.BBMin) * scale;