Skip to content

Commit d8875a7

Browse files
committed
Convert Skeleton and Bone over to use the JME cloner system for cloning...
this should do automatic fix-up and hopefully make bones attachments work properly again in clones.
1 parent 07e2336 commit d8875a7

2 files changed

Lines changed: 50 additions & 3 deletions

File tree

jme3-core/src/main/java/com/jme3/animation/Bone.java

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import com.jme3.math.*;
3636
import com.jme3.scene.Node;
3737
import com.jme3.util.TempVars;
38+
import com.jme3.util.clone.JmeCloneable;
39+
import com.jme3.util.clone.Cloner;
3840
import java.io.IOException;
3941
import java.util.ArrayList;
4042

@@ -62,13 +64,13 @@
6264
* @author Kirill Vainer
6365
* @author Rémy Bouquet
6466
*/
65-
public final class Bone implements Savable {
67+
public final class Bone implements Savable, JmeCloneable {
6668

6769
// Version #2: Changed naming of transforms as they were misleading
6870
public static final int SAVABLE_VERSION = 2;
6971
private String name;
7072
private Bone parent;
71-
private final ArrayList<Bone> children = new ArrayList<Bone>();
73+
private ArrayList<Bone> children = new ArrayList<Bone>();
7274
/**
7375
* If enabled, user can control bone transform with setUserTransforms.
7476
* Animation transforms are not applied to this bone when enabled.
@@ -167,6 +169,43 @@ public Bone(String name) {
167169
*/
168170
public Bone() {
169171
}
172+
173+
@Override
174+
public Object jmeClone() {
175+
try {
176+
Bone clone = (Bone)super.clone();
177+
return clone;
178+
} catch (CloneNotSupportedException ex) {
179+
throw new AssertionError();
180+
}
181+
}
182+
183+
@Override
184+
public void cloneFields( Cloner cloner, Object original ) {
185+
186+
this.parent = cloner.clone(parent);
187+
this.children = cloner.clone(children);
188+
189+
this.attachNode = cloner.clone(attachNode);
190+
191+
this.bindPos = cloner.clone(bindPos);
192+
this.bindRot = cloner.clone(bindRot);
193+
this.bindScale = cloner.clone(bindScale);
194+
195+
this.modelBindInversePos = cloner.clone(modelBindInversePos);
196+
this.modelBindInverseRot = cloner.clone(modelBindInverseRot);
197+
this.modelBindInverseScale = cloner.clone(modelBindInverseScale);
198+
199+
this.localPos = cloner.clone(localPos);
200+
this.localRot = cloner.clone(localRot);
201+
this.localScale = cloner.clone(localScale);
202+
203+
this.modelPos = cloner.clone(modelPos);
204+
this.modelRot = cloner.clone(modelRot);
205+
this.modelScale = cloner.clone(modelScale);
206+
207+
this.tmpTransform = cloner.clone(tmpTransform);
208+
}
170209

171210
/**
172211
* Returns the name of the bone, set in the constructor.

jme3-core/src/main/java/com/jme3/animation/Skeleton.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,19 @@ public Skeleton() {
122122

123123
@Override
124124
public Object jmeClone() {
125-
return new Skeleton(this);
125+
try {
126+
Skeleton clone = (Skeleton)super.clone();
127+
return clone;
128+
} catch (CloneNotSupportedException ex) {
129+
throw new AssertionError();
130+
}
126131
}
127132

128133
@Override
129134
public void cloneFields( Cloner cloner, Object original ) {
135+
this.rootBones = cloner.clone(rootBones);
136+
this.boneList = cloner.clone(boneList);
137+
this.skinningMatrixes = cloner.clone(skinningMatrixes);
130138
}
131139

132140
private void createSkinningMatrices() {

0 commit comments

Comments
 (0)