From 1d767981eed4ef6b748492ffc2f6beed80f0ab27 Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Mon, 25 Jun 2012 20:39:07 +0000 Subject: [PATCH] Fixes for mirror modifier (fixing several NPE that occured when model hed no binging or UV buffers, and fixing ClassCastException when model was small and ShorBuffer instead of IntBuffer was used for vertex indexing). git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9523 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../blender/modifiers/MirrorModifier.java | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java index d44147666..bf8d91810 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java @@ -11,8 +11,11 @@ import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.file.Pointer; import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.objects.ObjectHelper; + +import java.nio.Buffer; import java.nio.FloatBuffer; import java.nio.IntBuffer; +import java.nio.ShortBuffer; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -110,7 +113,7 @@ import java.util.logging.Logger; FloatBuffer cloneBindPosePosition = clone.getFloatBuffer(Type.BindPosePosition); FloatBuffer cloneNormals = clone.getFloatBuffer(Type.Normal); FloatBuffer cloneBindPoseNormals = clone.getFloatBuffer(Type.BindPoseNormal); - IntBuffer cloneIndexes = (IntBuffer) clone.getBuffer(Type.Index).getData(); + Buffer cloneIndexes = clone.getBuffer(Type.Index).getData(); // modyfying data for (int i = mirrorIndex; i < clonePosition.limit(); i += 3) { @@ -119,32 +122,46 @@ import java.util.logging.Logger; if (Math.abs(d) <= tolerance) { clonePosition.put(i, center[mirrorIndex]); - cloneBindPosePosition.put(i, center[mirrorIndex]); + if(cloneBindPosePosition != null) { + cloneBindPosePosition.put(i, center[mirrorIndex]); + } position.put(i, center[mirrorIndex]); - bindPosePosition.put(i, center[mirrorIndex]); + if(bindPosePosition != null) { + bindPosePosition.put(i, center[mirrorIndex]); + } } else { clonePosition.put(i, value + 2.0f * d); - cloneBindPosePosition.put(i, value + 2.0f * d); + if(cloneBindPosePosition != null) { + cloneBindPosePosition.put(i, value + 2.0f * d); + } } cloneNormals.put(i, -cloneNormals.get(i)); - cloneBindPoseNormals.put(i, -cloneNormals.get(i)); - + if(cloneBindPoseNormals != null) { + cloneBindPoseNormals.put(i, -cloneNormals.get(i)); + } + //modifying clone indexes int vertexIndex = (i - mirrorIndex) / 3; if (vertexIndex % 3 == 0 && vertexIndex