Cutscene viewer displaying weapons

This commit is contained in:
dexy 2019-11-27 13:32:07 +11:00
parent dead879d99
commit 0823702527
4 changed files with 84 additions and 4 deletions

View File

@ -152,6 +152,7 @@
<Compile Include="World\Trains.cs" />
<Compile Include="World\Vehicle.cs" />
<Compile Include="World\Water.cs" />
<Compile Include="World\Weapon.cs" />
<Compile Include="World\Weather.cs" />
</ItemGroup>
<ItemGroup>

View File

@ -0,0 +1,48 @@
using CodeWalker.GameFiles;
using SharpDX;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace CodeWalker.World
{
[TypeConverter(typeof(ExpandableObjectConverter))] public class Weapon
{
public string Name { get; set; } = string.Empty;
public MetaHash NameHash { get; set; } = 0;//base weapon name hash
public MetaHash ModelHash { get; set; } = 0;//weapon model name hash, can be _hi
public YmapEntityDef RenderEntity = new YmapEntityDef(); //placeholder entity object for rendering
public Vector3 Position { get; set; } = Vector3.Zero;
public Quaternion Rotation { get; set; } = Quaternion.Identity;
public void Init(string name, GameFileCache gfc, bool hidef = true)
{
Name = name;
var modelnamel = name.ToLowerInvariant();
MetaHash modelhash = JenkHash.GenHash(modelnamel);
MetaHash modelhashhi = JenkHash.GenHash(modelnamel + "_hi");
var ydrhash = hidef ? modelhashhi : modelhash;
NameHash = modelhash;
ModelHash = ydrhash;
UpdateEntity();
}
public void UpdateEntity()
{
RenderEntity.SetPosition(Position);
RenderEntity.SetOrientation(Rotation);
}
}
}

View File

@ -2749,6 +2749,23 @@ namespace CodeWalker.Rendering
}
public void RenderWeapon(Weapon weapon, ClipMapEntry animClip = null)
{
YdrFile ydr = gameFileCache.GetYdr(weapon.ModelHash);
if (ydr == null)
{
ydr = gameFileCache.GetYdr(weapon.NameHash);//fallback to low def version?
}
if ((ydr != null) && (ydr.Loaded) && (ydr.Drawable != null))
{
var d = ydr.Drawable;
var txdhash = weapon.NameHash;
RenderDrawable(d, null, weapon.RenderEntity, txdhash, null, null, animClip);
}
}

View File

@ -471,7 +471,7 @@ namespace CodeWalker.World
var pos = Position;
var rot = Rotation;
var animate = (obj.Ped != null) || (obj.Prop != null) || (obj.Vehicle != null);
var animate = (obj.Ped != null) || (obj.Prop != null) || (obj.Vehicle != null) || (obj.Weapon != null);
if (animate)
{
ycd.CutsceneMap.TryGetValue(obj.AnimHash, out cme);
@ -483,6 +483,7 @@ namespace CodeWalker.World
pos = pos + rot.Multiply(obj.Position);
rot = rot * obj.Rotation;
}
obj.AnimClip = cme;
}
if (obj.Ped != null)
{
@ -494,16 +495,19 @@ namespace CodeWalker.World
{
obj.Prop.Position = pos;
obj.Prop.Orientation = rot;
obj.AnimClip = cme;
}
if (obj.Vehicle != null)
{
obj.Vehicle.Position = pos;
obj.Vehicle.Rotation = rot;
obj.Vehicle.UpdateEntity();
obj.AnimClip = cme;
}
if (obj.Weapon != null)
{
obj.Weapon.Position = pos;
obj.Weapon.Rotation = rot;
obj.Weapon.UpdateEntity();
}
}
}
@ -537,6 +541,10 @@ namespace CodeWalker.World
{
renderer.RenderVehicle(obj.Vehicle, obj.AnimClip);
}
if (obj.Weapon != null)
{
renderer.RenderWeapon(obj.Weapon, obj.AnimClip);
}
}
}
@ -1054,6 +1062,7 @@ namespace CodeWalker.World
public Ped Ped { get; set; }
public YmapEntityDef Prop { get; set; }
public Vehicle Vehicle { get; set; }
public Weapon Weapon { get; set; }
public MetaHash AnimHash { get; set; }
public ClipMapEntry AnimClip { get; set; }
@ -1179,7 +1188,12 @@ namespace CodeWalker.World
private void InitWeapon(CutWeaponModelObject weap, GameFileCache gfc)
{
var name = weap.StreamingName.ToString();
Weapon = new Weapon();
Weapon.Init(name, gfc);
AnimHash = weap.StreamingName;
}
private void InitHiddenModel(CutHiddenModelObject hid, GameFileCache gfc)