allow empty keyframe sets (rotation, translation) to be supplied to SpatialTrack

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8595 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
bre..ns 13 years ago
parent de75b794c2
commit 21809776dc
  1. 46
      engine/src/core/com/jme3/animation/SpatialTrack.java

@ -10,6 +10,7 @@ import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Spatial;
import com.jme3.util.TempVars;
import java.util.Arrays;
/**
* This class represents the track for spatial animation.
@ -79,13 +80,17 @@ public class SpatialTrack implements Track {
int lastFrame = times.length - 1;
if (time < 0 || lastFrame == 0) {
if (rotations != null)
rotations.get(0, tempQ);
if (translations != null)
translations.get(0, tempV);
if (scales != null) {
scales.get(0, tempS);
}
} else if (time >= times[lastFrame]) {
if (rotations != null)
rotations.get(lastFrame, tempQ);
if (translations != null)
translations.get(lastFrame, tempV);
if (scales != null) {
scales.get(lastFrame, tempS);
@ -101,12 +106,16 @@ public class SpatialTrack implements Track {
float blend = (time - times[startFrame]) / (times[endFrame] - times[startFrame]);
if (rotations != null)
rotations.get(startFrame, tempQ);
if (translations != null)
translations.get(startFrame, tempV);
if (scales != null) {
scales.get(startFrame, tempS);
}
if (rotations != null)
rotations.get(endFrame, tempQ2);
if (translations != null)
translations.get(endFrame, tempV2);
if (scales != null) {
scales.get(endFrame, tempS2);
@ -116,7 +125,9 @@ public class SpatialTrack implements Track {
tempS.interpolate(tempS2, blend);
}
if (translations != null)
spatial.setLocalTranslation(tempV);
if (rotations != null)
spatial.setLocalRotation(tempQ);
if (scales != null) {
spatial.setLocalScale(tempS);
@ -141,25 +152,24 @@ public class SpatialTrack implements Track {
throw new RuntimeException("BoneTrack with no keyframes!");
}
assert times.length == translations.length
&& times.length == rotations.length;
this.times = times;
if (translations != null) {
assert times.length == translations.length;
this.translations = new CompactVector3Array();
this.translations.add(translations);
this.translations.freeze();
}
if (rotations != null) {
assert times.length == rotations.length;
this.rotations = new CompactQuaternionArray();
this.rotations.add(rotations);
this.rotations.freeze();
}
if (scales != null) {
assert times.length == scales.length;
this.scales = new CompactVector3Array();
this.scales.add(scales);
this.scales.freeze();
}
}
@ -167,7 +177,7 @@ public class SpatialTrack implements Track {
* @return the array of rotations of this track
*/
public Quaternion[] getRotations() {
return rotations.toObjectArray();
return rotations == null ? null : rotations.toObjectArray();
}
/**
@ -188,7 +198,7 @@ public class SpatialTrack implements Track {
* @return the array of translations of this track
*/
public Vector3f[] getTranslations() {
return translations.toObjectArray();
return translations == null ? null : translations.toObjectArray();
}
/**
@ -206,21 +216,13 @@ public class SpatialTrack implements Track {
public SpatialTrack clone() {
int tablesLength = times.length;
float[] times = this.times.clone();
Vector3f[] sourceTranslations = this.getTranslations();
Quaternion[] sourceRotations = this.getRotations();
Vector3f[] sourceScales = this.getScales();
float[] timesCopy = this.times.clone();
Vector3f[] translationsCopy = this.getTranslations() == null ? null : Arrays.copyOf(this.getTranslations(), tablesLength);
Quaternion[] rotationsCopy = this.getRotations() == null ? null : Arrays.copyOf(this.getRotations(), tablesLength);
Vector3f[] scalesCopy = this.getScales() == null ? null : Arrays.copyOf(this.getScales(), tablesLength);
Vector3f[] translations = new Vector3f[tablesLength];
Quaternion[] rotations = new Quaternion[tablesLength];
Vector3f[] scales = new Vector3f[tablesLength];
for (int i = 0; i < tablesLength; ++i) {
translations[i] = sourceTranslations[i].clone();
rotations[i] = sourceRotations[i].clone();
scales[i] = sourceScales != null ? sourceScales[i].clone() : new Vector3f(1.0f, 1.0f, 1.0f);
}
//need to use the constructor here because of the final fields used in this class
return new SpatialTrack(times, translations, rotations, scales);
return new SpatialTrack(timesCopy, translationsCopy, rotationsCopy, scalesCopy);
}
@Override

Loading…
Cancel
Save