@nehon said:
Paging?
Thanks I looked it up and now I use @anthyon and @Sploreg Terrain Grid.
But it still doesn’t really work and I don’t know why.
This time I can post some code:
[java]
private TerrainGrid grid;
@Override
public void simpleInitApp() {
Material matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matWire.getAdditionalRenderState().setWireframe(true);
matWire.setColor("Color", ColorRGBA.Pink);
int size = 129; //FastMath.nearestPowerOfTwo((int)GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds().getWidth())+1;
this.grid = new TerrainGrid("terrain", size, size, new ImageTileLoader(assetManager, new Namer() {
public String getName(int x, int y) {
return "Scenes/TerrainMountains/terrain_" + x + "_" + y + ".png";
}
}));
this.grid.addListener(this);
this.grid.setMaterial(matWire);
this.grid.setLocalTranslation(0, 0, 0);
int scaleWidth = 1;
this.grid.setLocalScale(scaleWidth, scaleWidth, scaleWidth);
this.rootNode.attachChild(this.grid);
TerrainLodControl control = new TerrainGridLodControl(this.grid, starshoot.getCamera());
control.setLodCalculator(new DistanceLodCalculator(3, 2.7f)); // patch size, and a multiplier
this.grid.addControl(control);
}
public ParticleEmitter createField(float x, float y, float z, float width) {
Material starMat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
starMat.setBoolean("PointSprite", true);
starMat.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png"));
Vector3f worldVec = grid.toWorldSpace(new Vector3f(x, -y, z));
float depth = 1000 + worldVec.getY();
long density = 900000;
float fieldWidth = width * 2;
int fieldAmount = (int) ((depth * fieldWidth * fieldWidth) / density);
ParticleEmitter emit = new ParticleEmitter("StarfieldEmitter_" + x + "_" + z, ParticleMesh.Type.Point, fieldAmount);
emit.setLocalTranslation(worldVec);
emit.setShape(new EmitterBoxShape(new Vector3f(-fieldWidth / 2, 0, -fieldWidth / 2), new Vector3f(fieldWidth / 2, -depth, fieldWidth / 2)));
emit.setGravity(0, 0, 0);
emit.setLowLife(Integer.MAX_VALUE);
emit.setHighLife(Integer.MAX_VALUE);
emit.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 0, 0));
emit.setImagesX(15);
emit.setStartSize(0.3f);
emit.setEndSize(0.3f);
emit.setStartColor(ColorRGBA.White);
emit.setEndColor(ColorRGBA.White);
emit.setSelectRandomImage(true);
emit.setParticlesPerSec(0);
emit.setMaterial(starMat);
return emit;
}
public void tileAttached(Vector3f cell, TerrainQuad quad) {
ParticleEmitter emitter = this.createField(cell.getX(), grid.toCellSpace(new Vector3f(0, 100, 0)).getY(), cell.getZ(), quad.getTerrainSize());
rootNode.attachChild(emitter);
emitter.emitAllParticles();
}
public void tileDetached(Vector3f cell, TerrainQuad quad) {
cell = grid.toCellSpace(grid.toWorldSpace(cell));
ParticleEmitter emitter = (ParticleEmitter) rootNode.getChild("StarfieldEmitter_" + cell.getX() + "_" + cell.getZ());
if (emitter != null) {
emitter.killAllParticles();
rootNode.detachChild(emitter);
}
}[/java]
The old emitters don’t always get deleted and the new emitters get created too late.