Skip to content
Open

Lua #301

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Game.Client/C_BaseAnimating.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,24 @@ public void Dispose() {
public TimeUnit_t GetPlaybackRate() => PlaybackRate;
public void SetPlaybackRate(TimeUnit_t rate) => PlaybackRate = (float)rate; // todo: double?
public ref readonly Matrix3x4 GetBone(int bone) => ref BoneAccessor.GetBone(bone);

public void GetBonePosition(int bone, out Vector3 origin, out QAngle angles) {
GetBoneTransform(bone, out Matrix3x4 boneToWorld);
MathLib.MatrixAngles(boneToWorld, out angles, out origin);
}

public void GetBoneTransform(int bone, out Matrix3x4 boneToWorld) {
Assert(GetModelPtr() != null && bone >= 0 && bone < GetModelPtr()!.NumBones());
BoneCache cache = GetBoneCache(null);

ref Matrix3x4 matrix = ref cache.GetCachedBone(bone);
if (Unsafe.IsNullRef(ref matrix)) {
boneToWorld = EntityToWorldTransform();
return;
}

boneToWorld = matrix;
}
public ref Matrix3x4 GetBoneForWrite(int bone) => ref BoneAccessor.GetBoneForWrite(bone);

BoneMergeCache? BoneMergeCache;
Expand Down
4 changes: 2 additions & 2 deletions Game.Client/C_BaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public override int DrawModel(StudioFlags flags) {
drawnFlags = flags | StudioFlags.Transparency;
if ((flags & (StudioFlags.ShadowDepthTexture | StudioFlags.SSAODepthTexture)) != 0)
drawnFlags = flags & ~StudioFlags.Transparency;
weapon.ViewModelDrawn(this);
weapon.ViewModelDrawn(this, drawnFlags);
}

if ((drawnFlags & StudioFlags.Render) != 0 && weapon != null && player != null && gGM != null && gGM.CallWithArgs((int)LUA_POOLEDSTRING.PostDrawViewModel)) {
Expand Down Expand Up @@ -133,7 +133,7 @@ public override int DrawModel(StudioFlags flags) {

// Tell the weapon itself that we've rendered, in case it wants to do something
if (weapon != null)
weapon.ViewModelDrawn(this);
weapon.ViewModelDrawn(this, flags);
}

return ret;
Expand Down
2 changes: 1 addition & 1 deletion Game.Client/C_Sun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ public partial class C_Sun : C_BaseEntity
public int OverlayMaterial;
// todo: RecvProxy_HDRColorScale
[NetworkVar("HDRColorScale")]
public int HDRColorScale;
public float HDRColorScale;
}
17 changes: 12 additions & 5 deletions Game.Client/GarrysMod/LuaMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,20 @@ static int IMesh__DrawSkinned(ILuaInterface lua) {
Matrix4x4 model = Matrix4x4.Identity;
renderContext.GetMatrix(MaterialMatrixMode.Model, out model);

int bone = 1;
while (IsMatrixMember(table, bone)) {
Matrix4x4 bind = table.GetMemberMatrix(bone, default);
int bone = 0;
while (true) {
if (!IsMatrixMember(table, bone)) {
if (bone != 0)
break;
bone = 1;
if (!IsMatrixMember(table, bone))
break;
}
if (bone > 52) {
lua.ErrorNoHalt($"Too many model transform matrices! ({53} max)\n");
break;
}
Matrix4x4 bind = table.GetMemberMatrix(bone, default);
if (transform)
MathLib.MatrixMultiply(model, bind, out bind);
renderContext.LoadBoneMatrix(bone, new ReadOnlySpan<Matrix4x4>(in bind).Cast<Matrix4x4, Matrix3x4>()[0]);
Expand Down Expand Up @@ -456,11 +463,11 @@ static int BoneData(ILuaInterface lua) {
uint index = (uint)lua.CheckNumber(1);
uint bone = (uint)lua.CheckNumber(2);
if (index >= 3) {
lua.Error($"Invalid bone matrix index. Must be integer [0,{index - 1}]\n");
lua.Error($"Invalid bone matrix index. Must be integer [0,{2}]\n");
return 0;
}
if (bone >= 53) {
lua.Error($"Invalid bone matrix bone. Must be integer [1,{52}]\n");
lua.Error($"Invalid bone matrix bone. Must be integer [0,{52}]\n");
return 0;
}

Expand Down
Loading
Loading