use of com.jme3.scene.shape.Line in project jmonkeyengine by jMonkeyEngine.
the class MotionPath method CreateLinearPath.
private Geometry CreateLinearPath() {
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.getAdditionalRenderState().setWireframe(true);
mat.setColor("Color", ColorRGBA.Blue);
Geometry lineGeometry = new Geometry("line", new Curve(spline, 0));
lineGeometry.setMaterial(mat);
return lineGeometry;
}
use of com.jme3.scene.shape.Line in project jmonkeyengine by jMonkeyEngine.
the class SceneWithAnimationLoader method load.
@Override
public Object load(AssetInfo assetInfo) throws IOException {
AssetKey<?> key = assetInfo.getKey();
if (!(key instanceof ModelKey))
throw new AssetLoadException("Invalid asset key");
InputStream stream = assetInfo.openStream();
Scanner scanner = new Scanner(stream);
AnimationList animList = new AnimationList();
String modelName = null;
try {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.startsWith("#"))
continue;
if (modelName == null) {
modelName = line;
continue;
}
String[] split = split(line);
if (split.length < 3)
throw new IOException("Unparseable string \"" + line + "\"");
int start;
int end;
try {
start = Integer.parseInt(split[0]);
end = Integer.parseInt(split[1]);
} catch (NumberFormatException e) {
throw new IOException("Unparseable string \"" + line + "\"", e);
}
animList.add(split[2], split.length > 3 ? split[3] : null, start, end);
}
} finally {
scanner.close();
stream.close();
}
return assetInfo.getManager().loadAsset(new SceneKey(key.getFolder() + modelName, animList));
}
use of com.jme3.scene.shape.Line in project jmonkeyengine by jMonkeyEngine.
the class ParticlesHelper method toParticleEmitter.
@SuppressWarnings("unchecked")
public ParticleEmitter toParticleEmitter(Structure particleSystem) throws BlenderFileException {
ParticleEmitter result = null;
Pointer pParticleSettings = (Pointer) particleSystem.getFieldValue("part");
if (pParticleSettings.isNotNull()) {
Structure particleSettings = pParticleSettings.fetchData().get(0);
int totPart = ((Number) particleSettings.getFieldValue("totpart")).intValue();
// draw type will be stored temporarily in the name (it is used during modifier applying operation)
int drawAs = ((Number) particleSettings.getFieldValue("draw_as")).intValue();
// P - point, L - line, N - None, B - Bilboard
char nameSuffix;
switch(drawAs) {
case PART_DRAW_NOT:
nameSuffix = 'N';
// no need to generate particles in this case
totPart = 0;
break;
case PART_DRAW_BB:
nameSuffix = 'B';
break;
case PART_DRAW_OB:
case PART_DRAW_GR:
nameSuffix = 'P';
// TODO: support groups and aobjects
LOGGER.warning("Neither object nor group particles supported yet! Using point representation instead!");
break;
case PART_DRAW_LINE:
nameSuffix = 'L';
// TODO: support lines
LOGGER.warning("Lines not yet supported! Using point representation instead!");
default:
// all others are rendered as points in blender
nameSuffix = 'P';
}
result = new ParticleEmitter(particleSettings.getName() + nameSuffix, Type.Triangle, totPart);
if (nameSuffix == 'N') {
// no need to set anything else
return result;
}
// setting the emitters shape (the shapes meshes will be set later during modifier applying operation)
int from = ((Number) particleSettings.getFieldValue("from")).intValue();
switch(from) {
case PART_FROM_VERT:
result.setShape(new EmitterMeshVertexShape());
break;
case PART_FROM_FACE:
result.setShape(new EmitterMeshFaceShape());
break;
case PART_FROM_VOLUME:
result.setShape(new EmitterMeshConvexHullShape());
break;
default:
LOGGER.warning("Default shape used! Unknown emitter shape value ('from' parameter: " + from + ')');
}
// reading acceleration
DynamicArray<Number> acc = (DynamicArray<Number>) particleSettings.getFieldValue("acc");
result.setGravity(-acc.get(0).floatValue(), -acc.get(1).floatValue(), -acc.get(2).floatValue());
// setting the colors
result.setEndColor(new ColorRGBA(1f, 1f, 1f, 1f));
result.setStartColor(new ColorRGBA(1f, 1f, 1f, 1f));
// reading size
float sizeFactor = nameSuffix == 'B' ? 1.0f : 0.3f;
float size = ((Number) particleSettings.getFieldValue("size")).floatValue() * sizeFactor;
result.setStartSize(size);
result.setEndSize(size);
// reading lifetime
int fps = blenderContext.getBlenderKey().getFps();
float lifetime = ((Number) particleSettings.getFieldValue("lifetime")).floatValue() / fps;
float randlife = ((Number) particleSettings.getFieldValue("randlife")).floatValue() / fps;
result.setLowLife(lifetime * (1.0f - randlife));
result.setHighLife(lifetime);
// preparing influencer
ParticleInfluencer influencer;
int phystype = ((Number) particleSettings.getFieldValue("phystype")).intValue();
switch(phystype) {
case PART_PHYS_NEWTON:
influencer = new NewtonianParticleInfluencer();
((NewtonianParticleInfluencer) influencer).setNormalVelocity(((Number) particleSettings.getFieldValue("normfac")).floatValue());
((NewtonianParticleInfluencer) influencer).setVelocityVariation(((Number) particleSettings.getFieldValue("randfac")).floatValue());
((NewtonianParticleInfluencer) influencer).setSurfaceTangentFactor(((Number) particleSettings.getFieldValue("tanfac")).floatValue());
((NewtonianParticleInfluencer) influencer).setSurfaceTangentRotation(((Number) particleSettings.getFieldValue("tanphase")).floatValue());
break;
case PART_PHYS_BOIDS:
case // TODO: support other influencers
PART_PHYS_KEYED:
LOGGER.warning("Boids and Keyed particles physic not yet supported! Empty influencer used!");
case PART_PHYS_NO:
default:
influencer = new EmptyParticleInfluencer();
}
result.setParticleInfluencer(influencer);
}
return result;
}
use of com.jme3.scene.shape.Line in project jmonkeyengine by jMonkeyEngine.
the class Glsl100ShaderGenerator method updateDefinesName.
/**
* transforms defines name is the shader node code.
* One can use a #if defined(inputVariableName) in a shaderNode code.
* This method is responsible for changing the variable name with the
* appropriate defined based on the mapping condition of this variable.
* Complex condition syntax are handled.
*
* @param nodeSource the sahderNode source code
* @param shaderNode the ShaderNode being processed
* @return the modified shaderNode source.
*/
protected String updateDefinesName(String nodeSource, ShaderNode shaderNode) {
String[] lines = nodeSource.split("\\n");
ConditionParser parser = new ConditionParser();
for (String line : lines) {
if (line.trim().startsWith("#if")) {
List<String> params = parser.extractDefines(line.trim());
//parser.getFormattedExpression();
String l = line.trim().replaceAll("defined", "").replaceAll("#if ", "").replaceAll("#ifdef", "");
boolean match = false;
for (String param : params) {
for (VariableMapping map : shaderNode.getInputMapping()) {
if ((map.getLeftVariable().getName()).equals(param)) {
if (map.getCondition() != null) {
l = l.replaceAll(param, map.getCondition());
match = true;
}
}
}
}
if (match) {
nodeSource = nodeSource.replace(line.trim(), "#if " + l);
}
}
}
return nodeSource;
}
use of com.jme3.scene.shape.Line in project jmonkeyengine by jMonkeyEngine.
the class LODGeomap method writeIndexArrayLodVariable.
public IndexBuffer writeIndexArrayLodVariable(int lod, int rightLod, int topLod, int leftLod, int bottomLod, int totalSize) {
int numIndexes = calculateNumIndexesLodDiff(lod);
IndexBuffer ib = IndexBuffer.createIndexBuffer(numIndexes, numIndexes);
VerboseBuffer buffer = new VerboseBuffer(ib);
//System.out.println(" for (z="+lod+"; z<"+(getWidth()-(1*lod))+"; z+="+lod+")");
for (int r = lod; r < getWidth() - (2 * lod); r += lod) {
// row
int rowIdx = r * getWidth();
int nextRowIdx = (r + 1 * lod) * getWidth();
for (int c = lod; c < getWidth() - (1 * lod); c += lod) {
// column
int idx = rowIdx + c;
buffer.put(idx);
idx = nextRowIdx + c;
buffer.put(idx);
}
// add degenerate triangles
if (r < getWidth() - (3 * lod)) {
int idx = nextRowIdx + getWidth() - (1 * lod) - 1;
buffer.put(idx);
// inset by 1
idx = nextRowIdx + (1 * lod);
buffer.put(idx);
//System.out.println("");
}
}
//System.out.println("\nright:");
//int runningBufferCount = buffer.getCount();
//System.out.println("buffer start: "+runningBufferCount);
// right
int br = getWidth() * (getWidth() - lod) - 1 - lod;
// bottom right -1
buffer.put(br);
int corner = getWidth() * getWidth() - 1;
// bottom right corner
buffer.put(corner);
if (rightLod > lod) {
// if lower LOD
int idx = corner;
// iterations
int it = (getWidth() - 1) / rightLod;
int lodDiff = rightLod / lod;
for (int i = it; i > 0; i--) {
// for each lod level of the neighbour
idx = getWidth() * (i * rightLod + 1) - 1;
for (int j = 1; j <= lodDiff; j++) {
// for each section in that lod level
int idxB = idx - (getWidth() * (j * lod)) - lod;
if (j == lodDiff && i == 1) {
// the last one
buffer.put(getWidth() - 1);
} else if (j == lodDiff) {
buffer.put(idxB);
buffer.put(idxB + lod);
} else {
buffer.put(idxB);
buffer.put(idx);
}
}
}
// reset winding order
// top-right +1row
buffer.put(getWidth() * (lod + 1) - lod - 1);
// top-right
buffer.put(getWidth() - 1);
} else {
//br+1);//degenerate to flip winding order
buffer.put(corner);
for (int row = getWidth() - lod; row > lod; row -= lod) {
// mult to get row
int idx = row * getWidth() - 1;
buffer.put(idx);
buffer.put(idx - lod);
}
buffer.put(getWidth() - 1);
}
// top (the order gets reversed here so the diagonals line up)
if (topLod > lod) {
// if lower LOD
if (rightLod > lod) {
// need to flip winding order
buffer.put(getWidth() - 1);
buffer.put(getWidth() * lod - 1);
buffer.put(getWidth() - 1);
}
int idx = getWidth() - 1;
// iterations
int it = (getWidth() - 1) / topLod;
int lodDiff = topLod / lod;
for (int i = it; i > 0; i--) {
// for each lod level of the neighbour
idx = (i * topLod);
for (int j = 1; j <= lodDiff; j++) {
// for each section in that lod level
int idxB = lod * getWidth() + (i * topLod) - (j * lod);
if (j == lodDiff && i == 1) {
// the last one
buffer.put(0);
} else if (j == lodDiff) {
buffer.put(idxB);
buffer.put(idx - topLod);
} else {
buffer.put(idxB);
buffer.put(idx);
}
}
}
} else {
if (rightLod > lod) {
buffer.put(getWidth() - 1);
}
for (int col = getWidth() - 1 - lod; col > 0; col -= lod) {
int idx = col + (lod * getWidth());
buffer.put(idx);
idx = col;
buffer.put(idx);
}
buffer.put(0);
}
buffer.put(0);
// left
if (leftLod > lod) {
// if lower LOD
int idx = 0;
// iterations
int it = (getWidth() - 1) / leftLod;
int lodDiff = leftLod / lod;
for (int i = 0; i < it; i++) {
// for each lod level of the neighbour
idx = getWidth() * (i * leftLod);
for (int j = 1; j <= lodDiff; j++) {
// for each section in that lod level
int idxB = idx + (getWidth() * (j * lod)) + lod;
if (j == lodDiff && i == it - 1) {
// the last one
buffer.put(getWidth() * getWidth() - getWidth());
} else if (j == lodDiff) {
buffer.put(idxB);
buffer.put(idxB - lod);
} else {
buffer.put(idxB);
buffer.put(idx);
}
}
}
} else {
buffer.put(0);
buffer.put(getWidth() * lod + lod);
buffer.put(0);
for (int row = lod; row < getWidth() - lod; row += lod) {
int idx = row * getWidth();
buffer.put(idx);
idx = row * getWidth() + lod;
buffer.put(idx);
}
buffer.put(getWidth() * (getWidth() - 1));
}
// bottom
if (bottomLod > lod) {
// if lower LOD
if (leftLod > lod) {
buffer.put(getWidth() * (getWidth() - 1));
buffer.put(getWidth() * (getWidth() - lod));
buffer.put(getWidth() * (getWidth() - 1));
}
int idx = getWidth() * getWidth() - getWidth();
// iterations
int it = (getWidth() - 1) / bottomLod;
int lodDiff = bottomLod / lod;
for (int i = 0; i < it; i++) {
// for each lod level of the neighbour
idx = getWidth() * getWidth() - getWidth() + (i * bottomLod);
for (int j = 1; j <= lodDiff; j++) {
// for each section in that lod level
int idxB = idx - (getWidth() * lod) + j * lod;
if (j == lodDiff && i == it - 1) {
// the last one
buffer.put(getWidth() * getWidth() - 1);
} else if (j == lodDiff) {
buffer.put(idxB);
buffer.put(idx + bottomLod);
} else {
buffer.put(idxB);
buffer.put(idx);
}
}
}
} else {
if (leftLod > lod) {
buffer.put(getWidth() * (getWidth() - 1));
buffer.put(getWidth() * getWidth() - (getWidth() * lod) + lod);
buffer.put(getWidth() * (getWidth() - 1));
}
for (int col = lod; col < getWidth() - lod; col += lod) {
// up
int idx = getWidth() * (getWidth() - 1 - lod) + col;
buffer.put(idx);
// down
idx = getWidth() * (getWidth() - 1) + col;
buffer.put(idx);
}
//buffer.put(getWidth()*getWidth()-1-lod); // <-- THIS caused holes at the end!
}
buffer.put(getWidth() * getWidth() - 1);
// fill in the rest of the buffer with degenerates, there should only be a couple
for (int i = buffer.getCount(); i < numIndexes; i++) {
buffer.put(getWidth() * getWidth() - 1);
}
return buffer.delegate;
}
Aggregations