4444import com .jme3 .renderer .Camera ;
4545import com .jme3 .scene .VertexBuffer .Type ;
4646import com .jme3 .util .clone .Cloner ;
47+ import com .jme3 .util .clone .IdentityCloneFunction ;
4748import com .jme3 .util .TempVars ;
4849import java .io .IOException ;
4950import java .util .Queue ;
@@ -492,6 +493,13 @@ public boolean isBatched() {
492493 */
493494 @ Override
494495 public Geometry clone (boolean cloneMaterial ) {
496+ return (Geometry )super .clone (cloneMaterial );
497+ }
498+
499+ /**
500+ * The old clone() method that did not use the new Cloner utility.
501+ */
502+ public Geometry oldClone (boolean cloneMaterial ) {
495503 Geometry geomClone = (Geometry ) super .clone (cloneMaterial );
496504
497505 // This geometry is managed,
@@ -535,6 +543,10 @@ public Geometry clone() {
535543 */
536544 @ Override
537545 public Spatial deepClone () {
546+ return super .deepClone ();
547+ }
548+
549+ public Spatial oldDeepClone () {
538550 Geometry geomClone = clone (true );
539551 geomClone .mesh = mesh .deepClone ();
540552 return geomClone ;
@@ -545,9 +557,42 @@ public Spatial deepClone() {
545557 */
546558 @ Override
547559 public void cloneFields ( Cloner cloner , Object original ) {
548- this .mesh = cloner .clone (mesh );
560+ super .cloneFields (cloner , original );
561+
562+ // If this is a grouped node and if our group node is
563+ // also cloned then we'll grab it's reference.
564+ if ( groupNode != null ) {
565+ if ( cloner .isCloned (groupNode ) ) {
566+ // Then resolve the reference
567+ this .groupNode = cloner .clone (groupNode );
568+ } else {
569+ // We are on our own now
570+ this .groupNode = null ;
571+ this .startIndex = -1 ;
572+ }
573+
574+ // The above is based on the fact that if we were
575+ // cloning the hierarchy that contained the parent
576+ // group then it would have been shallow cloned before
577+ // this child. Can't really be otherwise.
578+ }
579+
580+ this .cachedWorldMat = cloner .clone (cachedWorldMat );
581+
582+ // See if we are doing a shallow clone or a deep mesh clone
583+ boolean shallowClone = (cloner .getCloneFunction (Mesh .class ) instanceof IdentityCloneFunction );
584+
585+ // See if we clone the mesh using the special animation
586+ // semi-deep cloning
587+ if ( shallowClone && mesh != null && mesh .getBuffer (Type .BindPosePosition ) != null ) {
588+ // Then we need to clone the mesh a little deeper
589+ this .mesh = mesh .cloneForAnim ();
590+ } else {
591+ // Do whatever the cloner wants to do about it
592+ this .mesh = cloner .clone (mesh );
593+ }
594+
549595 this .material = cloner .clone (material );
550- this .groupNode = cloner .clone (groupNode );
551596 }
552597
553598 @ Override
0 commit comments