This commit is contained in:
2026-02-21 22:17:44 -08:00
parent 423807c62f
commit 0adcafd697
14 changed files with 981 additions and 59 deletions

View File

@ -108,9 +108,11 @@ class BoneAnimation extends Animation {
object.transform.rot.set(0, 0, 0, 1);
object.transform.buildMatrix();
var refs = mo.parent.raw.bone_actions;
if (refs != null && refs.length > 0) {
Data.getSceneRaw(refs[0], function(action: TSceneFormat) { play(action.name); });
if (mo.parent != null && mo.parent.raw != null && mo.parent.raw.bone_actions != null) {
var refs = mo.parent.raw.bone_actions;
if (refs.length > 0) {
Data.getSceneRaw(refs[0], function(action: TSceneFormat) { play(action.name); });
}
}
}
if (armatureObject.raw.relative_bone_constraints) relativeBoneConstraints = true;
@ -183,8 +185,10 @@ class BoneAnimation extends Animation {
}
function setAction(action: String) {
if (armature == null) return;
armature.initMats();
var a = armature.getAction(action);
if (a == null) return;
skeletonBones = a.bones;
skeletonMats = a.mats;
if(! rootMotionCacheInit) skeletonMats.push(Mat4.identity());
@ -193,8 +197,11 @@ class BoneAnimation extends Animation {
}
function getAction(action: String): Array<TObj> {
if (armature == null) return null;
armature.initMats();
return armature.getAction(action).bones;
var a = armature.getAction(action);
if (a == null) return null;
return a.bones;
}
function multParent(i: Int, fasts: Array<Mat4>, bones: Array<TObj>, mats: Array<Mat4>) {
@ -225,9 +232,9 @@ class BoneAnimation extends Animation {
}
override public function play(action = "", onComplete: Void->Void = null, blendTime = 0.2, speed = 1.0, loop = true) {
super.play(action, onComplete, blendTime, speed, loop);
if (action != "") {
setAction(action);
super.play(action, onComplete, blendTime, speed, loop);
var tempAnimParam = new ActionSampler(action);
registerAction("tempAction", tempAnimParam);
updateAnimation = function(mats){
@ -239,6 +246,10 @@ class BoneAnimation extends Animation {
override public function update(delta: FastFloat) {
this.delta = delta;
if (!isSkinned && skeletonBones == null) setAction(armature.actions[0].name);
// TODO: double check skip culling for skinned meshes if they need animation updates for bounds
// if (object != null && !object.visible) return;
if (object != null && (!object.visible || object.culled)) return;
if (skeletonBones == null || skeletonBones.length == 0) return;
@ -248,7 +259,6 @@ class BoneAnimation extends Animation {
super.update(delta);
if(updateAnimation != null) {
updateAnimation(skeletonMats);
}
@ -401,6 +411,7 @@ class BoneAnimation extends Animation {
}
var bones = sampler.getBoneAction();
if (bones == null) return;
for(b in bones){
if (b.anim != null) {
updateTrack(b.anim, sampler);
@ -410,13 +421,14 @@ class BoneAnimation extends Animation {
}
public function sampleAction(sampler: ActionSampler, actionMats: Array<Mat4>) {
if(! sampler.actionDataInit) {
var bones = getAction(sampler.action);
sampler.setBoneAction(bones);
}
var bones = sampler.getBoneAction();
if (bones == null) return;
actionMats[skeletonBones.length].setIdentity();
var rootMotionEnabled = sampler.rootMotionPos || sampler.rootMotionRot;
for (i in 0...bones.length) {
@ -427,7 +439,6 @@ class BoneAnimation extends Animation {
updateAnimSampled(bones[i].anim, actionMats[i], sampler);
}
}
}
function updateAnimSampled(anim: TAnimation, mm: Mat4, sampler: ActionSampler) {
@ -588,6 +599,9 @@ class BoneAnimation extends Animation {
public override function getTotalFrames(sampler: ActionSampler): Int {
var bones = getAction(sampler.action);
if (bones == null){
return 0;
}
var track = bones[0].anim.tracks[0];
return Std.int(track.frames[track.frames.length - 1] - track.frames[0]);
}
@ -1048,9 +1062,9 @@ class BoneAnimation extends Animation {
var rootLen = root.bone_length * rootMat.getScale().x;
// Get distance form root to goal
var goalLen = Math.abs(Vec4.distance(rootMat.getLoc(), goal));
var goalLen: FastFloat = Math.abs(Vec4.distance(rootMat.getLoc(), goal));
var totalLength = effectorLen + rootLen;
var totalLength: FastFloat = effectorLen + rootLen;
// Get tip location of effector bone
var effectorTipPos = new Vec4().setFrom(effectorMat.look()).normalize();
@ -1070,7 +1084,7 @@ class BoneAnimation extends Animation {
// Get unit vector of effector bone
var vectorEffector = new Vec4().setFrom(effectorMat.look()).normalize();
// Get dot product of vectors
var dot = new Vec4().setFrom(vectorRootEffector).dot(vectorRoot);
// Calmp between -1 and 1