Skip to content

Commit fd81fa0

Browse files
committed
update 3 demos to work with the new animation system
1 parent 7121bbf commit fd81fa0

3 files changed

Lines changed: 59 additions & 33 deletions

File tree

MinieExamples/src/main/java/jme3utilities/minie/test/BalanceDemo.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2626
*/
2727
package jme3utilities.minie.test;
2828

29+
import com.jme3.anim.AnimComposer;
2930
import com.jme3.animation.AnimChannel;
3031
import com.jme3.animation.AnimControl;
3132
import com.jme3.animation.SkeletonControl;
@@ -60,6 +61,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
6061
import com.jme3.scene.Mesh;
6162
import com.jme3.scene.Node;
6263
import com.jme3.scene.Spatial;
64+
import com.jme3.scene.control.AbstractControl;
6365
import com.jme3.scene.plugins.ogre.MaterialLoader;
6466
import com.jme3.scene.plugins.ogre.MeshLoader;
6567
import com.jme3.scene.shape.Box;
@@ -117,10 +119,18 @@ public class BalanceDemo extends ActionApplication {
117119
// *************************************************************************
118120
// fields
119121

122+
/**
123+
* SkeletonControl/SkinningControl of the loaded model
124+
*/
125+
private AbstractControl sc;
120126
/**
121127
* channel for playing canned animations
122128
*/
123129
private AnimChannel animChannel = null;
130+
/**
131+
* composer for playing canned animations
132+
*/
133+
private AnimComposer composer = null;
124134
/**
125135
* keeps the model's center of mass directly above its center of support
126136
*/
@@ -179,16 +189,12 @@ public class BalanceDemo extends ActionApplication {
179189
* visualizer for the center of support
180190
*/
181191
private PointVisualizer supportPoint;
182-
/**
183-
* SkeletonControl of the loaded model
184-
*/
185-
private SkeletonControl sc;
186192
/**
187193
* visualizer for the skeleton of the C-G model
188194
*/
189195
private SkeletonVisualizer sv;
190196
/**
191-
* name of the Animation to play on the C-G model
197+
* name of the Animation/Action to play on the C-G model
192198
*/
193199
private String animationName = null;
194200
/**
@@ -347,7 +353,6 @@ public void onAction(String actionString, boolean ongoing, float tpf) {
347353
case "toggle help":
348354
toggleHelp();
349355
return;
350-
351356
case "toggle meshes":
352357
toggleMeshes();
353358
return;
@@ -509,17 +514,21 @@ private void addModel(String modelName) {
509514
setHeight(cgModel, 2f);
510515
center(cgModel);
511516

512-
sc = RagUtils.findSkeletonControl(cgModel);
517+
sc = RagUtils.findSControl(cgModel);
513518
Spatial controlledSpatial = sc.getSpatial();
514519

515520
controlledSpatial.addControl(dac);
516521
dac.setPhysicsSpace(physicsSpace);
517522

518523
torso = dac.getTorsoLink();
519524

520-
AnimControl animControl
521-
= controlledSpatial.getControl(AnimControl.class);
522-
animChannel = animControl.createChannel();
525+
if (sc instanceof SkeletonControl) {
526+
AnimControl animControl
527+
= controlledSpatial.getControl(AnimControl.class);
528+
animChannel = animControl.createChannel();
529+
} else {
530+
composer = controlledSpatial.getControl(AnimComposer.class);
531+
}
523532

524533
sv = new SkeletonVisualizer(assetManager, sc);
525534
sv.setLineColor(ColorRGBA.Yellow); // TODO clean up visualization
@@ -635,7 +644,11 @@ private void initWhenReady() {
635644
/*
636645
* Start playing a canned animation.
637646
*/
638-
animChannel.setAnim(animationName);
647+
if (animChannel != null) {
648+
animChannel.setAnim(animationName);
649+
} else {
650+
composer.setCurrentAction(animationName);
651+
}
639652
}
640653

641654
/**

MinieExamples/src/main/java/jme3utilities/minie/test/BuoyDemo.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2626
*/
2727
package jme3utilities.minie.test;
2828

29+
import com.jme3.anim.AnimComposer;
2930
import com.jme3.animation.AnimChannel;
3031
import com.jme3.animation.AnimControl;
3132
import com.jme3.animation.SkeletonControl;
@@ -59,6 +60,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5960
import com.jme3.scene.Mesh;
6061
import com.jme3.scene.Node;
6162
import com.jme3.scene.Spatial;
63+
import com.jme3.scene.control.AbstractControl;
6264
import com.jme3.scene.plugins.ogre.MaterialLoader;
6365
import com.jme3.scene.plugins.ogre.MeshLoader;
6466
import com.jme3.scene.shape.Quad;
@@ -116,6 +118,10 @@ public class BuoyDemo extends ActionApplication {
116118
// *************************************************************************
117119
// fields
118120

121+
/**
122+
* SkeletonControl/SkinningControl of the loaded model
123+
*/
124+
private AbstractControl sc;
119125
/**
120126
* channel for playing canned animations
121127
*/
@@ -156,16 +162,12 @@ public class BuoyDemo extends ActionApplication {
156162
* scene processor for water effects
157163
*/
158164
private SimpleWaterProcessor processor;
159-
/**
160-
* SkeletonControl of the loaded model
161-
*/
162-
private SkeletonControl sc;
163165
/**
164166
* visualizer for the skeleton of the C-G model
165167
*/
166168
private SkeletonVisualizer sv;
167169
/**
168-
* name of the Animation to play on the C-G model
170+
* name of the Animation/Action to play on the C-G model
169171
*/
170172
private String animationName = null;
171173
// *************************************************************************
@@ -433,7 +435,7 @@ private void addModel(String modelName) {
433435
setHeight(cgModel, 2f);
434436
center(cgModel);
435437

436-
sc = RagUtils.findSkeletonControl(cgModel);
438+
sc = RagUtils.findSControl(cgModel);
437439
Spatial controlledSpatial = sc.getSpatial();
438440

439441
controlledSpatial.addControl(dac);
@@ -449,10 +451,16 @@ private void addModel(String modelName) {
449451
link.addIKController(buoy);
450452
}
451453

452-
AnimControl animControl
453-
= controlledSpatial.getControl(AnimControl.class);
454-
animChannel = animControl.createChannel();
455-
animChannel.setAnim(animationName);
454+
if (sc instanceof SkeletonControl) {
455+
AnimControl animControl
456+
= controlledSpatial.getControl(AnimControl.class);
457+
animChannel = animControl.createChannel();
458+
animChannel.setAnim(animationName);
459+
} else {
460+
AnimComposer composer
461+
= controlledSpatial.getControl(AnimComposer.class);
462+
composer.setCurrentAction(animationName);
463+
}
456464

457465
sv = new SkeletonVisualizer(assetManager, sc);
458466
sv.setLineColor(ColorRGBA.Yellow); // TODO clean up visualization

MinieExamples/src/main/java/jme3utilities/minie/test/TestDac.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2626
*/
2727
package jme3utilities.minie.test;
2828

29+
import com.jme3.anim.AnimComposer;
2930
import com.jme3.animation.AnimChannel;
3031
import com.jme3.animation.AnimControl;
3132
import com.jme3.animation.SkeletonControl;
@@ -68,6 +69,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
6869
import com.jme3.scene.Mesh;
6970
import com.jme3.scene.Node;
7071
import com.jme3.scene.Spatial;
72+
import com.jme3.scene.control.AbstractControl;
7173
import com.jme3.scene.plugins.ogre.MaterialLoader;
7274
import com.jme3.scene.plugins.ogre.MeshLoader;
7375
import com.jme3.scene.shape.Box;
@@ -140,9 +142,9 @@ public class TestDac extends ActionApplication {
140142
// fields
141143

142144
/**
143-
* channel for playing canned animations
145+
* SkeletonControl/SkinningControl of the loaded model
144146
*/
145-
private AnimChannel animChannel = null;
147+
private AbstractControl sc;
146148
/**
147149
* text displayed in the GUI node
148150
*/
@@ -171,7 +173,7 @@ public class TestDac extends ActionApplication {
171173
final private Mesh ballMesh = new Sphere(16, 32, ballRadius);
172174
final private NameGenerator nameGenerator = new NameGenerator();
173175
/**
174-
* root node of the C-G model on which the control is being tested
176+
* root node of the C-G model on which the Control is being tested
175177
*/
176178
private Node cgModel;
177179
/**
@@ -186,16 +188,12 @@ public class TestDac extends ActionApplication {
186188
* space for physics simulation
187189
*/
188190
private PhysicsSpace physicsSpace;
189-
/**
190-
* SkeletonControl of the loaded model
191-
*/
192-
private SkeletonControl sc;
193191
/**
194192
* visualizer for the skeleton of the C-G model
195193
*/
196194
private SkeletonVisualizer sv;
197195
/**
198-
* name of the animation to play on the C-G model
196+
* name of the Animation/Action to play on the C-G model
199197
*/
200198
private String animationName = null;
201199
/**
@@ -644,7 +642,7 @@ private void addModel(String modelName) {
644642
center(cgModel);
645643
resetTransform = cgModel.getLocalTransform().clone();
646644

647-
sc = RagUtils.findSkeletonControl(cgModel);
645+
sc = RagUtils.findSControl(cgModel);
648646
Spatial controlledSpatial = sc.getSpatial();
649647

650648
controlledSpatial.addControl(dac);
@@ -673,9 +671,16 @@ private void addModel(String modelName) {
673671
rightClavicle = dac.findBoneLink(rightClavicleName);
674672
upperBody = dac.findBoneLink(upperBodyName);
675673

676-
AnimControl animControl = controlledSpatial.getControl(AnimControl.class);
677-
animChannel = animControl.createChannel();
678-
animChannel.setAnim(animationName);
674+
if (sc instanceof SkeletonControl) {
675+
AnimControl animControl
676+
= controlledSpatial.getControl(AnimControl.class);
677+
AnimChannel animChannel = animControl.createChannel();
678+
animChannel.setAnim(animationName);
679+
} else {
680+
AnimComposer composer
681+
= controlledSpatial.getControl(AnimComposer.class);
682+
composer.setCurrentAction(animationName);
683+
}
679684

680685
sv = new SkeletonVisualizer(assetManager, sc);
681686
sv.setLineColor(ColorRGBA.Yellow); // TODO clean up visualization

0 commit comments

Comments
 (0)