mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2024-11-25 16:32:55 +08:00
Cutscene viewer displaying weapons
This commit is contained in:
parent
dead879d99
commit
0823702527
@ -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>
|
||||
|
48
CodeWalker.Core/World/Weapon.cs
Normal file
48
CodeWalker.Core/World/Weapon.cs
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user