Selected scenario vehicle nodes display car model

This commit is contained in:
dexyfex 2017-10-02 01:06:12 +11:00
parent 81e24ef86f
commit eab1526df5
5 changed files with 74 additions and 27 deletions

View File

@ -4371,6 +4371,7 @@ namespace CodeWalker.GameFiles
{ {
[TC(typeof(EXP))] public MUnk_4023740759 Parent { get; set; } [TC(typeof(EXP))] public MUnk_4023740759 Parent { get; set; }
public MCScenarioPointRegion Region { get; set; } public MCScenarioPointRegion Region { get; set; }
public ScenarioNode ScenarioNode { get; set; }
public CScenarioChainingNode _Data; public CScenarioChainingNode _Data;
public CScenarioChainingNode Data { get { return _Data; } set { _Data = value; } } public CScenarioChainingNode Data { get { return _Data; } set { _Data = value; } }

View File

@ -4789,6 +4789,9 @@ namespace CodeWalker
n1.ChainingNode.NotLast = true; n1.ChainingNode.NotLast = true;
n2.ChainingNode.NotFirst = true; n2.ChainingNode.NotFirst = true;
n1.ChainingNode.ScenarioNode = n1;
n2.ChainingNode.ScenarioNode = n2;
paths.AddNode(n1.ChainingNode); paths.AddNode(n1.ChainingNode);
paths.AddNode(n2.ChainingNode); paths.AddNode(n2.ChainingNode);
@ -5621,6 +5624,7 @@ namespace CodeWalker
thisnode.MyPoint.Type = stype; thisnode.MyPoint.Type = stype;
thisnode.ChainingNode = new MCScenarioChainingNode(); thisnode.ChainingNode = new MCScenarioChainingNode();
thisnode.ChainingNode.ScenarioNode = thisnode;
thisnode.ChainingNode.Chain = chain; thisnode.ChainingNode.Chain = chain;
thisnode.ChainingNode.Type = stype; thisnode.ChainingNode.Type = stype;
thisnode.ChainingNode.TypeHash = stype?.NameHash ?? 0; thisnode.ChainingNode.TypeHash = stype?.NameHash ?? 0;

View File

@ -576,6 +576,7 @@ namespace CodeWalker.World
NodeDict[cnode.Position] = exnode; NodeDict[cnode.Position] = exnode;
Nodes.Add(exnode); Nodes.Add(exnode);
} }
cnode.ScenarioNode = exnode;
return exnode; return exnode;
} }
private ScenarioNode EnsureNode(MCScenarioPoint point) private ScenarioNode EnsureNode(MCScenarioPoint point)
@ -745,6 +746,7 @@ namespace CodeWalker.World
if (copy.ChainingNode != null) if (copy.ChainingNode != null)
{ {
n.ChainingNode = new MCScenarioChainingNode(rgn, copy.ChainingNode); n.ChainingNode = new MCScenarioChainingNode(rgn, copy.ChainingNode);
n.ChainingNode.ScenarioNode = n;
} }
} }
else else
@ -1755,6 +1757,9 @@ namespace CodeWalker.World
public string NameLower { get; set; } public string NameLower { get; set; }
public MetaHash NameHash { get; set; } public MetaHash NameHash { get; set; }
public bool IsVehicle { get; set; } public bool IsVehicle { get; set; }
public string VehicleModelSet { get; set; }
public MetaHash VehicleModelSetHash { get; set; }
public virtual void Load(XmlNode node) public virtual void Load(XmlNode node)
{ {
@ -1762,6 +1767,16 @@ namespace CodeWalker.World
Name = Xml.GetChildInnerText(node, "Name"); Name = Xml.GetChildInnerText(node, "Name");
NameLower = Name.ToLowerInvariant(); NameLower = Name.ToLowerInvariant();
NameHash = JenkHash.GenHash(NameLower); 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() public override string ToString()

View File

@ -263,7 +263,7 @@ namespace CodeWalker.World
MapDataStoreNode dsn = new MapDataStoreNode(ymap); MapDataStoreNode dsn = new MapDataStoreNode(ymap);
if (dsn.Name != 0) if (dsn.Name != 0)
{ {
nodedict[dsn.Name] = dsn; nodedict[dsn.Name] = dsn;//perhaps should add as entry.ShortNameHash?
} }
else else
{ } { }

View File

@ -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() private void RenderWorldCollisionMeshes()
{ {
//enqueue collision meshes for rendering - from the world grid //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); 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 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); RenderCar(cg.Position, cgori, cg._CCarGen.carModel, cg._CCarGen.popGroup);
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);
}
} }
if (selectionItem.PathNode != null) if (selectionItem.PathNode != null)
{ {
@ -3202,6 +3211,24 @@ namespace CodeWalker
float arrowrad = 0.25f; float arrowrad = 0.25f;
RenderSelectionArrowOutline(sn.Position, Vector3.UnitY, Vector3.UnitZ, ori, arrowlen, arrowrad, cgrn); 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) if (selectionItem.ScenarioEdge != null)
{ {
@ -4230,7 +4257,7 @@ namespace CodeWalker
{ {
bool nearer = (hitdist < CurMouseHit.HitDist); //closer than the last.. bool nearer = (hitdist < CurMouseHit.HitDist); //closer than the last..
bool radsm = true; 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 b1 = (arche.BBMax - arche.BBMin) * scale;
//var b2 = (mousehit.Archetype.BBMax - mousehit.Archetype.BBMin) * scale; //var b2 = (mousehit.Archetype.BBMax - mousehit.Archetype.BBMin) * scale;