For anyone who want’s to try:
In this archive is the lib, the sources and the (very little) javadoc
http://www.filedropper.com/surfacenetsystem
And here is a quick and dirty testcase:
You need to change the material.
Removing block does not work
Adding blocks work more bad then good (And only with disabled smoothing)
Usage:
Left click to add a block
PGUP to increase the smoothing level
PGDN to decrease the smoothing level
[java]
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.collision.CollisionResult;
import com.jme3.collision.CollisionResults;
import com.jme3.input.KeyInput;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.material.RenderState.FaceCullMode;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Ray;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.Node;
import com.jme3.util.TangentBinormalGenerator;
import com.respublic.mapsystem.BlockArray;
import com.respublic.mapsystem.Surface;
import java.util.concurrent.Callable;
/**
- test
-
@author MichaelZuegg
/
public class ZMapTest1 extends SimpleApplication {
public static void main(String[] args) {
ZMapTest1 app = new ZMapTest1();
app.start();
}
private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (isPressed) {
if (name.equals(“AddBlock”)) {
addBlock();
}
if (name.equals(“RemoveBlock”)) {
removeBlock();
}
if (name.equals(“AddSmooth”)) {
smooth++;
updateMap();
}
if (name.equals(“RemoveSmooth”)) {
smooth–;
updateMap();
}
}
}
};
BlockArray blockArray;
Node mapNode;
Geometry mapDebug;
Geometry mapGeo;
Material debugMaterial;
Material mapMaterial;
int smooth = 0;
@Override
public void simpleInitApp() {
this.flyCam.setMoveSpeed(50f);
mapNode = new Node();
this.debugMaterial = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
this.debugMaterial.getAdditionalRenderState().setWireframe(true);
this.debugMaterial.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
this.debugMaterial.setColor(“Color”, ColorRGBA.Red);
this.mapMaterial = this.assetManager.loadMaterial(“Materials/MapMaterial.j3m”);
/* A white ambient light source. /
AmbientLight ambient = new AmbientLight();
ambient.setColor(new ColorRGBA(0.2f, 0.2f, 0.2f, 1));
rootNode.addLight(ambient);
/* A white, directional light source */
DirectionalLight sun = new DirectionalLight();
sun.setDirection((new Vector3f(-0.5f, -0.5f, -0.5f)).normalizeLocal());
sun.setColor(ColorRGBA.White);
rootNode.addLight(sun);
blockArray = new BlockArray(100, 30, 100, 1f);
for (int x = 0; x < 100; x++) {
for (int z = 0; z < 100; z++) {
blockArray.addBlock(x, 0, z);
}
}
inputManager.addMapping(“AddBlock”, new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addMapping(“RemoveBlock”, new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
inputManager.addMapping(“AddSmooth”, new KeyTrigger(KeyInput.KEY_PGUP));
inputManager.addMapping(“RemoveSmooth”, new KeyTrigger(KeyInput.KEY_PGDN));
inputManager.addListener(actionListener, new String[]{“AddBlock”, “RemoveBlock”, “AddSmooth”, “RemoveSmooth”});
this.rootNode.attachChild(this.mapNode);
this.updateMap();
}
public void updateMap() {
Surface surface = this.blockArray.generateSurface();
for (int i = 0; i < this.smooth; i++) {
surface.smoothSurface();
}
Mesh map = surface.getMesh();
//TangentBinormalGenerator.generate(map);
mapGeo = new Geometry(“Map”, map);
mapGeo.setMaterial(this.mapMaterial);
mapDebug = new Geometry(“MapDebug”, map);
mapDebug.setMaterial(this.debugMaterial);
Callable<Boolean> updater = new Callable<Boolean>() {
public Boolean call() throws Exception {
mapNode.detachAllChildren();
mapNode.attachChild(mapGeo);
return (true);
}
};
this.enqueue(updater);
}
public void addBlock() {
System.out.println(“Adding Block”);
Ray ray = new Ray(cam.getLocation(), cam.getDirection());
CollisionResults results = new CollisionResults();
this.mapNode.collideWith(ray, results);
if (results.size() > 0) {
CollisionResult closestCollision = results.getClosestCollision();
Vector3f contactPoint = closestCollision.getContactPoint();
System.out.println(“Adding Block:” + ((int) contactPoint.x) + “:” + ((int) contactPoint.y) + “:” + ((int) contactPoint.z));
this.blockArray.addBlock((int) contactPoint.x, (int) contactPoint.y, (int) contactPoint.z);
}
this.updateMap();
}
public void removeBlock() {
}
@Override
public void simpleUpdate(float tpf) {
//TODO: add update code
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
[/java]
@normen when downloading the plugin development stuff i alway get a networking error so currently i am not able to make a plugin out of this