From f8a7117e0f462518f58eb035ff7d7bc1b84d5185 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Thu, 5 Mar 2015 10:56:14 +0100 Subject: [PATCH 01/17] fix a NPE and a ClassCastExcpetion on Cinematic.clear() --- .../java/com/jme3/cinematic/Cinematic.java | 4 +- .../jme3/cinematic/events/AnimationEvent.java | 20 +++--- .../com/jme3/cinematic/CinematicTest.java | 69 +++++++++++++++++++ 3 files changed, 83 insertions(+), 10 deletions(-) create mode 100644 jme3-core/src/test/java/com/jme3/cinematic/CinematicTest.java diff --git a/jme3-core/src/main/java/com/jme3/cinematic/Cinematic.java b/jme3-core/src/main/java/com/jme3/cinematic/Cinematic.java index 373f6fac0..e610ef40b 100644 --- a/jme3-core/src/main/java/com/jme3/cinematic/Cinematic.java +++ b/jme3-core/src/main/java/com/jme3/cinematic/Cinematic.java @@ -702,7 +702,9 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { dispose(); cinematicEvents.clear(); timeLine.clear(); - eventsData.clear(); + if (eventsData != null) { + eventsData.clear(); + } } /** diff --git a/jme3-core/src/main/java/com/jme3/cinematic/events/AnimationEvent.java b/jme3-core/src/main/java/com/jme3/cinematic/events/AnimationEvent.java index e8bfc5392..738b445b1 100644 --- a/jme3-core/src/main/java/com/jme3/cinematic/events/AnimationEvent.java +++ b/jme3-core/src/main/java/com/jme3/cinematic/events/AnimationEvent.java @@ -43,7 +43,7 @@ import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; import com.jme3.scene.Spatial; import java.io.IOException; -import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.logging.Logger; @@ -431,15 +431,17 @@ public class AnimationEvent extends AbstractCinematicEvent { @Override public void dispose() { super.dispose(); - Object o = cinematic.getEventData(MODEL_CHANNELS, model); - if (o != null) { - ArrayList list = (ArrayList) o; - list.remove(channel); - if (list.isEmpty()) { - cinematic.removeEventData(MODEL_CHANNELS, model); + if (cinematic != null) { + Object o = cinematic.getEventData(MODEL_CHANNELS, model); + if (o != null) { + Collection values = ((HashMap) o).values(); + while (values.remove(channel)); + if (values.isEmpty()) { + cinematic.removeEventData(MODEL_CHANNELS, model); + } } + cinematic = null; + channel = null; } - cinematic = null; - channel = null; } } diff --git a/jme3-core/src/test/java/com/jme3/cinematic/CinematicTest.java b/jme3-core/src/test/java/com/jme3/cinematic/CinematicTest.java new file mode 100644 index 000000000..400dbaa9f --- /dev/null +++ b/jme3-core/src/test/java/com/jme3/cinematic/CinematicTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2009-2015 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.cinematic; + +import com.jme3.animation.AnimControl; +import com.jme3.animation.Animation; +import com.jme3.cinematic.events.AnimationEvent; +import com.jme3.scene.Node; +import org.junit.Test; + +/** + * + * @author davidB + */ +public class CinematicTest { + + /** + * No NPE or any exception when clear() a new Cinematic + */ + @Test + public void clearEmpty() { + Cinematic sut = new Cinematic(); + sut.clear(); + } + + /** + * No ClassCastException when clear() a Cinematic with AnimationEvent + */ + @Test + public void clearAnimationEvent() { + Cinematic sut = new Cinematic(); + Node model = new Node("model"); + AnimControl ac = new AnimControl(); + ac.addAnim(new Animation("animName", 1.0f)); + model.addControl(ac); + sut.enqueueCinematicEvent(new AnimationEvent(model, "animName")); + sut.initialize(null, null); + sut.clear(); + } +} From 07fcde3b73b1c728cb067df1ae41c24cf1668950 Mon Sep 17 00:00:00 2001 From: Maselbas Date: Sat, 16 May 2015 22:41:30 +0200 Subject: [PATCH 02/17] SDK SceneComposer : the DeleteShortcut cannot be activated if an other shortcut is already active --- .../gde/scenecomposer/tools/shortcuts/DeleteShortcut.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/DeleteShortcut.java b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/DeleteShortcut.java index cc13ece1d..d5dca8d14 100644 --- a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/DeleteShortcut.java +++ b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/DeleteShortcut.java @@ -29,7 +29,9 @@ public class DeleteShortcut extends ShortcutTool { @Override public boolean isActivableBy(KeyInputEvent kie) { if (kie.getKeyCode() == KeyInput.KEY_X && kie.isPressed()) { - if (Lookup.getDefault().lookup(ShortcutManager.class).isShiftDown()) { + ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class); + if (!scm.isActive() && scm.isShiftDown()) { + // ^ can't be enable if an other shortcut is allready active return true; } } @@ -99,7 +101,7 @@ public class DeleteShortcut extends ShortcutTool { @Override public void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) { } - + private class DeleteUndo extends AbstractUndoableSceneEdit { private Spatial spatial; From 258fee5753851b217445bcaca524f1c9753cb818 Mon Sep 17 00:00:00 2001 From: Maselbas Date: Sun, 17 May 2015 16:42:29 +0200 Subject: [PATCH 03/17] SDK SceneComposer : refactor and cleaner code, more functional code and less sides effects --- .../tools/shortcuts/MoveShortcut.java | 14 +- .../tools/shortcuts/RotateShortcut.java | 14 +- .../tools/shortcuts/ScaleShortcut.java | 14 +- .../tools/shortcuts/ShortcutManager.java | 216 ++++++++++-------- 4 files changed, 145 insertions(+), 113 deletions(-) diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/MoveShortcut.java b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/MoveShortcut.java index 6291ab932..e32e7183c 100644 --- a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/MoveShortcut.java +++ b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/MoveShortcut.java @@ -78,14 +78,16 @@ public class MoveShortcut extends ShortcutTool { if (kie.isPressed()) { Lookup.getDefault().lookup(ShortcutManager.class).activateShortcut(kie); - Vector3f axis = new Vector3f(); - boolean axisChanged = ShortcutManager.checkAxisKey(kie, axis); + boolean axisChanged = ShortcutManager.isAxisKey(kie); if (axisChanged) { - currentAxis = axis; + currentAxis = ShortcutManager.getAxisKey(kie); } - boolean numberChanged = ShortcutManager.checkNumberKey(kie, numberBuilder); - boolean enterHit = ShortcutManager.checkEnterHit(kie); - boolean escHit = ShortcutManager.checkEscHit(kie); + boolean numberChanged = ShortcutManager.isNumberKey(kie); + if(numberChanged){ + ShortcutManager.setNumberKey(kie, numberBuilder); + } + boolean enterHit = ShortcutManager.isEnterKey(kie); + boolean escHit = ShortcutManager.isEscKey(kie); if (escHit) { cancel(); diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/RotateShortcut.java b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/RotateShortcut.java index 8b9ffe404..aec5b6928 100644 --- a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/RotateShortcut.java +++ b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/RotateShortcut.java @@ -77,14 +77,16 @@ public class RotateShortcut extends ShortcutTool { if (kie.isPressed()) { Lookup.getDefault().lookup(ShortcutManager.class).activateShortcut(kie); - Vector3f axis = new Vector3f(); - boolean axisChanged = ShortcutManager.checkAxisKey(kie, axis); + boolean axisChanged = ShortcutManager.isAxisKey(kie); if (axisChanged) { - currentAxis = axis; + currentAxis = ShortcutManager.getAxisKey(kie); } - boolean numberChanged = ShortcutManager.checkNumberKey(kie, numberBuilder); - boolean enterHit = ShortcutManager.checkEnterHit(kie); - boolean escHit = ShortcutManager.checkEscHit(kie); + boolean numberChanged = ShortcutManager.isNumberKey(kie); + if(numberChanged){ + ShortcutManager.setNumberKey(kie, numberBuilder); + } + boolean enterHit = ShortcutManager.isEnterKey(kie); + boolean escHit = ShortcutManager.isEscKey(kie); if (escHit) { cancel(); diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/ScaleShortcut.java b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/ScaleShortcut.java index 8fa18858f..25266a676 100644 --- a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/ScaleShortcut.java +++ b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/ScaleShortcut.java @@ -77,14 +77,16 @@ public class ScaleShortcut extends ShortcutTool { if (kie.isPressed()) { Lookup.getDefault().lookup(ShortcutManager.class).activateShortcut(kie); - Vector3f axis = new Vector3f(); - boolean axisChanged = ShortcutManager.checkAxisKey(kie, axis); + boolean axisChanged = ShortcutManager.isAxisKey(kie); if (axisChanged) { - currentAxis = axis; + currentAxis = ShortcutManager.getAxisKey(kie); } - boolean numberChanged = ShortcutManager.checkNumberKey(kie, numberBuilder); - boolean enterHit = ShortcutManager.checkEnterHit(kie); - boolean escHit = ShortcutManager.checkEscHit(kie); + boolean numberChanged = ShortcutManager.isNumberKey(kie); + if(numberChanged){ + ShortcutManager.setNumberKey(kie, numberBuilder); + } + boolean enterHit = ShortcutManager.isEnterKey(kie); + boolean escHit = ShortcutManager.isEscKey(kie); if (escHit) { cancel(); diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/ShortcutManager.java b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/ShortcutManager.java index 187293e92..c7d6f3721 100644 --- a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/ShortcutManager.java +++ b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/ShortcutManager.java @@ -157,13 +157,13 @@ public class ShortcutManager { } private boolean checkCommandeKey(KeyInputEvent kie) { - if (checkCtrlHit(kie)) { + if (isCtrlKey(kie)) { ctrlDown = kie.isPressed(); return true; - } else if (checkAltHit(kie)) { + } else if (isAltKey(kie)) { altDown = kie.isPressed(); return true; - } else if (checkShiftHit(kie)) { + } else if (isShiftKey(kie)) { shiftDown = kie.isPressed(); return true; } @@ -178,11 +178,8 @@ public class ShortcutManager { * @param kie * @return true if the given kie is KEY_RETURN */ - public static boolean checkEnterHit(KeyInputEvent kie) { - if (kie.getKeyCode() == KeyInput.KEY_RETURN) { - return true; - } - return false; + public static boolean isEnterKey(KeyInputEvent kie) { + return (kie.getKeyCode() == KeyInput.KEY_RETURN); } /** @@ -190,11 +187,8 @@ public class ShortcutManager { * @param kie * @return true if the given kie is KEY_ESCAPE */ - public static boolean checkEscHit(KeyInputEvent kie) { - if (kie.getKeyCode() == KeyInput.KEY_ESCAPE) { - return true; - } - return false; + public static boolean isEscKey(KeyInputEvent kie) { + return (kie.getKeyCode() == KeyInput.KEY_ESCAPE); } /** @@ -202,11 +196,8 @@ public class ShortcutManager { * @param kie * @return true if the given kie is KEY_LCONTROL || KEY_RCONTROL */ - public static boolean checkCtrlHit(KeyInputEvent kie) { - if (kie.getKeyCode() == KeyInput.KEY_LCONTROL || kie.getKeyCode() == KeyInput.KEY_RCONTROL) { - return true; - } - return false; + public static boolean isCtrlKey(KeyInputEvent kie) { + return (kie.getKeyCode() == KeyInput.KEY_LCONTROL || kie.getKeyCode() == KeyInput.KEY_RCONTROL); } /** @@ -214,11 +205,8 @@ public class ShortcutManager { * @param kie * @return true if the given kie is KEY_LSHIFT || KEY_RSHIFT */ - public static boolean checkShiftHit(KeyInputEvent kie) { - if (kie.getKeyCode() == KeyInput.KEY_LSHIFT || kie.getKeyCode() == KeyInput.KEY_RSHIFT) { - return true; - } - return false; + public static boolean isShiftKey(KeyInputEvent kie) { + return (kie.getKeyCode() == KeyInput.KEY_LSHIFT || kie.getKeyCode() == KeyInput.KEY_RSHIFT); } /** @@ -226,9 +214,40 @@ public class ShortcutManager { * @param kie * @return true if the given kie is KEY_LMENU || KEY_RMENU */ - public static boolean checkAltHit(KeyInputEvent kie) { - if (kie.getKeyCode() == KeyInput.KEY_LMENU || kie.getKeyCode() == KeyInput.KEY_RMENU) { - return true; + public static boolean isAltKey(KeyInputEvent kie) { + return (kie.getKeyCode() == KeyInput.KEY_LMENU || kie.getKeyCode() == KeyInput.KEY_RMENU); + } + + /** + * + * @param kie + * @return + */ + public static boolean isNumberKey(KeyInputEvent kie) { + switch (kie.getKeyCode()) { + case KeyInput.KEY_MINUS: + case KeyInput.KEY_0: + case KeyInput.KEY_1: + case KeyInput.KEY_2: + case KeyInput.KEY_3: + case KeyInput.KEY_4: + case KeyInput.KEY_5: + case KeyInput.KEY_6: + case KeyInput.KEY_7: + case KeyInput.KEY_8: + case KeyInput.KEY_9: + case KeyInput.KEY_NUMPAD0: + case KeyInput.KEY_NUMPAD1: + case KeyInput.KEY_NUMPAD2: + case KeyInput.KEY_NUMPAD3: + case KeyInput.KEY_NUMPAD4: + case KeyInput.KEY_NUMPAD5: + case KeyInput.KEY_NUMPAD6: + case KeyInput.KEY_NUMPAD7: + case KeyInput.KEY_NUMPAD8: + case KeyInput.KEY_NUMPAD9: + case KeyInput.KEY_PERIOD: + return true; } return false; } @@ -236,65 +255,55 @@ public class ShortcutManager { /** * store the number kie into the numberBuilder * - * @param kie - * @param numberBuilder - * @return true if the given kie is handled as a number key event + * @param kie the KeiInputEvent to be handled as a number. + * @param numberBuilder the number builder that will be modified ! */ - public static boolean checkNumberKey(KeyInputEvent kie, StringBuilder numberBuilder) { - if (kie.getKeyCode() == KeyInput.KEY_MINUS) { - if (numberBuilder.length() > 0) { - if (numberBuilder.charAt(0) == '-') { - numberBuilder.replace(0, 1, ""); + public static void setNumberKey(KeyInputEvent kie, StringBuilder numberBuilder) { + switch (kie.getKeyCode()) { + case KeyInput.KEY_MINUS: + if (numberBuilder.length() > 0) { + if (numberBuilder.charAt(0) == '-') { + numberBuilder.replace(0, 1, ""); + } else { + numberBuilder.insert(0, '-'); + } } else { - numberBuilder.insert(0, '-'); + numberBuilder.append('-'); } - } else { - numberBuilder.append('-'); - } - return true; - } else if (kie.getKeyCode() == KeyInput.KEY_0 || kie.getKeyCode() == KeyInput.KEY_NUMPAD0) { - numberBuilder.append('0'); - return true; - } else if (kie.getKeyCode() == KeyInput.KEY_1 || kie.getKeyCode() == KeyInput.KEY_NUMPAD1) { - numberBuilder.append('1'); - return true; - } else if (kie.getKeyCode() == KeyInput.KEY_2 || kie.getKeyCode() == KeyInput.KEY_NUMPAD2) { - numberBuilder.append('2'); - return true; - } else if (kie.getKeyCode() == KeyInput.KEY_3 || kie.getKeyCode() == KeyInput.KEY_NUMPAD3) { - numberBuilder.append('3'); - return true; - } else if (kie.getKeyCode() == KeyInput.KEY_4 || kie.getKeyCode() == KeyInput.KEY_NUMPAD4) { - numberBuilder.append('4'); - return true; - } else if (kie.getKeyCode() == KeyInput.KEY_5 || kie.getKeyCode() == KeyInput.KEY_NUMPAD5) { - numberBuilder.append('5'); - return true; - } else if (kie.getKeyCode() == KeyInput.KEY_6 || kie.getKeyCode() == KeyInput.KEY_NUMPAD6) { - numberBuilder.append('6'); - return true; - } else if (kie.getKeyCode() == KeyInput.KEY_7 || kie.getKeyCode() == KeyInput.KEY_NUMPAD7) { - numberBuilder.append('7'); - return true; - } else if (kie.getKeyCode() == KeyInput.KEY_8 || kie.getKeyCode() == KeyInput.KEY_NUMPAD8) { - numberBuilder.append('8'); - return true; - } else if (kie.getKeyCode() == KeyInput.KEY_9 || kie.getKeyCode() == KeyInput.KEY_NUMPAD9) { - numberBuilder.append('9'); - return true; - } else if (kie.getKeyCode() == KeyInput.KEY_PERIOD) { - if (numberBuilder.indexOf(".") == -1) { // if it doesn't exist yet - if (numberBuilder.length() == 0 - || (numberBuilder.length() == 1 && numberBuilder.charAt(0) == '-')) { - numberBuilder.append("0."); - } else { - numberBuilder.append("."); + break; + case KeyInput.KEY_0: + case KeyInput.KEY_1: + case KeyInput.KEY_2: + case KeyInput.KEY_3: + case KeyInput.KEY_4: + case KeyInput.KEY_5: + case KeyInput.KEY_6: + case KeyInput.KEY_7: + case KeyInput.KEY_8: + case KeyInput.KEY_9: + case KeyInput.KEY_NUMPAD0: + case KeyInput.KEY_NUMPAD1: + case KeyInput.KEY_NUMPAD2: + case KeyInput.KEY_NUMPAD3: + case KeyInput.KEY_NUMPAD4: + case KeyInput.KEY_NUMPAD5: + case KeyInput.KEY_NUMPAD6: + case KeyInput.KEY_NUMPAD7: + case KeyInput.KEY_NUMPAD8: + case KeyInput.KEY_NUMPAD9: + numberBuilder.append(kie.getKeyChar()); + break; + case KeyInput.KEY_PERIOD: + if (numberBuilder.indexOf(".") == -1) { // if it doesn't exist yet + if (numberBuilder.length() == 0 + || (numberBuilder.length() == 1 && numberBuilder.charAt(0) == '-')) { + numberBuilder.append("0."); + } else { + numberBuilder.append("."); + } } - } - return true; + break; } - - return false; } /** @@ -311,25 +320,42 @@ public class ShortcutManager { } /** - * Check for axis input for key X,Y,Z and store the corresponding UNIT_ into - * the axisStore + * Test if the given kie can be handled as en axis input by the getAxisKey() + * method. * - * @param kie - * @param axisStore - * @return true if the given kie is handled as a Axis input + * @param kie the KeyInputEvent to test + * @return true is the kie can be handled as an axis input, else false */ - public static boolean checkAxisKey(KeyInputEvent kie, Vector3f axisStore) { - if (kie.getKeyCode() == KeyInput.KEY_X) { - axisStore.set(Vector3f.UNIT_X); - return true; - } else if (kie.getKeyCode() == KeyInput.KEY_Y) { - axisStore.set(Vector3f.UNIT_Y); - return true; - } else if (kie.getKeyCode() == KeyInput.KEY_Z) { - axisStore.set(Vector3f.UNIT_Z); - return true; + public static boolean isAxisKey(KeyInputEvent kie) { + switch (kie.getKeyCode()) { + case KeyInput.KEY_X: + case KeyInput.KEY_Y: + case KeyInput.KEY_Z: + return true; } return false; } + /** + * Handle the Kie as an axis input : return a Vector3f from the kie keyCode. + * + * @param kie the KeyInputEvent to handle as an Axis + * @return UNIT_X for 'x', UNIT_Y for 'y' and UNIT_Z for 'z' kie. + */ + public static Vector3f getAxisKey(KeyInputEvent kie) { + Vector3f result = Vector3f.ZERO; + switch (kie.getKeyCode()) { + case KeyInput.KEY_X: + result = Vector3f.UNIT_X; + break; + case KeyInput.KEY_Y: + result = Vector3f.UNIT_Y; + break; + case KeyInput.KEY_Z: + result = Vector3f.UNIT_Z; + break; + } + return result; + } + } From 878f2cbbbca2d794d8c2010368d210b3a7ca5717 Mon Sep 17 00:00:00 2001 From: Maselbas Date: Sun, 17 May 2015 20:40:25 +0200 Subject: [PATCH 04/17] Bullet PhysicsRigigBody : added set/getAngularFactor(Vector3f) and set/getLinearFactor(Vector3f), these methods are usefull for locking axis translations or rotation --- ...m_jme3_bullet_objects_PhysicsRigidBody.cpp | 62 +++++++++++++++++-- ...com_jme3_bullet_objects_PhysicsRigidBody.h | 30 ++++++++- .../jme3/bullet/objects/PhysicsRigidBody.java | 35 +++++++++-- 3 files changed, 114 insertions(+), 13 deletions(-) diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp index 0d9621bb8..39125f48e 100644 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp +++ b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp @@ -811,17 +811,17 @@ extern "C" { /* * Class: com_jme3_bullet_objects_PhysicsRigidBody * Method: getAngularFactor - * Signature: (J)F + * Signature: (JLcom/jme3/math/Vector3f;)V */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngularFactor - (JNIEnv *env, jobject object, jlong bodyId) { + JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngularFactor + (JNIEnv *env, jobject object, jlong bodyId, jobject factor) { btRigidBody* body = reinterpret_cast(bodyId); if (body == NULL) { jclass newExc = env->FindClass("java/lang/NullPointerException"); env->ThrowNew(newExc, "The native object does not exist."); - return 0; + return; } - return body->getAngularFactor().getX(); + jmeBulletUtil::convert(env, &body->getAngularFactor(), factor); } /* @@ -844,6 +844,58 @@ extern "C" { body->setAngularFactor(vec1); } + /* + * Class: com_jme3_bullet_objects_PhysicsRigidBody + * Method: setAngularFactor + * Signature: (JLcom/jme3/math/Vector3f;)V + */ + JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularFactor + (JNIEnv *env, jobject object, jlong bodyId, jobject factor) { + btRigidBody* body = reinterpret_cast(bodyId); + if (body == NULL) { + jclass newExc = env->FindClass("java/lang/NullPointerException"); + env->ThrowNew(newExc, "The native object does not exist."); + return; + } + btVector3 vec = btVector3(); + jmeBulletUtil::convert(env, factor, &vec); + body->setAngularFactor(vec); + } + + /* + * Class: com_jme3_bullet_objects_PhysicsRigidBody + * Method: getLinearFactor + * Signature: (JLcom/jme3/math/Vector3f;)V + */ + JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getLinearFactor + (JNIEnv *env, jobject object, jlong bodyId, jobject factor) { + btRigidBody* body = reinterpret_cast(bodyId); + if (body == NULL) { + jclass newExc = env->FindClass("java/lang/NullPointerException"); + env->ThrowNew(newExc, "The native object does not exist."); + return; + } + jmeBulletUtil::convert(env, &body->getLinearFactor(), factor); + } + + /* + * Class: com_jme3_bullet_objects_PhysicsRigidBody + * Method: setLinearFactor + * Signature: (JLcom/jme3/math/Vector3f;)V + */ + JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setLinearFactor + (JNIEnv *env, jobject object, jlong bodyId, jobject factor) { + btRigidBody* body = reinterpret_cast(bodyId); + if (body == NULL) { + jclass newExc = env->FindClass("java/lang/NullPointerException"); + env->ThrowNew(newExc, "The native object does not exist."); + return; + } + btVector3 vec = btVector3(); + jmeBulletUtil::convert(env, factor, &vec); + body->setLinearFactor(vec); + } + #ifdef __cplusplus } #endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.h b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.h index aa09a620a..d966f74e2 100644 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.h +++ b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.h @@ -396,10 +396,10 @@ JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngula /* * Class: com_jme3_bullet_objects_PhysicsRigidBody * Method: getAngularFactor - * Signature: (J)F + * Signature: (JLcom/jme3/math/Vector3f;)V */ -JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngularFactor - (JNIEnv *, jobject, jlong); +JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngularFactor + (JNIEnv *, jobject, jlong, jobject); /* * Class: com_jme3_bullet_objects_PhysicsRigidBody @@ -409,6 +409,30 @@ JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngula JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularFactor (JNIEnv *, jobject, jlong, jfloat); +/* + * Class: com_jme3_bullet_objects_PhysicsRigidBody + * Method: setAngularFactor + * Signature: (JLcom/jme3/math/Vector3f;)V + */ +JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularFactor + (JNIEnv *, jobject, jlong, jobject); + +/* + * Class: com_jme3_bullet_objects_PhysicsRigidBody + * Method: getLinearFactor + * Signature: (JLcom/jme3/math/Vector3f;)V + */ +JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getLinearFactor + (JNIEnv *, jobject, jlong, jobject); + +/* + * Class: com_jme3_bullet_objects_PhysicsRigidBody + * Method: setLinearFactor + * Signature: (JLcom/jme3/math/Vector3f;)V + */ +JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setLinearFactor + (JNIEnv *, jobject, jlong, jobject); + #ifdef __cplusplus } #endif diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java index 40417c775..c8d73d249 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java @@ -626,11 +626,13 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native float getAngularSleepingThreshold(long objectId); - public float getAngularFactor() { - return getAngularFactor(objectId); + public Vector3f getAngularFactor() { + Vector3f vec = new Vector3f(); + getAngularFactor(objectId, vec); + return vec; } - private native float getAngularFactor(long objectId); + private native void getAngularFactor(long objectId, Vector3f vec); public void setAngularFactor(float factor) { setAngularFactor(objectId, factor); @@ -638,6 +640,27 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native void setAngularFactor(long objectId, float factor); + public void setAngularFactor(Vector3f factor) { + setAngularFactor(objectId, factor); + } + + private native void setAngularFactor(long objectId, Vector3f factor); + + public Vector3f getLinearFactor() { + Vector3f vec = new Vector3f(); + getLinearFactor(objectId, vec); + return vec; + } + + private native void getLinearFactor(long objectId, Vector3f vec); + + public void setLinearFactor(Vector3f factor) { + setLinearFactor(objectId, factor); + } + + private native void setLinearFactor(long objectId, Vector3f factor); + + /** * do not use manually, joints are added automatically */ @@ -673,7 +696,8 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { capsule.write(getGravity(), "gravity", Vector3f.ZERO); capsule.write(getFriction(), "friction", 0.5f); capsule.write(getRestitution(), "restitution", 0); - capsule.write(getAngularFactor(), "angularFactor", 1); + capsule.write(getAngularFactor(), "angularFactor", Vector3f.UNIT_XYZ); + capsule.write(getLinearFactor(), "linearFactor", Vector3f.UNIT_XYZ); capsule.write(kinematic, "kinematic", false); capsule.write(getLinearDamping(), "linearDamping", 0); @@ -703,7 +727,8 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { setKinematic(capsule.readBoolean("kinematic", false)); setRestitution(capsule.readFloat("restitution", 0)); - setAngularFactor(capsule.readFloat("angularFactor", 1)); + setAngularFactor((Vector3f) capsule.readSavable("angularFactor", Vector3f.UNIT_XYZ.clone())); + setLinearFactor((Vector3f) capsule.readSavable("linearFactor", Vector3f.UNIT_XYZ.clone())); setDamping(capsule.readFloat("linearDamping", 0), capsule.readFloat("angularDamping", 0)); setSleepingThresholds(capsule.readFloat("linearSleepingThreshold", 0.8f), capsule.readFloat("angularSleepingThreshold", 1.0f)); setCcdMotionThreshold(capsule.readFloat("ccdMotionThreshold", 0)); From 37800618635081cf033b9e58d1571285a76c82bc Mon Sep 17 00:00:00 2001 From: Maselbas Date: Mon, 18 May 2015 00:34:42 +0200 Subject: [PATCH 05/17] Bullet PhysicsRididBody : compile time error fix --- ...m_jme3_bullet_objects_PhysicsRigidBody.cpp | 28 +++++++++---------- ...com_jme3_bullet_objects_PhysicsRigidBody.h | 4 +-- .../jme3/bullet/objects/PhysicsRigidBody.java | 4 +-- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp index 39125f48e..2bb6e057e 100644 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp +++ b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp @@ -829,20 +829,20 @@ extern "C" { * Method: setAngularFactor * Signature: (JF)V */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularFactor - (JNIEnv *env, jobject object, jlong bodyId, jfloat value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec1 = btVector3(); - vec1.setX(value); - vec1.setY(value); - vec1.setZ(value); - body->setAngularFactor(vec1); - } +// JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularFactor +// (JNIEnv *env, jobject object, jlong bodyId, jfloat value) { +// btRigidBody* body = reinterpret_cast(bodyId); +// if (body == NULL) { +// jclass newExc = env->FindClass("java/lang/NullPointerException"); +// env->ThrowNew(newExc, "The native object does not exist."); +// return; +// } +// btVector3 vec1 = btVector3(); +// vec1.setX(value); +// vec1.setY(value); +// vec1.setZ(value); +// body->setAngularFactor(vec1); +// } /* * Class: com_jme3_bullet_objects_PhysicsRigidBody diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.h b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.h index d966f74e2..cb714c7bc 100644 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.h +++ b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.h @@ -406,8 +406,8 @@ JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngularF * Method: setAngularFactor * Signature: (JF)V */ -JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularFactor - (JNIEnv *, jobject, jlong, jfloat); +//JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularFactor +// (JNIEnv *, jobject, jlong, jfloat); /* * Class: com_jme3_bullet_objects_PhysicsRigidBody diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java index c8d73d249..d17b595c7 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java @@ -635,11 +635,9 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native void getAngularFactor(long objectId, Vector3f vec); public void setAngularFactor(float factor) { - setAngularFactor(objectId, factor); + setAngularFactor(objectId, new Vector3f(factor, factor, factor)); } - private native void setAngularFactor(long objectId, float factor); - public void setAngularFactor(Vector3f factor) { setAngularFactor(objectId, factor); } From 5de3163fb8843fe3ca37e9c4e85f95dc73d5f4d6 Mon Sep 17 00:00:00 2001 From: Maselbas Date: Mon, 18 May 2015 22:36:45 +0200 Subject: [PATCH 06/17] Bullet RigidBody : removed commented code --- ...m_jme3_bullet_objects_PhysicsRigidBody.cpp | 19 ------------------- ...com_jme3_bullet_objects_PhysicsRigidBody.h | 7 ------- 2 files changed, 26 deletions(-) diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp index 2bb6e057e..c9fef97cb 100644 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp +++ b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp @@ -824,25 +824,6 @@ extern "C" { jmeBulletUtil::convert(env, &body->getAngularFactor(), factor); } - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setAngularFactor - * Signature: (JF)V - */ -// JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularFactor -// (JNIEnv *env, jobject object, jlong bodyId, jfloat value) { -// btRigidBody* body = reinterpret_cast(bodyId); -// if (body == NULL) { -// jclass newExc = env->FindClass("java/lang/NullPointerException"); -// env->ThrowNew(newExc, "The native object does not exist."); -// return; -// } -// btVector3 vec1 = btVector3(); -// vec1.setX(value); -// vec1.setY(value); -// vec1.setZ(value); -// body->setAngularFactor(vec1); -// } /* * Class: com_jme3_bullet_objects_PhysicsRigidBody diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.h b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.h index cb714c7bc..67ba9e609 100644 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.h +++ b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.h @@ -401,13 +401,6 @@ JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngula JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngularFactor (JNIEnv *, jobject, jlong, jobject); -/* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setAngularFactor - * Signature: (JF)V - */ -//JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularFactor -// (JNIEnv *, jobject, jlong, jfloat); /* * Class: com_jme3_bullet_objects_PhysicsRigidBody From 5989711f7315abe4c3da0f1516a3eb3a81da6716 Mon Sep 17 00:00:00 2001 From: Nehon Date: Wed, 15 Jul 2015 23:55:33 +0200 Subject: [PATCH 07/17] Added multi selection to the ShaderNode editor. One can now select several items by left clicking with ctrl or shit held. One can now move all selected items at once. One can now delete all selected items at once. --- .../editor/ConnectionCurve.java | 10 +- .../editor/ConnectionStraight.java | 8 +- .../materialdefinition/editor/Diagram.java | 133 ++++++++++++------ .../editor/DraggablePanel.java | 20 ++- .../materialdefinition/editor/NodePanel.java | 29 +--- .../editor/OutBusPanel.java | 4 +- 6 files changed, 120 insertions(+), 84 deletions(-) diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/ConnectionCurve.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/ConnectionCurve.java index ec2f4aa98..7c225f745 100644 --- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/ConnectionCurve.java +++ b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/ConnectionCurve.java @@ -123,7 +123,7 @@ public class ConnectionCurve extends JPanel implements ComponentListener, MouseI g2.setStroke(new BasicStroke(4)); Path2D.Double path1 = new Path2D.Double(); - if (getDiagram().selectedItem == this) { + if (getDiagram().getSelectedItems().contains(this)) { g.setColor(SELECTED_COLOR); } else { g.setColor(VERY_DARK_GREY); @@ -162,7 +162,7 @@ public class ConnectionCurve extends JPanel implements ComponentListener, MouseI ((Graphics2D) g).draw(path1); g2.setStroke(new BasicStroke(2)); - if (getDiagram().selectedItem == this) { + if (getDiagram().getSelectedItems().contains(this)) { g.setColor(Color.WHITE); } else { g.setColor(LIGHT_GREY); @@ -385,7 +385,7 @@ public class ConnectionCurve extends JPanel implements ComponentListener, MouseI } if (selected) { - getDiagram().select(this); + getDiagram().select(this, e.isShiftDown() || e.isControlDown()); e.consume(); } } @@ -407,9 +407,7 @@ public class ConnectionCurve extends JPanel implements ComponentListener, MouseI if (e.getKeyCode() == KeyEvent.VK_DELETE) { Diagram diag = getDiagram(); - if (diag.selectedItem == this) { - diag.removeSelectedConnection(); - } + diag.removeSelected(); } } diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/ConnectionStraight.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/ConnectionStraight.java index 3eba66a23..fc4873bd8 100644 --- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/ConnectionStraight.java +++ b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/ConnectionStraight.java @@ -209,7 +209,7 @@ public class ConnectionStraight extends JPanel implements ComponentListener, Mou g.drawLine(p1.x, p1.y, p2.x, p2.y); - if (getDiagram().selectedItem == this) { + if (getDiagram().getSelectedItems().contains(this)) { g.setColor(Color.CYAN); } else { g.setColor(Color.GRAY); @@ -489,7 +489,7 @@ public class ConnectionStraight extends JPanel implements ComponentListener, Mou } if (selected) { - getDiagram().select(this); + getDiagram().select(this, e.isShiftDown() || e.isControlDown()); e.consume(); } } @@ -511,9 +511,7 @@ public class ConnectionStraight extends JPanel implements ComponentListener, Mou if (e.getKeyCode() == KeyEvent.VK_DELETE) { Diagram diag = getDiagram(); - if (diag.selectedItem == this) { - diag.removeSelectedConnection(); - } + diag.removeSelected(); } } diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Diagram.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Diagram.java index 9d344355e..88876f3e5 100644 --- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Diagram.java +++ b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Diagram.java @@ -55,7 +55,7 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene protected Dot draggedFrom; protected Dot draggedTo; - protected Selectable selectedItem; + protected List selectedItems = new ArrayList(); protected List connections = new ArrayList(); protected List nodes = new ArrayList(); protected List outBuses = new ArrayList(); @@ -63,6 +63,9 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene private MatDefEditorlElement parent; private String currentTechniqueName; private final BackdropPanel backDrop = new BackdropPanel(); + private final Cursor defCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); + private final Cursor hndCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR); + private final Point pp = new Point(); @SuppressWarnings("LeakingThisInConstructor") public Diagram() { @@ -99,7 +102,7 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene } } - selectedItem = null; + selectedItems.clear(); repaint(); } else if (e.getButton() == MouseEvent.BUTTON2) { setCursor(hndCursor); @@ -204,13 +207,10 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene public void mouseExited(MouseEvent e) { } - protected void removeSelectedConnection() { - if (selectedItem instanceof Connection) { - Connection selectedConnection = (Connection) selectedItem; - removeConnection(selectedConnection); - selectedItem = null; - parent.notifyRemoveConnection(selectedConnection); - } + protected void removeSelectedConnection(Selectable selectedItem) { + Connection selectedConnection = (Connection) selectedItem; + removeConnection(selectedConnection); + parent.notifyRemoveConnection(selectedConnection); } private String fixNodeName(String name) { @@ -276,44 +276,58 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene np.revalidate(); repaint(); } - - protected void removeSelectedNode() { - if (selectedItem instanceof NodePanel) { - int result = JOptionPane.showConfirmDialog(null, "Delete this node and all its mappings?", "Delete Shader Node", JOptionPane.OK_CANCEL_OPTION); - if (result == JOptionPane.OK_OPTION) { - NodePanel selectedNode = (NodePanel) selectedItem; - nodes.remove(selectedNode); - for (Iterator it = connections.iterator(); it.hasNext();) { - Connection conn = it.next(); - if (conn.start.getNode() == selectedNode || conn.end.getNode() == selectedNode) { - it.remove(); - conn.end.disconnect(); - conn.start.disconnect(); - remove(conn); - } + + protected void removeSelected(){ + + int result = JOptionPane.showConfirmDialog(null, "Delete all selected items, nodes and mappings?", "Delete Selected", JOptionPane.OK_CANCEL_OPTION); + + if (result == JOptionPane.OK_OPTION) { + for (Selectable selectedItem : selectedItems) { + if (selectedItem instanceof NodePanel) { + removeSelectedNode(selectedItem); } + if (selectedItem instanceof Connection) { + removeSelectedConnection(selectedItem); + } + } + selectedItems.clear(); + } + } - selectedNode.cleanup(); - remove(selectedNode); - selectedItem = null; - repaint(); - parent.notifyRemoveNode(selectedNode); + private void removeSelectedNode(Selectable selectedItem) { + + NodePanel selectedNode = (NodePanel) selectedItem; + nodes.remove(selectedNode); + for (Iterator it = connections.iterator(); it.hasNext();) { + Connection conn = it.next(); + if (conn.start.getNode() == selectedNode || conn.end.getNode() == selectedNode) { + it.remove(); + conn.end.disconnect(); + conn.start.disconnect(); + remove(conn); } } + + selectedNode.cleanup(); + remove(selectedNode); + repaint(); + parent.notifyRemoveNode(selectedNode); } - private final Cursor defCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); - private final Cursor hndCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR); - private final Point pp = new Point(); + public List getSelectedItems() { + return selectedItems; + } @Override public void mouseDragged(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { if (draggedFrom == null) { - if (selectedItem instanceof OutBusPanel) { - OutBusPanel bus = (OutBusPanel) selectedItem; - MouseEvent me = SwingUtilities.convertMouseEvent(this, e, bus); - bus.dispatchEvent(me); + for (Selectable selectedItem : selectedItems) { + if (selectedItem instanceof OutBusPanel) { + OutBusPanel bus = (OutBusPanel) selectedItem; + MouseEvent me = SwingUtilities.convertMouseEvent(this, e, bus); + bus.dispatchEvent(me); + } } } } else if (SwingUtilities.isMiddleMouseButton(e)) { @@ -373,22 +387,53 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene * * @param selectable */ - public void select(Selectable selectable) { - parent.selectionChanged(doSelect(selectable)); + public void select(Selectable selectable, boolean multi) { + parent.selectionChanged(doSelect(selectable, multi)); + } + + public void multiMove(DraggablePanel movedPanel ,int xOffset, int yOffset){ + + for (Selectable selectedItem : selectedItems) { + if(selectedItem != movedPanel){ + if(selectedItem instanceof DraggablePanel){ + ((DraggablePanel)selectedItem).movePanel(xOffset, yOffset); + } + } + } } + public void multiStartDrag(DraggablePanel movedPanel){ + for (Selectable selectedItem : selectedItems) { + if(selectedItem != movedPanel){ + if(selectedItem instanceof DraggablePanel){ + ((DraggablePanel)selectedItem).saveLocation(); + } + } + } + } + /** * do select the item and repaint the diagram * * @param selectable * @return */ - private Selectable doSelect(Selectable selectable) { - this.selectedItem = selectable; + private Selectable doSelect(Selectable selectable, boolean multi) { + + + if (!multi && !selectedItems.contains(selectable)) { + selectedItems.clear(); + } + + if (selectable != null) { + selectedItems.add(selectable); + } + if (selectable instanceof Component) { ((Component) selectable).requestFocusInWindow(); } repaint(); + return selectable; } @@ -403,23 +448,23 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene for (NodePanel nodePanel : nodes) { if (nodePanel.getKey().equals(key)) { - return doSelect(nodePanel); + return doSelect(nodePanel, false); } } for (Connection connection : connections) { if (connection.getKey().equals(key)) { - return doSelect(connection); + return doSelect(connection, false); } } for (OutBusPanel outBusPanel : outBuses) { if (outBusPanel.getKey().equals(key)) { - return doSelect(outBusPanel); + return doSelect(outBusPanel, false); } } - return doSelect(null); + return null; } @Override diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/DraggablePanel.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/DraggablePanel.java index e81d1d5b6..7941cb8d5 100644 --- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/DraggablePanel.java +++ b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/DraggablePanel.java @@ -37,16 +37,22 @@ public class DraggablePanel extends JPanel implements MouseListener, MouseMotion @Override public void mousePressed(MouseEvent e) { if (e.getButton() != MouseEvent.BUTTON2) { - svdx = getLocation().x; + if (!vertical) { svdex = e.getXOnScreen(); } - svdy = getLocation().y; svdey = e.getYOnScreen(); + saveLocation(); + diagram.multiStartDrag(this); e.consume(); } } + protected void saveLocation() { + svdy = getLocation().y; + svdx = getLocation().x; + } + @Override public void mouseReleased(MouseEvent e) { } @@ -71,11 +77,19 @@ public class DraggablePanel extends JPanel implements MouseListener, MouseMotion xoffset = e.getLocationOnScreen().x - svdex; } int yoffset = e.getLocationOnScreen().y - svdey; - setLocation(Math.max(0, svdx + xoffset), Math.max(0, svdy + yoffset)); + movePanel(xoffset, yoffset); + diagram.multiMove(this, xoffset, yoffset); e.consume(); } } + protected void movePanel(int xoffset, int yoffset) { + if (vertical) { + xoffset = 0; + } + setLocation(Math.max(0, svdx + xoffset), Math.max(0, svdy + yoffset)); + } + public Diagram getDiagram() { return diagram; } diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/NodePanel.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/NodePanel.java index 49e04170d..540ce9742 100644 --- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/NodePanel.java +++ b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/NodePanel.java @@ -56,23 +56,6 @@ public class NodePanel extends DraggablePanel implements Selectable, PropertyCha protected List filePaths = new ArrayList(); protected Shader.ShaderType shaderType; -// private List listeners = Collections.synchronizedList(new LinkedList()); -// -// public void addPropertyChangeListener(PropertyChangeListener pcl) { -// listeners.add(pcl); -// } -// -// public void removePropertyChangeListener(PropertyChangeListener pcl) { -// listeners.remove(pcl); -// } -// -// protected void fire(String propertyName, Object old, Object nue) { -// //Passing 0 below on purpose, so you only synchronize for one atomic call: -// PropertyChangeListener[] pcls = (PropertyChangeListener[]) listeners.toArray(new PropertyChangeListener[0]); -// for (int i = 0; i < pcls.length; i++) { -// pcls[i].propertyChange(new PropertyChangeEvent(this, propertyName, old, nue)); -// } -// } public enum NodeType { Vertex(new Color(220, 220, 70)),//yellow @@ -201,13 +184,13 @@ public class NodePanel extends DraggablePanel implements Selectable, PropertyCha protected void paintComponent(Graphics g1) { Graphics2D g = (Graphics2D) g1; Color boderColor = Color.BLACK; - if (diagram.selectedItem == this) { + if (getDiagram().getSelectedItems().contains(this)) { boderColor = Color.WHITE; } g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // Anti-alias! RenderingHints.VALUE_ANTIALIAS_ON); // Color[] colors = {new Color(0, 0, 0, 0.7f), new Color(0, 0, 0, 0.15f)}; - if (diagram.selectedItem == this) { + if (getDiagram().getSelectedItems().contains(this)) { Color[] colors = new Color[]{new Color(0.6f, 0.6f, 1.0f, 0.8f), new Color(0.6f, 0.6f, 1.0f, 0.5f)}; float[] factors = {0f, 1f}; g.setPaint(new RadialGradientPaint(getWidth() / 2, getHeight() / 2, getWidth() / 2, factors, colors)); @@ -260,8 +243,8 @@ public class NodePanel extends DraggablePanel implements Selectable, PropertyCha @Override public void mousePressed(MouseEvent e) { - super.mousePressed(e); - diagram.select(this); + super.mousePressed(e); + diagram.select(this, e.isShiftDown() || e.isControlDown()); showToolBar(); } @@ -442,9 +425,7 @@ public class NodePanel extends DraggablePanel implements Selectable, PropertyCha public void delete() { Diagram diag = getDiagram(); - if (diag.selectedItem == this) { - diag.removeSelectedNode(); - } + diag.removeSelected(); } public void keyReleased(KeyEvent e) { diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/OutBusPanel.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/OutBusPanel.java index 521776dce..6a489dea6 100644 --- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/OutBusPanel.java +++ b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/OutBusPanel.java @@ -110,7 +110,7 @@ public class OutBusPanel extends DraggablePanel implements ComponentListener, Se Polygon p = new Polygon(xs, ys, 8); - if (diagram.selectedItem == this) { + if (getDiagram().getSelectedItems().contains(this)) { int[] xs2 = {0, width - 30, width - 30, width, width - 32, width - 32, 0, 0}; int[] ys2 = {10, 10, 0, getHeight() / 2 + 2, getHeight(), getHeight() - 8, getHeight() - 8, 10}; @@ -154,7 +154,7 @@ public class OutBusPanel extends DraggablePanel implements ComponentListener, Se return; } super.mousePressed(e); - diagram.select(this); + diagram.select(this, e.isShiftDown() || e.isControlDown()); } @Override From 7f2c7c5d356acc350e705168e972112bfb151e83 Mon Sep 17 00:00:00 2001 From: Dokthar Date: Fri, 17 Jul 2015 13:46:06 +0200 Subject: [PATCH 08/17] Bullet RigidBody : prevent from breaking the API & reverted --- .../jme3/bullet/objects/PhysicsRigidBody.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java index d17b595c7..a27d0ea7f 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java @@ -626,10 +626,16 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native float getAngularSleepingThreshold(long objectId); - public Vector3f getAngularFactor() { - Vector3f vec = new Vector3f(); - getAngularFactor(objectId, vec); - return vec; + public float getAngularFactor() { + return getAngularFactor(null).getX(); + } + + public Vector3f getAngularFactor(Vector3f store) { + // doing like this prevent from breaking the API + if(store == null) + store = new Vector3f(); + getAngularFactor(objectId, store); + return store; } private native void getAngularFactor(long objectId, Vector3f vec); @@ -694,8 +700,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { capsule.write(getGravity(), "gravity", Vector3f.ZERO); capsule.write(getFriction(), "friction", 0.5f); capsule.write(getRestitution(), "restitution", 0); - capsule.write(getAngularFactor(), "angularFactor", Vector3f.UNIT_XYZ); - capsule.write(getLinearFactor(), "linearFactor", Vector3f.UNIT_XYZ); + capsule.write(getAngularFactor(), "angularFactor", 1); capsule.write(kinematic, "kinematic", false); capsule.write(getLinearDamping(), "linearDamping", 0); @@ -725,8 +730,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { setKinematic(capsule.readBoolean("kinematic", false)); setRestitution(capsule.readFloat("restitution", 0)); - setAngularFactor((Vector3f) capsule.readSavable("angularFactor", Vector3f.UNIT_XYZ.clone())); - setLinearFactor((Vector3f) capsule.readSavable("linearFactor", Vector3f.UNIT_XYZ.clone())); + setAngularFactor(capsule.readFloat("angularFactor", 1)); setDamping(capsule.readFloat("linearDamping", 0), capsule.readFloat("angularDamping", 0)); setSleepingThresholds(capsule.readFloat("linearSleepingThreshold", 0.8f), capsule.readFloat("angularSleepingThreshold", 1.0f)); setCcdMotionThreshold(capsule.readFloat("ccdMotionThreshold", 0)); From 0ade3a69d484cfc926412bbb7da308037a56bf11 Mon Sep 17 00:00:00 2001 From: Kirill Vainer Date: Sat, 18 Jul 2015 17:47:40 -0400 Subject: [PATCH 09/17] GLRenderer: FBO always available in OpenGL ES 2 --- .../src/main/java/com/jme3/renderer/opengl/GLRenderer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java index 6d4e4abba..ebfbc53b0 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java +++ b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java @@ -376,7 +376,9 @@ public class GLRenderer implements Renderer { caps.add(Caps.TextureFilterAnisotropic); } - if (hasExtension("GL_EXT_framebuffer_object") || gl3 != null) { + if (hasExtension("GL_EXT_framebuffer_object") + || gl3 != null + || caps.contains(Caps.OpenGLES20)) { caps.add(Caps.FrameBuffer); limits.put(Limits.RenderBufferSize, getInteger(GLFbo.GL_MAX_RENDERBUFFER_SIZE_EXT)); From b1473c302c4076a4c336b65abe4f953a91abf1a2 Mon Sep 17 00:00:00 2001 From: Dokthar Date: Sun, 19 Jul 2015 20:46:03 +0200 Subject: [PATCH 10/17] Bullet RigidBody : modification of the serializer to support the old & new angular factor --- .../jme3/bullet/objects/PhysicsRigidBody.java | 116 ++++++++++++------ 1 file changed, 80 insertions(+), 36 deletions(-) diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java index a27d0ea7f..1d59f304a 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java @@ -51,7 +51,9 @@ import java.util.logging.Level; import java.util.logging.Logger; /** - *

PhysicsRigidBody - Basic physics object

+ *

+ * PhysicsRigidBody - Basic physics object

+ * * @author normenhansen */ public class PhysicsRigidBody extends PhysicsCollisionObject { @@ -66,6 +68,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Creates a new PhysicsRigidBody with the supplied collision shape + * * @param child * @param shape */ @@ -134,6 +137,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Sets the physics object location + * * @param location the location of the actual physics object */ public void setPhysicsLocation(Vector3f location) { @@ -144,6 +148,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Sets the physics object rotation + * * @param rotation the rotation of the actual physics object */ public void setPhysicsRotation(Matrix3f rotation) { @@ -154,6 +159,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Sets the physics object rotation + * * @param rotation the rotation of the actual physics object */ public void setPhysicsRotation(Quaternion rotation) { @@ -249,9 +255,10 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { // return Converter.convert(tempTrans.basis, rotation); // } /** - * Sets the node to kinematic mode. in this mode the node is not affected by physics - * but affects other physics objects. Iits kinetic force is calculated by the amount - * of movement it is exposed to and its weight. + * Sets the node to kinematic mode. in this mode the node is not affected by + * physics but affects other physics objects. Iits kinetic force is + * calculated by the amount of movement it is exposed to and its weight. + * * @param kinematic */ public void setKinematic(boolean kinematic) { @@ -272,8 +279,11 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native void setCcdSweptSphereRadius(long objectId, float radius); /** - * Sets the amount of motion that has to happen in one physics tick to trigger the continuous motion detection
- * This avoids the problem of fast objects moving through other objects, set to zero to disable (default) + * Sets the amount of motion that has to happen in one physics tick to + * trigger the continuous motion detection
+ * This avoids the problem of fast objects moving through other objects, set + * to zero to disable (default) + * * @param threshold */ public void setCcdMotionThreshold(float threshold) { @@ -306,6 +316,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Sets the mass of this PhysicsRigidBody, objects with mass=0 are static. + * * @param mass */ public void setMass(float mass) { @@ -345,8 +356,9 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Set the local gravity of this PhysicsRigidBody
- * Set this after adding the node to the PhysicsSpace, - * the PhysicsSpace assigns its current gravity to the physics node when its added. + * Set this after adding the node to the PhysicsSpace, the PhysicsSpace + * assigns its current gravity to the physics node when its added. + * * @param gravity the gravity vector to set */ public void setGravity(Vector3f gravity) { @@ -363,6 +375,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Sets the friction of this physics object + * * @param friction the friction of this physics object */ public void setFriction(float friction) { @@ -389,10 +402,11 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { public void setLinearDamping(float linearDamping) { setDamping(objectId, linearDamping, getAngularDamping()); } - + public void setAngularDamping(float angularDamping) { setAngularDamping(objectId, angularDamping); } + private native void setAngularDamping(long objectId, float factor); public float getLinearDamping() { @@ -414,7 +428,9 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native float getRestitution(long objectId); /** - * The "bouncyness" of the PhysicsRigidBody, best performance if restitution=0 + * The "bouncyness" of the PhysicsRigidBody, best performance if + * restitution=0 + * * @param restitution */ public void setRestitution(float restitution) { @@ -425,6 +441,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Get the current angular velocity of this PhysicsRigidBody + * * @return the current linear velocity */ public Vector3f getAngularVelocity() { @@ -437,6 +454,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Get the current angular velocity of this PhysicsRigidBody + * * @param vec the vector to store the velocity in */ public void getAngularVelocity(Vector3f vec) { @@ -445,6 +463,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Sets the angular velocity of this PhysicsRigidBody + * * @param vec the angular velocity of this PhysicsRigidBody */ public void setAngularVelocity(Vector3f vec) { @@ -456,6 +475,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Get the current linear velocity of this PhysicsRigidBody + * * @return the current linear velocity */ public Vector3f getLinearVelocity() { @@ -468,6 +488,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Get the current linear velocity of this PhysicsRigidBody + * * @param vec the vector to store the velocity in */ public void getLinearVelocity(Vector3f vec) { @@ -476,6 +497,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Sets the linear velocity of this PhysicsRigidBody + * * @param vec the linear velocity of this PhysicsRigidBody */ public void setLinearVelocity(Vector3f vec) { @@ -486,9 +508,11 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native void setLinearVelocity(long objectId, Vector3f vec); /** - * Apply a force to the PhysicsRigidBody, only applies force if the next physics update call - * updates the physics space.
- * To apply an impulse, use applyImpulse, use applyContinuousForce to apply continuous force. + * Apply a force to the PhysicsRigidBody, only applies force if the next + * physics update call updates the physics space.
+ * To apply an impulse, use applyImpulse, use applyContinuousForce to apply + * continuous force. + * * @param force the force * @param location the location of the force */ @@ -500,10 +524,10 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native void applyForce(long objectId, Vector3f force, Vector3f location); /** - * Apply a force to the PhysicsRigidBody, only applies force if the next physics update call - * updates the physics space.
+ * Apply a force to the PhysicsRigidBody, only applies force if the next + * physics update call updates the physics space.
* To apply an impulse, use applyImpulse. - * + * * @param force the force */ public void applyCentralForce(Vector3f force) { @@ -514,10 +538,10 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native void applyCentralForce(long objectId, Vector3f force); /** - * Apply a force to the PhysicsRigidBody, only applies force if the next physics update call - * updates the physics space.
+ * Apply a force to the PhysicsRigidBody, only applies force if the next + * physics update call updates the physics space.
* To apply an impulse, use applyImpulse. - * + * * @param torque the torque */ public void applyTorque(Vector3f torque) { @@ -529,6 +553,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Apply an impulse to the PhysicsRigidBody in the next physics update. + * * @param impulse applied impulse * @param rel_pos location relative to object */ @@ -540,7 +565,9 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native void applyImpulse(long objectId, Vector3f impulse, Vector3f rel_pos); /** - * Apply a torque impulse to the PhysicsRigidBody in the next physics update. + * Apply a torque impulse to the PhysicsRigidBody in the next physics + * update. + * * @param vec */ public void applyTorqueImpulse(Vector3f vec) { @@ -552,7 +579,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Clear all forces from the PhysicsRigidBody - * + * */ public void clearForces() { clearForces(objectId); @@ -576,7 +603,8 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native void setCollisionShape(long objectId, long collisionShapeId); /** - * reactivates this PhysicsRigidBody when it has been deactivated because it was not moving + * reactivates this PhysicsRigidBody when it has been deactivated because it + * was not moving */ public void activate() { activate(objectId); @@ -591,8 +619,10 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native boolean isActive(long objectId); /** - * sets the sleeping thresholds, these define when the object gets deactivated - * to save ressources. Low values keep the object active when it barely moves + * sets the sleeping thresholds, these define when the object gets + * deactivated to save ressources. Low values keep the object active when it + * barely moves + * * @param linear the linear sleeping threshold * @param angular the angular sleeping threshold */ @@ -629,11 +659,12 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { public float getAngularFactor() { return getAngularFactor(null).getX(); } - + public Vector3f getAngularFactor(Vector3f store) { - // doing like this prevent from breaking the API - if(store == null) + // doing like this prevent from breaking the API + if (store == null) { store = new Vector3f(); + } getAngularFactor(objectId, store); return store; } @@ -645,26 +676,25 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { } public void setAngularFactor(Vector3f factor) { - setAngularFactor(objectId, factor); + setAngularFactor(objectId, factor); } private native void setAngularFactor(long objectId, Vector3f factor); public Vector3f getLinearFactor() { Vector3f vec = new Vector3f(); - getLinearFactor(objectId, vec); + getLinearFactor(objectId, vec); return vec; } private native void getLinearFactor(long objectId, Vector3f vec); public void setLinearFactor(Vector3f factor) { - setLinearFactor(objectId, factor); + setLinearFactor(objectId, factor); } private native void setLinearFactor(long objectId, Vector3f factor); - /** * do not use manually, joints are added automatically */ @@ -675,15 +705,17 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { } /** - * + * */ public void removeJoint(PhysicsJoint joint) { joints.remove(joint); } /** - * Returns a list of connected joints. This list is only filled when - * the PhysicsRigidBody is actually added to the physics space or loaded from disk. + * Returns a list of connected joints. This list is only filled when the + * PhysicsRigidBody is actually added to the physics space or loaded from + * disk. + * * @return list of active joints connected to this PhysicsRigidBody */ public List getJoints() { @@ -700,7 +732,13 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { capsule.write(getGravity(), "gravity", Vector3f.ZERO); capsule.write(getFriction(), "friction", 0.5f); capsule.write(getRestitution(), "restitution", 0); - capsule.write(getAngularFactor(), "angularFactor", 1); + Vector3f angularFactor = getAngularFactor(null); + if (angularFactor.x == angularFactor.y && angularFactor.y == angularFactor.z) { + capsule.write(getAngularFactor(), "angularFactor", 1); + } else { + capsule.write(getAngularFactor(null), "angularFactor", Vector3f.UNIT_XYZ); + capsule.write(getLinearFactor(), "linearFactor", Vector3f.UNIT_XYZ); + } capsule.write(kinematic, "kinematic", false); capsule.write(getLinearDamping(), "linearDamping", 0); @@ -730,7 +768,13 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { setKinematic(capsule.readBoolean("kinematic", false)); setRestitution(capsule.readFloat("restitution", 0)); - setAngularFactor(capsule.readFloat("angularFactor", 1)); + Vector3f angularFactor = (Vector3f) capsule.readSavable("angularFactor", Vector3f.NAN.clone()); + if(angularFactor == Vector3f.NAN) { + setAngularFactor(capsule.readFloat("angularFactor", 1)); + } else { + setAngularFactor(angularFactor); + setLinearFactor((Vector3f) capsule.readSavable("linearFactor", Vector3f.UNIT_XYZ.clone())); + } setDamping(capsule.readFloat("linearDamping", 0), capsule.readFloat("angularDamping", 0)); setSleepingThresholds(capsule.readFloat("linearSleepingThreshold", 0.8f), capsule.readFloat("angularSleepingThreshold", 1.0f)); setCcdMotionThreshold(capsule.readFloat("ccdMotionThreshold", 0)); From abbdefdcef2ccadf1a1089f4fb2522219b16dfa4 Mon Sep 17 00:00:00 2001 From: Dokthar Date: Sun, 19 Jul 2015 21:04:54 +0200 Subject: [PATCH 11/17] Bullet RigidBody : revert IDE autoformatting noise --- .../jme3/bullet/objects/PhysicsRigidBody.java | 93 +++++++------------ 1 file changed, 31 insertions(+), 62 deletions(-) diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java index 1d59f304a..6f6eb4d76 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java @@ -51,9 +51,7 @@ import java.util.logging.Level; import java.util.logging.Logger; /** - *

- * PhysicsRigidBody - Basic physics object

- * + *

PhysicsRigidBody - Basic physics object

* @author normenhansen */ public class PhysicsRigidBody extends PhysicsCollisionObject { @@ -68,7 +66,6 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Creates a new PhysicsRigidBody with the supplied collision shape - * * @param child * @param shape */ @@ -137,7 +134,6 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Sets the physics object location - * * @param location the location of the actual physics object */ public void setPhysicsLocation(Vector3f location) { @@ -148,7 +144,6 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Sets the physics object rotation - * * @param rotation the rotation of the actual physics object */ public void setPhysicsRotation(Matrix3f rotation) { @@ -159,7 +154,6 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Sets the physics object rotation - * * @param rotation the rotation of the actual physics object */ public void setPhysicsRotation(Quaternion rotation) { @@ -255,10 +249,9 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { // return Converter.convert(tempTrans.basis, rotation); // } /** - * Sets the node to kinematic mode. in this mode the node is not affected by - * physics but affects other physics objects. Iits kinetic force is - * calculated by the amount of movement it is exposed to and its weight. - * + * Sets the node to kinematic mode. in this mode the node is not affected by physics + * but affects other physics objects. Iits kinetic force is calculated by the amount + * of movement it is exposed to and its weight. * @param kinematic */ public void setKinematic(boolean kinematic) { @@ -279,11 +272,8 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native void setCcdSweptSphereRadius(long objectId, float radius); /** - * Sets the amount of motion that has to happen in one physics tick to - * trigger the continuous motion detection
- * This avoids the problem of fast objects moving through other objects, set - * to zero to disable (default) - * + * Sets the amount of motion that has to happen in one physics tick to trigger the continuous motion detection
+ * This avoids the problem of fast objects moving through other objects, set to zero to disable (default) * @param threshold */ public void setCcdMotionThreshold(float threshold) { @@ -316,7 +306,6 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Sets the mass of this PhysicsRigidBody, objects with mass=0 are static. - * * @param mass */ public void setMass(float mass) { @@ -356,9 +345,8 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Set the local gravity of this PhysicsRigidBody
- * Set this after adding the node to the PhysicsSpace, the PhysicsSpace - * assigns its current gravity to the physics node when its added. - * + * Set this after adding the node to the PhysicsSpace, + * the PhysicsSpace assigns its current gravity to the physics node when its added. * @param gravity the gravity vector to set */ public void setGravity(Vector3f gravity) { @@ -375,7 +363,6 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Sets the friction of this physics object - * * @param friction the friction of this physics object */ public void setFriction(float friction) { @@ -402,11 +389,10 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { public void setLinearDamping(float linearDamping) { setDamping(objectId, linearDamping, getAngularDamping()); } - + public void setAngularDamping(float angularDamping) { setAngularDamping(objectId, angularDamping); } - private native void setAngularDamping(long objectId, float factor); public float getLinearDamping() { @@ -428,9 +414,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native float getRestitution(long objectId); /** - * The "bouncyness" of the PhysicsRigidBody, best performance if - * restitution=0 - * + * The "bouncyness" of the PhysicsRigidBody, best performance if restitution=0 * @param restitution */ public void setRestitution(float restitution) { @@ -441,7 +425,6 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Get the current angular velocity of this PhysicsRigidBody - * * @return the current linear velocity */ public Vector3f getAngularVelocity() { @@ -454,7 +437,6 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Get the current angular velocity of this PhysicsRigidBody - * * @param vec the vector to store the velocity in */ public void getAngularVelocity(Vector3f vec) { @@ -463,7 +445,6 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Sets the angular velocity of this PhysicsRigidBody - * * @param vec the angular velocity of this PhysicsRigidBody */ public void setAngularVelocity(Vector3f vec) { @@ -475,7 +456,6 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Get the current linear velocity of this PhysicsRigidBody - * * @return the current linear velocity */ public Vector3f getLinearVelocity() { @@ -488,7 +468,6 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Get the current linear velocity of this PhysicsRigidBody - * * @param vec the vector to store the velocity in */ public void getLinearVelocity(Vector3f vec) { @@ -497,7 +476,6 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Sets the linear velocity of this PhysicsRigidBody - * * @param vec the linear velocity of this PhysicsRigidBody */ public void setLinearVelocity(Vector3f vec) { @@ -508,11 +486,9 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native void setLinearVelocity(long objectId, Vector3f vec); /** - * Apply a force to the PhysicsRigidBody, only applies force if the next - * physics update call updates the physics space.
- * To apply an impulse, use applyImpulse, use applyContinuousForce to apply - * continuous force. - * + * Apply a force to the PhysicsRigidBody, only applies force if the next physics update call + * updates the physics space.
+ * To apply an impulse, use applyImpulse, use applyContinuousForce to apply continuous force. * @param force the force * @param location the location of the force */ @@ -524,10 +500,10 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native void applyForce(long objectId, Vector3f force, Vector3f location); /** - * Apply a force to the PhysicsRigidBody, only applies force if the next - * physics update call updates the physics space.
+ * Apply a force to the PhysicsRigidBody, only applies force if the next physics update call + * updates the physics space.
* To apply an impulse, use applyImpulse. - * + * * @param force the force */ public void applyCentralForce(Vector3f force) { @@ -538,10 +514,10 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native void applyCentralForce(long objectId, Vector3f force); /** - * Apply a force to the PhysicsRigidBody, only applies force if the next - * physics update call updates the physics space.
+ * Apply a force to the PhysicsRigidBody, only applies force if the next physics update call + * updates the physics space.
* To apply an impulse, use applyImpulse. - * + * * @param torque the torque */ public void applyTorque(Vector3f torque) { @@ -553,7 +529,6 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Apply an impulse to the PhysicsRigidBody in the next physics update. - * * @param impulse applied impulse * @param rel_pos location relative to object */ @@ -565,9 +540,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native void applyImpulse(long objectId, Vector3f impulse, Vector3f rel_pos); /** - * Apply a torque impulse to the PhysicsRigidBody in the next physics - * update. - * + * Apply a torque impulse to the PhysicsRigidBody in the next physics update. * @param vec */ public void applyTorqueImpulse(Vector3f vec) { @@ -579,7 +552,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { /** * Clear all forces from the PhysicsRigidBody - * + * */ public void clearForces() { clearForces(objectId); @@ -603,8 +576,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native void setCollisionShape(long objectId, long collisionShapeId); /** - * reactivates this PhysicsRigidBody when it has been deactivated because it - * was not moving + * reactivates this PhysicsRigidBody when it has been deactivated because it was not moving */ public void activate() { activate(objectId); @@ -619,10 +591,8 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { private native boolean isActive(long objectId); /** - * sets the sleeping thresholds, these define when the object gets - * deactivated to save ressources. Low values keep the object active when it - * barely moves - * + * sets the sleeping thresholds, these define when the object gets deactivated + * to save ressources. Low values keep the object active when it barely moves * @param linear the linear sleeping threshold * @param angular the angular sleeping threshold */ @@ -676,25 +646,26 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { } public void setAngularFactor(Vector3f factor) { - setAngularFactor(objectId, factor); + setAngularFactor(objectId, factor); } private native void setAngularFactor(long objectId, Vector3f factor); public Vector3f getLinearFactor() { Vector3f vec = new Vector3f(); - getLinearFactor(objectId, vec); + getLinearFactor(objectId, vec); return vec; } private native void getLinearFactor(long objectId, Vector3f vec); public void setLinearFactor(Vector3f factor) { - setLinearFactor(objectId, factor); + setLinearFactor(objectId, factor); } private native void setLinearFactor(long objectId, Vector3f factor); + /** * do not use manually, joints are added automatically */ @@ -705,17 +676,15 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { } /** - * + * */ public void removeJoint(PhysicsJoint joint) { joints.remove(joint); } /** - * Returns a list of connected joints. This list is only filled when the - * PhysicsRigidBody is actually added to the physics space or loaded from - * disk. - * + * Returns a list of connected joints. This list is only filled when + * the PhysicsRigidBody is actually added to the physics space or loaded from disk. * @return list of active joints connected to this PhysicsRigidBody */ public List getJoints() { From 89fe2e57bebffe9db7268d4d5c454ebd547edc46 Mon Sep 17 00:00:00 2001 From: jmekaelthas Date: Tue, 21 Jul 2015 22:23:15 +0200 Subject: [PATCH 12/17] Bugfix: fixed some issues with bones' animations. --- .../jme3/scene/plugins/blender/animations/Ipo.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/Ipo.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/Ipo.java index f5113129f..6665752b7 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/Ipo.java +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/Ipo.java @@ -145,7 +145,7 @@ public class Ipo { float[] times = new float[framesAmount + 1]; Vector3f[] translations = new Vector3f[framesAmount + 1]; - float[] translation = new float[] { localTranslation.x, localTranslation.y, localTranslation.z }; + float[] translation = new float[3]; Quaternion[] rotations = new Quaternion[framesAmount + 1]; float[] quaternionRotation = new float[] { localRotation.getX(), localRotation.getY(), localRotation.getZ(), localRotation.getW(), }; float[] eulerRotation = localRotation.toAngles(null); @@ -165,6 +165,8 @@ public class Ipo { // calculating track data for (int frame = startFrame; frame <= stopFrame; ++frame) { + boolean translationSet = false; + translation[0] = translation[1] = translation[2] = 0; int index = frame - startFrame; times[index] = index * timeBetweenFrames;// start + (frame - 1) * timeBetweenFrames; for (int j = 0; j < bezierCurves.length; ++j) { @@ -173,15 +175,18 @@ public class Ipo { // LOCATION case AC_LOC_X: translation[0] = (float) value; + translationSet = true; break; case AC_LOC_Y: if (swapAxes && value != 0) { value = -value; } translation[yIndex] = (float) value; + translationSet = true; break; case AC_LOC_Z: translation[zIndex] = (float) value; + translationSet = true; break; // EULER ROTATION @@ -235,7 +240,11 @@ public class Ipo { LOGGER.log(Level.WARNING, "Unknown ipo curve type: {0}.", bezierCurves[j].getType()); } } - translations[index] = localRotation.multLocal(new Vector3f(translation[0], translation[1], translation[2])); + if(translationSet) { + translations[index] = localRotation.multLocal(new Vector3f(translation[0], translation[1], translation[2])); + } else { + translations[index] = new Vector3f(); + } if(boneContext != null) { if(boneContext.getBone().getParent() == null && boneContext.is(BoneContext.NO_LOCAL_LOCATION)) { From aa1874442d98ed7c2aa8026ddf61ce3c8d257c75 Mon Sep 17 00:00:00 2001 From: Kirill Vainer Date: Sun, 2 Aug 2015 13:48:31 -0400 Subject: [PATCH 14/17] Travis-CI: release test --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 71c3b576f..0aeda268d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,9 +8,9 @@ cache: - gradle-cache - netbeans -branches: - only: - - master +# branches: +# only: +# - master notifications: slack: From 2bf5a5c0893d6b5548e313c409e72d19d1bb24f0 Mon Sep 17 00:00:00 2001 From: Kirill Vainer Date: Sun, 2 Aug 2015 14:49:44 -0400 Subject: [PATCH 15/17] Travis-CI: fix release deployment --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0aeda268d..25f23fcac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,10 +29,11 @@ script: deploy: provider: releases api_key: - secure: "KbFiMt0a8FxUKvCJUYwikLYaqqGMn1p6k4OsXnGqwptQZEUIayabNLHeaD2kTNT3e6AY1ETwQLff/lB2LttmIo4g5NWW63g1K3A/HwgnhJwETengiProZ/Udl+ugPeDL/+ar43HUhFq4knBnzFKnEcHAThTPVqH/RMDvZf1UUYI=" - file: build/distributions/jME3.1.0_snapshot-github_2015-06-20.zip + secure: PuEsJd6juXBH29ByITW3ntSAyrwWs0IeFvXJ5Y2YlhojhSMtTwkoWeB6YmDJWP4fhzbajk4TQ1HlOX2IxJXSW/8ShOEIUlGXz9fHiST0dkSM+iRAUgC5enCLW5ITPTiem7eY9ZhS9miIam7ngce9jHNMh75PTzZrEJtezoALT9w= + file: build/distributions/jME3.1.0_snapshot-github_2015-08-02.zip skip_cleanup: true on: + repo: jMonkeyEngine/jmonkeyengine tags: true # before_install: From a68a9747bb04693e9f70e3dddf81f8953c24052d Mon Sep 17 00:00:00 2001 From: Kirill Vainer Date: Tue, 4 Aug 2015 23:46:00 -0400 Subject: [PATCH 16/17] SDK Update Center URL: change 3.0 -> 3.1 Doesn't work yet, because the 3.1 folder is missing from the updates server. --- .../src/com/jme3/gde/core/updatecenters/Bundle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/jme3-core-updatecenters/src/com/jme3/gde/core/updatecenters/Bundle.properties b/sdk/jme3-core-updatecenters/src/com/jme3/gde/core/updatecenters/Bundle.properties index 5a898643f..dd627e347 100644 --- a/sdk/jme3-core-updatecenters/src/com/jme3/gde/core/updatecenters/Bundle.properties +++ b/sdk/jme3-core-updatecenters/src/com/jme3/gde/core/updatecenters/Bundle.properties @@ -1,6 +1,6 @@ #jMP update centers -com_jme3_gde_core_update_center_nightly=http://updates.jmonkeyengine.org/nightly/3.0/plugins/updates.xml -com_jme3_gde_core_update_center_stable=http://updates.jmonkeyengine.org/stable/3.0/plugins/updates.xml +com_jme3_gde_core_update_center_nightly=http://updates.jmonkeyengine.org/nightly/3.1/plugins/updates.xml +com_jme3_gde_core_update_center_stable=http://updates.jmonkeyengine.org/stable/3.1/plugins/updates.xml com_jme3_jmp_contributions_update_center=http://updates.jmonkeyengine.org/contributions/updates.xml #jMP update centers From a655acb8f0b6ac291ad0aa7f89de74e8a8ad1f21 Mon Sep 17 00:00:00 2001 From: Nehon Date: Fri, 7 Aug 2015 08:34:11 +0200 Subject: [PATCH 17/17] BatchNode now preserves the lineWidth for Line meshes when batching. --- .../src/main/java/com/jme3/scene/BatchNode.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/scene/BatchNode.java b/jme3-core/src/main/java/com/jme3/scene/BatchNode.java index 9a920093d..c3a0ab4bb 100644 --- a/jme3-core/src/main/java/com/jme3/scene/BatchNode.java +++ b/jme3-core/src/main/java/com/jme3/scene/BatchNode.java @@ -444,6 +444,7 @@ public class BatchNode extends GeometryGroupNode { int maxWeights = -1; Mesh.Mode mode = null; + float lineWidth = 1f; for (Geometry geom : geometries) { totalVerts += geom.getVertexCount(); totalTris += geom.getTriangleCount(); @@ -452,6 +453,7 @@ public class BatchNode extends GeometryGroupNode { maxVertCount = geom.getVertexCount(); } Mesh.Mode listMode; + float listLineWidth = 1f; int components; switch (geom.getMesh().getMode()) { case Points: @@ -462,6 +464,7 @@ public class BatchNode extends GeometryGroupNode { case LineStrip: case Lines: listMode = Mesh.Mode.Lines; + listLineWidth = geom.getMesh().getLineWidth(); components = 2; break; case TriangleFan: @@ -491,13 +494,21 @@ public class BatchNode extends GeometryGroupNode { if (mode != null && mode != listMode) { throw new UnsupportedOperationException("Cannot combine different" + " primitive types: " + mode + " != " + listMode); - } + } mode = listMode; + if (mode == Mesh.Mode.Lines) { + if (lineWidth != 1f && listLineWidth != lineWidth) { + throw new UnsupportedOperationException("When using Mesh Line mode, cannot combine meshes with different line width " + + lineWidth + " != " + listLineWidth); + } + lineWidth = listLineWidth; + } compsForBuf[VertexBuffer.Type.Index.ordinal()] = components; } outMesh.setMaxNumWeights(maxWeights); outMesh.setMode(mode); + outMesh.setLineWidth(lineWidth); if (totalVerts >= 65536) { // make sure we create an UnsignedInt buffer so // we can fit all of the meshes