From 4f83b4d1d327c10aac29a2e72ec2e1d94574e9ae Mon Sep 17 00:00:00 2001 From: TothBenoit Date: Fri, 11 Oct 2024 16:02:21 +0200 Subject: [PATCH] Animation : Fix transition between re-targeted animation and non-re-targeted animation --- h3d/anim/SmoothTarget.hx | 14 +++++++++++++- h3d/scene/Skin.hx | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/h3d/anim/SmoothTarget.hx b/h3d/anim/SmoothTarget.hx index 8a57256185..ea8a56eb9f 100644 --- a/h3d/anim/SmoothTarget.hx +++ b/h3d/anim/SmoothTarget.hx @@ -36,6 +36,7 @@ class SmoothTarget extends Animation { initObjects(); } + static var tmpMat : Matrix = new h3d.Matrix(); function initObjects() { objects = []; for( o in target.getObjects() ) { @@ -45,8 +46,19 @@ class SmoothTarget extends Animation { s.targetSkin = o.targetSkin; s.targetJoint = o.targetJoint; objects.push(s); - if( o.targetSkin != null ) + if( o.targetSkin != null ) { mat = @:privateAccess o.targetSkin.currentRelPose[o.targetJoint]; + if ( mat != null && o.targetSkin.prevEnableRetargeting ) { + var j = @:privateAccess o.targetSkin.skinData.allJoints[o.targetJoint]; + if ( j != null && j.retargetAnim ) { + tmpMat.load(mat); + mat = tmpMat; + mat._41 = j.defMat._41; + mat._42 = j.defMat._42; + mat._43 = j.defMat._43; + } + } + } else if( o.targetObject != null ) mat = o.targetObject.defaultTransform; if( mat == null ) diff --git a/h3d/scene/Skin.hx b/h3d/scene/Skin.hx index 105d8d54e6..dd64f1a6b0 100644 --- a/h3d/scene/Skin.hx +++ b/h3d/scene/Skin.hx @@ -78,6 +78,7 @@ class Skin extends MultiMaterial { public var showJoints : Bool; public var enableRetargeting : Bool = true; + public var prevEnableRetargeting : Bool = true; public function new(s, ?mat, ?parent) { super(null, mat, parent); @@ -248,6 +249,7 @@ class Skin extends MultiMaterial { } skinShader.bonesMatrixes = currentPalette; jointsUpdated = false; + prevEnableRetargeting = enableRetargeting; } override function emit( ctx : RenderContext ) {