Support for 'Fit curve' mode in array modifier added.

(also several small fixes to array modifier added)

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7680 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Kae..pl 14 years ago
parent 3cdbd90d5a
commit e0188e7a13
  1. 2
      engine/src/blender/com/jme3/scene/plugins/blender/helpers/v249/CurvesHelper.java
  2. 36
      engine/src/blender/com/jme3/scene/plugins/blender/helpers/v249/ModifierHelper.java
  3. BIN
      engine/src/test-data/Blender/2.4x/modifiers.blend

@ -536,12 +536,14 @@ public class CurvesHelper extends AbstractBlenderHelper {
}
List<Geometry> result = new ArrayList<Geometry>(vertexBuffers.length);
Float oneReferenceToCurveLength = new Float(curveLength);//its important for array modifier to use one reference here
for (int i = 0; i < vertexBuffers.length; ++i) {
Mesh mesh = new Mesh();
mesh.setBuffer(Type.Position, 3, vertexBuffers[i]);
mesh.setBuffer(Type.Index, 3, indexBuffers[i]);
mesh.setBuffer(Type.Normal, 3, normalBuffers[i]);
Geometry g = new Geometry("g" + i, mesh);
g.setUserData("curveLength", oneReferenceToCurveLength);
g.updateModelBound();
result.add(g);
}

@ -35,6 +35,7 @@ import java.nio.FloatBuffer;
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.Map.Entry;
@ -74,6 +75,7 @@ import com.jme3.scene.plugins.blender.utils.DataRepository.LoadedFeatureDataType
import com.jme3.scene.plugins.blender.utils.DynamicArray;
import com.jme3.scene.plugins.blender.utils.Pointer;
import com.jme3.scene.plugins.ogre.AnimData;
import com.jme3.scene.shape.Curve;
/**
* A class that is used in modifiers calculations.
@ -149,7 +151,32 @@ public class ModifierHelper extends AbstractBlenderHelper {
params.put("length", modifier.getFieldValue("length"));
break;
case 2:// FITCURVE
// TODO: implement after loading curves is added; warning will be generated during modifier applying
Pointer pCurveOb = (Pointer) modifier.getFieldValue("curve_ob");
float length = 0;
if(pCurveOb.isNotNull()) {
Structure curveStructure = pCurveOb.fetchData(dataRepository.getInputStream()).get(0);
ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class);
Node curveObject = (Node)objectHelper.toObject(curveStructure, dataRepository);
Set<Number> referencesToCurveLengths = new HashSet<Number>(curveObject.getChildren().size());
for(Spatial spatial : curveObject.getChildren()) {
if(spatial instanceof Geometry) {
Mesh mesh = ((Geometry) spatial).getMesh();
if(mesh instanceof Curve) {
length += ((Curve) mesh).getLength();
} else {
//if bevel object has several parts then each mesh will have the same reference
//to length value (and we should use only one)
Number curveLength = spatial.getUserData("curveLength");
if(curveLength!=null && !referencesToCurveLengths.contains(curveLength)) {
length += curveLength.floatValue();
referencesToCurveLengths.add(curveLength);
}
}
}
}
}
params.put("length", Float.valueOf(length));
params.put("fittype", Integer.valueOf(1));// treat it like FIXED LENGTH
break;
default:
assert false : "Unknown array modifier fit type: " + fittype;
@ -184,8 +211,7 @@ public class ModifierHelper extends AbstractBlenderHelper {
params.put("endcap", pEndCap);
}
loadedModifier = params;
}
if (Modifier.MIRROR_MODIFIER_DATA.equals(modifier.getType())) {// ****************MIRROR MODIFIER
} else if (Modifier.MIRROR_MODIFIER_DATA.equals(modifier.getType())) {// ****************MIRROR MODIFIER
Map<String, Object> params = new HashMap<String, Object>();
params.put("flag", modifier.getFieldValue("flag"));
@ -471,7 +497,7 @@ public class ModifierHelper extends AbstractBlenderHelper {
count = (int) (length / translationVector.length()) - 1;
}
} else if (fittype == 2) {// Fit curve
LOGGER.warning("Fit curve mode in array modifier not yet implemented!");// TODO: implement fit curve
throw new IllegalStateException("Fit curve should be transformed to Fixed Length array type!");
} else {
throw new IllegalStateException("Unknown fit type: " + fittype);
}
@ -479,7 +505,7 @@ public class ModifierHelper extends AbstractBlenderHelper {
// adding translated nodes and caps
if (count > 0) {
Node[] arrayNodes = new Node[count];
Vector3f newTranslation = node.getLocalTranslation().clone();
Vector3f newTranslation = new Vector3f();
for (int i = 0; i < count; ++i) {
newTranslation.addLocal(translationVector);
Node nodeClone = (Node) node.clone();

Loading…
Cancel
Save