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
This commit is contained in:
parent
a6d42c21bb
commit
1d767981ee
@ -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<cloneIndexes.limit()) {
|
||||
int index = cloneIndexes.get(vertexIndex + 2);
|
||||
cloneIndexes.put(vertexIndex + 2, cloneIndexes.get(vertexIndex + 1));
|
||||
cloneIndexes.put(vertexIndex + 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) {
|
||||
if (mirrorU && clone.getBuffer(Type.TexCoord) != null) {
|
||||
FloatBuffer cloneUVs = (FloatBuffer) clone.getBuffer(Type.TexCoord).getData();
|
||||
for (int i = 0; i < cloneUVs.limit(); i += 2) {
|
||||
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();
|
||||
for (int i = 1; i < cloneUVs.limit(); i += 2) {
|
||||
cloneUVs.put(i, 1.0f - cloneUVs.get(i));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user