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