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
3.0
Kae..pl 13 years ago
parent a6d42c21bb
commit 1d767981ee
  1. 39
      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.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.FloatBuffer;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -110,7 +113,7 @@ import java.util.logging.Logger;
FloatBuffer cloneBindPosePosition = clone.getFloatBuffer(Type.BindPosePosition); FloatBuffer cloneBindPosePosition = clone.getFloatBuffer(Type.BindPosePosition);
FloatBuffer cloneNormals = clone.getFloatBuffer(Type.Normal); FloatBuffer cloneNormals = clone.getFloatBuffer(Type.Normal);
FloatBuffer cloneBindPoseNormals = clone.getFloatBuffer(Type.BindPoseNormal); FloatBuffer cloneBindPoseNormals = clone.getFloatBuffer(Type.BindPoseNormal);
IntBuffer cloneIndexes = (IntBuffer) clone.getBuffer(Type.Index).getData(); Buffer cloneIndexes = clone.getBuffer(Type.Index).getData();
// modyfying data // modyfying data
for (int i = mirrorIndex; i < clonePosition.limit(); i += 3) { for (int i = mirrorIndex; i < clonePosition.limit(); i += 3) {
@ -119,32 +122,46 @@ import java.util.logging.Logger;
if (Math.abs(d) <= tolerance) { if (Math.abs(d) <= tolerance) {
clonePosition.put(i, center[mirrorIndex]); clonePosition.put(i, center[mirrorIndex]);
cloneBindPosePosition.put(i, center[mirrorIndex]); if(cloneBindPosePosition != null) {
cloneBindPosePosition.put(i, center[mirrorIndex]);
}
position.put(i, center[mirrorIndex]); position.put(i, center[mirrorIndex]);
bindPosePosition.put(i, center[mirrorIndex]); if(bindPosePosition != null) {
bindPosePosition.put(i, center[mirrorIndex]);
}
} else { } else {
clonePosition.put(i, value + 2.0f * d); 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)); cloneNormals.put(i, -cloneNormals.get(i));
cloneBindPoseNormals.put(i, -cloneNormals.get(i)); if(cloneBindPoseNormals != null) {
cloneBindPoseNormals.put(i, -cloneNormals.get(i));
}
//modifying clone indexes //modifying clone indexes
int vertexIndex = (i - mirrorIndex) / 3; int vertexIndex = (i - mirrorIndex) / 3;
if (vertexIndex % 3 == 0 && vertexIndex<cloneIndexes.limit()) { if (vertexIndex % 3 == 0 && vertexIndex<cloneIndexes.limit()) {
int index = cloneIndexes.get(vertexIndex + 2); if(cloneIndexes instanceof ShortBuffer) {
cloneIndexes.put(vertexIndex + 2, cloneIndexes.get(vertexIndex + 1)); short index = ((ShortBuffer)cloneIndexes).get(vertexIndex + 2);
cloneIndexes.put(vertexIndex + 1, index); ((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) { if (mirrorU && clone.getBuffer(Type.TexCoord) != null) {
FloatBuffer cloneUVs = (FloatBuffer) clone.getBuffer(Type.TexCoord).getData(); FloatBuffer cloneUVs = (FloatBuffer) clone.getBuffer(Type.TexCoord).getData();
for (int i = 0; i < cloneUVs.limit(); i += 2) { for (int i = 0; i < cloneUVs.limit(); i += 2) {
cloneUVs.put(i, 1.0f - cloneUVs.get(i)); cloneUVs.put(i, 1.0f - cloneUVs.get(i));
} }
} }
if (mirrorV) { if (mirrorV && clone.getBuffer(Type.TexCoord) != null) {
FloatBuffer cloneUVs = (FloatBuffer) clone.getBuffer(Type.TexCoord).getData(); FloatBuffer cloneUVs = (FloatBuffer) clone.getBuffer(Type.TexCoord).getData();
for (int i = 1; i < cloneUVs.limit(); i += 2) { for (int i = 1; i < cloneUVs.limit(); i += 2) {
cloneUVs.put(i, 1.0f - cloneUVs.get(i)); cloneUVs.put(i, 1.0f - cloneUVs.get(i));

Loading…
Cancel
Save