From 5635bc2ff1e937117e4f44fdcd9eaf42d70262f4 Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Sat, 15 Sep 2012 13:49:34 +0000 Subject: [PATCH] Geometry : fixed an issue where batching information were copied over cloning causing problem because the cloned geometry was marked as batched but was not. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9731 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- engine/src/core/com/jme3/scene/Geometry.java | 29 ++++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/engine/src/core/com/jme3/scene/Geometry.java b/engine/src/core/com/jme3/scene/Geometry.java index ee07711c8..ca957fc1b 100644 --- a/engine/src/core/com/jme3/scene/Geometry.java +++ b/engine/src/core/com/jme3/scene/Geometry.java @@ -62,7 +62,6 @@ public class Geometry extends Spatial { // Version #1: removed shared meshes. // models loaded with shared mesh will be automatically fixed. public static final int SAVABLE_VERSION = 1; - private static final Logger logger = Logger.getLogger(Geometry.class.getName()); protected Mesh mesh; protected transient int lodLevel = 0; @@ -323,25 +322,27 @@ public class Geometry extends Spatial { prevBatchTransforms = null; cachedOffsetMat = null; //once the geometry is removed from the screnegraph the batchNode needs to be rebatched. - this.batchNode.setNeedsFullRebatch(true); - this.batchNode = null; + if (batchNode != null) { + this.batchNode.setNeedsFullRebatch(true); + this.batchNode = null; + } setCullHint(CullHint.Dynamic); } @Override - public boolean removeFromParent() { + public boolean removeFromParent() { return super.removeFromParent(); } @Override protected void setParent(Node parent) { super.setParent(parent); - //if the geometry is batched we also have to unbatch it - if(parent==null && isBatched()){ - unBatch(); + //if the geometry is batched we also have to unbatch it + if (parent == null && isBatched()) { + unBatch(); } } - + /** * Recomputes the cached offset matrix used when the geometry is batched * */ @@ -384,7 +385,6 @@ public class Geometry extends Spatial { // refreshFlags |= RF_TRANSFORM; // setBoundRefresh(); // } - /** * Recomputes the matrix returned by {@link Geometry#getWorldMatrix() }. * This will require a localized transform update for this geometry. @@ -484,6 +484,11 @@ public class Geometry extends Spatial { @Override public Geometry clone(boolean cloneMaterial) { Geometry geomClone = (Geometry) super.clone(cloneMaterial); + //this geometry is batched but the clonned one should not be + if (isBatched()) { + geomClone.batchNode = null; + geomClone.unBatch(); + } geomClone.cachedWorldMat = cachedWorldMat.clone(); if (material != null) { if (cloneMaterial) { @@ -559,11 +564,11 @@ public class Geometry extends Spatial { material = (Material) ic.readSavable("material", null); } ignoreTransform = ic.readBoolean("ignoreTransform", false); - - if (ic.getSavableVersion(Geometry.class) == 0){ + + if (ic.getSavableVersion(Geometry.class) == 0) { // Fix shared mesh (if set) Mesh sharedMesh = getUserData(UserData.JME_SHAREDMESH); - if (sharedMesh != null){ + if (sharedMesh != null) { getMesh().extractVertexData(sharedMesh); } }