5454import com .jme3 .scene .Node ;
5555import com .jme3 .scene .SceneGraphVisitorAdapter ;
5656import com .jme3 .scene .Spatial ;
57+ import com .jme3 .scene .control .AbstractControl ;
5758import com .jme3 .util .TempVars ;
5859
5960import java .util .ArrayList ;
@@ -88,7 +89,7 @@ public class ArmatureDebugAppState extends BaseAppState {
8889 */
8990 public static final float CLICK_MAX_DELAY = 0.2f ;
9091
91- private Node debugNode = new Node ("debugNode " );
92+ private Node debugNode = new Node ("ArmaturesDebugNode " );
9293 private final Map <Armature , ArmatureDebugger > armatures = new HashMap <>();
9394 private final List <Consumer <Joint >> selectionListeners = new ArrayList <>();
9495 private boolean displayNonDeformingJoints = false ;
@@ -102,8 +103,8 @@ public class ArmatureDebugAppState extends BaseAppState {
102103 @ Override
103104 protected void initialize (Application app ) {
104105
105- this . inputManager = app .getInputManager ();
106- this . cam = app .getCamera ();
106+ inputManager = app .getInputManager ();
107+ cam = app .getCamera ();
107108
108109 vp = app .getRenderManager ().createMainView ("ArmatureDebugView" , cam );
109110 vp .attachScene (debugNode );
@@ -191,20 +192,23 @@ public ArmatureDebugger addArmatureFrom(Armature armature, Spatial sp) {
191192 }
192193
193194 // Use a visitor to find joints that actually deform the mesh
194- JointInfoVisitor visitor = new JointInfoVisitor (armature );
195- sp .depthFirstTraversal (visitor );
195+ JointInfoVisitor jointVisitor = new JointInfoVisitor (armature );
196+ sp .depthFirstTraversal (jointVisitor );
197+
198+ Spatial target = sp ;
196199
197- // Create a new ArmatureDebugger
198- debugger = new ArmatureDebugger (sp .getName () + "_ArmatureDebugger" , armature , visitor .deformingJoints );
199- debugger .setLocalTransform (sp .getWorldTransform ());
200200 if (sp instanceof Node ) {
201201 List <Geometry > geoms = new ArrayList <>();
202202 collectGeometries ((Node ) sp , geoms );
203203 if (geoms .size () == 1 ) {
204- debugger . setLocalTransform ( geoms .get (0 ). getWorldTransform () );
204+ target = geoms .get (0 );
205205 }
206206 }
207207
208+ // Create a new ArmatureDebugger
209+ debugger = new ArmatureDebugger (sp .getName () + "_ArmatureDebugger" , armature , jointVisitor .deformingJoints );
210+ debugger .addControl (new ArmatureDebuggerLink (target ));
211+
208212 // Store and attach the new debugger
209213 armatures .put (armature , debugger );
210214 debugNode .attachChild (debugger );
@@ -443,4 +447,22 @@ public void visit(Geometry geo) {
443447 }
444448
445449 }
450+
451+ private static class ArmatureDebuggerLink extends AbstractControl {
452+
453+ private final Spatial target ;
454+
455+ public ArmatureDebuggerLink (Spatial target ) {
456+ this .target = target ;
457+ }
458+
459+ @ Override
460+ protected void controlUpdate (float tpf ) {
461+ spatial .setLocalTransform (target .getWorldTransform ());
462+ }
463+
464+ @ Override
465+ protected void controlRender (RenderManager rm , ViewPort vp ) {
466+ }
467+ }
446468}
0 commit comments