parent
c769611f9f
commit
05e907acca
@ -1,108 +0,0 @@ |
||||
/* |
||||
* Copyright (c) 2009-2012 jMonkeyEngine |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* |
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
package com.jme3.anim; |
||||
|
||||
import com.jme3.export.*; |
||||
import com.jme3.math.*; |
||||
import com.jme3.util.clone.Cloner; |
||||
import com.jme3.util.clone.JmeCloneable; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
/** |
||||
* Contains a list of transforms and times for each keyframe. |
||||
* |
||||
* @author Rémy Bouquet |
||||
*/ |
||||
public final class JointTrack extends TransformTrack implements JmeCloneable, Savable { |
||||
|
||||
private Joint target; |
||||
|
||||
/** |
||||
* Serialization-only. Do not use. |
||||
*/ |
||||
public JointTrack() { |
||||
super(); |
||||
} |
||||
|
||||
/** |
||||
* Creates a joint track for the given joint index |
||||
* |
||||
* @param target The Joint target of this track |
||||
* @param times a float array with the time of each frame |
||||
* @param translations the translation of the bone for each frame |
||||
* @param rotations the rotation of the bone for each frame |
||||
* @param scales the scale of the bone for each frame |
||||
*/ |
||||
public JointTrack(Joint target, float[] times, Vector3f[] translations, Quaternion[] rotations, Vector3f[] scales) { |
||||
super(times, translations, rotations, scales); |
||||
this.target = target; |
||||
this.defaultTransform = target.getLocalTransform(); |
||||
} |
||||
|
||||
@Override |
||||
public boolean interpolate(double t) { |
||||
boolean running = super.interpolate(t); |
||||
Transform transform = getInterpolatedTransform(); |
||||
target.setLocalTransform(transform); |
||||
return running; |
||||
} |
||||
|
||||
public void setTarget(Joint target) { |
||||
this.target = target; |
||||
} |
||||
|
||||
@Override |
||||
public Object jmeClone() { |
||||
return super.clone(); |
||||
} |
||||
|
||||
@Override |
||||
public void cloneFields(Cloner cloner, Object original) { |
||||
this.target = cloner.clone(target); |
||||
} |
||||
|
||||
@Override |
||||
public void write(JmeExporter ex) throws IOException { |
||||
super.write(ex); |
||||
OutputCapsule oc = ex.getCapsule(this); |
||||
oc.write(target, "target", null); |
||||
} |
||||
|
||||
@Override |
||||
public void read(JmeImporter im) throws IOException { |
||||
super.read(im); |
||||
InputCapsule ic = im.getCapsule(this); |
||||
target = (Joint) ic.readSavable("target", null); |
||||
} |
||||
|
||||
} |
@ -1,111 +0,0 @@ |
||||
/* |
||||
* Copyright (c) 2009-2012 jMonkeyEngine |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* |
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
package com.jme3.anim; |
||||
|
||||
import com.jme3.export.*; |
||||
import com.jme3.math.*; |
||||
import com.jme3.scene.Spatial; |
||||
import com.jme3.util.clone.Cloner; |
||||
import com.jme3.util.clone.JmeCloneable; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
/** |
||||
* Contains a list of transforms and times for each keyframe. |
||||
* |
||||
* @author Rémy Bouquet |
||||
*/ |
||||
public final class SpatialTrack extends TransformTrack implements JmeCloneable, Savable { |
||||
|
||||
private Spatial target; |
||||
|
||||
/** |
||||
* Serialization-only. Do not use. |
||||
*/ |
||||
public SpatialTrack() { |
||||
super(); |
||||
} |
||||
|
||||
/** |
||||
* Creates a spatial track for the given Spatial |
||||
* |
||||
* @param target The Spatial target of this track |
||||
* @param times a float array with the time of each frame |
||||
* @param translations the translation of the bone for each frame |
||||
* @param rotations the rotation of the bone for each frame |
||||
* @param scales the scale of the bone for each frame |
||||
*/ |
||||
public SpatialTrack(Spatial target, float[] times, Vector3f[] translations, Quaternion[] rotations, Vector3f[] scales) { |
||||
super(times, translations, rotations, scales); |
||||
this.target = target; |
||||
defaultTransform = target.getLocalTransform(); |
||||
} |
||||
|
||||
@Override |
||||
public boolean interpolate(double t) { |
||||
|
||||
boolean running = super.interpolate(t); |
||||
Transform transform = getInterpolatedTransform(); |
||||
target.setLocalTransform(transform); |
||||
return running; |
||||
} |
||||
|
||||
public void setTarget(Spatial target) { |
||||
this.target = target; |
||||
} |
||||
|
||||
@Override |
||||
public Object jmeClone() { |
||||
return super.clone(); |
||||
} |
||||
|
||||
@Override |
||||
public void cloneFields(Cloner cloner, Object original) { |
||||
|
||||
this.target = cloner.clone(target); |
||||
} |
||||
|
||||
@Override |
||||
public void write(JmeExporter ex) throws IOException { |
||||
super.write(ex); |
||||
OutputCapsule oc = ex.getCapsule(this); |
||||
oc.write(target, "target", null); |
||||
} |
||||
|
||||
@Override |
||||
public void read(JmeImporter im) throws IOException { |
||||
super.read(im); |
||||
InputCapsule ic = im.getCapsule(this); |
||||
target = (Spatial) ic.readSavable("target", null); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,99 @@ |
||||
package com.jme3.anim.tween; |
||||
|
||||
import com.jme3.anim.AnimClip; |
||||
import com.jme3.anim.TransformTrack; |
||||
import com.jme3.anim.tween.action.Action; |
||||
import com.jme3.anim.util.HasLocalTransform; |
||||
import com.jme3.anim.util.Weighted; |
||||
import com.jme3.export.InputCapsule; |
||||
import com.jme3.export.JmeExporter; |
||||
import com.jme3.export.JmeImporter; |
||||
import com.jme3.export.OutputCapsule; |
||||
import com.jme3.math.Transform; |
||||
import com.jme3.util.clone.Cloner; |
||||
import com.jme3.util.clone.JmeCloneable; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
public class AnimClipTween implements Tween, Weighted, JmeCloneable { |
||||
|
||||
private AnimClip clip; |
||||
private Transform transform = new Transform(); |
||||
private float weight = 1f; |
||||
private Action parentAction; |
||||
|
||||
public AnimClipTween() { |
||||
} |
||||
|
||||
public AnimClipTween(AnimClip clip) { |
||||
this.clip = clip; |
||||
} |
||||
|
||||
@Override |
||||
public double getLength() { |
||||
return clip.getLength(); |
||||
} |
||||
|
||||
@Override |
||||
public boolean interpolate(double t) { |
||||
// Sanity check the inputs
|
||||
if (t < 0) { |
||||
return true; |
||||
} |
||||
if (parentAction != null) { |
||||
weight = parentAction.getWeightForTween(this); |
||||
} |
||||
TransformTrack[] tracks = clip.getTracks(); |
||||
for (TransformTrack track : tracks) { |
||||
HasLocalTransform target = track.getTarget(); |
||||
transform.set(target.getLocalTransform()); |
||||
track.getTransformAtTime(t, transform); |
||||
|
||||
if (weight == 1f) { |
||||
target.setLocalTransform(transform); |
||||
} else { |
||||
Transform tr = target.getLocalTransform(); |
||||
tr.interpolateTransforms(tr, transform, weight); |
||||
target.setLocalTransform(tr); |
||||
} |
||||
} |
||||
return t < clip.getLength(); |
||||
} |
||||
|
||||
@Override |
||||
public void write(JmeExporter ex) throws IOException { |
||||
OutputCapsule oc = ex.getCapsule(this); |
||||
oc.write(clip, "clip", null); |
||||
} |
||||
|
||||
@Override |
||||
public void read(JmeImporter im) throws IOException { |
||||
InputCapsule ic = im.getCapsule(this); |
||||
clip = (AnimClip) ic.readSavable("clip", null); |
||||
} |
||||
|
||||
@Override |
||||
public Object jmeClone() { |
||||
try { |
||||
AnimClipTween clone = (AnimClipTween) super.clone(); |
||||
return clone; |
||||
} catch (CloneNotSupportedException ex) { |
||||
throw new AssertionError(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void cloneFields(Cloner cloner, Object original) { |
||||
clip = cloner.clone(clip); |
||||
} |
||||
|
||||
// @Override
|
||||
// public void setWeight(float weight) {
|
||||
// this.weight = weight;
|
||||
// }
|
||||
|
||||
@Override |
||||
public void setParentAction(Action action) { |
||||
this.parentAction = action; |
||||
} |
||||
} |
@ -0,0 +1,64 @@ |
||||
package com.jme3.anim.tween.action; |
||||
|
||||
import com.jme3.anim.tween.Tween; |
||||
import com.jme3.anim.util.Weighted; |
||||
import com.jme3.export.InputCapsule; |
||||
import com.jme3.export.JmeExporter; |
||||
import com.jme3.export.JmeImporter; |
||||
import com.jme3.export.OutputCapsule; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
public abstract class Action implements Tween, Weighted { |
||||
|
||||
protected Tween[] tweens; |
||||
protected float weight = 1; |
||||
protected double length; |
||||
protected Action parentAction; |
||||
|
||||
protected Action(Tween... tweens) { |
||||
this.tweens = tweens; |
||||
for (Tween tween : tweens) { |
||||
if (tween instanceof Weighted) { |
||||
((Weighted) tween).setParentAction(this); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public double getLength() { |
||||
return length; |
||||
} |
||||
|
||||
@Override |
||||
public boolean interpolate(double t) { |
||||
if (parentAction != null) { |
||||
weight = parentAction.getWeightForTween(this); |
||||
} |
||||
|
||||
return doInterpolate(t); |
||||
} |
||||
|
||||
public abstract float getWeightForTween(Tween tween); |
||||
|
||||
public abstract boolean doInterpolate(double t); |
||||
|
||||
public abstract void reset(); |
||||
|
||||
@Override |
||||
public void setParentAction(Action parentAction) { |
||||
this.parentAction = parentAction; |
||||
} |
||||
|
||||
@Override |
||||
public void read(JmeImporter im) throws IOException { |
||||
InputCapsule ic = im.getCapsule(this); |
||||
tweens = (Tween[]) ic.readSavableArray("tweens", null); |
||||
} |
||||
|
||||
@Override |
||||
public void write(JmeExporter ex) throws IOException { |
||||
OutputCapsule oc = ex.getCapsule(this); |
||||
oc.write(tweens, "tweens", null); |
||||
} |
||||
} |
@ -0,0 +1,75 @@ |
||||
package com.jme3.anim.tween.action; |
||||
|
||||
import com.jme3.anim.tween.AbstractTween; |
||||
import com.jme3.anim.tween.Tween; |
||||
|
||||
public class SequenceAction extends Action { |
||||
|
||||
private int currentIndex = 0; |
||||
private double accumTime; |
||||
private double transitionTime = 0; |
||||
private float mainWeight = 1.0f; |
||||
private double transitionLength = 0.4f; |
||||
private TransitionTween transition = new TransitionTween(transitionLength); |
||||
|
||||
|
||||
public SequenceAction(Tween... tweens) { |
||||
super(tweens); |
||||
for (Tween tween : tweens) { |
||||
length += tween.getLength(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public float getWeightForTween(Tween tween) { |
||||
return weight * mainWeight; |
||||
} |
||||
|
||||
@Override |
||||
public boolean doInterpolate(double t) { |
||||
Tween currentTween = tweens[currentIndex]; |
||||
if (transition.getLength() > currentTween.getLength()) { |
||||
transition.setLength(currentTween.getLength()); |
||||
} |
||||
|
||||
transition.interpolate(t - transitionTime); |
||||
|
||||
boolean running = currentTween.interpolate(t - accumTime); |
||||
if (!running) { |
||||
accumTime += currentTween.getLength(); |
||||
currentIndex++; |
||||
transitionTime = accumTime; |
||||
transition.setLength(transitionLength); |
||||
} |
||||
|
||||
if (t >= length) { |
||||
reset(); |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
public void reset() { |
||||
currentIndex = 0; |
||||
accumTime = 0; |
||||
transitionTime = 0; |
||||
mainWeight = 1; |
||||
} |
||||
|
||||
public void setTransitionLength(double transitionLength) { |
||||
this.transitionLength = transitionLength; |
||||
} |
||||
|
||||
private class TransitionTween extends AbstractTween { |
||||
|
||||
|
||||
public TransitionTween(double length) { |
||||
super(length); |
||||
} |
||||
|
||||
@Override |
||||
protected void doInterpolate(double t) { |
||||
mainWeight = (float) t; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,10 @@ |
||||
package com.jme3.anim.util; |
||||
|
||||
import com.jme3.export.Savable; |
||||
import com.jme3.math.Transform; |
||||
|
||||
public interface HasLocalTransform extends Savable { |
||||
public void setLocalTransform(Transform transform); |
||||
|
||||
public Transform getLocalTransform(); |
||||
} |
@ -0,0 +1,11 @@ |
||||
package com.jme3.anim.util; |
||||
|
||||
import com.jme3.anim.tween.action.Action; |
||||
import com.jme3.math.Transform; |
||||
|
||||
public interface Weighted { |
||||
|
||||
// public void setWeight(float weight);
|
||||
|
||||
public void setParentAction(Action action); |
||||
} |
Loading…
Reference in new issue