aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Slack <[email protected]>2012-11-29 09:05:57 -0800
committerJoshua Slack <[email protected]>2012-11-29 09:05:57 -0800
commita5fd58ef4176c834a3b57fc70302d7ae9e2e4025 (patch)
tree6cafab2eed61952e1253f29df99b01204592633f
parentc4cf9be8fcbd4d0787213e5d5aeb7330382ac540 (diff)
parent0ee7564335609c407fc5a564c567a3e3bee561e2 (diff)
Merge pull request #7 from ricardolpd/pull_request_Branch
Adds resetOnStop flag to reset animation automatically once its stopped
-rw-r--r--.gitignore1
-rw-r--r--trunk/ardor3d-animation/src/main/java/com/ardor3d/extension/animation/skeletal/AnimationManager.java64
-rw-r--r--trunk/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationStateExample.java32
3 files changed, 86 insertions, 11 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e660fd9
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+bin/
diff --git a/trunk/ardor3d-animation/src/main/java/com/ardor3d/extension/animation/skeletal/AnimationManager.java b/trunk/ardor3d-animation/src/main/java/com/ardor3d/extension/animation/skeletal/AnimationManager.java
index 5ec9bf5..30e2e9b 100644
--- a/trunk/ardor3d-animation/src/main/java/com/ardor3d/extension/animation/skeletal/AnimationManager.java
+++ b/trunk/ardor3d-animation/src/main/java/com/ardor3d/extension/animation/skeletal/AnimationManager.java
@@ -85,6 +85,16 @@ public class AnimationManager {
protected AnimationUpdateState _currentAnimationState = AnimationUpdateState.Play;
/**
+ * boolean flag to allow stop state to be updated one last time.
+ */
+ protected boolean _canSetStopState = false;
+
+ /**
+ * boolean flag to reset Clips automatically once they are stopped.
+ */
+ protected boolean _resetClipsOnStop = false;
+
+ /**
* Listeners for changes to this manager's AnimationUpdateState.
*/
protected final List<AnimationUpdateStateListener> _updateStateListeners = Lists.newArrayList();
@@ -152,6 +162,24 @@ public class AnimationManager {
_globalTimer = timer;
}
+ /**
+ *
+ * @return True if clips will reset if the currentUpdateState is Stop.
+ */
+ public boolean isResetClipsOnStop() {
+ return _resetClipsOnStop;
+ }
+
+ /**
+ * @param resetClipsOnStop
+ * True if clips are to be reset when currentUpdateState is Stop, false otherwise.
+ *
+ *
+ */
+ public void setResetClipsOnStop(final boolean resetClipsOnStop) {
+ _resetClipsOnStop = resetClipsOnStop;
+ }
+
public void play() {
setAnimationUpdateState(AnimationUpdateState.Play);
}
@@ -160,7 +188,8 @@ public class AnimationManager {
setAnimationUpdateState(AnimationUpdateState.Pause);
}
- public void stop() {
+ public void stop(final boolean resetOnStop) {
+ setResetClipsOnStop(resetOnStop);
setAnimationUpdateState(AnimationUpdateState.Stop);
}
@@ -200,12 +229,21 @@ public class AnimationManager {
}
}
} else {
- // must be resuming from stop, so restart clips
- for (final AnimationClipInstance instance : _clipInstances.values()) {
- if (instance.isActive()) {
- instance.setStartTime(currentTime);
+ // if newState is check if we will restart clips.
+ if (_resetClipsOnStop) {
+ for (final AnimationClipInstance instance : _clipInstances.values()) {
+ if (instance.isActive()) {
+ instance.setStartTime(currentTime);
+ }
}
}
+
+ }
+ } else {
+ for (final AnimationClipInstance instance : _clipInstances.values()) {
+ if (instance.isActive()) {
+ instance.setStartTime(currentTime);
+ }
}
}
@@ -327,10 +365,20 @@ public class AnimationManager {
public void update() {
if (_currentAnimationState != AnimationUpdateState.Play) {
- // no animation allowed. Exit.
- return;
+ if (_resetClipsOnStop) {
+ if (_currentAnimationState == AnimationUpdateState.Stop && !_canSetStopState) {
+ _canSetStopState = true;
+ } else {
+ // pause state or reset update has occurred
+ return;
+ }
+ } else {
+ // stop update without reseting
+ return;
+ }
+ } else {
+ _canSetStopState = false;
}
-
// grab current global time
final double globalTime = _globalTimer.getTimeInSeconds();
diff --git a/trunk/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationStateExample.java b/trunk/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationStateExample.java
index 10a6002..ee705bc 100644
--- a/trunk/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationStateExample.java
+++ b/trunk/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationStateExample.java
@@ -13,6 +13,7 @@ package com.ardor3d.example.pipeline;
import java.io.IOException;
import java.util.EnumSet;
import java.util.List;
+import java.util.concurrent.Callable;
import com.ardor3d.example.ExampleBase;
import com.ardor3d.example.Purpose;
@@ -45,11 +46,13 @@ import com.ardor3d.extension.ui.event.ActionListener;
import com.ardor3d.extension.ui.layout.AnchorLayout;
import com.ardor3d.extension.ui.layout.AnchorLayoutData;
import com.ardor3d.extension.ui.util.Alignment;
+import com.ardor3d.framework.CanvasRenderer;
import com.ardor3d.framework.NativeCanvas;
import com.ardor3d.light.DirectionalLight;
import com.ardor3d.math.ColorRGBA;
import com.ardor3d.math.Vector3;
import com.ardor3d.renderer.Camera;
+import com.ardor3d.renderer.RenderContext;
import com.ardor3d.renderer.Renderer;
import com.ardor3d.renderer.state.CullState;
import com.ardor3d.renderer.state.CullState.Face;
@@ -59,6 +62,8 @@ import com.ardor3d.scenegraph.Node;
import com.ardor3d.scenegraph.Spatial;
import com.ardor3d.scenegraph.hint.DataMode;
import com.ardor3d.scenegraph.visitor.Visitor;
+import com.ardor3d.util.GameTaskQueue;
+import com.ardor3d.util.GameTaskQueueManager;
import com.ardor3d.util.ReadOnlyTimer;
import com.ardor3d.util.geom.MeshCombiner;
import com.ardor3d.util.resource.ResourceLocatorTool;
@@ -98,7 +103,16 @@ public class AnimationStateExample extends ExampleBase {
@Override
protected void initExample() {
_canvas.setTitle("Ardor3D - Animation State Example");
- _canvas.getCanvasRenderer().getRenderer().setBackgroundColor(ColorRGBA.GRAY);
+ final CanvasRenderer canvasRenderer = _canvas.getCanvasRenderer();
+ final RenderContext renderContext = canvasRenderer.getRenderContext();
+ final Renderer renderer = canvasRenderer.getRenderer();
+ GameTaskQueueManager.getManager(renderContext).getQueue(GameTaskQueue.RENDER).enqueue(new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ renderer.setBackgroundColor(ColorRGBA.GRAY);
+ return null;
+ }
+ });
// set camera
final Camera cam = _canvas.getCanvasRenderer().getCamera();
@@ -201,9 +215,21 @@ public class AnimationStateExample extends ExampleBase {
});
basePanel.add(stopButton);
+ final UICheckBox resetAnimCheck = new UICheckBox("Reset Animation On Stop");
+ resetAnimCheck
+ .setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, stopButton, Alignment.BOTTOM_LEFT, 0, -5));
+ resetAnimCheck.setSelected(false);
+ resetAnimCheck.addActionListener(new ActionListener() {
+ public void actionPerformed(final ActionEvent event) {
+ manager.setResetClipsOnStop(resetAnimCheck.isSelected());
+
+ }
+ });
+ basePanel.add(resetAnimCheck);
+
final UICheckBox gpuSkinningCheck = new UICheckBox("Use GPU skinning");
- gpuSkinningCheck.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, stopButton, Alignment.BOTTOM_LEFT, 0,
- -5));
+ gpuSkinningCheck.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, resetAnimCheck, Alignment.BOTTOM_LEFT,
+ 0, -5));
gpuSkinningCheck.setSelected(false);
gpuSkinningCheck.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent event) {