Skip to content

Commit f47db10

Browse files
authored
Update ArmatureDebugger.java
1 parent 9a10591 commit f47db10

File tree

1 file changed

+114
-38
lines changed

1 file changed

+114
-38
lines changed

jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureDebugger.java

Lines changed: 114 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
package com.jme3.scene.debug.custom;
2-
31
/*
4-
* Copyright (c) 2009-2021 jMonkeyEngine
2+
* Copyright (c) 2009-2025 jMonkeyEngine
53
* All rights reserved.
64
*
75
* Redistribution and use in source and binary forms, with or without
@@ -31,9 +29,11 @@
3129
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3230
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3331
*/
32+
package com.jme3.scene.debug.custom;
3433

3534
import com.jme3.anim.Armature;
3635
import com.jme3.anim.Joint;
36+
import com.jme3.anim.SkinningControl;
3737
import com.jme3.asset.AssetManager;
3838
import com.jme3.collision.Collidable;
3939
import com.jme3.collision.CollisionResults;
@@ -55,104 +55,166 @@
5555
public class ArmatureDebugger extends Node {
5656

5757
/**
58-
* The lines of the bones or the wires between their heads.
58+
* The node responsible for rendering the bones/wires and their outlines.
5959
*/
6060
private ArmatureNode armatureNode;
61-
61+
/**
62+
* The {@link Armature} instance being debugged.
63+
*/
6264
private Armature armature;
63-
65+
/**
66+
* A node containing all {@link Geometry} objects representing the joint points.
67+
*/
6468
private Node joints;
69+
/**
70+
* A node containing all {@link Geometry} objects representing the bone outlines.
71+
*/
6572
private Node outlines;
73+
/**
74+
* A node containing all {@link Geometry} objects representing the bone wires/lines.
75+
*/
6676
private Node wires;
6777
/**
6878
* The dotted lines between a bone's tail and the had of its children. Not
6979
* available if the length data was not provided.
7080
*/
7181
private ArmatureInterJointsWire interJointWires;
72-
82+
/**
83+
* Default constructor for `ArmatureDebugger`.
84+
* Use {@link #ArmatureDebugger(String, Armature, List)} for a functional instance.
85+
*/
7386
public ArmatureDebugger() {
7487
}
7588

7689
/**
77-
* Creates a debugger with no length data. The wires will be a connection
78-
* between the bones' heads only. The points will show the bones' heads only
79-
* and no dotted line of inter bones connection will be visible.
90+
* Convenience constructor that creates an {@code ArmatureDebugger} and immediately
91+
* initializes its materials based on the provided {@code AssetManager}
92+
* and {@code SkinningControl}.
93+
*
94+
* @param assetManager The {@link AssetManager} used to load textures and materials
95+
* for the debug visualization.
96+
* @param skControl The {@link SkinningControl} from which to extract the
97+
* {@link Armature} and its associated joints.
98+
*/
99+
public ArmatureDebugger(AssetManager assetManager, SkinningControl skControl) {
100+
this(null, skControl.getArmature(), skControl.getArmature().getJointList());
101+
initialize(assetManager, null);
102+
}
103+
104+
/**
105+
* Creates an `ArmatureDebugger` instance without explicit bone length data.
106+
* In this configuration, the visual representation will consist of wires
107+
* connecting the bone heads, and points representing the bone heads.
108+
* No dotted lines for inter-bone connections will be visible.
80109
*
81-
* @param name the name of the debugger's node
82-
* @param armature the armature that will be shown
83-
* @param deformingJoints a list of joints
110+
* @param name The name of this debugger's root node.
111+
* @param armature The {@link Armature} to be visualized.
112+
* @param deformingJoints A {@link List} of {@link Joint} objects that are
113+
* considered deforming joints.
84114
*/
85115
public ArmatureDebugger(String name, Armature armature, List<Joint> deformingJoints) {
86116
super(name);
87117
this.armature = armature;
118+
// Ensure the armature's world transforms are up-to-date before visualization.
88119
armature.update();
89120

121+
// Initialize the main container nodes for different visual elements.
90122
joints = new Node("joints");
91123
outlines = new Node("outlines");
92124
wires = new Node("bones");
93125
this.attachChild(joints);
94126
this.attachChild(outlines);
95127
this.attachChild(wires);
96-
Node ndJoints = new Node("non deforming Joints");
97-
Node ndOutlines = new Node("non deforming Joints outlines");
98-
Node ndWires = new Node("non deforming Joints wires");
128+
129+
// Create child nodes specifically for non-deforming joints' visualization
130+
Node ndJoints = new Node("NonDeformingJoints");
131+
Node ndOutlines = new Node("NonDeformingOutlines");
132+
Node ndWires = new Node("NonDeformingWires");
99133
joints.attachChild(ndJoints);
100134
outlines.attachChild(ndOutlines);
101135
wires.attachChild(ndWires);
102-
Node outlineDashed = new Node("Outlines Dashed");
103-
Node wiresDashed = new Node("Wires Dashed");
104-
wiresDashed.attachChild(new Node("dashed non defrom"));
105-
outlineDashed.attachChild(new Node("dashed non defrom"));
136+
137+
Node outlineDashed = new Node("DashedOutlines");
138+
Node wiresDashed = new Node("DashedWires");
139+
wiresDashed.attachChild(new Node("DashedNonDeformingWires"));
140+
outlineDashed.attachChild(new Node("DashedNonDeformingOutlines"));
106141
outlines.attachChild(outlineDashed);
107142
wires.attachChild(wiresDashed);
108143

144+
// Initialize the core ArmatureNode which handles the actual mesh generation.
109145
armatureNode = new ArmatureNode(armature, joints, wires, outlines, deformingJoints);
110-
111146
this.attachChild(armatureNode);
112147

148+
// By default, non-deforming joints are hidden.
113149
displayNonDeformingJoint(false);
114150
}
115151

152+
/**
153+
* Sets the visibility of non-deforming joints and their associated outlines and wires.
154+
*
155+
* @param display `true` to make non-deforming joints visible, `false` to hide them.
156+
*/
116157
public void displayNonDeformingJoint(boolean display) {
117-
joints.getChild(0).setCullHint(display ? CullHint.Dynamic : CullHint.Always);
118-
outlines.getChild(0).setCullHint(display ? CullHint.Dynamic : CullHint.Always);
119-
wires.getChild(0).setCullHint(display ? CullHint.Dynamic : CullHint.Always);
120-
((Node) outlines.getChild(1)).getChild(0).setCullHint(display ? CullHint.Dynamic : CullHint.Always);
121-
((Node) wires.getChild(1)).getChild(0).setCullHint(display ? CullHint.Dynamic : CullHint.Always);
158+
CullHint cullHint = display ? CullHint.Dynamic : CullHint.Always;
159+
160+
joints.getChild(0).setCullHint(cullHint);
161+
outlines.getChild(0).setCullHint(cullHint);
162+
wires.getChild(0).setCullHint(cullHint);
163+
164+
((Node) outlines.getChild(1)).getChild(0).setCullHint(cullHint);
165+
((Node) wires.getChild(1)).getChild(0).setCullHint(cullHint);
122166
}
123167

168+
/**
169+
* Initializes the materials and camera for the debugger's visual components.
170+
* This method should be called after the `ArmatureDebugger` is added to a scene graph
171+
* and an {@link AssetManager} and {@link Camera} are available.
172+
*
173+
* @param assetManager The {@link AssetManager} to load textures and materials.
174+
* @param camera The scene's primary {@link Camera}, used by the `ArmatureNode`
175+
* for billboard rendering of joint points.
176+
*/
124177
public void initialize(AssetManager assetManager, Camera camera) {
125178

126179
armatureNode.setCamera(camera);
127180

181+
// Material for joint points (billboarded dots).
128182
Material matJoints = new Material(assetManager, "Common/MatDefs/Misc/Billboard.j3md");
129-
Texture t = assetManager.loadTexture("Common/Textures/dot.png");
130-
matJoints.setTexture("Texture", t);
183+
Texture tex = assetManager.loadTexture("Common/Textures/dot.png");
184+
matJoints.setTexture("Texture", tex);
131185
matJoints.getAdditionalRenderState().setDepthTest(false);
132186
matJoints.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
133187
joints.setQueueBucket(RenderQueue.Bucket.Translucent);
134188
joints.setMaterial(matJoints);
135189

190+
// Material for bone wires/lines (unshaded, vertex colored).
136191
Material matWires = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
137192
matWires.setBoolean("VertexColor", true);
138-
matWires.getAdditionalRenderState().setLineWidth(1f);
193+
matWires.getAdditionalRenderState().setDepthTest(false);
139194
wires.setMaterial(matWires);
140195

196+
// Material for bone outlines (unshaded, vertex colored).
141197
Material matOutline = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
142198
matOutline.setBoolean("VertexColor", true);
143-
matOutline.getAdditionalRenderState().setLineWidth(1f);
199+
matOutline.getAdditionalRenderState().setDepthTest(false);
144200
outlines.setMaterial(matOutline);
145201

202+
// Material for dashed outlines. This assumes a "DashedLine.j3md" shader.
146203
Material matOutline2 = new Material(assetManager, "Common/MatDefs/Misc/DashedLine.j3md");
147-
matOutline2.getAdditionalRenderState().setLineWidth(1);
204+
matOutline2.getAdditionalRenderState().setDepthTest(false);
148205
outlines.getChild(1).setMaterial(matOutline2);
149206

207+
// Material for dashed wires. This assumes a "DashedLine.j3md" shader.
150208
Material matWires2 = new Material(assetManager, "Common/MatDefs/Misc/DashedLine.j3md");
151-
matWires2.getAdditionalRenderState().setLineWidth(1);
209+
matWires2.getAdditionalRenderState().setDepthTest(false);
152210
wires.getChild(1).setMaterial(matWires2);
153-
154211
}
155212

213+
/**
214+
* Returns the {@link Armature} instance associated with this debugger.
215+
*
216+
* @return The {@link Armature} being debugged.
217+
*/
156218
public Armature getArmature() {
157219
return armature;
158220
}
@@ -168,21 +230,35 @@ public int collideWith(Collidable other, CollisionResults results) {
168230
return armatureNode.collideWith(other, results);
169231
}
170232

171-
protected Joint select(Geometry g) {
172-
return armatureNode.select(g);
233+
/**
234+
* Selects and returns the {@link Joint} associated with a given {@link Geometry}.
235+
* This is an internal helper method, likely used for picking operations.
236+
*
237+
* @param geo The {@link Geometry} representing a part of a joint.
238+
* @return The {@link Joint} corresponding to the geometry, or `null` if not found.
239+
*/
240+
protected Joint select(Geometry geo) {
241+
return armatureNode.select(geo);
173242
}
174243

175244
/**
176-
* @return the armature wires
245+
* Returns the {@link ArmatureNode} which is responsible for generating and
246+
* managing the visual mesh of the bones and wires.
247+
*
248+
* @return The {@link ArmatureNode} instance.
177249
*/
178250
public ArmatureNode getBoneShapes() {
179251
return armatureNode;
180252
}
181253

182254
/**
183-
* @return the dotted line between bones (can be null)
255+
* Returns the {@link ArmatureInterJointsWire} instance, which represents the
256+
* dotted lines connecting a bone's tail to the head of its children.
257+
* This will be `null` if the debugger was created without bone length data.
258+
*
259+
* @return The {@link ArmatureInterJointsWire} instance, or `null` if not present.
184260
*/
185261
public ArmatureInterJointsWire getInterJointWires() {
186262
return interJointWires;
187263
}
188-
}
264+
}

0 commit comments

Comments
 (0)