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. 102
      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) {
@ -119,45 +122,50 @@ import java.util.logging.Logger;
FloatBuffer cloneNormals = clone.getFloatBuffer(Type.Normal); FloatBuffer cloneNormals = clone.getFloatBuffer(Type.Normal);
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();
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 if (Math.abs(d) <= tolerance) {
for (int i = mirrorIndex; i < clonePosition.limit(); i += 3) { clonePosition.put(valueIndex, center[mirrorIndex]);
float value = clonePosition.get(i); if(cloneBindPosePosition != null) {
float d = center[mirrorIndex] - value; cloneBindPosePosition.put(valueIndex, center[mirrorIndex]);
}
if (Math.abs(d) <= tolerance) { position.put(valueIndex, center[mirrorIndex]);
clonePosition.put(i, center[mirrorIndex]); if(bindPosePosition != null) {
if(cloneBindPosePosition != null) { bindPosePosition.put(valueIndex, center[mirrorIndex]);
cloneBindPosePosition.put(i, 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]); cloneNormals.put(valueIndex, -cloneNormals.get(valueIndex));
if(bindPosePosition != null) { if(cloneBindPoseNormals != null) {
bindPosePosition.put(i, center[mirrorIndex]); cloneBindPoseNormals.put(valueIndex, -cloneNormals.get(valueIndex));
} }
} else { }
clonePosition.put(i, value + 2.0f * d); }
if(cloneBindPosePosition != null) { modifiedIndexes.clear();
cloneBindPosePosition.put(i, value + 2.0f * d);
} //flipping index order
} for (int i = 0; i < cloneIndexes.limit(); i += 3) {
cloneNormals.put(i, -cloneNormals.get(i)); if(cloneIndexes instanceof ShortBuffer) {
if(cloneBindPoseNormals != null) { short index = ((ShortBuffer)cloneIndexes).get(i + 2);
cloneBindPoseNormals.put(i, -cloneNormals.get(i)); ((ShortBuffer)cloneIndexes).put(i + 2, ((ShortBuffer)cloneIndexes).get(i + 1));
} ((ShortBuffer)cloneIndexes).put(i + 1, index);
} else {
//modifying clone indexes int index = ((IntBuffer)cloneIndexes).get(i + 2);
int vertexIndex = (i - mirrorIndex) / 3; ((IntBuffer)cloneIndexes).put(i + 2, ((IntBuffer)cloneIndexes).get(i + 1));
if (vertexIndex % 3 == 0 && vertexIndex<cloneIndexes.limit()) { ((IntBuffer)cloneIndexes).put(i + 1, index);
if(cloneIndexes instanceof ShortBuffer) { }
short index = ((ShortBuffer)cloneIndexes).get(vertexIndex + 2);
((ShortBuffer)cloneIndexes).put(vertexIndex + 2, ((ShortBuffer)cloneIndexes).get(vertexIndex + 1));
((ShortBuffer)cloneIndexes).put(vertexIndex + 1, index);
} else {
int index = ((IntBuffer)cloneIndexes).get(vertexIndex + 2);
((IntBuffer)cloneIndexes).put(vertexIndex + 2, ((IntBuffer)cloneIndexes).get(vertexIndex + 1));
((IntBuffer)cloneIndexes).put(vertexIndex + 1, index);
}
}
} }
if (mirrorU && clone.getBuffer(Type.TexCoord) != null) { if (mirrorU && clone.getBuffer(Type.TexCoord) != null) {

Loading…
Cancel
Save