it = selectedEntities.iterator(); it.hasNext();) {
- Spatial spatial1 = it.next();
- CommandControl commandControl = spatial1.getControl(CommandControl.class);
- if (commandControl == null) {
- return;
- }
- try {
- Command commandInst = commands.get(command).newInstance();
- commandInst.setPriority(10);
- commandControl.clearCommands();
- commandControl.initializeCommand(commandInst);
- Command.TargetResult info = commandInst.setTargetLocation(location);
- if (info == Command.TargetResult.Accept || info == Command.TargetResult.AcceptEnemy || info == Command.TargetResult.AcceptFriendly) {
- commandControl.addCommand(commandInst);
- }
- } catch (InstantiationException ex) {
- Logger.getLogger(UserCommandControl.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- Logger.getLogger(UserCommandControl.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
-
-
- public void setSpatial(Spatial spatial) {
- userEntity = spatial;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void render(RenderManager rm, ViewPort vp) {
- }
-
- public Control cloneForSpatial(Spatial spatial) {
- throw new UnsupportedOperationException("Not supported.");
- }
-
- public void write(JmeExporter ex) throws IOException {
- throw new UnsupportedOperationException("Not supported.");
- }
-
- public void read(JmeImporter im) throws IOException {
- throw new UnsupportedOperationException("Not supported.");
- }
-
-}
diff --git a/src/main/java/com/jme3/monkeyzone/controls/UserInputControl.java b/src/main/java/com/jme3/monkeyzone/controls/UserInputControl.java
deleted file mode 100644
index c9bf1e0..0000000
--- a/src/main/java/com/jme3/monkeyzone/controls/UserInputControl.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.controls;
-
-import com.jme3.export.JmeExporter;
-import com.jme3.export.JmeImporter;
-import com.jme3.input.InputManager;
-import com.jme3.input.KeyInput;
-import com.jme3.input.MouseInput;
-import com.jme3.input.controls.ActionListener;
-import com.jme3.input.controls.AnalogListener;
-import com.jme3.input.controls.KeyTrigger;
-import com.jme3.input.controls.MouseAxisTrigger;
-import com.jme3.input.controls.MouseButtonTrigger;
-import com.jme3.math.Quaternion;
-import com.jme3.math.Vector3f;
-import com.jme3.monkeyzone.messages.ActionMessage;
-import com.jme3.renderer.Camera;
-import com.jme3.renderer.RenderManager;
-import com.jme3.renderer.ViewPort;
-import com.jme3.scene.Spatial;
-import com.jme3.scene.control.Control;
-import java.io.IOException;
-
-/**
- * When attached to a Spatial, searches for ManualControl and sends user
- * input there, only used on client for current user entity.
- * @author normenhansen
- */
-public class UserInputControl implements Control, ActionListener, AnalogListener {
- //TODO: add support for joysticks, mouse axis etc. and localization
-
- private InputManager inputManager;
- private Spatial spatial = null;
- private ManualControl manualControl = null;
- private boolean enabled = true;
- private float moveX = 0;
- private float moveY = 0;
- private float moveZ = 0;
- private float steerX = 0;
- private float steerY = 0;
- private Camera cam;
-
- public UserInputControl(InputManager inputManager, Camera cam) {
- this.inputManager = inputManager;
- this.cam = cam;
- prepareInputManager();
- }
-
- private void prepareInputManager() {
- inputManager.addMapping("UserInput_Left_Key", new KeyTrigger(KeyInput.KEY_A));
- inputManager.addMapping("UserInput_Right_Key", new KeyTrigger(KeyInput.KEY_D));
- inputManager.addMapping("UserInput_Up_Key", new KeyTrigger(KeyInput.KEY_W));
- inputManager.addMapping("UserInput_Down_Key", new KeyTrigger(KeyInput.KEY_S));
- inputManager.addMapping("UserInput_Left_Arrow_Key", new KeyTrigger(KeyInput.KEY_LEFT));
- inputManager.addMapping("UserInput_Right_Arrow_Key", new KeyTrigger(KeyInput.KEY_RIGHT));
- inputManager.addMapping("UserInput_Space_Key", new KeyTrigger(KeyInput.KEY_SPACE));
- inputManager.addMapping("UserInput_Enter_Key", new KeyTrigger(KeyInput.KEY_RETURN));
- inputManager.addMapping("UserInput_Left_Mouse", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
- inputManager.addMapping("UserInput_Mouse_Axis_X_Left", new MouseAxisTrigger(MouseInput.AXIS_X, true));
- inputManager.addMapping("UserInput_Mouse_Axis_X_Right", new MouseAxisTrigger(MouseInput.AXIS_X, false));
- inputManager.addMapping("UserInput_Mouse_Axis_Y_Up", new MouseAxisTrigger(MouseInput.AXIS_Y, true));
- inputManager.addMapping("UserInput_Mouse_Axis_Y_Down", new MouseAxisTrigger(MouseInput.AXIS_Y, false));
- inputManager.addListener(this,
- "UserInput_Left_Key",
- "UserInput_Right_Key",
- "UserInput_Up_Key",
- "UserInput_Down_Key",
- "UserInput_Left_Arrow_Key",
- "UserInput_Right_Arrow_Key",
- "UserInput_Space_Key",
- "UserInput_Enter_Key",
- "UserInput_Left_Mouse",
- "UserInput_Mouse_Axis_X_Left",
- "UserInput_Mouse_Axis_X_Right",
- "UserInput_Mouse_Axis_Y_Up",
- "UserInput_Mouse_Axis_Y_Down");
- }
-
- public void setSpatial(Spatial spatial) {
- this.spatial = spatial;
- if (spatial == null) {
- manualControl = null;
- return;
- }
- manualControl = spatial.getControl(ManualControl.class);
- if (manualControl == null) {
- throw new IllegalStateException("Cannot add UserInputControl to spatial without ManualControl!");
- }
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void update(float tpf) {
- //'trick' to apply steering when it has been set by onAnalog and reset it to zero after
- if (steerX != 0) {
- steerX = 0;
- } else {
- manualControl.steerX(steerX);
- }
- if (steerY != 0) {
- steerY = 0;
- } else {
- manualControl.steerY(steerY);
- }
- //TODO: replace with special spatial
- Vector3f currentUp = spatial.getWorldRotation().mult(Vector3f.UNIT_Y);
- Vector3f camLocation = spatial.getWorldTranslation().add(currentUp);
- cam.setLocation(camLocation);
- cam.setRotation(spatial.getWorldRotation());
- cam.lookAt(camLocation.addLocal(manualControl.getAimDirection()), spatial.getWorldRotation().mult(Vector3f.UNIT_Y));
- }
-
- public void render(RenderManager rm, ViewPort vp) {
- }
-
- public void onAnalog(String binding, float value, float tpf) {
- if (!isEnabled() || manualControl == null) {
- return;
- }
- if (binding.equals("UserInput_Mouse_Axis_X_Left")) {
- steerX = value / tpf;
- steerX = steerX > 1 ? 1 : steerX;
- manualControl.steerX(steerX);
- } else if (binding.equals("UserInput_Mouse_Axis_X_Right")) {
- steerX = value / tpf;
- steerX = steerX > 1 ? 1 : steerX;
- manualControl.steerX(-steerX);
- } else if (binding.equals("UserInput_Mouse_Axis_Y_Up")) {
- steerY = value / tpf;
- steerY = steerY > 1 ? 1 : steerY;
- manualControl.steerY(steerY);
- } else if (binding.equals("UserInput_Mouse_Axis_Y_Down")) {
- steerY = value / tpf;
- steerY = steerY > 1 ? 1 : steerY;
- manualControl.steerY(-steerY);
- }
- }
-
- public void onAction(String binding, boolean value, float tpf) {
- if (!isEnabled() || manualControl == null) {
- return;
- }
- if (binding.equals("UserInput_Left_Key")) {
- if (value) {
- moveX += 1;
- manualControl.moveX(moveX);
- } else {
- moveX -= 1;
- manualControl.moveX(moveX);
- }
- } else if (binding.equals("UserInput_Right_Key")) {
- if (value) {
- moveX -= 1;
- manualControl.moveX(moveX);
- } else {
- moveX += 1;
- manualControl.moveX(moveX);
- }
- } else if (binding.equals("UserInput_Up_Key")) {
- if (value) {
- moveZ += 1;
- manualControl.moveZ(moveZ);
- } else {
- moveZ -= 1;
- manualControl.moveZ(moveZ);
- }
- } else if (binding.equals("UserInput_Down_Key")) {
- if (value) {
- moveZ -= 1;
- manualControl.moveZ(moveZ);
- } else {
- moveZ += 1;
- manualControl.moveZ(moveZ);
- }
- } else if (binding.equals("UserInput_Space_Key")) {
- manualControl.performAction(ActionMessage.JUMP_ACTION, value);
- } else if (binding.equals("UserInput_Enter_Key")) {
- manualControl.performAction(ActionMessage.ENTER_ACTION, value);
- } else if (binding.equals("UserInput_Left_Mouse")) {
- manualControl.performAction(ActionMessage.SHOOT_ACTION, value);
- }
- }
-
- public Control cloneForSpatial(Spatial spatial) {
- throw new UnsupportedOperationException("Not supported.");
- }
-
- public void write(JmeExporter ex) throws IOException {
- throw new UnsupportedOperationException("Not supported.");
- }
-
- public void read(JmeImporter im) throws IOException {
- throw new UnsupportedOperationException("Not supported.");
- }
-}
diff --git a/src/main/java/com/jme3/monkeyzone/messages/ActionMessage.java b/src/main/java/com/jme3/monkeyzone/messages/ActionMessage.java
deleted file mode 100644
index b764253..0000000
--- a/src/main/java/com/jme3/monkeyzone/messages/ActionMessage.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.messages;
-
-import com.jme3.monkeyzone.controls.NetworkActionEnabled;
-import com.jme3.network.physicssync.PhysicsSyncMessage;
-import com.jme3.network.serializing.Serializable;
-import com.jme3.scene.Spatial;
-
-/**
- * perform action for player (human and AI), used bidirectional
- * @author normenhansen
- */
-@Serializable()
-public class ActionMessage extends PhysicsSyncMessage {
-
- public final static int NULL_ACTION = 0;
- public final static int JUMP_ACTION = 1;
- public final static int ENTER_ACTION = 2;
- public final static int SHOOT_ACTION = 3;
-
- public int action;
- public boolean pressed;
-
- public ActionMessage() {
- }
-
- public ActionMessage(long id, int action, boolean pressed) {
- this.syncId = id;
- this.action = action;
- this.pressed = pressed;
- }
-
- @Override
- public void applyData(Object object) {
- ((Spatial)object).getControl(NetworkActionEnabled.class).doPerformAction(action, pressed);
- }
-}
diff --git a/src/main/java/com/jme3/monkeyzone/messages/AutoControlMessage.java b/src/main/java/com/jme3/monkeyzone/messages/AutoControlMessage.java
deleted file mode 100644
index 3fa6d99..0000000
--- a/src/main/java/com/jme3/monkeyzone/messages/AutoControlMessage.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.messages;
-
-import com.jme3.bullet.collision.PhysicsCollisionObject;
-import com.jme3.math.Vector3f;
-import com.jme3.monkeyzone.controls.NetworkedAutonomousControl;
-import com.jme3.network.physicssync.PhysicsSyncMessage;
-import com.jme3.network.serializing.Serializable;
-import com.jme3.scene.Spatial;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * automatic (AI) control message, used bidirectional
- * @author normenhansen
- */
-@Serializable()
-public class AutoControlMessage extends PhysicsSyncMessage {
-
- public Vector3f aimAt = new Vector3f();
- public Vector3f moveTo = new Vector3f();
-
- public AutoControlMessage() {
- }
-
- public AutoControlMessage(long id, Vector3f aimAt, Vector3f moveTo) {
-// setReliable(false);
- this.syncId = id;
- this.aimAt.set(aimAt);
- this.moveTo.set(moveTo);
- }
-
- @Override
- public void applyData(Object object) {
- NetworkedAutonomousControl netControl = ((Spatial) object).getControl(NetworkedAutonomousControl.class);
- assert (netControl != null);
- if(netControl==null){
- Logger.getLogger(AutoControlMessage.class.getName()).log(Level.SEVERE, "Entity {0} has to Autonomous Control, message not accepted", ((Spatial)object).getUserData("entity_id").toString());
- return;
- }
- netControl.doAimAt(aimAt);
- netControl.doMoveTo(moveTo);
- }
-}
diff --git a/src/main/java/com/jme3/monkeyzone/messages/ChatMessage.java b/src/main/java/com/jme3/monkeyzone/messages/ChatMessage.java
deleted file mode 100644
index ea1cfff..0000000
--- a/src/main/java/com/jme3/monkeyzone/messages/ChatMessage.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.messages;
-
-import com.jme3.network.AbstractMessage;
-import com.jme3.network.serializing.Serializable;
-
-/**
- * basic chat message, name is filled on server
- * @author normenhansen
- */
-@Serializable()
-public class ChatMessage extends AbstractMessage {
-
- public String text;
- public String name;
-
- public ChatMessage() {
- }
-
- public ChatMessage(String text) {
- this.text = text;
- }
-
- public ChatMessage(String name, String text) {
- this.text = text;
- this.name = name;
- }
-
-}
diff --git a/src/main/java/com/jme3/monkeyzone/messages/ClientJoinMessage.java b/src/main/java/com/jme3/monkeyzone/messages/ClientJoinMessage.java
deleted file mode 100644
index 7f02338..0000000
--- a/src/main/java/com/jme3/monkeyzone/messages/ClientJoinMessage.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.messages;
-
-import com.jme3.network.AbstractMessage;
-import com.jme3.network.serializing.Serializable;
-
-/**
- * sent from client to join server
- * @author normenhansen
- */
-@Serializable()
-public class ClientJoinMessage extends AbstractMessage{
- public String name;
- public String pass;
-
- public ClientJoinMessage() {
- }
-
- public ClientJoinMessage(String name, String pass) {
- this.name = name;
- this.pass = pass;
- }
-
-}
diff --git a/src/main/java/com/jme3/monkeyzone/messages/HandshakeMessage.java b/src/main/java/com/jme3/monkeyzone/messages/HandshakeMessage.java
deleted file mode 100644
index 3518c8e..0000000
--- a/src/main/java/com/jme3/monkeyzone/messages/HandshakeMessage.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.messages;
-
-import com.jme3.network.AbstractMessage;
-import com.jme3.network.serializing.Serializable;
-
-/**
- * used for first handshake. contains protocol, client and server version.
- * should never change.
- * @author normenhansen
- */
-@Serializable()
-public class HandshakeMessage extends AbstractMessage {
-
- public int protocol_version;
- public int client_version;
- public int server_version;
-
- public HandshakeMessage() {
- }
-
- public HandshakeMessage(int protocol_version, int client_version, int server_version) {
- this.protocol_version = protocol_version;
- this.client_version = client_version;
- this.server_version = server_version;
- }
-
-}
diff --git a/src/main/java/com/jme3/monkeyzone/messages/ManualControlMessage.java b/src/main/java/com/jme3/monkeyzone/messages/ManualControlMessage.java
deleted file mode 100644
index 72c3103..0000000
--- a/src/main/java/com/jme3/monkeyzone/messages/ManualControlMessage.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.messages;
-
-import com.jme3.bullet.collision.PhysicsCollisionObject;
-import com.jme3.monkeyzone.controls.NetworkedManualControl;
-import com.jme3.network.physicssync.PhysicsSyncMessage;
-import com.jme3.network.serializing.Serializable;
-import com.jme3.scene.Spatial;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Manual (human) control message, used bidirectional
- * @author normenhansen
- */
-@Serializable()
-public class ManualControlMessage extends PhysicsSyncMessage {
-
- public float aimX;
- public float aimY;
- public float moveX;
- public float moveY;
- public float moveZ;
-
- public ManualControlMessage() {
- }
-
- public ManualControlMessage(ManualControlMessage msg) {
-// setReliable(false);
- this.syncId = msg.syncId;
- this.aimX = msg.aimX;
- this.aimY = msg.aimY;
- this.moveX = msg.moveX;
- this.moveY = msg.moveY;
- this.moveZ = msg.moveZ;
- }
-
- public ManualControlMessage(long id, float aimX, float aimY, float moveX, float moveY, float moveZ) {
-// setReliable(false);
- this.syncId = id;
- this.aimX = aimX;
- this.aimY = aimY;
- this.moveX = moveX;
- this.moveY = moveY;
- this.moveZ = moveZ;
- }
-
- @Override
- public void applyData(Object object) {
- NetworkedManualControl netControl = ((Spatial) object).getControl(NetworkedManualControl.class);
- assert (netControl != null);
- netControl.doMoveX(moveX);
- netControl.doMoveY(moveY);
- netControl.doMoveZ(moveZ);
- netControl.doSteerX(aimX);
- netControl.doSteerY(aimY);
- }
-}
diff --git a/src/main/java/com/jme3/monkeyzone/messages/ServerAddEntityMessage.java b/src/main/java/com/jme3/monkeyzone/messages/ServerAddEntityMessage.java
deleted file mode 100644
index bad7584..0000000
--- a/src/main/java/com/jme3/monkeyzone/messages/ServerAddEntityMessage.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.messages;
-
-import com.jme3.math.Quaternion;
-import com.jme3.math.Vector3f;
-import com.jme3.monkeyzone.WorldManager;
-import com.jme3.network.physicssync.PhysicsSyncMessage;
-import com.jme3.network.serializing.Serializable;
-
-/**
- * used by the server to add an entity on the client
- * @author normenhansen
- */
-@Serializable()
-public class ServerAddEntityMessage extends PhysicsSyncMessage {
-
- public long entityId;
- public String modelIdentifier;
- public Vector3f location;
- public Quaternion rotation;
-
- public ServerAddEntityMessage() {
- }
-
- public ServerAddEntityMessage(long id, String modelIdentifier, Vector3f location, Quaternion rotation) {
- this.syncId = -1;
- this.entityId = id;
- this.modelIdentifier = modelIdentifier;
- this.location = location;
- this.rotation = rotation;
- }
-
- public void applyData(Object obj) {
- WorldManager manager = (WorldManager) obj;
- manager.addEntity(entityId, modelIdentifier, location, rotation);
- }
-}
diff --git a/src/main/java/com/jme3/monkeyzone/messages/ServerAddPlayerMessage.java b/src/main/java/com/jme3/monkeyzone/messages/ServerAddPlayerMessage.java
deleted file mode 100644
index f87be5c..0000000
--- a/src/main/java/com/jme3/monkeyzone/messages/ServerAddPlayerMessage.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.messages;
-
-import com.jme3.monkeyzone.WorldManager;
-import com.jme3.network.physicssync.PhysicsSyncMessage;
-import com.jme3.network.serializing.Serializable;
-
-/**
- * used by the server to add a player on the client
- * @author normenhansen
- */
-@Serializable()
-public class ServerAddPlayerMessage extends PhysicsSyncMessage{
- public long playerId;
- public String name;
- public int group_id;
- public int ai_id;
-
- public ServerAddPlayerMessage() {
- }
-
- public ServerAddPlayerMessage(long id, String name, int group_id, int ai_id) {
- this.syncId = -1;
- this.playerId = id;
- this.name = name;
- this.group_id = group_id;
- this.ai_id = ai_id;
- }
-
- @Override
- public void applyData(Object object) {
- WorldManager manager = (WorldManager) object;
- manager.addPlayer(playerId, group_id, name, ai_id);
- }
-
-}
diff --git a/src/main/java/com/jme3/monkeyzone/messages/ServerDisableEntityMessage.java b/src/main/java/com/jme3/monkeyzone/messages/ServerDisableEntityMessage.java
deleted file mode 100644
index 59c5942..0000000
--- a/src/main/java/com/jme3/monkeyzone/messages/ServerDisableEntityMessage.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.messages;
-
-import com.jme3.monkeyzone.WorldManager;
-import com.jme3.network.physicssync.PhysicsSyncMessage;
-import com.jme3.network.serializing.Serializable;
-
-/**
- * used by the server to add an entity on the client
- * @author normenhansen
- */
-@Serializable()
-public class ServerDisableEntityMessage extends PhysicsSyncMessage {
-
- public long entityId;
-
- public ServerDisableEntityMessage() {
- }
-
- public ServerDisableEntityMessage(long id) {
- this.entityId = id;
- this.syncId = -1;
- }
-
- @Override
- public void applyData(Object object) {
- WorldManager manager = (WorldManager) object;
- manager.disableEntity(entityId);
- }
-}
diff --git a/src/main/java/com/jme3/monkeyzone/messages/ServerEffectMessage.java b/src/main/java/com/jme3/monkeyzone/messages/ServerEffectMessage.java
deleted file mode 100644
index 71a3aba..0000000
--- a/src/main/java/com/jme3/monkeyzone/messages/ServerEffectMessage.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.messages;
-
-import com.jme3.math.Quaternion;
-import com.jme3.math.Vector3f;
-import com.jme3.monkeyzone.ClientEffectsManager;
-import com.jme3.monkeyzone.WorldManager;
-import com.jme3.network.physicssync.PhysicsSyncMessage;
-import com.jme3.network.serializing.Serializable;
-
-/**
- * Message sent to play effect on client
- * @author normenhansen
- */
-@Serializable()
-public class ServerEffectMessage extends PhysicsSyncMessage {
-
- public long effectId;
- public String name;
- public Vector3f location;
- public Quaternion rotation;
- public Vector3f endLocation;
- public Quaternion endRotation;
- public float playTime;
-
- public ServerEffectMessage() {
- }
-
- public ServerEffectMessage(long id, String name, Vector3f location, Quaternion rotation, Vector3f endLocation, Quaternion endRotation, float time) {
- this.syncId = -2;
- this.effectId = id;
- this.name = name;
- this.location = location;
- this.rotation = rotation;
- this.endLocation = endLocation;
- this.endRotation = endRotation;
- this.playTime = time;
- }
-
- @Override
- public void applyData(Object object) {
- ClientEffectsManager manager = (ClientEffectsManager) object;
- manager.playEffect(effectId, name, location, endLocation, rotation, endRotation, playTime);
- }
-}
diff --git a/src/main/java/com/jme3/monkeyzone/messages/ServerEnableEntityMessage.java b/src/main/java/com/jme3/monkeyzone/messages/ServerEnableEntityMessage.java
deleted file mode 100644
index 82f6cad..0000000
--- a/src/main/java/com/jme3/monkeyzone/messages/ServerEnableEntityMessage.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.messages;
-
-import com.jme3.math.Quaternion;
-import com.jme3.math.Vector3f;
-import com.jme3.monkeyzone.WorldManager;
-import com.jme3.network.physicssync.PhysicsSyncMessage;
-import com.jme3.network.serializing.Serializable;
-
-/**
- * used by the server to add an entity on the client
- * @author normenhansen
- */
-@Serializable()
-public class ServerEnableEntityMessage extends PhysicsSyncMessage {
-
- public long entityId;
- public Vector3f location;
- public Quaternion rotation;
-
- public ServerEnableEntityMessage() {
- }
-
- public ServerEnableEntityMessage(long id, Vector3f location, Quaternion rotation) {
- this.syncId = -1;
- this.entityId = id;
- this.location = location;
- this.rotation = rotation;
- }
-
- public void applyData(Object obj) {
- WorldManager manager = (WorldManager) obj;
- manager.enableEntity(entityId, location, rotation);
- }
-}
diff --git a/src/main/java/com/jme3/monkeyzone/messages/ServerEnterEntityMessage.java b/src/main/java/com/jme3/monkeyzone/messages/ServerEnterEntityMessage.java
deleted file mode 100644
index 437df9f..0000000
--- a/src/main/java/com/jme3/monkeyzone/messages/ServerEnterEntityMessage.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.messages;
-
-import com.jme3.monkeyzone.WorldManager;
-import com.jme3.network.physicssync.PhysicsSyncMessage;
-import com.jme3.network.serializing.Serializable;
-
-/**
- * Message sent when entering entity
- * @author normenhansen
- */
-@Serializable()
-public class ServerEnterEntityMessage extends PhysicsSyncMessage{
-
- public long player_id;
- public long entity_id;
-
- public ServerEnterEntityMessage() {
- }
-
- public ServerEnterEntityMessage(long player_id, long entity_id) {
- syncId = -1;
- this.player_id = player_id;
- this.entity_id = entity_id;
- }
-
- @Override
- public void applyData(Object object) {
- WorldManager manager = (WorldManager) object;
- manager.enterEntity(player_id, entity_id);
- }
-}
diff --git a/src/main/java/com/jme3/monkeyzone/messages/ServerEntityDataMessage.java b/src/main/java/com/jme3/monkeyzone/messages/ServerEntityDataMessage.java
deleted file mode 100644
index 40eb798..0000000
--- a/src/main/java/com/jme3/monkeyzone/messages/ServerEntityDataMessage.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.messages;
-
-import com.jme3.network.physicssync.PhysicsSyncMessage;
-import com.jme3.network.serializing.Serializable;
-import com.jme3.scene.Spatial;
-
-/**
- * sets userdata in a client-side entity
- * @author normenhansen
- */
-@Serializable()
-public class ServerEntityDataMessage extends PhysicsSyncMessage {
-
- public String name;
- public byte type;
- public int intData;
- public float floatData;
- public long longData;
- public boolean booleanData;
- public String stringData;
-
- public ServerEntityDataMessage() {
- }
-
- public ServerEntityDataMessage(long id, String name, Object value) {
- this.name = name;
- syncId = id;
- type = getObjectType(value);
- switch (type) {
- case 0:
- intData = (Integer) value;
- break;
- case 1:
- floatData = (Float) value;
- break;
- case 2:
- booleanData = (Boolean) value;
- break;
- case 3:
- stringData = (String) value;
- break;
- case 4:
- longData = (Long) value;
- break;
- default:
- throw new UnsupportedOperationException("Cannot apply wrong userdata type.");
- }
- }
-
- @Override
- public void applyData(Object object) {
- Spatial spat = ((Spatial) object);
- switch (type) {
- case 0:
- spat.setUserData(name, intData);
- break;
- case 1:
- spat.setUserData(name, floatData);
- break;
- case 2:
- spat.setUserData(name, booleanData);
- break;
- case 3:
- spat.setUserData(name, stringData);
- break;
- case 4:
- spat.setUserData(name, longData);
- break;
- default:
- throw new UnsupportedOperationException("Cannot apply wrong userdata type.");
- }
- }
-
- private static byte getObjectType(Object type) {
- if (type instanceof Integer) {
- return 0;
- } else if (type instanceof Float) {
- return 1;
- } else if (type instanceof Boolean) {
- return 2;
- } else if (type instanceof String) {
- return 3;
- } else if (type instanceof Long) {
- return 4;
- } else {
- throw new IllegalArgumentException("Unsupported type: " + type.getClass().getName());
- }
- }
-}
diff --git a/src/main/java/com/jme3/monkeyzone/messages/ServerJoinMessage.java b/src/main/java/com/jme3/monkeyzone/messages/ServerJoinMessage.java
deleted file mode 100644
index 98ab8de..0000000
--- a/src/main/java/com/jme3/monkeyzone/messages/ServerJoinMessage.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.messages;
-
-import com.jme3.network.AbstractMessage;
-import com.jme3.network.serializing.Serializable;
-
-/**
- * sent to client to signal that if it has logged in, contains human players id
- * @author normenhansen
- */
-@Serializable()
-public class ServerJoinMessage extends AbstractMessage{
- public boolean rejected;
- public long id;
- public int group_id;
- public String name;
-
- public ServerJoinMessage() {
- }
-
- public ServerJoinMessage(long id, int group_id, String name, boolean rejected) {
- this.rejected = rejected;
- this.id = id;
- this.group_id = group_id;
- this.name = name;
- }
-
-}
diff --git a/src/main/java/com/jme3/monkeyzone/messages/ServerPlayerDataMessage.java b/src/main/java/com/jme3/monkeyzone/messages/ServerPlayerDataMessage.java
deleted file mode 100644
index a30e369..0000000
--- a/src/main/java/com/jme3/monkeyzone/messages/ServerPlayerDataMessage.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.messages;
-
-import com.jme3.network.AbstractMessage;
-import com.jme3.network.serializing.Serializable;
-
-/**
- *
- * @author normenhansen
- */
-@Serializable()
-public class ServerPlayerDataMessage extends AbstractMessage {
-
- public long id;
- public String name;
- public byte type;
- public int intData;
- public float floatData;
- public long longData;
- public boolean booleanData;
- public String stringData;
-
- public ServerPlayerDataMessage() {
- }
-}
diff --git a/src/main/java/com/jme3/monkeyzone/messages/ServerRemoveEntityMessage.java b/src/main/java/com/jme3/monkeyzone/messages/ServerRemoveEntityMessage.java
deleted file mode 100644
index 204a036..0000000
--- a/src/main/java/com/jme3/monkeyzone/messages/ServerRemoveEntityMessage.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.messages;
-
-import com.jme3.monkeyzone.WorldManager;
-import com.jme3.network.physicssync.PhysicsSyncMessage;
-import com.jme3.network.serializing.Serializable;
-
-/**
- * used by the server to add an entity on the client
- * @author normenhansen
- */
-@Serializable()
-public class ServerRemoveEntityMessage extends PhysicsSyncMessage {
-
- public long entityId;
-
- public ServerRemoveEntityMessage() {
- }
-
- public ServerRemoveEntityMessage(long id) {
- this.entityId = id;
- this.syncId = -1;
- }
-
- @Override
- public void applyData(Object object) {
- WorldManager manager = (WorldManager) object;
- manager.removeEntity(entityId);
- }
-}
diff --git a/src/main/java/com/jme3/monkeyzone/messages/ServerRemovePlayerMessage.java b/src/main/java/com/jme3/monkeyzone/messages/ServerRemovePlayerMessage.java
deleted file mode 100644
index e342e17..0000000
--- a/src/main/java/com/jme3/monkeyzone/messages/ServerRemovePlayerMessage.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.messages;
-
-import com.jme3.monkeyzone.WorldManager;
-import com.jme3.network.physicssync.PhysicsSyncMessage;
-import com.jme3.network.serializing.Serializable;
-
-/**
- * used by the server to add an entity on the client
- * @author normenhansen
- */
-@Serializable()
-public class ServerRemovePlayerMessage extends PhysicsSyncMessage {
-
- public long playerId;
-
- public ServerRemovePlayerMessage() {
- }
-
- public ServerRemovePlayerMessage(long id) {
- this.syncId = -1;
- this.playerId = id;
- }
-
- @Override
- public void applyData(Object object) {
- WorldManager manager = (WorldManager) object;
- manager.removePlayer(playerId);
- }
-}
diff --git a/src/main/java/com/jme3/monkeyzone/messages/StartGameMessage.java b/src/main/java/com/jme3/monkeyzone/messages/StartGameMessage.java
deleted file mode 100644
index e054957..0000000
--- a/src/main/java/com/jme3/monkeyzone/messages/StartGameMessage.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.monkeyzone.messages;
-
-import com.jme3.network.AbstractMessage;
-import com.jme3.network.serializing.Serializable;
-
-/**
- * used to load a level on the client and to report that a level has been loaded
- * to the server.
- * @author normenhansen
- */
-@Serializable()
-public class StartGameMessage extends AbstractMessage{
- public String levelName;
- public String[] modelNames;
-
- public StartGameMessage() {
- }
-
- public StartGameMessage(String levelName) {
- this.levelName = levelName;
- }
-
- public StartGameMessage(String levelName, String[] modelNames) {
- this.levelName = levelName;
- this.modelNames = modelNames;
- }
-}
diff --git a/src/main/java/com/jme3/network/physicssync/PhysicsSyncManager.java b/src/main/java/com/jme3/network/physicssync/PhysicsSyncManager.java
deleted file mode 100644
index 3749c8e..0000000
--- a/src/main/java/com/jme3/network/physicssync/PhysicsSyncManager.java
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.network.physicssync;
-
-import com.jme3.app.Application;
-import com.jme3.app.state.AbstractAppState;
-import com.jme3.bullet.control.CharacterControl;
-import com.jme3.bullet.control.RigidBodyControl;
-import com.jme3.bullet.control.VehicleControl;
-import com.jme3.bullet.objects.PhysicsRigidBody;
-import com.jme3.network.Server;
-import com.jme3.network.Client;
-import com.jme3.network.HostedConnection;
-import com.jme3.network.Message;
-import com.jme3.network.MessageListener;
-import com.jme3.scene.Spatial;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Map.Entry;
-import java.util.concurrent.Callable;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Handles syncing of physics enabled server/client games. Puts messages in a queue
- * and executes them based on server time stamp plus an offset on the client.
- * The offset is calculated for each arriving message, if the time offset change
- * is bigger than maxDelay or smaller than zero (the message would be played either
- * very late or has happened already) then the offset time is adjusted.
- *
- * @author normenhansen
- */
-public class PhysicsSyncManager extends AbstractAppState implements MessageListener {
-
- private Server server;
- private Client client;
- private float syncFrequency = 0.25f;
- LinkedList validators = new LinkedList();
- HashMap syncObjects = new HashMap();
- double time = 0;
- double offset = Double.MIN_VALUE;
- private double maxDelay = 0.50;
- float syncTimer = 0;
- LinkedList messageQueue = new LinkedList();
- Application app;
-
- public PhysicsSyncManager(Application app, Server server) {
- this.app = app;
- this.server = server;
- }
-
- public PhysicsSyncManager(Application app, Client client) {
- this.app = app;
- this.client = client;
- }
-
- /**
- * updates the PhysicsSyncManager, executes messages on client and sends
- * sync info on the server.
- * @param tpf
- */
- @Override
- public void update(float tpf) {
- time += tpf;
- if (time < 0) {
- //TODO: overflow
- time = 0;
- }
- if (client != null) {
- for (Iterator it = messageQueue.iterator(); it.hasNext();) {
- PhysicsSyncMessage message = it.next();
- if (message.time >= time + offset) {
- doMessage(message);
- it.remove();
- }
- }
- } else if (server != null) {
- syncTimer += tpf;
- if (syncTimer >= syncFrequency) {
- sendSyncData();
- syncTimer = 0;
- }
- }
- }
-
- /**
- * add an object to the list of objects managed by this sync manager
- * @param id
- * @param object
- */
- public void addObject(long id, Object object) {
- syncObjects.put(id, object);
- }
-
- /**
- * removes an object from the list of objects managed by this sync manager
- * @param object
- */
- public void removeObject(Object object) {
- for (Iterator> it = syncObjects.entrySet().iterator(); it.hasNext();) {
- Entry entry = it.next();
- if (entry.getValue() == object) {
- it.remove();
- return;
- }
- }
- }
-
- /**
- * removes an object from the list of objects managed by this sync manager
- * @param id
- */
- public void removeObject(long id) {
- syncObjects.remove(id);
- }
-
- public void clearObjects() {
- syncObjects.clear();
- }
-
- /**
- * executes a message immediately
- * @param message
- */
- protected void doMessage(PhysicsSyncMessage message) {
- Object object = syncObjects.get(message.syncId);
- if (object != null) {
- message.applyData(object);
- } else {
- Logger.getLogger(PhysicsSyncManager.class.getName()).log(Level.WARNING, "Cannot find physics object for: ({0}){1}", new Object[]{message.syncId, message});
- }
- }
-
- /**
- * enqueues the message and updates the offset of the sync manager based on the
- * time stamp
- * @param message
- */
- protected void enqueueMessage(PhysicsSyncMessage message) {
- if (offset == Double.MIN_VALUE) {
- offset = this.time - message.time;
- Logger.getLogger(PhysicsSyncManager.class.getName()).log(Level.INFO, "Initial offset {0}", offset);
- }
- double delayTime = (message.time + offset) - time;
- if (delayTime > maxDelay) {
- offset -= delayTime - maxDelay;
- Logger.getLogger(PhysicsSyncManager.class.getName()).log(Level.INFO, "Decrease offset due to high delaytime ({0})", delayTime);
- } else if (delayTime < 0) {
- offset -= delayTime;
- Logger.getLogger(PhysicsSyncManager.class.getName()).log(Level.INFO, "Increase offset due to low delaytime ({0})", delayTime);
- }
- messageQueue.add(message);
- }
-
- /**
- * sends sync data for all active physics objects
- */
- protected void sendSyncData() {
- for (Iterator> it = syncObjects.entrySet().iterator(); it.hasNext();) {
- Entry entry = it.next();
- if (entry.getValue() instanceof Spatial) {
- Spatial spat = (Spatial) entry.getValue();
- PhysicsRigidBody body = spat.getControl(RigidBodyControl.class);
- if (body == null) {
- body = spat.getControl(VehicleControl.class);
- }
- if (body != null && body.isActive()) {
- SyncRigidBodyMessage msg = new SyncRigidBodyMessage(entry.getKey(), body);
- broadcast(msg);
- continue;
- }
- CharacterControl control = spat.getControl(CharacterControl.class);
- if (control != null) {
- SyncCharacterMessage msg = new SyncCharacterMessage(entry.getKey(), control);
- broadcast(msg);
- }
- }
- }
- }
-
- /**
- * use to broadcast physics control messages if server, applies timestamp to
- * PhysicsSyncMessage, call from OpenGL thread!
- * @param msg
- */
- public void broadcast(PhysicsSyncMessage msg) {
- if (server == null) {
- Logger.getLogger(PhysicsSyncManager.class.getName()).log(Level.SEVERE, "Broadcasting message on client {0}", msg);
- return;
- }
- msg.time = time;
- server.broadcast(msg);
- }
-
- /**
- * send data to a specific client
- * @param client
- * @param msg
- */
- public void send(int client, PhysicsSyncMessage msg) {
- if (server == null) {
- Logger.getLogger(PhysicsSyncManager.class.getName()).log(Level.SEVERE, "Broadcasting message on client {0}", msg);
- return;
- }
- send(server.getConnection(client), msg);
- }
-
- /**
- * send data to a specific client
- * @param client
- * @param msg
- */
- public void send(HostedConnection client, PhysicsSyncMessage msg) {
- msg.time = time;
- if (client == null) {
- Logger.getLogger(PhysicsSyncManager.class.getName()).log(Level.SEVERE, "Client null when sending: {0}", client);
- return;
- }
- client.send(msg);
- }
-
- /**
- * registers the types of messages this PhysicsSyncManager listens to
- * @param classes
- */
- public void setMessageTypes(Class... classes) {
- if (server != null) {
- server.removeMessageListener(this);
- server.addMessageListener(this, classes);
- } else if (client != null) {
- client.removeMessageListener(this);
- client.addMessageListener(this, classes);
- }
- }
-
- public void messageReceived(Object source, final Message message) {
- assert (message instanceof PhysicsSyncMessage);
- if (client != null) {
- app.enqueue(new Callable() {
-
- public Void call() throws Exception {
- enqueueMessage((PhysicsSyncMessage) message);
- return null;
- }
- });
- } else if (server != null) {
- app.enqueue(new Callable() {
-
- public Void call() throws Exception {
- for (Iterator it = validators.iterator(); it.hasNext();) {
- SyncMessageValidator syncMessageValidator = it.next();
- if (!syncMessageValidator.checkMessage((PhysicsSyncMessage) message)) {
- return null;
- }
- }
- broadcast((PhysicsSyncMessage) message);
- doMessage((PhysicsSyncMessage) message);
- return null;
- }
- });
- }
- }
-
- public void addMessageValidator(SyncMessageValidator validator) {
- validators.add(validator);
- }
-
- public void removeMessageValidator(SyncMessageValidator validator) {
- validators.remove(validator);
- }
-
- public Server getServer() {
- return server;
- }
-
- public Client getClient() {
- return client;
- }
-
- public double getMaxDelay() {
- return maxDelay;
- }
-
- public void setMaxDelay(double maxDelay) {
- this.maxDelay = maxDelay;
- }
-
- public float getSyncFrequency() {
- return syncFrequency;
- }
-
- public void setSyncFrequency(float syncFrequency) {
- this.syncFrequency = syncFrequency;
- }
-}
diff --git a/src/main/java/com/jme3/network/physicssync/PhysicsSyncMessage.java b/src/main/java/com/jme3/network/physicssync/PhysicsSyncMessage.java
deleted file mode 100644
index e65538f..0000000
--- a/src/main/java/com/jme3/network/physicssync/PhysicsSyncMessage.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.network.physicssync;
-
-import com.jme3.network.AbstractMessage;
-import com.jme3.network.serializing.Serializable;
-
-/**
- * Abstract physics sync message, can be used with PhysicsSyncManager, contains
- * timestamp and id. Override applyData method to apply the data to the object
- * with the specific id when it arrives.
- * @author normenhansen
- */
-@Serializable()
-public abstract class PhysicsSyncMessage extends AbstractMessage {
-
- public long syncId = -1;
- public double time;
-
- public PhysicsSyncMessage() {
- super(true);
- }
-
- public PhysicsSyncMessage(long id) {
- super(true);
- this.syncId = id;
- }
-
- public abstract void applyData(Object object);
-}
diff --git a/src/main/java/com/jme3/network/physicssync/SyncCharacterMessage.java b/src/main/java/com/jme3/network/physicssync/SyncCharacterMessage.java
deleted file mode 100644
index a750c09..0000000
--- a/src/main/java/com/jme3/network/physicssync/SyncCharacterMessage.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.network.physicssync;
-
-import com.jme3.bullet.control.CharacterControl;
-import com.jme3.math.Vector3f;
-import com.jme3.network.serializing.Serializable;
-import com.jme3.scene.Spatial;
-
-/**
- * Sync message for character objects
- * @author normenhansen
- */
-@Serializable()
-public class SyncCharacterMessage extends PhysicsSyncMessage {
-
- public Vector3f location = new Vector3f();
- public Vector3f walkDirection = new Vector3f();
- public Vector3f viewDirection = new Vector3f();
-
- public SyncCharacterMessage() {
- }
-
- public SyncCharacterMessage(long id, CharacterControl character) {
-// setReliable(false);
- this.syncId = id;
- character.getPhysicsLocation(location);
- this.walkDirection.set(character.getWalkDirection());
- this.viewDirection.set(character.getViewDirection());
- }
-
- public void readData(CharacterControl character) {
- character.getPhysicsLocation(location);
- this.walkDirection.set(character.getWalkDirection());
- this.viewDirection.set(character.getViewDirection());
- }
-
- public void applyData(Object character) {
- ((Spatial) character).getControl(CharacterControl.class).setPhysicsLocation(location);
- ((Spatial) character).getControl(CharacterControl.class).setWalkDirection(walkDirection);
- ((Spatial) character).getControl(CharacterControl.class).setViewDirection(viewDirection);
- }
-}
diff --git a/src/main/java/com/jme3/network/physicssync/SyncMessageValidator.java b/src/main/java/com/jme3/network/physicssync/SyncMessageValidator.java
deleted file mode 100644
index fc5af2e..0000000
--- a/src/main/java/com/jme3/network/physicssync/SyncMessageValidator.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.network.physicssync;
-
-/**
- *
- * @author normenhansen
- */
-public interface SyncMessageValidator {
- public boolean checkMessage(PhysicsSyncMessage message);
-}
diff --git a/src/main/java/com/jme3/network/physicssync/SyncRigidBodyMessage.java b/src/main/java/com/jme3/network/physicssync/SyncRigidBodyMessage.java
deleted file mode 100644
index b17ef4f..0000000
--- a/src/main/java/com/jme3/network/physicssync/SyncRigidBodyMessage.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 2009-2011 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jme3.network.physicssync;
-
-import com.jme3.bullet.control.RigidBodyControl;
-import com.jme3.bullet.control.VehicleControl;
-import com.jme3.bullet.objects.PhysicsRigidBody;
-import com.jme3.math.Matrix3f;
-import com.jme3.math.Vector3f;
-import com.jme3.network.serializing.Serializable;
-import com.jme3.scene.Spatial;
-
-/**
- * sync message for physics objects (RigidBody + Vehicle)
- * @author normenhansen
- */
-@Serializable()
-public class SyncRigidBodyMessage extends PhysicsSyncMessage {
-
- public Vector3f location;
- public Matrix3f rotation;
- public Vector3f linearVelocity;
- public Vector3f angularVelocity;
-
- public SyncRigidBodyMessage() {
- }
-
- public SyncRigidBodyMessage(long id, PhysicsRigidBody body) {
-// setReliable(false);
- this.syncId = id;
- location = body.getPhysicsLocation(new Vector3f());
- rotation = body.getPhysicsRotationMatrix(new Matrix3f());
- linearVelocity = new Vector3f();
- body.getLinearVelocity(linearVelocity);
- angularVelocity = new Vector3f();
- body.getAngularVelocity(angularVelocity);
- }
-
- public void readData(PhysicsRigidBody body) {
- location = body.getPhysicsLocation(new Vector3f());
- rotation = body.getPhysicsRotationMatrix(new Matrix3f());
- linearVelocity = new Vector3f();
- body.getLinearVelocity(linearVelocity);
- angularVelocity = new Vector3f();
- body.getAngularVelocity(angularVelocity);
- }
-
- public void applyData(Object body) {
- if (body == null) {
- return;
- }
- PhysicsRigidBody rigidBody = ((Spatial) body).getControl(RigidBodyControl.class);
- if (rigidBody == null) {
- rigidBody = ((Spatial) body).getControl(VehicleControl.class);
- }
- rigidBody.setPhysicsLocation(location);
- rigidBody.setPhysicsRotation(rotation);
- rigidBody.setLinearVelocity(linearVelocity);
- rigidBody.setAngularVelocity(angularVelocity);
- }
-}
diff --git a/src/main/java/jme3tools/navmesh/Cell.java b/src/main/java/jme3tools/navmesh/Cell.java
deleted file mode 100644
index ff38ddf..0000000
--- a/src/main/java/jme3tools/navmesh/Cell.java
+++ /dev/null
@@ -1,760 +0,0 @@
-package jme3tools.navmesh;
-
-import com.jme3.export.InputCapsule;
-import com.jme3.export.JmeExporter;
-import com.jme3.export.JmeImporter;
-import com.jme3.export.OutputCapsule;
-import com.jme3.export.Savable;
-import com.jme3.math.Vector2f;
-import com.jme3.math.Vector3f;
-import java.io.IOException;
-import java.util.Random;
-
-/**
- * A Cell represents a single triangle within a NavigationMesh. It contains
- * functions for testing a path against the cell, and various ways to resolve
- * collisions with the cell walls. Portions of the A* path finding algorythm are
- * provided within this class as well, but the path finding process is managed
- * by the parent Navigation Mesh.
- *
- * Portions Copyright (C) Greg Snook, 2000
- *
- * @author TR
- *
- */
-public class Cell implements Savable {
-
- static final int VERT_A = 0;
- static final int VERT_B = 1;
- static final int VERT_C = 2;
- static final int SIDE_AB = 0;
- static final int SIDE_BC = 1;
- static final int SIDE_CA = 2;
-
- enum PathResult {
-
- /**
- * The path does not cross this cell
- */
- NoRelationship,
-
- /**
- * The path ends in this cell
- */
- EndingCell,
-
- /**
- * The path exits this cell through side X
- */
- ExitingCell;
-
- };
-
- class ClassifyResult {
-
- PathResult result = PathResult.NoRelationship;
- int side = 0;
- Cell cell = null;
- Vector2f intersection = new Vector2f();
-
- @Override
- public String toString() {
- return result.toString() + " " + cell;
- }
- }
-
- /**
- * A plane containing the cell triangle
- */
- private Plane cellPlane = new Plane();
-
- /**
- * pointers to the verticies of this triangle held in the
- * NavigationMesh's vertex pool
- */
- private Vector3f[] verticies = new Vector3f[3];
-
- /**
- * The center of the triangle
- */
- private Vector3f center = new Vector3f();
-
- /**
- * a 2D line representing each cell Side
- */
- private Line2D[] sides = new Line2D[3];
-
- /**
- * pointers to cells that attach to this cell. A null link denotes a solid
- * edge. Pathfinding Data...
- */
- private Cell[] links = new Cell[3];
-
- /**
- * an identifier for the current pathfinding session.
- */
- private volatile int sessionID;
-
- /**
- * total cost to use this cell as part of a path
- */
- private volatile float arrivalCost;
-
- /**
- * our estimated cost to the goal from here
- */
- private volatile float heuristic;
-
- /**
- * are we currently listed as an Open cell to revisit and test?
- */
- private volatile boolean open;
-
- /**
- * the side we arrived through.
- */
- private volatile int arrivalWall;
-
- /**
- * the pre-computed midpoint of each wall.
- */
- private Vector3f[] wallMidpoints = new Vector3f[3];
-
- /**
- * the distances between each wall midpoint of sides (0-1, 1-2, 2-0)
- */
- private float[] wallDistances = new float[3];
-
- void initialize(Vector3f pointA, Vector3f pointB, Vector3f pointC) {
- verticies[VERT_A] = pointA;
- verticies[VERT_B] = pointB;
- verticies[VERT_C] = pointC;
-
- // object must be re-linked
- links[SIDE_AB] = null;
- links[SIDE_BC] = null;
- links[SIDE_CA] = null;
-
- // now that the vertex pointers are set, compute additional data about
- // the Cell
- computeCellData();
- }
-
- void computeCellData() {
- // create 2D versions of our verticies
- Vector2f point1 = new Vector2f(verticies[VERT_A].x, verticies[VERT_A].z);
- Vector2f point2 = new Vector2f(verticies[VERT_B].x, verticies[VERT_B].z);
- Vector2f point3 = new Vector2f(verticies[VERT_C].x, verticies[VERT_C].z);
-
- // innitialize our sides
- sides[SIDE_AB] = new Line2D(point1, point2); // line AB
- sides[SIDE_BC] = new Line2D(point2, point3); // line BC
- sides[SIDE_CA] = new Line2D(point3, point1); // line CA
-
- cellPlane.setPlanePoints(verticies[VERT_A], verticies[VERT_B],
- verticies[VERT_C]);
-
- // compute midpoint as centroid of polygon
- center.x = ((verticies[VERT_A].x + verticies[VERT_B].x + verticies[VERT_C].x) / 3);
- center.y = ((verticies[VERT_A].y + verticies[VERT_B].y + verticies[VERT_C].y) / 3);
- center.z = ((verticies[VERT_A].z + verticies[VERT_B].z + verticies[VERT_C].z) / 3);
-
- // compute the midpoint of each cell wall
- wallMidpoints[0] = new Vector3f(
- (verticies[VERT_A].x + verticies[VERT_B].x) / 2.0f,
- (verticies[VERT_A].y + verticies[VERT_B].y) / 2.0f,
- (verticies[VERT_A].z + verticies[VERT_B].z) / 2.0f);
- wallMidpoints[1] = new Vector3f(
- (verticies[VERT_C].x + verticies[VERT_B].x) / 2.0f,
- (verticies[VERT_C].y + verticies[VERT_B].y) / 2.0f,
- (verticies[VERT_C].z + verticies[VERT_B].z) / 2.0f);
-
- wallMidpoints[2] = new Vector3f(
- (verticies[VERT_C].x + verticies[VERT_A].x) / 2.0f,
- (verticies[VERT_C].y + verticies[VERT_A].y) / 2.0f,
- (verticies[VERT_C].z + verticies[VERT_A].z) / 2.0f);
-
- // compute the distances between the wall midpoints
- Vector3f wallVector;
- wallVector = wallMidpoints[0].subtract(wallMidpoints[1]);
- wallDistances[0] = wallVector.length();
-
- wallVector = wallMidpoints[1].subtract(wallMidpoints[2]);
- wallDistances[1] = wallVector.length();
-
- wallVector = wallMidpoints[2].subtract(wallMidpoints[0]);
- wallDistances[2] = wallVector.length();
-
- }
-
- /**
- * Navigation Mesh is created as a pool of raw cells. The cells are then
- * compared against each other to find common edges and create links.
- * This routine is called from a potentially adjacent cell to test if
- * a link should exist between the two.
- *
- * @param pointA
- * @param pointB
- * @param caller
- * @return
- */
- boolean requestLink(Vector3f pointA, Vector3f pointB, Cell caller, float epsilon) {
- // return true if we share the two provided verticies with the calling
- // cell.
- if (verticies[VERT_A].distanceSquared(pointA) <= epsilon) {
- if (verticies[VERT_B].distanceSquared(pointB) <= epsilon) {
- links[SIDE_AB] = caller;
- return true;
- } else if (verticies[VERT_C].distanceSquared(pointB) <= epsilon) {
- links[SIDE_CA] = caller;
- return true;
- }
- } else if (verticies[VERT_B].distanceSquared(pointA) <= epsilon) {
- if (verticies[VERT_A].equals(pointB)) {
- links[SIDE_AB] = caller;
- return true;
- } else if (verticies[VERT_C].distanceSquared(pointB) <= epsilon) {
- links[SIDE_BC] = caller;
- return true;
- }
- } else if (verticies[VERT_C].distanceSquared(pointA) <= epsilon) {
- if (verticies[VERT_A].distanceSquared(pointB) <= epsilon) {
- links[SIDE_CA] = caller;
- return true;
- } else if (verticies[VERT_B].distanceSquared(pointB) <= epsilon) {
- links[SIDE_BC] = caller;
- return true;
- }
- }
-
- // we are not adjacent to the calling cell
- return false;
- }
-
- /**
- * Sets a link to the calling cell on the enumerated edge.
- *
- * @param Side
- * @param Caller
- */
- private void setLink(int Side, Cell Caller) {
- links[Side] = Caller;
- }
-
- /**
- * Uses the X and Z information of the vector to calculate Y on the cell plane
- * @param point
- */
- public float getHeightOnCell(Vector3f point){
- return cellPlane.solveForY(point.x, point.z);
- }
-
- /**
- * Uses the X and Z information of the vector to calculate Y on the cell plane
- * @param point
- */
- public void computeHeightOnCell(Vector3f point) {
- point.y = getHeightOnCell(point);
- }
-
- /**
- * Test to see if a 2D point is within the cell. There are probably better
- * ways to do this, but this seems plenty fast for the time being.
- *
- * @param point
- * @return
- */
- public boolean contains(Vector2f point) {
- // we are "in" the cell if we are on the right hand side of all edge
- // lines of the cell
- int InteriorCount = 0;
-
- for (int i = 0; i < 3; i++) {
- Line2D.PointSide SideResult = sides[i].getSide(
- point, 1.0e-6f);
-
- if (SideResult != Line2D.PointSide.Left) {
- InteriorCount++;
- }
- }
- // if(InteriorCount == 3)
- // System.out.println("Point "+TestPoint+" is in Cell:"+this);
- // else
- // System.out.println("Point "+TestPoint+" is NOT in Cell:"+this);
- return (InteriorCount == 3);
- }
-
- /**
- * Test to see if a 3D point is within the cell by projecting it down to 2D
- * and calling the above method.
- * @param point
- * @return
- */
- public boolean contains(Vector3f point) {
- return (contains(new Vector2f(point.x, point.z)));
- }
-
- public Vector3f getVertex(int Vert) {
- return (verticies[Vert]);
- }
-
- public Vector3f getCenter() {
- return (center);
- }
-
- Cell getLink(int side) {
- return (links[side]);
- }
-
- Line2D getWall(int side){
- return sides[side];
- }
-
- float getArrivalCost() {
- return (arrivalCost);
- }
-
- float getHeuristic() {
- return (heuristic);
- }
-
- float getTotalCost() {
- return (arrivalCost + heuristic);
- }
-
- int getArrivalWall() {
- return (arrivalWall);
- }
-
- public float getWallLength(int side){
- return wallDistances[side];
- }
-
- public Vector3f getWallMidpoint(int side) {
- return (wallMidpoints[side]);
- }
-
- /**
- * Classifies a Path in relationship to this cell. A path is represented by
- * a 2D line where Point A is the start of the path and Point B is the
- * desired position.
- *
- * If the path exits this cell on a side which is linked to another cell,
- * that cell index is returned in the NextCell parameter and SideHit
- * contains the side number of the wall exited through.
- *
- * If the path collides with a side of the cell which has no link (a solid
- * edge), SideHit contains the side number (0-2) of the colliding wall.
- *
- * In either case PointOfIntersection will contain the point where the path
- * intersected with the wall of the cell if it is provided by the caller.
- */
- ClassifyResult classifyPathToCell(Line2D MotionPath) {
- // System.out.println("Cell:"+m_Vertex[0].toString()+" "+m_Vertex[1].toString()+" "+m_Vertex[2].toString());
- // System.out.println(" Path:"+MotionPath);
- int interiorCount = 0;
- ClassifyResult result = new ClassifyResult();
-
- // Check our MotionPath against each of the three cell walls
- for (int i = 0; i < 3; ++i) {
- // Classify the MotionPath endpoints as being either ON_LINE,
- // or to its LEFT_SIDE or RIGHT_SIDE.
- // Since our triangle vertices are in clockwise order,
- // we know that points to the right of each line are inside the
- // cell.
- // Points to the left are outside.
- // We do this test using the ClassifyPoint function of Line2D
-
- // If the destination endpoint of the MotionPath
- // is Not on the right side of this wall...
- Line2D.PointSide end = sides[i].getSide(
- MotionPath.getPointB(), 0.0f);
- if (end != Line2D.PointSide.Right) {
-// && end != Line2D.POINT_CLASSIFICATION.ON_LINE) {
- // ..and the starting endpoint of the MotionPath
- // is Not on the left side of this wall...
- if (sides[i].getSide(MotionPath.getPointA(), 0.0f) != Line2D.PointSide.Left) {
- // Check to see if we intersect the wall
- // using the Intersection function of Line2D
- Line2D.LineIntersect IntersectResult = MotionPath.intersect(sides[i], result.intersection);
-
- if (IntersectResult == Line2D.LineIntersect.SegmentsIntersect || IntersectResult == Line2D.LineIntersect.ABisectsB) {
- // record the link to the next adjacent cell
- // (or NULL if no attachement exists)
- // and the enumerated ID of the side we hit.
- result.cell = links[i];
- result.side = i;
- result.result = PathResult.ExitingCell;
- // System.out.println("exits this cell");
- return result;
-
- // pNextCell = m_Link[i];
- // Side = i;
- // return (PATH_RESULT.EXITING_CELL);
- }
- }
- } else {
- // The destination endpoint of the MotionPath is on the right
- // side.
- // Increment our InteriorCount so we'll know how many walls we
- // were
- // to the right of.
- interiorCount++;
- }
- }
-
- // An InteriorCount of 3 means the destination endpoint of the
- // MotionPath
- // was on the right side of all walls in the cell.
- // That means it is located within this triangle, and this is our ending
- // cell.
- if (interiorCount == 3) {
- // System.out.println(" ends within this cell");
- result.result = PathResult.EndingCell;
- return result;
- // return (PATH_RESULT.ENDING_CELL);
- }
- // System.out.println("No intersection with this cell at all");
- // We only reach here is if the MotionPath does not intersect the cell
- // at all.
- return result;
- // return (PATH_RESULT.NO_RELATIONSHIP);
- }
-
- /**
- * ProjectPathOnCellWall projects a path intersecting the wall with the wall
- * itself. This can be used to convert a path colliding with a cell wall to
- * a resulting path moving along the wall. The input parameter MotionPath
- * MUST contain a starting point (EndPointA) which is the point of
- * intersection with the path and cell wall number [SideNumber] and an
- * ending point (EndPointB) which resides outside of the cell.
- */
- void projectPathOnCellWall(int sideNumber, Line2D motionPath) {
- // compute the normalized vector of the cell wall in question
- Vector2f WallNormal = sides[sideNumber].getPointB().subtract(
- sides[sideNumber].getPointA());
- WallNormal = WallNormal.normalize();
-
- // determine the vector of our current movement
- Vector2f MotionVector = motionPath.getPointB().subtract(
- motionPath.getPointA());
-
- // compute dot product of our MotionVector and the normalized cell wall
- // this gives us the magnatude of our motion along the wall
-
- float DotResult = MotionVector.dot(WallNormal);
-
- // our projected vector is then the normalized wall vector times our new
- // found magnatude
- MotionVector = WallNormal.mult(DotResult);
-
- // redirect our motion path along the new reflected direction
- motionPath.setPointB(motionPath.getPointA().add(MotionVector));
-
- //
- // Make sure starting point of motion path is within the cell
- //
- Vector2f NewPoint = motionPath.getPointA();
- forcePointToCellColumn(NewPoint);
- motionPath.setPointA(NewPoint);
-
- //
- // Make sure destination point does not intersect this wall again
- //
- NewPoint = motionPath.getPointB();
- forcePointToWallInterior(sideNumber, NewPoint);
- motionPath.setPointB(NewPoint);
-
- }
-
- /**
- * Force a 2D point to the interior side of the specified wall.
- *
- * @param sideNumber
- * @param point
- * @return
- */
- boolean forcePointToWallInterior(int sideNumber, Vector2f point) {
- float Distance = sides[sideNumber].signedDistance(point);
- float Epsilon = 0.001f;
-
- if (Distance <= Epsilon) {
- if (Distance <= 0.0f) {
- Distance -= Epsilon;
- }
-
- Distance = Math.abs(Distance);
- Distance = (Epsilon > Distance ? Epsilon : Distance);
-
- // this point needs adjustment
- Vector2f Normal = sides[sideNumber].getNormal();
- Normal = Normal.mult(Distance);
- point.x += Normal.x;
- point.y += Normal.y;
- return (true);
- }
- return (false);
- }
-
- /**
- * Force a 3D point to the interior side of the specified wall.
- *
- * @param sideNumber
- * @param point
- * @return
- */
- boolean forcePointToWallInterior(int sideNumber, Vector3f point) {
- Vector2f TestPoint2D = new Vector2f(point.x, point.z);
- boolean PointAltered = forcePointToWallInterior(sideNumber, TestPoint2D);
-
- if (PointAltered) {
- point.x = TestPoint2D.x;
- point.z = TestPoint2D.y;
- }
-
- return (PointAltered);
- }
-
- /**
- * Force a 2D point to the interior cell by forcing it to the interior of
- * each wall.
- *
- * @param point
- * @return
- */
- boolean forcePointToCellColumn(Vector2f point) {
- // create a motion path from the center of the cell to our point
- Line2D TestPath = new Line2D(new Vector2f(center.x,
- center.z), point);
-
- ClassifyResult result = classifyPathToCell(TestPath);
- // compare this path to the cell.
-
- if (result.result == PathResult.ExitingCell) {
- Vector2f PathDirection = new Vector2f(result.intersection.x
- - center.x, result.intersection.y - center.z);
-
- PathDirection = PathDirection.mult(0.9f);
-
- point.x = center.x + PathDirection.x;
- point.y = center.z + PathDirection.y;
- return true;
- } else if (result.result == PathResult.NoRelationship) {
- point.x = center.x;
- point.y = center.z;
- return true;
- }
-
- return false;
- }
-
- /**
- * Force a 3D point to the interior cell by forcing it to the interior of
- * each wall
- * @param point
- * @return
- */
- boolean forcePointToCellColumn(Vector3f point) {
- Vector2f TestPoint2D = new Vector2f(point.x, point.z);
- boolean PointAltered = forcePointToCellColumn(TestPoint2D);
-
- if (PointAltered) {
- point.x = TestPoint2D.x;
- point.z = TestPoint2D.y;
- }
- return (PointAltered);
- }
-
- /**
- * Process this cells neighbors using A*
- *
- * @param heap
- * @return
- */
- boolean processCell(Heap heap) {
- if (sessionID == heap.getSessionID()) {
- // once we have been processed, we are closed
- open = false;
-
- // querry all our neigbors to see if they need to be added to the
- // Open heap
- for (int i = 0; i < 3; ++i) {
- if (links[i] != null) {
- // abs(i-m_ArrivalWall) is a formula to determine which
- // distance measurement to use.
- // The Distance measurements between the wall midpoints of
- // this cell
- // are held in the order ABtoBC, BCtoCA and CAtoAB.
- // We add this distance to our known m_ArrivalCost to
- // compute
- // the total cost to reach the next adjacent cell.
- links[i].queryForPath(heap, this, arrivalCost
- + wallDistances[Math.abs(i - arrivalWall)]);
- }
- }
- return true;
- }
- return false;
- }
-
- /**
- * Process this cell using the A* heuristic
- *
- * @param heap
- * @param caller
- * @param arrivalCost
- * @return
- */
- boolean queryForPath(Heap heap, Cell caller, float arrivalCost) {
- if (sessionID != heap.getSessionID()) {
- // this is a new session, reset our internal data
- sessionID = heap.getSessionID();
-
- if (caller != null) {
- open = true;
- computeHeuristic(heap.getGoal());
- this.arrivalCost = arrivalCost;
-
- // remember the side this caller is entering from
- if (caller.equals(links[0])) {
- arrivalWall = 0;
- } else if (caller.equals(links[1])) {
- arrivalWall = 1;
- } else if (caller.equals(links[2])) {
- arrivalWall = 2;
- }
- } else {
- // we are the cell that contains the starting location
- // of the A* search.
- open = false;
- this.arrivalCost = 0;
- heuristic = 0;
- arrivalWall = 0;
- }
- // add this cell to the Open heap
- heap.addCell(this);
- return true;
- } else if (open) {
- // m_Open means we are already in the Open Heap.
- // If this new caller provides a better path, adjust our data
- // Then tell the Heap to resort our position in the list.
- if ((arrivalCost + heuristic) < (this.arrivalCost + heuristic)) {
- this.arrivalCost = arrivalCost;
-
- // remember the side this caller is entering from
- if (caller.equals(links[0])) {
- arrivalWall = 0;
- } else if (caller.equals(links[1])) {
- arrivalWall = 1;
- } else if (caller.equals(links[2])) {
- arrivalWall = 2;
- }
- // ask the heap to resort our position in the priority heap
- heap.adjustCell(this);
- return true;
- }
- }
- // this cell is closed
- return false;
- }
-
-
- /**
- * Compute the A* Heuristic for this cell given a Goal point
- * @param goal
- */
- void computeHeuristic(Vector3f goal) {
- // our heuristic is the estimated distance (using the longest axis
- // delta) between our
- // cell center and the goal location
-
-// float XDelta = Math.abs(goal.x - center.x);
-// float YDelta = Math.abs(goal.y - center.y);
-// float ZDelta = Math.abs(goal.z - center.z);
-
-// heuristic = Math.max(Math.max(XDelta, YDelta), ZDelta);
- heuristic = goal.distance(center);
- }
-
- @Override
- public String toString() {
- return "Cell: " + center.x + "," + center.z;
- }
-
- public Vector3f getNormal() {
- return this.cellPlane.getNormal();
- }
-
- public Vector3f getRandomPoint() {
- Random rand = new Random();
- Vector2f ret =
- this.sides[0].getPointA().add(this.sides[0].getDirection().mult(rand.nextFloat()).add(
- this.sides[1].getDirection().mult(rand.nextFloat())));
- forcePointToCellColumn(ret);
- Vector3f vec = new Vector3f(ret.x, 0, ret.y);
- computeHeightOnCell(vec);
- return vec;
- }
-
- public void write(JmeExporter e) throws IOException {
- OutputCapsule capsule = e.getCapsule(this);
-// capsule.write(terrain, "terrain", null);
-// capsule.write(cellPlane, "cellPlane", null);
- capsule.write(verticies, "verticies", null);
-// capsule.write(center, "center", null);
-// capsule.write(sides, "sides", null);
- capsule.write(links, "links", null);
-// capsule.write(wallMidpoints, "midpoints", null);
-// capsule.write(wallDistances, "distances", null);
- }
-
- public void read(JmeImporter e) throws IOException {
- InputCapsule capsule = e.getCapsule(this);
-
- Savable[] verts = capsule.readSavableArray("verticies", null);
- for (int i = 0; i < verts.length; i++){
- verticies[i] = (Vector3f) verts[i];
- }
-
- Savable[] savLinks = capsule.readSavableArray("links", null);
- for (int i = 0; i < savLinks.length; i++){
- links[i] = (Cell) savLinks[i];
- }
-
- computeCellData();
-
-// cellPlane = (Plane) capsule.readSavable("cellPlane", new Plane());
-// center = (Vector3f) capsule.readSavable("center", new Vector3f());
-// sides = (Line2D[]) capsule.readSavableArray("sides", new Line2D[3]);
-// wallMidpoints = (Vector3f[]) capsule.readSavableArray("midpoints", new Vector3f[3]);
-// wallDistances = capsule.readFloatArray("distances", new float[3]);
-
-
- }
-
- void checkAndLink(Cell other, float epsilon) {
- if (getLink(Cell.SIDE_AB) == null
- && other.requestLink(getVertex(0), getVertex(1), this, epsilon)) {
- setLink(Cell.SIDE_AB, other);
- } else if (getLink(Cell.SIDE_BC) == null
- && other.requestLink(getVertex(1), getVertex(2), this, epsilon)) {
- setLink(Cell.SIDE_BC, other);
- } else if (getLink(Cell.SIDE_CA) == null
- && other.requestLink(getVertex(2), getVertex(0), this, epsilon)) {
- setLink(Cell.SIDE_CA, other);
- }
- }
-
- void unLink(Cell c) {
- if (c == links[0]) {
- links[0] = null;
- c.unLink(this);
- } else if (c == links[1]) {
- links[1] = null;
- c.unLink(this);
- } else if (c == links[2]) {
- links[2] = null;
- c.unLink(this);
- }
- }
-}
diff --git a/src/main/java/jme3tools/navmesh/Heap.java b/src/main/java/jme3tools/navmesh/Heap.java
deleted file mode 100644
index dbf20e2..0000000
--- a/src/main/java/jme3tools/navmesh/Heap.java
+++ /dev/null
@@ -1,86 +0,0 @@
-package jme3tools.navmesh;
-
-import jme3tools.navmesh.util.MinHeap;
-import com.jme3.math.Vector3f;
-
-/**
- * A NavigationHeap is a priority-ordered list facilitated by the STL heap
- * functions. This class is also used to hold the current path finding session
- * ID and the desired goal point for NavigationCells to query. Thanks to Amit J.
- * Patel for detailing the use of STL heaps in this way. It's much faster than a
- * linked list or multimap approach.
- *
- * Portions Copyright (C) Greg Snook, 2000
- *
- * @author TR
- *
- */
-class Heap {
-
- private MinHeap nodes = new MinHeap();
- private int sessionID;
- private Vector3f goal;
-
- int getSessionID() {
- return sessionID;
- }
-
- Vector3f getGoal() {
- return goal;
- }
-
- void initialize(int sessionID, Vector3f goal) {
- this.goal = goal;
- this.sessionID = sessionID;
- nodes.clear();
- }
-
- void addCell(Cell pCell) {
- Node newNode = new Node(pCell, pCell.getTotalCost());
- nodes.add(newNode);
- }
-
- /**
- * Adjust a cell in the heap to reflect it's updated cost value. NOTE: Cells
- * may only sort up in the heap.
- */
- void adjustCell(Cell pCell) {
- Node n = findNodeIterator(pCell);
-
- if (n != nodes.lastElement()) {
- // update the node data
- n.cell = pCell;
- n.cost = pCell.getTotalCost();
-
- nodes.sort();
- }
- }
-
- /**
- * @return true if the heap is not empty
- */
- boolean isNotEmpty() {
- return !nodes.isEmpty();
- }
-
- /**
- * Pop the top off the heap and remove the best value for processing.
- */
- Node getTop() {
- return (Node) nodes.deleteMin();
- }
-
- /**
- * Search the container for a given cell. May be slow, so don't do this
- * unless nessesary.
- */
- Node findNodeIterator(Cell pCell) {
- for (Object n : nodes) {
-
- if (((Node) n).cell.equals(pCell)) {
- return ((Node) n);
- }
- }
- return (Node) nodes.lastElement();
- }
-}
diff --git a/src/main/java/jme3tools/navmesh/Line2D.java b/src/main/java/jme3tools/navmesh/Line2D.java
deleted file mode 100644
index 3e5a957..0000000
--- a/src/main/java/jme3tools/navmesh/Line2D.java
+++ /dev/null
@@ -1,350 +0,0 @@
-package jme3tools.navmesh;
-
-import com.jme3.export.InputCapsule;
-import com.jme3.export.JmeExporter;
-import com.jme3.export.JmeImporter;
-import com.jme3.export.OutputCapsule;
-import com.jme3.export.Savable;
-import java.io.IOException;
-
-import com.jme3.math.Vector2f;
-
-/**
- *
- * Line2D represents a line in 2D space. Line data is held as a line segment having two
- * endpoints and as a fictional 3D plane extending verticaly. The Plane is then used for
- * spanning and point clasification tests. A Normal vector is used internally to represent
- * the fictional plane.
- *
- * Portions Copyright (C) Greg Snook, 2000
- * @author TR
- *
- */
-class Line2D implements Savable {
-
- enum PointSide {
-
- /**
- * The point is on, or very near, the line
- */
- OnLine,
- /**
- * looking from endpoint A to B, the test point is on the left
- */
- Left,
- /**
- * looking from endpoint A to B, the test point is on the right
- */
- Right;
- }
-
- enum LineIntersect {
-
- /**
- * both lines are parallel and overlap each other
- */
- CoLinear,
- /**
- * lines intersect, but their segments do not
- */
- LinesIntersect,
- /**
- * both line segments bisect each other
- */
- SegmentsIntersect,
- /**
- * line segment B is crossed by line A
- */
- ABisectsB,
- /**
- * line segment A is crossed by line B
- */
- BBisectsA,
- /**
- * the lines are paralell
- */
- Parallel;
- }
- /**
- * Endpoint A of our line segment
- */
- private Vector2f pointA;
- /**
- * Endpoint B of our line segment
- */
- private Vector2f pointB;
- /**
- * 'normal' of the ray.
- * a vector pointing to the right-hand side of the line
- * when viewed from PointA towards PointB
- */
- private volatile Vector2f normal;
-
- public Line2D(Vector2f pointA, Vector2f pointB) {
- this.pointA = pointA;
- this.pointB = pointB;
- normal = null;
- }
-
- public void setPointA(Vector2f point) {
- this.pointA = point;
- normal = null;
- }
-
- public void setPointB(Vector2f point) {
- this.pointB = point;
- normal = null;
- }
-
- public void setPoints(Vector2f PointA, Vector2f PointB) {
- this.pointA = PointA;
- this.pointB = PointB;
- normal = null;
- }
-
- public Vector2f getNormal() {
- if (normal == null)
- computeNormal();
-
- return normal;
- }
-
- public void setPoints(float PointAx, float PointAy, float PointBx, float PointBy) {
- pointA.x = PointAx;
- pointA.y = PointAy;
- pointB.x = PointBx;
- pointB.y = PointBy;
- normal = null;
- }
-
- public Vector2f getPointA() {
- return pointA;
- }
-
- public Vector2f getPointB() {
- return pointB;
- }
-
- public float length() {
- float xdist = pointB.x - pointA.x;
- float ydist = pointB.y - pointA.y;
-
- xdist *= xdist;
- ydist *= ydist;
-
- return (float) Math.sqrt(xdist + ydist);
- }
-
- public Vector2f getDirection() {
- return pointB.subtract(pointA).normalizeLocal();
- }
-
- private void computeNormal() {
- // Get Normailized direction from A to B
- normal = getDirection();
-
- // Rotate by -90 degrees to get normal of line
- float oldY = normal.y;
- normal.y = -normal.x;
- normal.x = oldY;
- }
-
- /**
- *
- Determines the signed distance from a point to this line. Consider the line as
- if you were standing on PointA of the line looking towards PointB. Posative distances
- are to the right of the line, negative distances are to the left.
- */
- public float signedDistance(Vector2f point) {
- if (normal == null) {
- computeNormal();
- }
-
- return point.subtract(pointA).dot(normal); //.x*m_Normal.x + TestVector.y*m_Normal.y;//DotProduct(TestVector,m_Normal);
- }
-
- /**
- * Determines where a point lies in relation to this line. Consider the line as
- * if you were standing on PointA of the line looking towards PointB. The incomming
- * point is then classified as being on the Left, Right or Centered on the line.
- */
- public PointSide getSide(Vector2f point, float epsilon) {
- PointSide result = PointSide.OnLine;
- float distance = signedDistance(point);
-
- if (distance > epsilon) {
- result = PointSide.Right;
- } else if (distance < -epsilon) {
- result = PointSide.Left;
- }
-
- return result;
- }
-
- /**
- * this line A = x0, y0 and B = x1, y1
- * other is A = x2, y2 and B = x3, y3
- * @param other
- * @param intersectionPoint
- * @return
- */
- public LineIntersect intersect(Line2D other, Vector2f intersectionPoint) {
- float denom = (other.pointB.y - other.pointA.y) * (this.pointB.x - this.pointA.x)
- - (other.pointB.x - other.pointA.x) * (this.pointB.y - this.pointA.y);
- float u0 = (other.pointB.x - other.pointA.x) * (this.pointA.y - other.pointA.y)
- - (other.pointB.y - other.pointA.y) * (this.pointA.x - other.pointA.x);
- float u1 = (other.pointA.x - this.pointA.x) * (this.pointB.y - this.pointA.y)
- - (other.pointA.y - this.pointA.y) * (this.pointB.x - this.pointA.x);
-
- //if parallel
- if (denom == 0.0f) {
- //if collinear
- if (u0 == 0.0f && u1 == 0.0f) {
- return LineIntersect.CoLinear;
- } else {
- return LineIntersect.Parallel;
- }
- } else {
- //check if they intersect
- u0 = u0 / denom;
- u1 = u1 / denom;
-
- float x = this.pointA.x + u0 * (this.pointB.x - this.pointA.x);
- float y = this.pointA.y + u0 * (this.pointB.y - this.pointA.y);
-
- if (intersectionPoint != null) {
- intersectionPoint.x = x; //(m_PointA.x + (FactorAB * Bx_minus_Ax));
- intersectionPoint.y = y; //(m_PointA.y + (FactorAB * By_minus_Ay));
- }
-
- // now determine the type of intersection
- if ((u0 >= 0.0f) && (u0 <= 1.0f) && (u1 >= 0.0f) && (u1 <= 1.0f)) {
- return LineIntersect.SegmentsIntersect;
- } else if ((u1 >= 0.0f) && (u1 <= 1.0f)) {
- return (LineIntersect.ABisectsB);
- } else if ((u0 >= 0.0f) && (u0 <= 1.0f)) {
- return (LineIntersect.BBisectsA);
- }
-
- return LineIntersect.LinesIntersect;
- }
- }
-
- /**
- * Determines if two segments intersect, and if so the point of intersection. The current
- * member line is considered line AB and the incomming parameter is considered line CD for
- * the purpose of the utilized equations.
- *
- * A = PointA of the member line
- * B = PointB of the member line
- * C = PointA of the provided line
- * D = PointB of the provided line
- */
- @Deprecated
- public LineIntersect intersectionOLD(Line2D Line, Vector2f pIntersectPoint) {
- float Ay_minus_Cy = pointA.y - Line.getPointA().y;
- float Dx_minus_Cx = Line.getPointB().x - Line.getPointA().x;
- float Ax_minus_Cx = pointA.x - Line.getPointA().x;
- float Dy_minus_Cy = Line.getPointB().y - Line.getPointA().y;
- float Bx_minus_Ax = pointB.x - pointA.x;
- float By_minus_Ay = pointB.y - pointA.y;
-
-
- java.awt.geom.Line2D l1 = new java.awt.geom.Line2D.Float(this.pointA.x, this.pointA.y, this.pointB.x, this.pointB.y);
- if (l1.intersectsLine(Line.getPointA().x, Line.getPointA().y, Line.getPointB().x, Line.getPointB().y)) //return LINE_CLASSIFICATION.LINES_INTERSECT;
- {
- System.out.println("They intersect");
- } else //return LINE_CLASSIFICATION.COLLINEAR;
- {
- System.out.println("They DO NOT intersect");
- }
-
- float Numerator = (Ay_minus_Cy * Dx_minus_Cx) - (Ax_minus_Cx * Dy_minus_Cy);
- float Denominator = (Bx_minus_Ax * Dy_minus_Cy) - (By_minus_Ay * Dx_minus_Cx);
-
- // if lines do not intersect, return now
- if (Denominator != 0.0f) {
- if (Numerator != 0.0f) {
- System.out.println("App says They DO NOT intersect");
- return LineIntersect.CoLinear;
- }
- System.out.println("App says They DO NOT intersect");
- return LineIntersect.Parallel;
- }
-
- float FactorAB = Numerator / Denominator;
- float FactorCD = ((Ay_minus_Cy * Bx_minus_Ax) - (Ax_minus_Cx * By_minus_Ay)) / Denominator;
-
- // posting (hitting a vertex exactly) is not allowed, shift the results
- // if they are within a minute range of the end vertecies
-// if (fabs(FactorCD) < 1.0e-6f)
-// {
-// FactorCD = 1.0e-6f;
-// }
-// if (fabs(FactorCD - 1.0f) < 1.0e-6f)
-// {
-// FactorCD = 1.0f - 1.0e-6f;
-// }
-
-
- // if an interection point was provided, fill it in now
- if (pIntersectPoint != null) {
- pIntersectPoint.x = (pointA.x + (FactorAB * Bx_minus_Ax));
- pIntersectPoint.y = (pointA.y + (FactorAB * By_minus_Ay));
- }
-
- System.out.println("App says They DO intersect");
- // now determine the type of intersection
- if ((FactorAB >= 0.0f) && (FactorAB <= 1.0f) && (FactorCD >= 0.0f) && (FactorCD <= 1.0f)) {
- return LineIntersect.SegmentsIntersect;
- } else if ((FactorCD >= 0.0f) && (FactorCD <= 1.0f)) {
- return (LineIntersect.ABisectsB);
- } else if ((FactorAB >= 0.0f) && (FactorAB <= 1.0f)) {
- return (LineIntersect.BBisectsA);
- }
-
- return LineIntersect.LinesIntersect;
-
- }
-
-
-
- public static void selfTest() {
- Line2D a = new Line2D(new Vector2f(-2, 0), new Vector2f(2, 0));
- Line2D b = new Line2D(new Vector2f(-2, 1), new Vector2f(2, -1));
- Line2D.LineIntersect res = a.intersect(b, null);
- if (res == LineIntersect.CoLinear || res == LineIntersect.Parallel) {
- System.out.println("Failed intersection verrification");
- }
-
- if (a.getSide(new Vector2f(0, 1), 0.0f) != PointSide.Left) {
- System.out.println("Failed left test");
- }
-
- if (a.getSide(new Vector2f(0, -1), 0.0f) != PointSide.Right) {
- System.out.println("Failed right test");
- }
-
- if (a.getSide(new Vector2f(0, 0), 0.0f) != PointSide.OnLine) {
- System.out.println("Failed on line test");
- }
- }
-
- public String toString() {
- return "Line:" + pointA.x + "/" + pointA.y + " -> " + pointB.x + "/" + pointB.y;
- }
-
- public void write(JmeExporter e) throws IOException {
- OutputCapsule capsule = e.getCapsule(this);
- capsule.write(pointA, "pointA", null);
- capsule.write(pointB, "pointB", null);
- capsule.write(normal, "normal", null);
- }
-
- public void read(JmeImporter e) throws IOException {
- InputCapsule capsule = e.getCapsule(this);
- pointA = (Vector2f) capsule.readSavable("pointA", new Vector2f());
- pointB = (Vector2f) capsule.readSavable("pointB", new Vector2f());
- normal = (Vector2f) capsule.readSavable("normal", new Vector2f());
- }
-}
diff --git a/src/main/java/jme3tools/navmesh/NavMesh.java b/src/main/java/jme3tools/navmesh/NavMesh.java
deleted file mode 100644
index 2ae29d6..0000000
--- a/src/main/java/jme3tools/navmesh/NavMesh.java
+++ /dev/null
@@ -1,517 +0,0 @@
-package jme3tools.navmesh;
-
-import java.io.IOException;
-import java.util.ArrayList;
-
-import jme3tools.navmesh.Cell.ClassifyResult;
-import jme3tools.navmesh.Cell.PathResult;
-import jme3tools.navmesh.Line2D.LineIntersect;
-import jme3tools.navmesh.Path.Waypoint;
-import com.jme3.export.InputCapsule;
-import com.jme3.export.JmeExporter;
-import com.jme3.export.JmeImporter;
-import com.jme3.export.OutputCapsule;
-import com.jme3.export.Savable;
-import com.jme3.math.Vector2f;
-import com.jme3.math.Vector3f;
-import com.jme3.scene.Mesh;
-import com.jme3.scene.VertexBuffer.Type;
-import com.jme3.scene.mesh.IndexBuffer;
-import com.jme3.util.BufferUtils;
-import java.nio.FloatBuffer;
-import java.util.List;
-
-/**
- * A NavigationMesh is a collection of NavigationCells used to control object
- * movement while also providing path finding line-of-sight testing. It serves
- * as a parent to all the Actor objects which exist upon it.
- *
- * Portions Copyright (C) Greg Snook, 2000
- *
- * @author TR
- *
- */
-public class NavMesh implements Savable {
-
- /**
- * the cells that make up this mesh
- */
- private ArrayList cellList = new ArrayList();
-
- /**
- * path finding data...
- */
- private volatile int sessionID = 0;
- private volatile Heap heap = new Heap();
-
- public void clear() {
- cellList.clear();
- }
-
- /**
- * Add a new cell, defined by the three vertices in clockwise order, to this
- * mesh.
- *
- * @param pointA
- * @param PointB
- * @param PointC
- */
- public void addCell(Vector3f pointA, Vector3f PointB, Vector3f PointC) {
- Cell newCell = new Cell();
- newCell.initialize(pointA.clone(), PointB.clone(), PointC.clone());
- cellList.add(newCell);
- }
-
- /**
- * Does noting at this point. Stubbed for future use in animating the mesh
- * @param elapsedTime
- */
- void Update(float elapsedTime) {
- }
-
- public int getNumCells() {
- return cellList.size();
- }
-
- public Cell getCell(int index) {
- return (cellList.get(index));
- }
-
- /**
- * Force a point to be inside the cell
- */
- public Vector3f snapPointToCell(Cell cell, Vector3f point) {
- if (!cell.contains(point))
- cell.forcePointToCellColumn(point);
-
- cell.computeHeightOnCell(point);
- return point;
- }
-
- /**
- * Force a point to be inside the nearest cell on the mesh
- */
- Vector3f snapPointToMesh(Vector3f point) {
- return snapPointToCell(findClosestCell(point), point);
- }
-
- /**
- * Find the closest cell on the mesh to the given point
- */
- public Cell findClosestCell(Vector3f point) {
- float closestDistance = 3.4E+38f;
- float closestHeight = 3.4E+38f;
- boolean foundHomeCell = false;
- float thisDistance;
- Cell closestCell = null;
-
- for (Cell cell : cellList) {
- if (cell.contains(point)) {
- thisDistance = Math.abs(cell.getHeightOnCell(point) - point.y);
-
- if (foundHomeCell) {
- if (thisDistance < closestHeight) {
- closestCell = cell;
- closestHeight = thisDistance;
- }
- } else {
- closestCell = cell;
- closestHeight = thisDistance;
- foundHomeCell = true;
- }
- }
-
- if (!foundHomeCell) {
- Vector2f start = new Vector2f(cell.getCenter().x, cell.getCenter().z);
- Vector2f end = new Vector2f(point.x, point.z);
- Line2D motionPath = new Line2D(start, end);
-
- ClassifyResult Result = cell.classifyPathToCell(motionPath);
-
- if (Result.result == Cell.PathResult.ExitingCell) {
- Vector3f ClosestPoint3D = new Vector3f(
- Result.intersection.x, 0.0f, Result.intersection.y);
- cell.computeHeightOnCell(ClosestPoint3D);
-
- ClosestPoint3D = ClosestPoint3D.subtract(point);
-
- thisDistance = ClosestPoint3D.length();
-
- if (thisDistance < closestDistance) {
- closestDistance = thisDistance;
- closestCell = cell;
- }
- }
- }
- }
-
- return closestCell;
- }
-
- /**
- * Build a navigation path using the provided points and the A* method
- */
- public boolean buildNavigationPath(Path navPath,
- Cell startCell, Vector3f startPos,
- Cell endCell, Vector3f endPos,
- float entityRadius) {
-
- // Increment our path finding session ID
- // This Identifies each pathfinding session
- // so we do not need to clear out old data
- // in the cells from previous sessions.
- sessionID++;
-
- // load our data into the Heap object
- // to prepare it for use.
- heap.initialize(sessionID, startPos);
-
- // We are doing a reverse search, from EndCell to StartCell.
- // Push our EndCell onto the Heap at the first cell to be processed
- endCell.queryForPath(heap, null, 0.0f);
-
- // process the heap until empty, or a path is found
- boolean foundPath = false;
- while (heap.isNotEmpty() && !foundPath) {
-
- // pop the top cell (the open cell with the lowest cost) off the
- // Heap
- Node currentNode = heap.getTop();
-
- // if this cell is our StartCell, we are done
- if (currentNode.cell.equals(startCell)) {
- foundPath = true;
- } else {
- // Process the Cell, Adding it's neighbors to the Heap as needed
- currentNode.cell.processCell(heap);
- }
- }
-
- Vector2f intersectionPoint = new Vector2f();
-
- // if we found a path, build a waypoint list
- // out of the cells on the path
- if (!foundPath)
- return false;
-
- // Setup the Path object, clearing out any old data
- navPath.initialize(this, startPos, startCell, endPos, endCell);
-
- Vector3f lastWayPoint = startPos;
-
- // Step through each cell linked by our A* algorythm
- // from StartCell to EndCell
- Cell currentCell = startCell;
- while (currentCell != null && currentCell != endCell) {
- // add the link point of the cell as a way point (the exit
- // wall's center)
- int linkWall = currentCell.getArrivalWall();
- Vector3f newWayPoint = currentCell.getWallMidpoint(linkWall).clone();
-
- Line2D wall = currentCell.getWall(linkWall);
- float length = wall.length();
- float distBlend = entityRadius / length;
-
- Line2D lineToGoal = new Line2D(new Vector2f(lastWayPoint.x, lastWayPoint.z),
- new Vector2f(endPos.x, endPos.z));
- LineIntersect result = lineToGoal.intersect(wall, intersectionPoint);
- switch (result){
- case SegmentsIntersect:
- float d1 = wall.getPointA().distance(intersectionPoint);
- float d2 = wall.getPointB().distance(intersectionPoint);
- if (d1 > entityRadius && d2 > entityRadius){
- // we can fit through the wall if we go
- // directly to the goal.
- newWayPoint = new Vector3f(intersectionPoint.x, 0, intersectionPoint.y);
- }else{
- // cannot fit directly.
- // try to find point where we can
- if (d1 < d2){
- intersectionPoint.interpolateLocal(wall.getPointA(), wall.getPointB(), distBlend);
- newWayPoint = new Vector3f(intersectionPoint.x, 0, intersectionPoint.y);
- }else{
- intersectionPoint.interpolateLocal(wall.getPointB(), wall.getPointA(), distBlend);
- newWayPoint = new Vector3f(intersectionPoint.x, 0, intersectionPoint.y);
- }
- }
- currentCell.computeHeightOnCell(newWayPoint);
- break;
- case LinesIntersect:
- case ABisectsB:
- case BBisectsA:
- Vector2f lastPt2d = new Vector2f(lastWayPoint.x, lastWayPoint.z);
- Vector2f endPos2d = new Vector2f(endPos.x, endPos.z);
-
- Vector2f normalEnd = endPos2d.subtract(lastPt2d).normalizeLocal();
- Vector2f normalA = wall.getPointA().subtract(lastPt2d).normalizeLocal();
- Vector2f normalB = wall.getPointB().subtract(lastPt2d).normalizeLocal();
- if (normalA.dot(normalEnd) < normalB.dot(normalEnd)){
- // choose point b
- intersectionPoint.interpolateLocal(wall.getPointB(), wall.getPointA(), distBlend);
- newWayPoint = new Vector3f(intersectionPoint.x, 0, intersectionPoint.y);
- }else{
- // choose point a
- intersectionPoint.interpolateLocal(wall.getPointA(), wall.getPointB(), distBlend);
- newWayPoint = new Vector3f(intersectionPoint.x, 0, intersectionPoint.y);
- }
- currentCell.computeHeightOnCell(newWayPoint);
-
- break;
- case CoLinear:
- case Parallel:
- break;
- }
-
-// newWayPoint = snapPointToCell(currentCell, newWayPoint);
- lastWayPoint = newWayPoint.clone();
-
- navPath.addWaypoint(newWayPoint, currentCell);
-
- // get the next cell
- currentCell = currentCell.getLink(linkWall);
- }
-
- // cap the end of the path.
- navPath.finishPath();
-
- // further: optimize the path
- List newPath = new ArrayList();
- Waypoint curWayPoint = navPath.getFirst();
- newPath.add(curWayPoint);
- while (curWayPoint != navPath.getLast()){
- curWayPoint = navPath.getFurthestVisibleWayPoint(curWayPoint);
- newPath.add(curWayPoint);
- }
-
- navPath.initialize(this, startPos, startCell, endPos, endCell);
- for (Waypoint newWayPoint : newPath){
- navPath.addWaypoint(newWayPoint.getPosition(), newWayPoint.getCell());
- }
- navPath.finishPath();
-
- return true;
- }
-
- /**
- * Resolve a movement vector on the mesh
- *
- * @param startPos
- * @param startCell
- * @param endPos
- * @return
- */
- public Cell resolveMotionOnMesh(Vector3f startPos, Cell startCell, Vector3f endPos, Vector3f modifiedEndPos) {
- int i = 0;
- // create a 2D motion path from our Start and End positions, tossing out
- // their Y values to project them
- // down to the XZ plane.
- Line2D motionLine = new Line2D(new Vector2f(startPos.x, startPos.z),
- new Vector2f(endPos.x, endPos.z));
-
- // these three will hold the results of our tests against the cell walls
- ClassifyResult result = null;
-
- // TestCell is the cell we are currently examining.
- Cell currentCell = startCell;
-
- do {
- i++;
- // use NavigationCell to determine how our path and cell interact
- // if(TestCell.IsPointInCellCollumn(MotionPath.EndPointA()))
- // System.out.println("Start is in cell");
- // else
- // System.out.println("Start is NOT in cell");
- // if(TestCell.IsPointInCellCollumn(MotionPath.EndPointB()))
- // System.out.println("End is in cell");
- // else
- // System.out.println("End is NOT in cell");
- result = currentCell.classifyPathToCell(motionLine);
-
- // if exiting the cell...
- if (result.result == PathResult.ExitingCell) {
- // Set if we are moving to an adjacent cell or we have hit a
- // solid (unlinked) edge
- if (result.cell != null) {
- // moving on. Set our motion origin to the point of
- // intersection with this cell
- // and continue, using the new cell as our test cell.
- motionLine.setPointA(result.intersection);
- currentCell = result.cell;
- } else {
- // we have hit a solid wall. Resolve the collision and
- // correct our path.
- motionLine.setPointA(result.intersection);
- currentCell.projectPathOnCellWall(result.side, motionLine);
-
- // add some friction to the new MotionPath since we are
- // scraping against a wall.
- // we do this by reducing the magnatude of our motion by 10%
- Vector2f Direction = motionLine.getPointB().subtract(
- motionLine.getPointA()).mult(0.9f);
- // Direction.mult(0.9f);
- motionLine.setPointB(motionLine.getPointA().add(
- Direction));
- }
- } else if (result.result == Cell.PathResult.NoRelationship) {
- // Although theoretically we should never encounter this case,
- // we do sometimes find ourselves standing directly on a vertex
- // of the cell.
- // This can be viewed by some routines as being outside the
- // cell.
- // To accomodate this rare case, we can force our starting point
- // to be within
- // the current cell by nudging it back so we may continue.
- Vector2f NewOrigin = motionLine.getPointA();
- // NewOrigin.x -= 0.01f;
- currentCell.forcePointToCellColumn(NewOrigin);
- motionLine.setPointA(NewOrigin);
- }
- }//
- // Keep testing until we find our ending cell or stop moving due to
- // friction
- //
- while ((result.result != Cell.PathResult.EndingCell)
- && (motionLine.getPointA().x != motionLine.getPointB().x && motionLine.getPointA().y != motionLine.getPointB().y) && i < 5000);
- //
- if (i >= 5000) {
- System.out.println("Loop detected in ResolveMotionOnMesh");
- }
- // we now have our new host cell
-
- // Update the new control point position,
- // solving for Y using the Plane member of the NavigationCell
- modifiedEndPos.x = motionLine.getPointB().x;
- modifiedEndPos.y = 0.0f;
- modifiedEndPos.z = motionLine.getPointB().y;
- currentCell.computeHeightOnCell(modifiedEndPos);
-
- return currentCell;
- }
-
- /**
- * Test to see if two points on the mesh can view each other
- * FIXME: EndCell is the last visible cell?
- *
- * @param StartCell
- * @param StartPos
- * @param EndPos
- * @return
- */
- boolean isInLineOfSight(Cell StartCell, Vector3f StartPos, Vector3f EndPos) {
- Line2D MotionPath = new Line2D(new Vector2f(StartPos.x, StartPos.z),
- new Vector2f(EndPos.x, EndPos.z));
-
- Cell testCell = StartCell;
- Cell.ClassifyResult result = testCell.classifyPathToCell(MotionPath);
-
- while (result.result == Cell.PathResult.ExitingCell) {
- if (result.cell == null)// hit a wall, so the point is not visible
- {
- return false;
- }
- result = result.cell.classifyPathToCell(MotionPath);
-
- }
-
- return (result.result == Cell.PathResult.EndingCell);
- }
-
- /**
- * Link all the cells that are in our pool
- */
- public void linkCells() {
-// for (int i = 0; i < cellList.size(); i++){
-// for (int j = i+1; j < cellList.size(); j++){
-// cellList.get(i).checkAndLink(cellList.get(j));
-// }
-// }
- for (Cell pCellA : cellList) {
- for (Cell pCellB : cellList) {
- if (pCellA != pCellB) {
- pCellA.checkAndLink(pCellB, 0.001f);
- }
- }
- }
- }
-
- private void addFace(Vector3f vertA, Vector3f vertB, Vector3f vertC) {
- // some art programs can create linear polygons which have two or more
- // identical vertices. This creates a poly with no surface area,
- // which will wreak havok on our navigation mesh algorithms.
- // We only except polygons with unique vertices.
- if ((!vertA.equals(vertB)) && (!vertB.equals(vertC)) && (!vertC.equals(vertA))) {
- addCell(vertA, vertB, vertC);
- }else{
- System.out.println("Warning, Face winding incorrect");
- }
- }
-
- public void loadFromData(Vector3f[] positions, short[][] indices){
- Plane up = new Plane();
- up.setPlanePoints(Vector3f.UNIT_X, Vector3f.ZERO, Vector3f.UNIT_Z);
- up.getNormal();
-
- for (int i = 0; i < indices.length/3; i++) {
- Vector3f vertA = positions[indices[i][0]];
- Vector3f vertB = positions[indices[i][1]];
- Vector3f vertC = positions[indices[i][2]];
-
- Plane p = new Plane();
- p.setPlanePoints(vertA, vertB, vertC);
- if (up.pseudoDistance(p.getNormal()) <= 0.0f) {
- System.out.println("Warning, normal of the plane faces downward!!!");
- continue;
- }
-
- addFace(vertA, vertB, vertC);
- }
-
- linkCells();
- }
-
- public void loadFromMesh(Mesh mesh) {
- clear();
-
- Vector3f a = new Vector3f();
- Vector3f b = new Vector3f();
- Vector3f c = new Vector3f();
-
- Plane up = new Plane();
- up.setPlanePoints(Vector3f.UNIT_X, Vector3f.ZERO, Vector3f.UNIT_Z);
- up.getNormal();
-
- IndexBuffer ib = mesh.getIndexBuffer();
- FloatBuffer pb = mesh.getFloatBuffer(Type.Position);
- pb.clear();
- for (int i = 0; i < mesh.getTriangleCount()*3; i+=3){
- int i1 = ib.get(i+0);
- int i2 = ib.get(i+1);
- int i3 = ib.get(i+2);
- BufferUtils.populateFromBuffer(a, pb, i1);
- BufferUtils.populateFromBuffer(b, pb, i2);
- BufferUtils.populateFromBuffer(c, pb, i3);
-
- Plane p = new Plane();
- p.setPlanePoints(a, b, c);
- if (up.pseudoDistance(p.getNormal()) <= 0.0f) {
- System.out.println("Warning, normal of the plane faces downward!!!");
- continue;
- }
-
- addFace(a, b, c);
- }
-
- linkCells();
- }
-
- public void write(JmeExporter e) throws IOException {
- OutputCapsule capsule = e.getCapsule(this);
- capsule.writeSavableArrayList(cellList, "cellarray", null);
- }
-
- @SuppressWarnings("unchecked")
- public void read(JmeImporter e) throws IOException {
- InputCapsule capsule = e.getCapsule(this);
- cellList = (ArrayList) capsule.readSavableArrayList("cellarray", new ArrayList());
- }
-}
diff --git a/src/main/java/jme3tools/navmesh/NavMeshPathfinder.java b/src/main/java/jme3tools/navmesh/NavMeshPathfinder.java
deleted file mode 100644
index f999ea2..0000000
--- a/src/main/java/jme3tools/navmesh/NavMeshPathfinder.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package jme3tools.navmesh;
-
-import jme3tools.navmesh.Path.Waypoint;
-import com.jme3.math.Vector2f;
-import com.jme3.math.Vector3f;
-
-public class NavMeshPathfinder {
-
- private NavMesh navMesh;
- private Path path = new Path();
- private float entityRadius;
-
- private Vector2f currentPos = new Vector2f();
- private Vector3f currentPos3d = new Vector3f();
- private Cell currentCell;
-
- private Vector2f goalPos;
- private Vector3f goalPos3d;
- private Cell goalCell;
-
- private Waypoint nextWaypoint;
-
- public NavMeshPathfinder(NavMesh navMesh){
- this.navMesh = navMesh;
- }
-
- public Vector3f getPosition() {
- return currentPos3d;
- }
-
- public void setPosition(Vector3f position) {
- this.currentPos3d.set(position);
- this.currentPos.set(currentPos3d.x, currentPos3d.z);
- }
-
- public float getEntityRadius() {
- return entityRadius;
- }
-
- public void setEntityRadius(float entityRadius) {
- this.entityRadius = entityRadius;
- }
-
- public Vector3f warp(Vector3f newPos){
- Vector3f newPos2d = new Vector3f(newPos.x, 0, newPos.z);
- currentCell = navMesh.findClosestCell(newPos2d);
- currentPos3d.set(navMesh.snapPointToCell(currentCell, newPos2d));
- currentPos3d.setY(newPos.getY());
- currentPos.set(currentPos3d.getX(), currentPos3d.getZ());
- return currentPos3d;
- }
-
- public boolean computePath(Vector3f goal){
- goalPos3d = goal;
- goalPos = new Vector2f(goalPos3d.getX(), goalPos3d.getZ());
- Vector3f goalPos2d = new Vector3f(goalPos.getX(), 0, goalPos.getY());
- goalCell = navMesh.findClosestCell(goalPos2d);
- boolean result = navMesh.buildNavigationPath(path, currentCell, currentPos3d, goalCell, goalPos3d, entityRadius);
- if (!result){
- goalPos = null;
- goalCell = null;
- return false;
- }
- nextWaypoint = path.getFirst();
- return true;
- }
-
- public void clearPath(){
- path.clear();
- goalPos = null;
- goalCell = null;
- nextWaypoint = null;
- }
-
- public Vector3f getWaypointPosition(){
- return nextWaypoint.getPosition();
- }
-
- public Vector3f getDirectionToWaypoint(){
- Vector3f waypt = nextWaypoint.getPosition();
- return waypt.subtract(currentPos3d).normalizeLocal();
- }
-
- public float getDistanceToWaypoint(){
- return currentPos3d.distance(nextWaypoint.getPosition());
- }
-
- public Vector3f onMove(Vector3f moveVec){
- if (moveVec.equals(Vector3f.ZERO))
- return currentPos3d;
-
- Vector3f newPos2d = new Vector3f(currentPos3d);
- newPos2d.addLocal(moveVec);
- newPos2d.setY(0);
-
- Vector3f currentPos2d = new Vector3f(currentPos3d);
- currentPos2d.setY(0);
-
- Cell nextCell = navMesh.resolveMotionOnMesh(currentPos2d, currentCell, newPos2d, newPos2d);
- currentCell = nextCell;
- newPos2d.setY(currentPos3d.getY());
- return newPos2d;
- }
-
- public boolean isAtGoalWaypoint(){
- return nextWaypoint == path.getLast();
- }
-
- public void gotoToNextWaypoint(){
- nextWaypoint = path.getFurthestVisibleWayPoint(nextWaypoint);
- Vector3f waypt = nextWaypoint.getPosition();
- currentPos3d.setX(waypt.getX());
- currentPos3d.setZ(waypt.getZ());
- currentPos.set(waypt.getX(), waypt.getZ());
- currentCell = nextWaypoint.getCell();
- }
-
-}
diff --git a/src/main/java/jme3tools/navmesh/Node.java b/src/main/java/jme3tools/navmesh/Node.java
deleted file mode 100644
index 2564ef4..0000000
--- a/src/main/java/jme3tools/navmesh/Node.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package jme3tools.navmesh;
-
-/**
- * A NavigationNode represents an entry in the NavigationHeap. It provides some
- * simple operators to classify it against other NavigationNodes when the heap
- * is sorted.
- *
- * Portions Copyright (C) Greg Snook, 2000
- *
- * @author TR
- *
- */
-class Node implements Comparable {
-
- /**
- * pointer to the cell in question
- */
- Cell cell = null;
- /**
- * (g + h) in A* represents the cost of traveling through this cell
- */
- float cost = 0.0f;
-
- public Node() {
- }
-
- public Node(Cell c, float costs) {
- cell = c;
- cost = costs;
- }
-
- /**
- * To compare two nodes, we compare the cost or `f' value, which is the sum
- * of the g and h values defined by A*.
- *
- * @param o
- * the Object to be compared.
- * @return a negative integer, zero, or a positive integer as this object is
- * less than, equal to, or greater than the specified object.
- */
- public int compareTo(Node o) {
- if (this.cost < (o.cost)) {
- return -1;
- } else if ((this.cost > (o.cost))) {
- return 1;
- } else {
- return 0;
- }
- }
-}
diff --git a/src/main/java/jme3tools/navmesh/Path.java b/src/main/java/jme3tools/navmesh/Path.java
deleted file mode 100644
index fb9ad16..0000000
--- a/src/main/java/jme3tools/navmesh/Path.java
+++ /dev/null
@@ -1,179 +0,0 @@
-package jme3tools.navmesh;
-
-import jme3tools.navmesh.Path.Waypoint;
-import com.jme3.math.Vector3f;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-/**
- * NavigationPath is a collection of waypoints that define a movement path for
- * an Actor. This object is ownded by an Actor and filled by
- * NavigationMesh::BuildNavigationPath().
- *
- * Portions Copyright (C) Greg Snook, 2000
- *
- * @author TR
- *
- */
-public class Path implements Iterable {
-
- public class Waypoint {
-
- private Vector3f position;
- private Cell cell;
-
- /**
- * The cell which owns the waypoint
- */
- public Cell getCell() {
- return cell;
- }
-
- public void setCell(Cell cell) {
- this.cell = cell;
- }
-
- /**
- * 3D position of waypoint
- */
- public Vector3f getPosition() {
- return position;
- }
-
- public void setPosition(Vector3f position) {
- this.position = position;
- }
-
- @Override
- public String toString() {
- return "Waypoint[position=" + position.x + ", " + position.z + " cell:"
- + cell + "]";
- }
- }
-
- private NavMesh owner;
- private Waypoint start = new Waypoint();
- private Waypoint end = new Waypoint();
- private ArrayList waypointList = new ArrayList();
-
- /**
- * Sets up a new path from StartPoint to EndPoint. It adds the StartPoint as
- * the first waypoint in the list and waits for further calls to AddWayPoint
- * and EndPath to complete the list
- *
- * @param parent
- * @param startPoint
- * @param startCell
- * @param endPoint
- * @param endCell
- */
- public void initialize(NavMesh parent,
- Vector3f startPoint, Cell startCell,
- Vector3f endPoint, Cell endCell) {
-
- waypointList.clear();
-
- this.owner = parent;
-
- start.setPosition(startPoint);
- start.setCell(startCell);
-
- end.setPosition(endPoint);
- end.setCell(endCell);
-
- // setup the waypoint list with our start and end points
- waypointList.add(start);
- }
-
- public void clear() {
- waypointList.clear();
- }
-
- public int size(){
- return waypointList.size();
- }
-
- public Iterator iterator() {
- return waypointList.iterator();
- }
-
- /**
- * Adds a new waypoint to the end of the list
- */
- public void addWaypoint(Vector3f point, Cell cell) {
- Waypoint newPoint = new Waypoint();
- newPoint.setPosition(point);
- newPoint.setCell(cell);
- waypointList.add(newPoint);
- }
-
- /**
- * Caps the end of the waypoint list by adding our final destination point.
- */
- void finishPath() {
- // cap the waypoint path with the last endpoint
- waypointList.add(end);
- }
-
- public NavMesh getOwner() {
- return owner;
- }
-
- public Waypoint getStart() {
- return start;
- }
-
- public Waypoint getEnd() {
- return end;
- }
-
- public Waypoint getFirst(){
- return waypointList.get(0);
- }
-
- public Waypoint getLast(){
- return waypointList.get(waypointList.size()-1);
- }
-
- public ArrayList getWaypoints() {
- return waypointList;
- }
-
- /**
- * Find the furthest visible waypoint from the VantagePoint provided. This
- * is used to smooth out irregular paths.
- *
- * @param vantagePoint
- * @return
- */
- public Waypoint getFurthestVisibleWayPoint(Waypoint vantagePoint) {
- // see if we are already talking about the last waypoint
- if (vantagePoint == getLast()) {
- return vantagePoint;
- }
-
- int i = waypointList.indexOf(vantagePoint);
- if (i < 0) {
- // The given waypoint does not belong to this path.
- return vantagePoint;
- }
-
- Waypoint testPoint = waypointList.get(++i);
- if (testPoint == getLast()) {
- System.out.println(" WAY IND was last");
- return testPoint;
- }
-
- Waypoint visibleWaypoint = testPoint;
- while (testPoint != getLast()) {
- if (!owner.isInLineOfSight(vantagePoint.cell, vantagePoint.position,
- testPoint.position)) {
-// System.out.println(" WAY IND was:" + i);
- return visibleWaypoint;
- }
- visibleWaypoint = testPoint;
- testPoint = waypointList.get(++i);
- }
- return testPoint;
- }
-}
diff --git a/src/main/java/jme3tools/navmesh/Plane.java b/src/main/java/jme3tools/navmesh/Plane.java
deleted file mode 100644
index ae27f9f..0000000
--- a/src/main/java/jme3tools/navmesh/Plane.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package jme3tools.navmesh;
-
-/**
- * A Plane in 3D Space represented in point-normal form (Ax + By + Cz + D = 0).
- *
- * The convention for the distance constant D is:
- *
- * D = -(A, B, C) dot (X, Y, Z)
- *
- * Portions Copyright (C) Greg Snook, 2000
- *
- * @author TR
- *
- */
-public class Plane extends com.jme3.math.Plane {
-
- /**
- * Given Z and Y, Solve for X on the plane
- *
- * @param y
- * @param z
- * @return
- */
- public float solveForX(float y, float z) {
- // Ax + By + Cz + D = 0
- // Ax = -(By + Cz + D)
- // x = -(By + Cz + D)/A
-
- // if (m_Normal[x] != null)
- // {
- // using jme plane we have to flip the sign as the constant is
- // calculated different
- // return ( -(normal.y*Y + normal.z*Z + constant) / normal.x );
- return (-(normal.y * y + normal.z * z - constant) / normal.x);
- // }
- //
- // return (0.0f);
- }
-
- /**
- * Given X and Z, Solve for Y on the plane
- *
- * @param x
- * @param z
- * @return
- */
- public float solveForY(float x, float z) {
- // Ax + By + Cz + D = 0
- // By = -(Ax + Cz + D)
- // y = -(Ax + Cz + D)/B
-
- // if (m_Normal[1])
- // {
- // using jme plane we have to flip the sign as the constant is
- // calculated different
- // return ( -(normal.x*X + normal.z*Z + constant) / normal.y );
- return (-(normal.x * x + normal.z * z - constant) / normal.y);
- // }
- //
- // return (0.0f);
- }
-
- /**
- * Given X and Y, Solve for Z on the plane
- *
- * @param x
- * @param y
- * @return
- */
- public float solveForZ(float x, float y) {
- // Ax + By + Cz + D = 0
- // Cz = -(Ax + By + D)
- // z = -(Ax + By + D)/C
-
- // if (m_Normal[2])
- // {
- // using jme plane we have to flip the sign as the constant is
- // calculated different
- // return ( -(normal.x*X + normal.y*Y + constant) / normal.z );
- return (-(normal.x * x + normal.y * y - constant) / normal.z);
- // }
- //
- // return (0.0f);
- }
-}
diff --git a/src/main/java/jme3tools/navmesh/util/GenGui.form b/src/main/java/jme3tools/navmesh/util/GenGui.form
deleted file mode 100644
index 8458f26..0000000
--- a/src/main/java/jme3tools/navmesh/util/GenGui.form
+++ /dev/null
@@ -1,395 +0,0 @@
-
-
-
diff --git a/src/main/java/jme3tools/navmesh/util/GenGui.java b/src/main/java/jme3tools/navmesh/util/GenGui.java
deleted file mode 100644
index 58ebbb5..0000000
--- a/src/main/java/jme3tools/navmesh/util/GenGui.java
+++ /dev/null
@@ -1,373 +0,0 @@
-package jme3tools.navmesh.util;
-
-import jme3tools.navmesh.util.NavMeshGenerator;
-import java.io.File;
-import javax.swing.JFileChooser;
-import javax.swing.JFrame;
-
-public class GenGui extends javax.swing.JFrame {
-
- private NavMeshGenerator navMeshGen;
- private JFileChooser chooser = new JFileChooser();
-
- public GenGui(NavMeshGenerator navMeshGen) {
- initComponents();
- this.navMeshGen = navMeshGen;
- setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- }
-
- @SuppressWarnings("unchecked")
- // //GEN-BEGIN:initComponents
- private void initComponents() {
-
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- jLabel4 = new javax.swing.JLabel();
- jLabel5 = new javax.swing.JLabel();
- jLabel6 = new javax.swing.JLabel();
- jLabel7 = new javax.swing.JLabel();
- jLabel8 = new javax.swing.JLabel();
- jLabel9 = new javax.swing.JLabel();
- jLabel10 = new javax.swing.JLabel();
- jLabel11 = new javax.swing.JLabel();
- jLabel12 = new javax.swing.JLabel();
- jLabel13 = new javax.swing.JLabel();
- jLabel14 = new javax.swing.JLabel();
- jLabel15 = new javax.swing.JLabel();
- jLabel16 = new javax.swing.JLabel();
- jButton1 = new javax.swing.JButton();
- jSlider1 = new javax.swing.JSlider();
- jSlider2 = new javax.swing.JSlider();
- jSlider3 = new javax.swing.JSlider();
- jSlider4 = new javax.swing.JSlider();
- jSlider5 = new javax.swing.JSlider();
- jSlider6 = new javax.swing.JSlider();
- jSlider7 = new javax.swing.JSlider();
- jSlider8 = new javax.swing.JSlider();
- jSlider9 = new javax.swing.JSlider();
- jSlider10 = new javax.swing.JSlider();
- jSlider11 = new javax.swing.JSlider();
- jSlider12 = new javax.swing.JSlider();
- jSlider13 = new javax.swing.JSlider();
- jSlider14 = new javax.swing.JSlider();
- jCheckBox1 = new javax.swing.JCheckBox();
- jCheckBox2 = new javax.swing.JCheckBox();
- jButton2 = new javax.swing.JButton();
-
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
-
- jLabel1.setText("Cell Size: ");
-
- jLabel2.setText("Cell Height: ");
-
- jLabel3.setText("Min Trav. Height: ");
-
- jLabel4.setText("Max Trav. Step: ");
-
- jLabel5.setText("Max Trav. Slope");
-
- jLabel6.setText("Clip Ledges: ");
-
- jLabel7.setText("Trav. Area Border Size: ");
-
- jLabel8.setText("Smooth Thresh: ");
-
- jLabel9.setText("Conservative Expansion: ");
-
- jLabel10.setText("Min Unconn. Region Size: ");
-
- jLabel11.setText("Merge Region Size: ");
-
- jLabel12.setText("Max Edge Length: ");
-
- jLabel13.setText("Edge Max Deviation: ");
-
- jLabel14.setText("Max Verts/Poly: ");
-
- jLabel15.setText("Contour Sample Dist: ");
-
- jLabel16.setText("Contour Max Dev: ");
-
- jButton1.setText("Update");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
-
- jSlider1.setMinimum(10);
-
- jSlider2.setMaximum(150);
- jSlider2.setMinimum(10);
-
- jSlider3.setMaximum(150);
- jSlider3.setValue(100);
-
- jSlider4.setMaximum(150);
- jSlider4.setValue(10);
-
- jSlider5.setMaximum(90);
- jSlider5.setMinimum(1);
- jSlider5.setValue(45);
-
- jSlider6.setValue(30);
-
- jSlider7.setMaximum(150);
- jSlider7.setMinimum(10);
-
- jSlider8.setMaximum(150);
- jSlider8.setMinimum(10);
- jSlider8.setValue(20);
-
- jSlider9.setMinimum(10);
-
- jSlider10.setMaximum(150);
- jSlider10.setValue(0);
-
- jSlider11.setMaximum(150);
- jSlider11.setMinimum(10);
-
- jSlider12.setMaximum(6);
- jSlider12.setMinimum(3);
-
- jSlider13.setMaximum(250);
- jSlider13.setValue(10);
-
- jSlider14.setMaximum(250);
- jSlider14.setValue(10);
-
- jCheckBox1.setSelected(true);
-
- jButton2.setText("Export");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
-
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel4)
- .addGap(53, 53, 53)
- .addComponent(jSlider4, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel5)
- .addGap(56, 56, 56)
- .addComponent(jSlider5, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel8)
- .addGap(55, 55, 55)
- .addComponent(jSlider9, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel11)
- .addGap(39, 39, 39)
- .addComponent(jSlider6, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel12)
- .addGap(44, 44, 44)
- .addComponent(jSlider10, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel13)
- .addGap(32, 32, 32)
- .addComponent(jSlider11, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel14)
- .addGap(55, 55, 55)
- .addComponent(jSlider12, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel15)
- .addGap(30, 30, 30)
- .addComponent(jSlider13, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel16)
- .addGap(43, 43, 43)
- .addComponent(jSlider14, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jButton2))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel1)
- .addGap(88, 88, 88)
- .addComponent(jSlider1, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel2)
- .addComponent(jLabel3))
- .addGap(48, 48, 48)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jSlider3, 0, 0, Short.MAX_VALUE)
- .addComponent(jSlider2, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel10)
- .addComponent(jLabel9)
- .addComponent(jLabel7)
- .addComponent(jLabel6))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jCheckBox1)
- .addComponent(jSlider8, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
- .addComponent(jCheckBox2)
- .addComponent(jSlider7, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel1)
- .addComponent(jSlider1, 0, 0, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel2)
- .addComponent(jSlider2, 0, 0, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jSlider3, 0, 0, Short.MAX_VALUE)
- .addComponent(jLabel3))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel4)
- .addComponent(jSlider4, 0, 0, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel5)
- .addComponent(jSlider5, 0, 0, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel6)
- .addComponent(jCheckBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jSlider8, 0, 0, Short.MAX_VALUE)
- .addComponent(jLabel7))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel8)
- .addComponent(jSlider9, 0, 0, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel9)
- .addComponent(jCheckBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel10)
- .addComponent(jSlider7, 0, 0, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jSlider6, 0, 0, Short.MAX_VALUE)
- .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel12)
- .addComponent(jSlider10, 0, 0, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel13)
- .addComponent(jSlider11, 0, 0, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel14)
- .addComponent(jSlider12, 0, 0, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel15)
- .addComponent(jSlider13, 0, 0, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel16)
- .addComponent(jSlider14, 0, 0, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton2))
- .addContainerGap())
- );
-
- pack();
- }// //GEN-END:initComponents
-
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
- navMeshGen.setCellSize(jSlider1.getValue() / 10f);
- navMeshGen.setCellHeight(jSlider2.getValue() / 10f);
- navMeshGen.setMinTraversableHeight(jSlider3.getValue() / 10f);
-
- navMeshGen.setMaxTraversableStep(jSlider4.getValue() / 10f);
- navMeshGen.setMaxTraversableSlope(jSlider5.getValue());
- navMeshGen.setClipLedges(jCheckBox1.isSelected());
-
- navMeshGen.setTraversableAreaBorderSize(jSlider8.getValue() / 10f);
- navMeshGen.setSmoothingThreshold(jSlider9.getValue() / 10);
- navMeshGen.setUseConservativeExpansion(jCheckBox2.isSelected());
-
- navMeshGen.setMinUnconnectedRegionSize(jSlider7.getValue() / 10);
- navMeshGen.setMergeRegionSize(jSlider6.getValue() / 10);
- navMeshGen.setMaxEdgeLength(jSlider10.getValue() / 10f);
- navMeshGen.setEdgeMaxDeviation(jSlider11.getValue() / 10f);
-
- navMeshGen.setMaxVertsPerPoly(jSlider12.getValue());
- navMeshGen.setContourSampleDistance(jSlider13.getValue() / 10f);
- navMeshGen.setContourMaxDeviation(jSlider14.getValue() / 10f);
-
- navMeshGen.printParams();
-
-// test.regenerateNavMesh();
- }//GEN-LAST:event_jButton1ActionPerformed
-
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
- chooser.setAcceptAllFileFilterUsed(true);
- chooser.setDialogTitle("Export NavMesh");
- chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
- chooser.setMultiSelectionEnabled(false);
- if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION){
- File file = chooser.getSelectedFile();
- }
- }//GEN-LAST:event_jButton2ActionPerformed
-
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JCheckBox jCheckBox1;
- private javax.swing.JCheckBox jCheckBox2;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel10;
- private javax.swing.JLabel jLabel11;
- private javax.swing.JLabel jLabel12;
- private javax.swing.JLabel jLabel13;
- private javax.swing.JLabel jLabel14;
- private javax.swing.JLabel jLabel15;
- private javax.swing.JLabel jLabel16;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JLabel jLabel5;
- private javax.swing.JLabel jLabel6;
- private javax.swing.JLabel jLabel7;
- private javax.swing.JLabel jLabel8;
- private javax.swing.JLabel jLabel9;
- private javax.swing.JSlider jSlider1;
- private javax.swing.JSlider jSlider10;
- private javax.swing.JSlider jSlider11;
- private javax.swing.JSlider jSlider12;
- private javax.swing.JSlider jSlider13;
- private javax.swing.JSlider jSlider14;
- private javax.swing.JSlider jSlider2;
- private javax.swing.JSlider jSlider3;
- private javax.swing.JSlider jSlider4;
- private javax.swing.JSlider jSlider5;
- private javax.swing.JSlider jSlider6;
- private javax.swing.JSlider jSlider7;
- private javax.swing.JSlider jSlider8;
- private javax.swing.JSlider jSlider9;
- // End of variables declaration//GEN-END:variables
-
-}
diff --git a/src/main/java/jme3tools/navmesh/util/Heap.java b/src/main/java/jme3tools/navmesh/util/Heap.java
deleted file mode 100644
index 3ab2e21..0000000
--- a/src/main/java/jme3tools/navmesh/util/Heap.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * Copyright 2006-2007 Columbia University.
- *
- * This file is part of MEAPsoft.
- *
- * MEAPsoft is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * MEAPsoft is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MEAPsoft; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- * See the file "COPYING" for the text of the license.
- */
-package jme3tools.navmesh.util;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.Vector;
-
-/**
- * Abstract implementation of the basic functions needed for a binary
- * heap using java.util.Vector as a back end.
- *
- * Unlike java.util.TreeSet, this data structure can handle duplicate
- * entries. The implementations of the methods given here implement a
- * MinHeap. It is abstract so that we can have a MinHeap class that
- * supports deleteMin() and a MaxHeap class that supports deleteMax()
- * but neither of them support both.
- *
- * @author Ron Weiss (ronw@ee.columbia.edu)
- */
-public abstract class Heap extends Vector {
- // Comparator to use to compare two elements in this Heap (if this
- // is null, assume that all elements are Comparable)
-
- private Comparator comp = null;
- // Does the current instance obey the heap property?
- // (all operations aside from sort() are guaranteed to maintain
- // the heap property, this is just to keep track of whether or not
- // sort() has screwed stuff up).
- protected boolean isHeap = true;
-
- /**
- * Creates an empty Heap.
- */
- public Heap() {
- super();
- }
-
- /**
- * Use given Comparator for all comparisons between elements in
- * this Heap. Otherwise rely on compareTo methods and Comparable
- * Objects.
- */
- public Heap(Comparator c) {
- super();
- comp = c;
- }
-
- /**
- * Creates an empty Heap with the given capacity.
- */
- public Heap(int capacity) {
- super(capacity);
- }
-
- /**
- * Create a new Heap containing the elements of the given
- * Collection.
- */
- public Heap(Collection c) {
- super();
- addAll(c);
- }
-
- /**
- * Remove the Object at the given index from the Heap
- */
- @Override
- public T remove(int index) {
- if (!isHeap) {
- rebuildHeap();
- }
-
- T o = get(index);
-
- set(index, get(size() - 1));
- removeElementAt(size() - 1);
-
- heapify(index);
-
- return o;
- }
-
- /**
- * Remove the Object o from the Heap and return true. Returns
- * false if o is not in the Heap (as measured by o.equals()).
- */
- @Override
- public boolean remove(Object o) {
- boolean found = false;
- for (int i = 0; i < size(); i++) {
- if (o == null ? get(i) == null : o.equals(get(i))) {
- found = true;
- remove(i);
-
- break;
- }
- }
-
- return found;
- }
-
- /**
- * Add o to the Heap.
- */
- @Override
- public boolean add(T o) {
- if (!isHeap) {
- rebuildHeap();
- }
-
- boolean b = super.add(o);
-
- for (int node = size() - 1; node > 0;) {
- int cmp;
- int parent = (int) ((node - 1) / 2);
-
- if (cmp(node, parent) < 0) {
- // swap them and reheapify
- T tmp = get(node);
- set(node, get(parent));
- set(parent, tmp);
- }
-
- node = parent;
- }
-
- //System.out.print("\nContents: ");
- //for(int x = 0; x < size(); x++)
- // System.out.print(get(x) + " ");
- //System.out.println();
-
- return b;
- }
-
- /**
- * Add the contents of a Collection to the Heap.
- */
- @Override
- public boolean addAll(Collection c) {
- boolean b = super.addAll(c);
- rebuildHeap();
- return (b);
- }
-
- /**
- * Ensure that every element in this heap obeys the heap property.
- * Runs in linear time.
- *
- * This is meant to be called if/when the Comparator associated
- * with this object is modified.
- */
- public void rebuildHeap() {
- // do the whole linear time build-heap thing
- for (int i = (int) (size() / 2); i >= 0; i--) {
- heapify(i);
- }
-
- isHeap = true;
- }
-
- /**
- * Perform an in place heap sort on the data stored in this heap.
- * After calling sort, a call to this objects iterator() method
- * will iterate through the data stored in the heap in ascending
- * sorted order. This is not a stable sort.
- */
- public void sort() {
- Object[] a = toArray();
- if (comp == null) {
- Arrays.sort(a);
- } else {
- Arrays.sort((T[])a, comp);
- }
-
- elementData = a;
-
- // there is some wierdo off by one error here that I cannot find...
- //for(int x = size()-1; x > 0; x--)
- //{
- // // swap end of heap with the root, then heapify whats
- // // left.
- // Object tmp = get(x);
- // set(x, get(0));
- // set(0, tmp);
- //
- // heapify(0, x);
- //}
-
- // the above code destroys the heap property - the array is
- // essentially in reverse sorted order (with respect to the
- // first element in the heap (min if MinHeap, max if MaxHeap))
- //
- // The next call to one of the Heap methods will rebuild the
- // heap.
- isHeap = false;
- }
-
- /**
- * Compare two Objects in this heap - wrapper around
- * compareTo/Comparator.compare.
- */
- protected int cmp(int node1, int node2) {
- int c = 0;
- if (comp != null) {
- c = comp.compare(get(node1), get(node2));
- } else {
- c = ((Comparable) get(node1)).compareTo(get(node2));
- }
-
- return c;
- }
-
- /**
- * Ensure that the subtree of the given size rooted at node obeys
- * the heap property
- */
- private void heapify(int node, int size) {
- if (node > size) {
- return;
- }
-
- int left = (node + 1) * 2 - 1;
- int right = (node + 1) * 2;
-
- int minidx = node;
-
- if (left < size && cmp(left, node) <= 0) {
- minidx = left;
- }
- if (right < size && cmp(right, node) <= 0 && cmp(right, left) <= 0) {
- minidx = right;
- }
-
- if (minidx != node) {
- // swap them and recurse on the subtree rooted at minidx
- T tmp = get(node);
- set(node, get(minidx));
- set(minidx, tmp);
-
- heapify(minidx, size);
- }
- }
-
- /**
- * Ensure that the subtree rooted at node obeys the heap property
- */
- private void heapify(int node) {
- heapify(node, size());
- }
-
- /**
- * Do the contents of this object currently obey the heap
- * property?
- */
- public boolean isHeap() {
- return isHeap;
- }
-}
diff --git a/src/main/java/jme3tools/navmesh/util/MaxHeap.java b/src/main/java/jme3tools/navmesh/util/MaxHeap.java
deleted file mode 100644
index 397caa3..0000000
--- a/src/main/java/jme3tools/navmesh/util/MaxHeap.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright 2006-2007 Columbia University.
- *
- * This file is part of MEAPsoft.
- *
- * MEAPsoft is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * MEAPsoft is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MEAPsoft; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- * See the file "COPYING" for the text of the license.
- */
-
-package jme3tools.navmesh.util;
-
-import java.util.Collection;
-import java.util.Comparator;
-
-// I can't believe that the huge Java API doesn't already include such
-// a basic data structure
-
-/**
- * Implementation of a binary max heap.
- *
- * @author Ron Weiss (ronw@ee.columbia.edu)
- */
-public class MaxHeap extends Heap
-{
- /**
- * Creates an empty MaxHeap.
- */
- public MaxHeap()
- {
- super();
- }
-
- /**
- * Use given Comparator for all comparisons between elements in
- * this MaxHeap. Otherwise rely on compareTo methods and
- * Comparable Objects.
- */
- public MaxHeap(Comparator c)
- {
- super(c);
- }
-
- /**
- * Creates an empty MaxHeap with the given capacity.
- */
- public MaxHeap(int capacity)
- {
- super(capacity);
- }
-
- /**
- * Create a new MaxHeap containing the elements of the given
- * Collection.
- */
- public MaxHeap(Collection c)
- {
- super(c);
- }
-
- /**
- * Delete the largest element of this MaxHeap.
- */
- public Object deleteMax()
- {
- return remove(0);
- }
-
- /**
- * Compare two Objects in this heap - wrapper around
- * compareTo/Comparator.compare
- */
- protected int cmp(int node1, int node2)
- {
- return -super.cmp(node1, node2);
- }
-}
diff --git a/src/main/java/jme3tools/navmesh/util/MinHeap.java b/src/main/java/jme3tools/navmesh/util/MinHeap.java
deleted file mode 100644
index 8886afd..0000000
--- a/src/main/java/jme3tools/navmesh/util/MinHeap.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright 2006-2007 Columbia University.
- *
- * This file is part of MEAPsoft.
- *
- * MEAPsoft is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * MEAPsoft is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MEAPsoft; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- * See the file "COPYING" for the text of the license.
- */
-
-package jme3tools.navmesh.util;
-
-import java.util.Collection;
-import java.util.Comparator;
-
-/**
- * Implementation of a binary min heap
- *
- * @author Ron Weiss (ronw@ee.columbia.edu)
- */
-public class MinHeap extends Heap
-{
- /**
- * Creates an empty MinHeap.
- */
- public MinHeap()
- {
- super();
- }
-
- /**
- * Use given Comparator for all comparisons between elements in
- * this MinHeap. Otherwise rely on compareTo methods and
- * Comparable Objects.
- */
- public MinHeap(Comparator c)
- {
- super(c);
- }
-
- /**
- * Creates an empty MinHeap with the given capacity.
- */
- public MinHeap(int capacity)
- {
- super(capacity);
- }
-
- /**
- * Create a new MinHeap containing the elements of the given
- * Collection.
- */
- public MinHeap(Collection c)
- {
- super(c);
- }
-
- /**
- * Delete the smallest element of this MinHeap.
- */
- public Object deleteMin()
- {
- return remove(0);
- }
-
- /**
- * Perform heap sort on the data stored in this heap. After
- * calling sort, a call to this objects iterator() method will
- * iterate through the data stored in the heap in sorted order.
- * This is not a stable sort.
- */
- public void sort()
- {
- super.sort();
-
- // this just so happens to maintain the min-heap property
- isHeap = true;
- }
-}
diff --git a/src/main/java/jme3tools/navmesh/util/NavMeshGenerator.java b/src/main/java/jme3tools/navmesh/util/NavMeshGenerator.java
deleted file mode 100644
index da8218d..0000000
--- a/src/main/java/jme3tools/navmesh/util/NavMeshGenerator.java
+++ /dev/null
@@ -1,268 +0,0 @@
-package jme3tools.navmesh.util;
-
-import com.jme3.math.FastMath;
-import com.jme3.scene.Mesh;
-import com.jme3.scene.VertexBuffer.Type;
-import com.jme3.scene.mesh.IndexBuffer;
-import com.jme3.terrain.Terrain;
-import java.nio.FloatBuffer;
-import org.critterai.nmgen.NavmeshGenerator;
-import org.critterai.nmgen.TriangleMesh;
-
-public class NavMeshGenerator {
-
- private org.critterai.nmgen.NavmeshGenerator nmgen;
- private float cellSize = 1f;
- private float cellHeight = 1.5f;
- private float minTraversableHeight = 7.5f;
- private float maxTraversableStep = 1f;
- private float maxTraversableSlope = 48.0f;
- private boolean clipLedges = false;
- private float traversableAreaBorderSize = 1.2f;
- private int smoothingThreshold = 2;
- private boolean useConservativeExpansion = true;
- private int minUnconnectedRegionSize = 3;
- private int mergeRegionSize = 10;
- private float maxEdgeLength = 0;
- private float edgeMaxDeviation = 2.4f;
- private int maxVertsPerPoly = 6;
- private float contourSampleDistance = 25;
- private float contourMaxDeviation = 25;
-
- public NavMeshGenerator() {
- }
-
- public void printParams() {
- System.out.println("Cell Size: " + cellSize);
- System.out.println("Cell Height: " + cellHeight);
- System.out.println("Min Trav. Height: " + minTraversableHeight);
- System.out.println("Max Trav. Step: " + maxTraversableStep);
- System.out.println("Max Trav. Slope: " + maxTraversableSlope);
- System.out.println("Clip Ledges: " + clipLedges);
- System.out.println("Trav. Area Border Size: " + traversableAreaBorderSize);
- System.out.println("Smooth Thresh.: " + smoothingThreshold);
- System.out.println("Use Cons. Expansion: " + useConservativeExpansion);
- System.out.println("Min Unconn. Region Size: " + minUnconnectedRegionSize);
- System.out.println("Merge Region Size: " + mergeRegionSize);
- System.out.println("Max Edge Length: " + maxEdgeLength);
- System.out.println("Edge Max Dev.: " + edgeMaxDeviation);
- System.out.println("Max Verts/Poly: " + maxVertsPerPoly);
- System.out.println("Contour Sample Dist: " + contourSampleDistance);
- System.out.println("Contour Max Dev.: " + contourMaxDeviation);
- }
-
- public Mesh optimize(Mesh mesh) {
- nmgen = new NavmeshGenerator(cellSize, cellHeight, minTraversableHeight,
- maxTraversableStep, maxTraversableSlope,
- clipLedges, traversableAreaBorderSize,
- smoothingThreshold, useConservativeExpansion,
- minUnconnectedRegionSize, mergeRegionSize,
- maxEdgeLength, edgeMaxDeviation, maxVertsPerPoly,
- contourSampleDistance, contourMaxDeviation);
-
- FloatBuffer pb = mesh.getFloatBuffer(Type.Position);
- IndexBuffer ib = mesh.getIndexBuffer();
-
- // copy positions to float array
- float[] positions = new float[pb.capacity()];
- pb.clear();
- pb.get(positions);
-
- // generate int array of indices
- int[] indices = new int[ib.size()];
- for (int i = 0; i < indices.length; i++) {
- indices[i] = ib.get(i);
- }
-
- TriangleMesh triMesh = nmgen.build(positions, indices, null, null);
- if (triMesh == null) {
- return null;
- }
-
- int[] indices2 = triMesh.indices;
- float[] positions2 = triMesh.vertices;
-
- Mesh mesh2 = new Mesh();
- mesh2.setBuffer(Type.Position, 3, positions2);
- mesh2.setBuffer(Type.Index, 3, indices2);
- mesh2.updateBound();
- mesh2.updateCounts();
-
- return mesh2;
- }
-
- public Mesh optimize(Terrain terr) {
- float[] floats = terr.getHeightMap();
- int length = floats.length;
- float size = (int) FastMath.sqrt(floats.length) * 3;
- float[] vertices = new float[length * 3];
- int[] indices = new int[length * 3];
-
- //TODO: indices are wrong
- for (int i = 0; i < length * 3; i += 3) {
- float xPos = (float) Math.IEEEremainder(i, size);
- float yPos = floats[i/3];
- float zPos = i / (int) size;
- vertices[i] = xPos;
- vertices[i + 1] = yPos;
- vertices[i + 2] = yPos;
- indices[i] = i;
- indices[i + 1] = i + 1;
- indices[i + 2] = i + 2;
- }
- Mesh mesh2 = new Mesh();
- mesh2.setBuffer(Type.Position, 3, vertices);
- mesh2.setBuffer(Type.Index, 3, indices);
- mesh2.updateBound();
- mesh2.updateCounts();
- return mesh2;
- }
-
- /**
- * @return The height resolution used when sampling the source mesh. Value must be > 0.
- */
- public float getCellHeight() {
- return cellHeight;
- }
-
- /**
- * @param cellHeight - The height resolution used when sampling the source mesh. Value must be > 0.
- */
- public void setCellHeight(float cellHeight) {
- this.cellHeight = cellHeight;
- }
-
- /**
- * @return The width and depth resolution used when sampling the the source mesh.
- */
- public float getCellSize() {
- return cellSize;
- }
-
- /**
- * @param cellSize - The width and depth resolution used when sampling the the source mesh.
- */
- public void setCellSize(float cellSize) {
- this.cellSize = cellSize;
- }
-
- public boolean isClipLedges() {
- return clipLedges;
- }
-
- public void setClipLedges(boolean clipLedges) {
- this.clipLedges = clipLedges;
- }
-
- public float getContourMaxDeviation() {
- return contourMaxDeviation;
- }
-
- public void setContourMaxDeviation(float contourMaxDeviation) {
- this.contourMaxDeviation = contourMaxDeviation;
- }
-
- public float getContourSampleDistance() {
- return contourSampleDistance;
- }
-
- public void setContourSampleDistance(float contourSampleDistance) {
- this.contourSampleDistance = contourSampleDistance;
- }
-
- public float getEdgeMaxDeviation() {
- return edgeMaxDeviation;
- }
-
- public void setEdgeMaxDeviation(float edgeMaxDeviation) {
- this.edgeMaxDeviation = edgeMaxDeviation;
- }
-
- public float getMaxEdgeLength() {
- return maxEdgeLength;
- }
-
- public void setMaxEdgeLength(float maxEdgeLength) {
- this.maxEdgeLength = maxEdgeLength;
- }
-
- public float getMaxTraversableSlope() {
- return maxTraversableSlope;
- }
-
- public void setMaxTraversableSlope(float maxTraversableSlope) {
- this.maxTraversableSlope = maxTraversableSlope;
- }
-
- public float getMaxTraversableStep() {
- return maxTraversableStep;
- }
-
- public void setMaxTraversableStep(float maxTraversableStep) {
- this.maxTraversableStep = maxTraversableStep;
- }
-
- public int getMaxVertsPerPoly() {
- return maxVertsPerPoly;
- }
-
- public void setMaxVertsPerPoly(int maxVertsPerPoly) {
- this.maxVertsPerPoly = maxVertsPerPoly;
- }
-
- public int getMergeRegionSize() {
- return mergeRegionSize;
- }
-
- public void setMergeRegionSize(int mergeRegionSize) {
- this.mergeRegionSize = mergeRegionSize;
- }
-
- public float getMinTraversableHeight() {
- return minTraversableHeight;
- }
-
- public void setMinTraversableHeight(float minTraversableHeight) {
- this.minTraversableHeight = minTraversableHeight;
- }
-
- public int getMinUnconnectedRegionSize() {
- return minUnconnectedRegionSize;
- }
-
- public void setMinUnconnectedRegionSize(int minUnconnectedRegionSize) {
- this.minUnconnectedRegionSize = minUnconnectedRegionSize;
- }
-
- public NavmeshGenerator getNmgen() {
- return nmgen;
- }
-
- public void setNmgen(NavmeshGenerator nmgen) {
- this.nmgen = nmgen;
- }
-
- public int getSmoothingThreshold() {
- return smoothingThreshold;
- }
-
- public void setSmoothingThreshold(int smoothingThreshold) {
- this.smoothingThreshold = smoothingThreshold;
- }
-
- public float getTraversableAreaBorderSize() {
- return traversableAreaBorderSize;
- }
-
- public void setTraversableAreaBorderSize(float traversableAreaBorderSize) {
- this.traversableAreaBorderSize = traversableAreaBorderSize;
- }
-
- public boolean isUseConservativeExpansion() {
- return useConservativeExpansion;
- }
-
- public void setUseConservativeExpansion(boolean useConservativeExpansion) {
- this.useConservativeExpansion = useConservativeExpansion;
- }
-}
| | | |