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
3.0
Kae..pl 12 years ago
parent 1ee8375d82
commit 27131024ee
  1. 72
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java

@ -1,5 +1,18 @@
package com.jme3.scene.plugins.blender.modifiers; 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.math.Vector3f;
import com.jme3.scene.Geometry; import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh; 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.file.Structure;
import com.jme3.scene.plugins.blender.objects.ObjectHelper; 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. * This modifier allows to array modifier to the object.
* *
@ -102,6 +104,7 @@ import java.util.logging.Logger;
boolean mirrorV = (flag & 0x02) != 0; boolean mirrorV = (flag & 0x02) != 0;
// boolean mirrorVGroup = (flag & 0x20) != 0; // boolean mirrorVGroup = (flag & 0x20) != 0;
Set<Integer> modifiedIndexes = new HashSet<Integer>();
List<Geometry> geometriesToAdd = new ArrayList<Geometry>(); List<Geometry> geometriesToAdd = new ArrayList<Geometry>();
for (int mirrorIndex = 0; mirrorIndex < 3; ++mirrorIndex) { for (int mirrorIndex = 0; mirrorIndex < 3; ++mirrorIndex) {
if (mirrorFactor[mirrorIndex] == -1.0f) { if (mirrorFactor[mirrorIndex] == -1.0f) {
@ -120,43 +123,48 @@ import java.util.logging.Logger;
FloatBuffer cloneBindPoseNormals = clone.getFloatBuffer(Type.BindPoseNormal); FloatBuffer cloneBindPoseNormals = clone.getFloatBuffer(Type.BindPoseNormal);
Buffer cloneIndexes = clone.getBuffer(Type.Index).getData(); Buffer cloneIndexes = clone.getBuffer(Type.Index).getData();
// modyfying data for (int i = 0; i < cloneIndexes.limit(); ++i) {
for (int i = mirrorIndex; i < clonePosition.limit(); i += 3) { int index = cloneIndexes instanceof ShortBuffer ? ((ShortBuffer)cloneIndexes).get(i) : ((IntBuffer)cloneIndexes).get(i);
float value = clonePosition.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; float d = center[mirrorIndex] - value;
if (Math.abs(d) <= tolerance) { if (Math.abs(d) <= tolerance) {
clonePosition.put(i, center[mirrorIndex]); clonePosition.put(valueIndex, center[mirrorIndex]);
if(cloneBindPosePosition != null) { if(cloneBindPosePosition != null) {
cloneBindPosePosition.put(i, center[mirrorIndex]); cloneBindPosePosition.put(valueIndex, center[mirrorIndex]);
} }
position.put(i, center[mirrorIndex]); position.put(valueIndex, center[mirrorIndex]);
if(bindPosePosition != null) { if(bindPosePosition != null) {
bindPosePosition.put(i, center[mirrorIndex]); bindPosePosition.put(valueIndex, center[mirrorIndex]);
} }
} else { } else {
clonePosition.put(i, value + 2.0f * d); clonePosition.put(valueIndex, value + 2.0f * d);
if(cloneBindPosePosition != null) { if(cloneBindPosePosition != null) {
cloneBindPosePosition.put(i, value + 2.0f * d); cloneBindPosePosition.put(valueIndex, value + 2.0f * d);
} }
} }
cloneNormals.put(i, -cloneNormals.get(i)); cloneNormals.put(valueIndex, -cloneNormals.get(valueIndex));
if(cloneBindPoseNormals != null) { if(cloneBindPoseNormals != null) {
cloneBindPoseNormals.put(i, -cloneNormals.get(i)); cloneBindPoseNormals.put(valueIndex, -cloneNormals.get(valueIndex));
} }
}
}
modifiedIndexes.clear();
//modifying clone indexes //flipping index order
int vertexIndex = (i - mirrorIndex) / 3; for (int i = 0; i < cloneIndexes.limit(); i += 3) {
if (vertexIndex % 3 == 0 && vertexIndex<cloneIndexes.limit()) {
if(cloneIndexes instanceof ShortBuffer) { if(cloneIndexes instanceof ShortBuffer) {
short index = ((ShortBuffer)cloneIndexes).get(vertexIndex + 2); short index = ((ShortBuffer)cloneIndexes).get(i + 2);
((ShortBuffer)cloneIndexes).put(vertexIndex + 2, ((ShortBuffer)cloneIndexes).get(vertexIndex + 1)); ((ShortBuffer)cloneIndexes).put(i + 2, ((ShortBuffer)cloneIndexes).get(i + 1));
((ShortBuffer)cloneIndexes).put(vertexIndex + 1, index); ((ShortBuffer)cloneIndexes).put(i + 1, index);
} else { } else {
int index = ((IntBuffer)cloneIndexes).get(vertexIndex + 2); int index = ((IntBuffer)cloneIndexes).get(i + 2);
((IntBuffer)cloneIndexes).put(vertexIndex + 2, ((IntBuffer)cloneIndexes).get(vertexIndex + 1)); ((IntBuffer)cloneIndexes).put(i + 2, ((IntBuffer)cloneIndexes).get(i + 1));
((IntBuffer)cloneIndexes).put(vertexIndex + 1, index); ((IntBuffer)cloneIndexes).put(i + 1, index);
}
} }
} }

Loading…
Cancel
Save