mirror of
https://github.com/4sval/FModel.git
synced 2026-08-06 03:03:04 -05:00
fix picking texture + static meshes
This commit is contained in:
parent
a636c1ff84
commit
f288791b71
|
|
@ -1 +1 @@
|
|||
Subproject commit 3a7ddc13bb370e5988bc122a7cf67ad8036ccaf1
|
||||
Subproject commit c6fcae365d91d7d9501e2be79e78dfba136b4670
|
||||
|
|
@ -33,17 +33,26 @@ void main()
|
|||
vec4 finalPos = vec4(0.0);
|
||||
vec4 finalNormal = vec4(0.0);
|
||||
vec4 finalTangent = vec4(0.0);
|
||||
for(int i = 0 ; i < 4; i++)
|
||||
if (vBoneIds != vBoneWeights)
|
||||
{
|
||||
int boneIndex = int(vBoneIds[i]);
|
||||
if(boneIndex < 0) break;
|
||||
for(int i = 0 ; i < 4; i++)
|
||||
{
|
||||
int boneIndex = int(vBoneIds[i]);
|
||||
if(boneIndex < 0) break;
|
||||
|
||||
mat4 boneMatrix = uFinalBonesMatrix[boneIndex];
|
||||
float weight = vBoneWeights[i];
|
||||
mat4 boneMatrix = uFinalBonesMatrix[boneIndex];
|
||||
float weight = vBoneWeights[i];
|
||||
|
||||
finalPos += boneMatrix * bindPos * weight;
|
||||
finalNormal += boneMatrix * bindNormal * weight;
|
||||
finalTangent += boneMatrix * bindTangent * weight;
|
||||
finalPos += boneMatrix * bindPos * weight;
|
||||
finalNormal += boneMatrix * bindNormal * weight;
|
||||
finalTangent += boneMatrix * bindTangent * weight;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
finalPos = bindPos;
|
||||
finalNormal = bindNormal;
|
||||
finalTangent = bindTangent;
|
||||
}
|
||||
|
||||
gl_Position = uProjection * uView * vInstanceMatrix * finalPos;
|
||||
|
|
|
|||
|
|
@ -20,16 +20,24 @@ void main()
|
|||
|
||||
vec4 finalPos = vec4(0.0);
|
||||
vec4 finalNormal = vec4(0.0);
|
||||
for(int i = 0 ; i < 4; i++)
|
||||
if (vBoneIds != vBoneWeights)
|
||||
{
|
||||
int boneIndex = int(vBoneIds[i]);
|
||||
if(boneIndex < 0) break;
|
||||
for(int i = 0 ; i < 4; i++)
|
||||
{
|
||||
int boneIndex = int(vBoneIds[i]);
|
||||
if(boneIndex < 0) break;
|
||||
|
||||
mat4 boneMatrix = uFinalBonesMatrix[boneIndex];
|
||||
float weight = vBoneWeights[i];
|
||||
mat4 boneMatrix = uFinalBonesMatrix[boneIndex];
|
||||
float weight = vBoneWeights[i];
|
||||
|
||||
finalPos += boneMatrix * bindPos * weight;
|
||||
finalNormal += boneMatrix * bindNormal * weight;
|
||||
finalPos += boneMatrix * bindPos * weight;
|
||||
finalNormal += boneMatrix * bindNormal * weight;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
finalPos = bindPos;
|
||||
finalNormal = bindNormal;
|
||||
}
|
||||
|
||||
float scaleFactor = distance(vec3(finalPos), uViewPos) * 0.0025;
|
||||
|
|
|
|||
|
|
@ -1,15 +1,38 @@
|
|||
#version 460 core
|
||||
|
||||
layout (location = 1) in vec3 vPos;
|
||||
layout (location = 7) in vec4 vBoneIds;
|
||||
layout (location = 8) in vec4 vBoneWeights;
|
||||
layout (location = 9) in mat4 vInstanceMatrix;
|
||||
layout (location = 13) in vec3 vMorphTarget;
|
||||
layout (location = 13) in vec3 vMorphTargetPos;
|
||||
|
||||
uniform mat4 uView;
|
||||
uniform mat4 uProjection;
|
||||
uniform float uMorphTime;
|
||||
uniform mat4 uFinalBonesMatrix[250];
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 pos = mix(vPos, vMorphTarget, uMorphTime);
|
||||
gl_Position = uProjection * uView * vInstanceMatrix * vec4(pos, 1.0);
|
||||
vec4 bindPos = vec4(mix(vPos, vMorphTargetPos, uMorphTime), 1.0);
|
||||
|
||||
vec4 finalPos = vec4(0.0);
|
||||
if (vBoneIds != vBoneWeights)
|
||||
{
|
||||
for(int i = 0 ; i < 4; i++)
|
||||
{
|
||||
int boneIndex = int(vBoneIds[i]);
|
||||
if(boneIndex < 0) break;
|
||||
|
||||
mat4 boneMatrix = uFinalBonesMatrix[boneIndex];
|
||||
float weight = vBoneWeights[i];
|
||||
|
||||
finalPos += boneMatrix * bindPos * weight;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
finalPos = bindPos;
|
||||
}
|
||||
|
||||
gl_Position = uProjection * uView * vInstanceMatrix * finalPos;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,18 @@ public class Animation : IDisposable
|
|||
|
||||
bonePosition *= Constants.SCALE_DOWN_RATIO;
|
||||
|
||||
switch (anim.BoneModes[trackIndex])
|
||||
{
|
||||
case EBoneRetargetingMode.Animation:
|
||||
case EBoneRetargetingMode.Mesh:
|
||||
case EBoneRetargetingMode.AnimationScaled:
|
||||
case EBoneRetargetingMode.AnimationRelative:
|
||||
case EBoneRetargetingMode.OrientAndScale:
|
||||
case EBoneRetargetingMode.Count:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
BoneTransforms[trackIndex][frame] = new Transform
|
||||
{
|
||||
Relation = bone.ParentIndex >= 0 ? BoneTransforms[bone.ParentIndex][frame].Matrix : originalTransform.Relation,
|
||||
|
|
|
|||
|
|
@ -77,22 +77,21 @@ public class Skeleton : IDisposable
|
|||
shader.SetUniform($"uFinalBonesMatrix[{boneIndex}]", Matrix4x4.Identity);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetUniform(float deltaSeconds, bool outline, Shader shader)
|
||||
public void SetUniform(Shader shader, float deltaSeconds = 0f, bool updateElapsedTime = false)
|
||||
{
|
||||
if (!IsLoaded) return;
|
||||
if (Anim == null) SetPoseUniform(shader);
|
||||
else
|
||||
{
|
||||
if (!outline) Anim.ElapsedTime += deltaSeconds / Anim.TimePerFrame;
|
||||
foreach ((var boneName, var trackIndex) in UnrealSkeleton.ReferenceSkeleton.FinalNameToIndexMap)
|
||||
if (!updateElapsedTime) Anim.ElapsedTime += deltaSeconds / Anim.TimePerFrame;
|
||||
foreach (var boneIndex in BonesTransformByIndex.Keys)
|
||||
{
|
||||
if (!BonesIndexByLoweredName.TryGetValue(boneName.ToLower(), out var boneIndex))
|
||||
continue;
|
||||
if (!InvertedBonesMatrixByIndex.TryGetValue(boneIndex, out var invertMatrix))
|
||||
throw new ArgumentNullException($"no inverse matrix for bone '{boneIndex}'");
|
||||
if (boneIndex >= Constants.MAX_BONE_UNIFORM)
|
||||
break;
|
||||
if (!InvertedBonesMatrixByIndex.TryGetValue(boneIndex, out var invertMatrix))
|
||||
throw new ArgumentNullException($"no inverse matrix for bone '{boneIndex}'");
|
||||
if (!Anim.TrackIndexByBoneIndex.TryGetValue(boneIndex, out var trackIndex))
|
||||
throw new ArgumentNullException($"no track index for bone '{boneIndex}'");
|
||||
|
||||
shader.SetUniform($"uFinalBonesMatrix[{boneIndex}]", invertMatrix * Anim.InterpolateBoneTransform(trackIndex));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -266,7 +266,7 @@ public class Model : IDisposable
|
|||
if (!options.TryGetModel(attached, out var attachedModel))
|
||||
continue;
|
||||
|
||||
attachedModel.Transforms[attachedModel.SelectedInstance].Relation = socket.Transform.Matrix * socketRelation;
|
||||
attachedModel.Transforms[attachedModel.SelectedInstance].Relation = socket.Transform.LocalMatrix * socketRelation;
|
||||
attachedModel.UpdateMatrices(options);
|
||||
}
|
||||
}
|
||||
|
|
@ -382,7 +382,7 @@ public class Model : IDisposable
|
|||
|
||||
_vao.Bind();
|
||||
shader.SetUniform("uMorphTime", MorphTime);
|
||||
if (HasSkeleton) Skeleton.SetUniform(deltaSeconds, outline, shader);
|
||||
if (HasSkeleton) Skeleton.SetUniform(shader, deltaSeconds, outline);
|
||||
if (!outline)
|
||||
{
|
||||
shader.SetUniform("uUvCount", UvCount);
|
||||
|
|
@ -413,6 +413,8 @@ public class Model : IDisposable
|
|||
|
||||
_vao.Bind();
|
||||
shader.SetUniform("uMorphTime", MorphTime);
|
||||
if (HasSkeleton) Skeleton.SetUniform(shader);
|
||||
|
||||
foreach (var section in Sections)
|
||||
{
|
||||
if (!section.Show) continue;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user