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
This commit is contained in:
parent
1ee8375d82
commit
27131024ee
@ -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,44 +123,49 @@ 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)) {
|
||||||
float d = center[mirrorIndex] - value;
|
modifiedIndexes.add((int)index);
|
||||||
|
int valueIndex = index * 3 + mirrorIndex;
|
||||||
|
|
||||||
if (Math.abs(d) <= tolerance) {
|
float value = clonePosition.get(valueIndex);
|
||||||
clonePosition.put(i, center[mirrorIndex]);
|
float d = center[mirrorIndex] - value;
|
||||||
if(cloneBindPosePosition != null) {
|
|
||||||
cloneBindPosePosition.put(i, center[mirrorIndex]);
|
|
||||||
}
|
|
||||||
position.put(i, center[mirrorIndex]);
|
|
||||||
if(bindPosePosition != null) {
|
|
||||||
bindPosePosition.put(i, center[mirrorIndex]);
|
|
||||||
}
|
|
||||||
} 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
|
if (Math.abs(d) <= tolerance) {
|
||||||
int vertexIndex = (i - mirrorIndex) / 3;
|
clonePosition.put(valueIndex, center[mirrorIndex]);
|
||||||
if (vertexIndex % 3 == 0 && vertexIndex<cloneIndexes.limit()) {
|
if(cloneBindPosePosition != null) {
|
||||||
if(cloneIndexes instanceof ShortBuffer) {
|
cloneBindPosePosition.put(valueIndex, center[mirrorIndex]);
|
||||||
short index = ((ShortBuffer)cloneIndexes).get(vertexIndex + 2);
|
}
|
||||||
((ShortBuffer)cloneIndexes).put(vertexIndex + 2, ((ShortBuffer)cloneIndexes).get(vertexIndex + 1));
|
position.put(valueIndex, center[mirrorIndex]);
|
||||||
((ShortBuffer)cloneIndexes).put(vertexIndex + 1, index);
|
if(bindPosePosition != null) {
|
||||||
} else {
|
bindPosePosition.put(valueIndex, center[mirrorIndex]);
|
||||||
int index = ((IntBuffer)cloneIndexes).get(vertexIndex + 2);
|
}
|
||||||
((IntBuffer)cloneIndexes).put(vertexIndex + 2, ((IntBuffer)cloneIndexes).get(vertexIndex + 1));
|
} else {
|
||||||
((IntBuffer)cloneIndexes).put(vertexIndex + 1, index);
|
clonePosition.put(valueIndex, value + 2.0f * d);
|
||||||
}
|
if(cloneBindPosePosition != null) {
|
||||||
}
|
cloneBindPosePosition.put(valueIndex, value + 2.0f * d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cloneNormals.put(valueIndex, -cloneNormals.get(valueIndex));
|
||||||
|
if(cloneBindPoseNormals != null) {
|
||||||
|
cloneBindPoseNormals.put(valueIndex, -cloneNormals.get(valueIndex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
modifiedIndexes.clear();
|
||||||
|
|
||||||
|
//flipping index order
|
||||||
|
for (int i = 0; i < cloneIndexes.limit(); i += 3) {
|
||||||
|
if(cloneIndexes instanceof ShortBuffer) {
|
||||||
|
short index = ((ShortBuffer)cloneIndexes).get(i + 2);
|
||||||
|
((ShortBuffer)cloneIndexes).put(i + 2, ((ShortBuffer)cloneIndexes).get(i + 1));
|
||||||
|
((ShortBuffer)cloneIndexes).put(i + 1, index);
|
||||||
|
} else {
|
||||||
|
int index = ((IntBuffer)cloneIndexes).get(i + 2);
|
||||||
|
((IntBuffer)cloneIndexes).put(i + 2, ((IntBuffer)cloneIndexes).get(i + 1));
|
||||||
|
((IntBuffer)cloneIndexes).put(i + 1, index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mirrorU && clone.getBuffer(Type.TexCoord) != null) {
|
if (mirrorU && clone.getBuffer(Type.TexCoord) != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user