implement JmeCloneable to simplify BoneTrack cloning, set a good example
This commit is contained in:
parent
8a3d628263
commit
4b68a4c9dc
@ -35,6 +35,8 @@ import com.jme3.export.*;
|
|||||||
import com.jme3.math.Quaternion;
|
import com.jme3.math.Quaternion;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
import com.jme3.util.TempVars;
|
import com.jme3.util.TempVars;
|
||||||
|
import com.jme3.util.clone.Cloner;
|
||||||
|
import com.jme3.util.clone.JmeCloneable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
@ -43,7 +45,7 @@ import java.util.BitSet;
|
|||||||
*
|
*
|
||||||
* @author Kirill Vainer
|
* @author Kirill Vainer
|
||||||
*/
|
*/
|
||||||
public final class BoneTrack implements Track {
|
public final class BoneTrack implements JmeCloneable, Track {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bone index in the skeleton which this track affects.
|
* Bone index in the skeleton which this track affects.
|
||||||
@ -274,29 +276,44 @@ public final class BoneTrack implements Track {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method creates a clone of the current object.
|
* Create a deep clone of this track.
|
||||||
* @return a clone of the current object
|
*
|
||||||
|
* @return a new track
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public BoneTrack clone() {
|
public BoneTrack clone() {
|
||||||
int tablesLength = times.length;
|
return Cloner.deepClone(this);
|
||||||
|
}
|
||||||
|
|
||||||
float[] times = this.times.clone();
|
/**
|
||||||
Vector3f[] sourceTranslations = this.getTranslations();
|
* Create a shallow clone for the JME cloner.
|
||||||
Quaternion[] sourceRotations = this.getRotations();
|
*
|
||||||
Vector3f[] sourceScales = this.getScales();
|
* @return a new track
|
||||||
|
*/
|
||||||
Vector3f[] translations = new Vector3f[tablesLength];
|
@Override
|
||||||
Quaternion[] rotations = new Quaternion[tablesLength];
|
public BoneTrack jmeClone() {
|
||||||
Vector3f[] scales = new Vector3f[tablesLength];
|
try {
|
||||||
for (int i = 0; i < tablesLength; ++i) {
|
return (BoneTrack) super.clone();
|
||||||
translations[i] = sourceTranslations[i].clone();
|
} catch (CloneNotSupportedException exception) {
|
||||||
rotations[i] = sourceRotations[i].clone();
|
throw new RuntimeException("Can't clone track", exception);
|
||||||
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 BoneTrack(targetBoneIndex, times, translations, rotations, scales);
|
* Callback from {@link com.jme3.util.clone.Cloner} to convert this
|
||||||
|
* shallow-cloned track into a deep-cloned one, using the specified cloner
|
||||||
|
* to resolve copied fields.
|
||||||
|
*
|
||||||
|
* @param cloner the cloner currently cloning this control (not null)
|
||||||
|
* @param original the track from which this track was shallow-cloned
|
||||||
|
* (unused)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void cloneFields(Cloner cloner, Object original) {
|
||||||
|
translations = cloner.clone(translations);
|
||||||
|
rotations = cloner.clone(rotations);
|
||||||
|
scales = cloner.clone(scales);
|
||||||
|
times = cloner.clone(times);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user