|
|
|
@ -60,7 +60,6 @@ import com.jme3.scene.Geometry; |
|
|
|
|
import com.jme3.scene.Mesh; |
|
|
|
|
import com.jme3.scene.Node; |
|
|
|
|
import com.jme3.scene.Spatial; |
|
|
|
|
import com.jme3.scene.VertexBuffer; |
|
|
|
|
import com.jme3.scene.VertexBuffer.Type; |
|
|
|
|
import com.jme3.scene.plugins.blender.data.FileBlockHeader; |
|
|
|
|
import com.jme3.scene.plugins.blender.data.Structure; |
|
|
|
@ -184,7 +183,8 @@ public class ModifierHelper extends AbstractBlenderHelper { |
|
|
|
|
params.put("endcap", pEndCap); |
|
|
|
|
} |
|
|
|
|
loadedModifier = params; |
|
|
|
|
} if (Modifier.MIRROR_MODIFIER_DATA.equals(modifier.getType())) {//****************MIRROR MODIFIER
|
|
|
|
|
} |
|
|
|
|
if (Modifier.MIRROR_MODIFIER_DATA.equals(modifier.getType())) {// ****************MIRROR MODIFIER
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>(); |
|
|
|
|
|
|
|
|
|
params.put("flag", modifier.getFieldValue("flag")); |
|
|
|
@ -253,9 +253,12 @@ public class ModifierHelper extends AbstractBlenderHelper { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* This method applies particles emitter to the given node. |
|
|
|
|
* @param node the particles emitter node |
|
|
|
|
* @param modifier the modifier containing the emitter data |
|
|
|
|
* @param dataRepository the data repository |
|
|
|
|
* @param node |
|
|
|
|
* the particles emitter node |
|
|
|
|
* @param modifier |
|
|
|
|
* the modifier containing the emitter data |
|
|
|
|
* @param dataRepository |
|
|
|
|
* the data repository |
|
|
|
|
* @return node with particles' emitter applied |
|
|
|
|
*/ |
|
|
|
|
protected Node applyParticleSystemModifierData(Node node, Modifier modifier, DataRepository dataRepository) { |
|
|
|
@ -455,9 +458,7 @@ public class ModifierHelper extends AbstractBlenderHelper { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Vector3f translationVector = new Vector3f(offset[0] + scale[0] + objectOffset[0], |
|
|
|
|
offset[1] + scale[1] + objectOffset[1], |
|
|
|
|
offset[2] + scale[2] + objectOffset[2]); |
|
|
|
|
Vector3f translationVector = new Vector3f(offset[0] + scale[0] + objectOffset[0], offset[1] + scale[1] + objectOffset[1], offset[2] + scale[2] + objectOffset[2]); |
|
|
|
|
|
|
|
|
|
// getting/calculating repeats amount
|
|
|
|
|
int count = 0; |
|
|
|
@ -519,7 +520,27 @@ public class ModifierHelper extends AbstractBlenderHelper { |
|
|
|
|
(flag & 0x20) != 0 ? -1.0f : 1.0f |
|
|
|
|
}; |
|
|
|
|
float[] center = new float[] { 0.0f, 0.0f, 0.0f }; |
|
|
|
|
Pointer pObject = (Pointer) modifierData.get("mirrorob"); |
|
|
|
|
if (pObject != null) { |
|
|
|
|
Structure objectStructure; |
|
|
|
|
try { |
|
|
|
|
objectStructure = pObject.fetchData(dataRepository.getInputStream()).get(0); |
|
|
|
|
ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); |
|
|
|
|
Node object = (Node) objectHelper.toObject(objectStructure, dataRepository); |
|
|
|
|
if (object != null) { |
|
|
|
|
Vector3f translation = object.getWorldTranslation(); |
|
|
|
|
center[0] = translation.x; |
|
|
|
|
center[1] = translation.y; |
|
|
|
|
center[2] = translation.z; |
|
|
|
|
} |
|
|
|
|
} catch (BlenderFileException e) { |
|
|
|
|
LOGGER.severe("Cannot load mirror's reference object. Cause: " + e.getLocalizedMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
float tolerance = ((Number) modifierData.get("tolerance")).floatValue(); |
|
|
|
|
boolean mirrorU = (flag & 0x01) != 0; |
|
|
|
|
boolean mirrorV = (flag & 0x02) != 0; |
|
|
|
|
// boolean mirrorVGroup = (flag & 0x20) != 0;
|
|
|
|
|
|
|
|
|
|
List<Geometry> geometriesToAdd = new ArrayList<Geometry>(); |
|
|
|
|
for (int mirrorIndex = 0; mirrorIndex < 3; ++mirrorIndex) { |
|
|
|
@ -529,18 +550,44 @@ public class ModifierHelper extends AbstractBlenderHelper { |
|
|
|
|
Mesh mesh = ((Geometry) spatial).getMesh(); |
|
|
|
|
Mesh clone = mesh.deepClone(); |
|
|
|
|
|
|
|
|
|
VertexBuffer position = clone.getBuffer(Type.Position); |
|
|
|
|
VertexBuffer bindPosePosition = clone.getBuffer(Type.BindPosePosition); |
|
|
|
|
FloatBuffer positionBuffer = (FloatBuffer) position.getData(); |
|
|
|
|
FloatBuffer bindPosePositionBuffer = (FloatBuffer) bindPosePosition.getData(); |
|
|
|
|
positionBuffer.rewind(); |
|
|
|
|
bindPosePositionBuffer.rewind(); |
|
|
|
|
for(int i=mirrorIndex;i<positionBuffer.limit();i+=3) { |
|
|
|
|
float value = positionBuffer.get(i); |
|
|
|
|
positionBuffer.put(i, Math.abs(value) <= tolerance ? 0.0f : -value); |
|
|
|
|
// getting buffers
|
|
|
|
|
FloatBuffer position = (FloatBuffer) mesh.getBuffer(Type.Position).getData(); |
|
|
|
|
FloatBuffer bindPosePosition = (FloatBuffer) mesh.getBuffer(Type.BindPosePosition).getData(); |
|
|
|
|
|
|
|
|
|
FloatBuffer clonePosition = (FloatBuffer) clone.getBuffer(Type.Position).getData(); |
|
|
|
|
FloatBuffer cloneBindPosePosition = (FloatBuffer) clone.getBuffer(Type.BindPosePosition).getData(); |
|
|
|
|
FloatBuffer cloneNormals = (FloatBuffer) clone.getBuffer(Type.Normal).getData(); |
|
|
|
|
FloatBuffer cloneBindPoseNormals = (FloatBuffer) clone.getBuffer(Type.BindPoseNormal).getData(); |
|
|
|
|
|
|
|
|
|
// modyfying data
|
|
|
|
|
for (int i = mirrorIndex; i < clonePosition.limit(); i += 3) { |
|
|
|
|
float value = clonePosition.get(i); |
|
|
|
|
float d = center[mirrorIndex] - value; |
|
|
|
|
|
|
|
|
|
if (Math.abs(d) <= tolerance) { |
|
|
|
|
clonePosition.put(i, center[mirrorIndex]); |
|
|
|
|
cloneBindPosePosition.put(i, center[mirrorIndex]); |
|
|
|
|
position.put(i, center[mirrorIndex]); |
|
|
|
|
bindPosePosition.put(i, center[mirrorIndex]); |
|
|
|
|
} else { |
|
|
|
|
clonePosition.put(i, value + 2.0f * d); |
|
|
|
|
cloneBindPosePosition.put(i, value + 2.0f * d); |
|
|
|
|
} |
|
|
|
|
cloneNormals.put(i, -cloneNormals.get(i)); |
|
|
|
|
cloneBindPoseNormals.put(i, -cloneNormals.get(i)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
value = bindPosePositionBuffer.get(i); |
|
|
|
|
bindPosePositionBuffer.put(i, Math.abs(value) <= tolerance ? 0.0f : -value); |
|
|
|
|
if(mirrorU) { |
|
|
|
|
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) { |
|
|
|
|
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)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Geometry geometry = new Geometry(null, clone); |
|
|
|
@ -588,7 +635,8 @@ public class ModifierHelper extends AbstractBlenderHelper { |
|
|
|
|
scales[j] = sourceScales[j].clone(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
boneTracks[i] = new BoneTrack(sourceTracks[i].getTargetBoneIndex(), sourceTracks[i].getTimes(),//times do not change, no need to clone them,
|
|
|
|
|
boneTracks[i] = new BoneTrack(sourceTracks[i].getTargetBoneIndex(), sourceTracks[i].getTimes(),// times do not change, no need
|
|
|
|
|
// to clone them,
|
|
|
|
|
translations, rotations, scales); |
|
|
|
|
} |
|
|
|
|
result.setTracks(boneTracks); |
|
|
|
|