Hey guys,
I want to implement the “NavMesh”-Code into a custom control. But it doesn’t work at all. I always get an error message.
“Exception in Control, scene content is removed” - After that nothing is visible any more. Can someone help me, please.
Here is the code:
public class ElliteControl extends AbstractControl {
private Vector3f targetLocation = new Vector3f(60, 7, -30);
private NavMeshPathfinder navi;
private float speed = 0; // not important
private Waypoint wayPoint;
@Override
protected void controlUpdate(float tpf) {
wayPoint = navi.getNextWaypoint();
if (wayPoint == null) {
return;
}
Vector3f vector = wayPoint.getPosition().subtract(spatial.getWorldTranslation());
if (!(vector.length() < 1)) {
spatial.move(vector.normalize().multLocal(tpf));
} else {
navi.goToNextWaypoint();
}
spatial.rotate(getSpeed() * tpf, 0, 0);
}
@Override
protected void controlRender(RenderManager rm, ViewPort vp) {
}
@Override
public Control cloneForSpatial(Spatial spatial) {
ElliteControl control = new ElliteControl();
control.setTargetLocation(targetLocation);
control.setSpatial(spatial);
Geometry geom = (Geometry) spatial;
Mesh mesh = geom.getMesh();
NavMesh navMesh = new NavMesh(mesh);
navi = new NavMeshPathfinder(navMesh);
navi.setPosition(getTargetLocation());
return control;
}
@Override
public void setSpatial(Spatial spatial) {
if (spatial != null) {
Geometry geom = (Geometry) spatial.getParent().getChild("Ellite");
Mesh mesh = geom.getMesh();
NavMesh navMesh = new NavMesh(mesh);
navi = new NavMeshPathfinder(navMesh);
navi.setPosition(getTargetLocation());
}
}
/* HERE ARE ALL THE "SET" AND "GET" -METHODS ************/
/* NOTHING SPECIAL */
/**
* @return the targetLocation
*/
public Vector3f getTargetLocation() {
return targetLocation;
}
/**
* @param targetLocation the targetLocation to set
*/
public void setTargetLocation(Vector3f targetLocation) {
this.targetLocation = targetLocation;
}
/**
* @return the speed
*/
public float getSpeed() {
return speed;
}
/**
* @param speed the speed to set
*/
public void setSpeed(float speed) {
this.speed = speed;
}
}
I hope you can help me, monkeys.
Thank you,
Domenic