From 21809776dc9b6dac441b06ac901f0fb3454f964d Mon Sep 17 00:00:00 2001 From: "bre..ns" Date: Tue, 8 Nov 2011 04:29:22 +0000 Subject: [PATCH] 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 --- .../core/com/jme3/animation/SpatialTrack.java | 80 ++++++++++--------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/engine/src/core/com/jme3/animation/SpatialTrack.java b/engine/src/core/com/jme3/animation/SpatialTrack.java index c839ecb67..ff29000f5 100644 --- a/engine/src/core/com/jme3/animation/SpatialTrack.java +++ b/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,14 +80,18 @@ public class SpatialTrack implements Track { int lastFrame = times.length - 1; if (time < 0 || lastFrame == 0) { - rotations.get(0, tempQ); - translations.get(0, tempV); + 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]) { - rotations.get(lastFrame, tempQ); - translations.get(lastFrame, tempV); + if (rotations != null) + rotations.get(lastFrame, tempQ); + if (translations != null) + translations.get(lastFrame, tempV); if (scales != null) { scales.get(lastFrame, tempS); } @@ -101,13 +106,17 @@ public class SpatialTrack implements Track { float blend = (time - times[startFrame]) / (times[endFrame] - times[startFrame]); - rotations.get(startFrame, tempQ); - translations.get(startFrame, tempV); + if (rotations != null) + rotations.get(startFrame, tempQ); + if (translations != null) + translations.get(startFrame, tempV); if (scales != null) { scales.get(startFrame, tempS); } - rotations.get(endFrame, tempQ2); - translations.get(endFrame, tempV2); + if (rotations != null) + rotations.get(endFrame, tempQ2); + if (translations != null) + translations.get(endFrame, tempV2); if (scales != null) { scales.get(endFrame, tempS2); } @@ -116,8 +125,10 @@ public class SpatialTrack implements Track { tempS.interpolate(tempS2, blend); } - spatial.setLocalTranslation(tempV); - spatial.setLocalRotation(tempQ); + 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; - this.translations = new CompactVector3Array(); - this.translations.add(translations); - this.translations.freeze(); - this.rotations = new CompactQuaternionArray(); - this.rotations.add(rotations); - this.rotations.freeze(); - + 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(); - - 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); - } + 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); + //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