Clone method added to BoneAnimation.
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7688 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
19403e5660
commit
38eb3de309
@ -36,6 +36,9 @@ import com.jme3.export.JmeImporter;
|
|||||||
import com.jme3.export.InputCapsule;
|
import com.jme3.export.InputCapsule;
|
||||||
import com.jme3.export.OutputCapsule;
|
import com.jme3.export.OutputCapsule;
|
||||||
import com.jme3.export.Savable;
|
import com.jme3.export.Savable;
|
||||||
|
import com.jme3.math.Quaternion;
|
||||||
|
import com.jme3.math.Vector3f;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
@ -45,7 +48,7 @@ import java.util.BitSet;
|
|||||||
*
|
*
|
||||||
* @author Kirill Vainer
|
* @author Kirill Vainer
|
||||||
*/
|
*/
|
||||||
public final class BoneAnimation implements Savable {
|
public final class BoneAnimation implements Savable, Cloneable {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private float length;
|
private float length;
|
||||||
@ -120,6 +123,41 @@ public final class BoneAnimation implements Savable {
|
|||||||
return "BoneAnim[name=" + name + ", length=" + length + "]";
|
return "BoneAnim[name=" + name + ", length=" + length + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BoneAnimation clone() {
|
||||||
|
BoneAnimation result;
|
||||||
|
try {
|
||||||
|
result = (BoneAnimation)super.clone();
|
||||||
|
} catch (CloneNotSupportedException e) {
|
||||||
|
result = new BoneAnimation(name, length);
|
||||||
|
}
|
||||||
|
if(result.tracks == null) {
|
||||||
|
result.tracks = new BoneTrack[tracks.length];
|
||||||
|
}
|
||||||
|
for (int i = 0; i < tracks.length; ++i) {
|
||||||
|
int tablesLength = tracks[i].getTimes().length;
|
||||||
|
|
||||||
|
float[] times = tracks[i].getTimes().clone();
|
||||||
|
Vector3f[] sourceTranslations = tracks[i].getTranslations();
|
||||||
|
Quaternion[] sourceRotations = tracks[i].getRotations();
|
||||||
|
Vector3f[] sourceScales = tracks[i].getScales();
|
||||||
|
|
||||||
|
Vector3f[] translations = new Vector3f[tablesLength];
|
||||||
|
Quaternion[] rotations = new Quaternion[tablesLength];
|
||||||
|
Vector3f[] scales = new Vector3f[tablesLength];
|
||||||
|
for (int j = 0; j < tablesLength; ++j) {
|
||||||
|
translations[j] = sourceTranslations[j].clone();
|
||||||
|
rotations[j] = sourceRotations[j].clone();
|
||||||
|
scales[j] = sourceScales != null ? sourceScales[j].clone() : new Vector3f(1.0f, 1.0f, 1.0f);
|
||||||
|
}
|
||||||
|
// times do not change, no need to clone them
|
||||||
|
result.tracks[i] = new BoneTrack(tracks[i].getTargetBoneIndex(), times,
|
||||||
|
translations, rotations, scales);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void write(JmeExporter e) throws IOException {
|
public void write(JmeExporter e) throws IOException {
|
||||||
OutputCapsule out = e.getCapsule(this);
|
OutputCapsule out = e.getCapsule(this);
|
||||||
out.write(name, "name", null);
|
out.write(name, "name", null);
|
||||||
@ -127,6 +165,7 @@ public final class BoneAnimation implements Savable {
|
|||||||
out.write(tracks, "tracks", null);
|
out.write(tracks, "tracks", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void read(JmeImporter i) throws IOException {
|
public void read(JmeImporter i) throws IOException {
|
||||||
InputCapsule in = i.getCapsule(this);
|
InputCapsule in = i.getCapsule(this);
|
||||||
name = in.readString("name", null);
|
name = in.readString("name", null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user