From 27131024eed6e559c88d0f2c5858769814e73e42 Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Fri, 5 Oct 2012 15:36:53 +0000 Subject: [PATCH] Bugfix: in mirror modifier not all vertex indexes were properly inverted when object was smooth. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9836 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../blender/modifiers/MirrorModifier.java | 102 ++++++++++-------- 1 file changed, 55 insertions(+), 47 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 2e391d33c..0d82cce51 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 @@ -1,5 +1,18 @@ package com.jme3.scene.plugins.blender.modifiers; +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.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + import com.jme3.math.Vector3f; import com.jme3.scene.Geometry; import com.jme3.scene.Mesh; @@ -12,17 +25,6 @@ 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; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - /** * This modifier allows to array modifier to the object. * @@ -102,6 +104,7 @@ import java.util.logging.Logger; boolean mirrorV = (flag & 0x02) != 0; // boolean mirrorVGroup = (flag & 0x20) != 0; + Set modifiedIndexes = new HashSet(); List geometriesToAdd = new ArrayList(); for (int mirrorIndex = 0; mirrorIndex < 3; ++mirrorIndex) { if (mirrorFactor[mirrorIndex] == -1.0f) { @@ -119,45 +122,50 @@ import java.util.logging.Logger; FloatBuffer cloneNormals = clone.getFloatBuffer(Type.Normal); FloatBuffer cloneBindPoseNormals = clone.getFloatBuffer(Type.BindPoseNormal); Buffer cloneIndexes = clone.getBuffer(Type.Index).getData(); + + for (int i = 0; i < cloneIndexes.limit(); ++i) { + int index = cloneIndexes instanceof ShortBuffer ? ((ShortBuffer)cloneIndexes).get(i) : ((IntBuffer)cloneIndexes).get(i); + if(!modifiedIndexes.contains((int)index)) { + modifiedIndexes.add((int)index); + int valueIndex = index * 3 + mirrorIndex; + + float value = clonePosition.get(valueIndex); + float d = center[mirrorIndex] - value; - // modyfying data - for (int i = mirrorIndex; i < clonePosition.limit(); i += 3) { - float value = clonePosition.get(i); - float d = center[mirrorIndex] - value; - - if (Math.abs(d) <= tolerance) { - clonePosition.put(i, center[mirrorIndex]); - if(cloneBindPosePosition != null) { - cloneBindPosePosition.put(i, center[mirrorIndex]); + if (Math.abs(d) <= tolerance) { + clonePosition.put(valueIndex, center[mirrorIndex]); + if(cloneBindPosePosition != null) { + cloneBindPosePosition.put(valueIndex, center[mirrorIndex]); + } + position.put(valueIndex, center[mirrorIndex]); + if(bindPosePosition != null) { + bindPosePosition.put(valueIndex, center[mirrorIndex]); + } + } else { + clonePosition.put(valueIndex, value + 2.0f * d); + if(cloneBindPosePosition != null) { + cloneBindPosePosition.put(valueIndex, value + 2.0f * d); + } } - position.put(i, center[mirrorIndex]); - if(bindPosePosition != null) { - bindPosePosition.put(i, center[mirrorIndex]); + cloneNormals.put(valueIndex, -cloneNormals.get(valueIndex)); + if(cloneBindPoseNormals != null) { + cloneBindPoseNormals.put(valueIndex, -cloneNormals.get(valueIndex)); } - } else { - clonePosition.put(i, value + 2.0f * d); - if(cloneBindPosePosition != null) { - cloneBindPosePosition.put(i, value + 2.0f * d); - } - } - cloneNormals.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