فهرست منبع

Merge remote-tracking branch 'origin/master' into experimental

Kirill Vainer 9 سال پیش
والد
کامیت
8f54af3263

+ 16 - 7
jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionIK.java

@@ -174,7 +174,7 @@ public class ConstraintDefinitionIK extends ConstraintDefinition {
     private static class BonesChain extends ArrayList<BoneContext> {
         private static final long serialVersionUID = -1850524345643600718L;
 
-        private List<Matrix> bonesMatrices = new ArrayList<Matrix>();
+        private List<Matrix> localBonesMatrices = new ArrayList<Matrix>();
 
         public BonesChain(Bone bone, boolean useTail, int bonesAffected, Collection<Long> alteredOmas, BlenderContext blenderContext) {
             if (bone != null) {
@@ -187,12 +187,21 @@ public class ConstraintDefinitionIK extends ConstraintDefinition {
                     this.add(boneContext);
                     alteredOmas.add(boneContext.getBoneOma());
 
-                    Space space = this.size() < bonesAffected ? Space.CONSTRAINT_SPACE_LOCAL : Space.CONSTRAINT_SPACE_WORLD;
-                    Transform transform = constraintHelper.getTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), space);
-                    bonesMatrices.add(new DTransform(transform).toMatrix());
+                    Transform transform = constraintHelper.getTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), Space.CONSTRAINT_SPACE_WORLD);
+                    localBonesMatrices.add(new DTransform(transform).toMatrix());
 
                     bone = bone.getParent();
                 }
+                
+                if(localBonesMatrices.size() > 0) {
+                	// making the matrices describe the local transformation
+                    Matrix parentWorldMatrix = localBonesMatrices.get(localBonesMatrices.size() - 1);
+                    for(int i=localBonesMatrices.size() - 2;i>=0;--i) {
+                    	SimpleMatrix m = parentWorldMatrix.invert().mult(localBonesMatrices.get(i));
+                    	parentWorldMatrix = localBonesMatrices.get(i);
+                    	localBonesMatrices.set(i, new Matrix(m));
+                    }
+                }
             }
         }
 
@@ -211,16 +220,16 @@ public class ConstraintDefinitionIK extends ConstraintDefinition {
                 SimpleMatrix m = parentWorldMatrix.invert().mult(boneMatrix);
                 boneMatrix = new Matrix(m);
             }
-            bonesMatrices.set(index, boneMatrix);
+            localBonesMatrices.set(index, boneMatrix);
         }
 
         public Matrix getWorldMatrix(int index) {
             if (index == this.size() - 1) {
-                return new Matrix(bonesMatrices.get(this.size() - 1));
+                return new Matrix(localBonesMatrices.get(this.size() - 1));
             }
 
             SimpleMatrix result = this.getWorldMatrix(index + 1);
-            result = result.mult(bonesMatrices.get(index));
+            result = result.mult(localBonesMatrices.get(index));
             return new Matrix(result);
         }
     }

+ 1 - 1
jme3-blender/src/main/java/com/jme3/scene/plugins/blender/curves/CurvesTemporalMesh.java

@@ -180,8 +180,8 @@ public class CurvesTemporalMesh extends TemporalMesh {
         if (bevelObject != null && beziers.size() > 0) {
             this.append(this.applyBevelAndTaper(this, bevelObject, taperObject, blenderContext));
         } else {
-            int originalVerticesAmount = vertices.size();
             for (BezierLine bezierLine : beziers) {
+            	int originalVerticesAmount = vertices.size();
                 vertices.add(bezierLine.vertices[0]);
                 Vector3f v = bezierLine.vertices[1].subtract(bezierLine.vertices[0]).normalizeLocal();
                 float temp = v.x;

+ 8 - 0
jme3-core/src/main/java/com/jme3/input/DefaultJoystickAxis.java

@@ -135,6 +135,14 @@ public class DefaultJoystickAxis implements JoystickAxis {
         return deadZone;
     }        
 
+    /**
+     *  Sets/overrides the dead zone for this axis.  This indicates that values
+     *  within +/- deadZone should be ignored.
+     */
+    public void setDeadZone( float f ) {
+        this.deadZone = f;
+    }     
+
     @Override
     public String toString(){
         return "JoystickAxis[name=" + name + ", parent=" + parent.getName() + ", id=" + axisIndex 

+ 28 - 29
jme3-core/src/main/java/com/jme3/input/InputManager.java

@@ -39,6 +39,7 @@ import com.jme3.math.FastMath;
 import com.jme3.math.Vector2f;
 import com.jme3.util.IntMap;
 import com.jme3.util.IntMap.Entry;
+import com.jme3.util.SafeArrayList;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.logging.Level;
@@ -96,16 +97,15 @@ public class InputManager implements RawInputListener {
     private boolean eventsPermitted = false;
     private boolean mouseVisible = true;
     private boolean safeMode = false;
-    private float axisDeadZone = 0.05f;
-    private Vector2f cursorPos = new Vector2f();
+    private float globalAxisDeadZone = 0.05f;
+    private final Vector2f cursorPos = new Vector2f();
     private Joystick[] joysticks;
     private final IntMap<ArrayList<Mapping>> bindings = new IntMap<ArrayList<Mapping>>();
     private final HashMap<String, Mapping> mappings = new HashMap<String, Mapping>();
     private final IntMap<Long> pressedButtons = new IntMap<Long>();
     private final IntMap<Float> axisValues = new IntMap<Float>();
-    private ArrayList<RawInputListener> rawListeners = new ArrayList<RawInputListener>();
-    private RawInputListener[] rawListenerArray = null;
-    private ArrayList<InputEvent> inputQueue = new ArrayList<InputEvent>();
+    private final SafeArrayList<RawInputListener> rawListeners = new SafeArrayList<RawInputListener>(RawInputListener.class);
+    private final ArrayList<InputEvent> inputQueue = new ArrayList<InputEvent>();
 
     private static class Mapping {
 
@@ -248,8 +248,8 @@ public class InputManager implements RawInputListener {
         }
     }
 
-    private void invokeAnalogsAndActions(int hash, float value, boolean applyTpf) {
-        if (value < axisDeadZone) {
+    private void invokeAnalogsAndActions(int hash, float value, float effectiveDeadZone, boolean applyTpf) {
+        if (value < effectiveDeadZone) {
             invokeAnalogs(hash, value, !applyTpf);
             return;
         }
@@ -287,12 +287,14 @@ public class InputManager implements RawInputListener {
     /**
      * Callback from RawInputListener. Do not use.
      */
+    @Override
     public void beginInput() {
     }
 
     /**
      * Callback from RawInputListener. Do not use.
      */
+    @Override
     public void endInput() {
     }
 
@@ -304,17 +306,18 @@ public class InputManager implements RawInputListener {
         int joyId = evt.getJoyIndex();
         int axis = evt.getAxisIndex();
         float value = evt.getValue();
-        if (value < axisDeadZone && value > -axisDeadZone) {
+        float effectiveDeadZone = Math.max(globalAxisDeadZone, evt.getAxis().getDeadZone()); 
+        if (value < effectiveDeadZone && value > -effectiveDeadZone) {
             int hash1 = JoyAxisTrigger.joyAxisHash(joyId, axis, true);
             int hash2 = JoyAxisTrigger.joyAxisHash(joyId, axis, false);
 
             Float val1 = axisValues.get(hash1);
             Float val2 = axisValues.get(hash2);
 
-            if (val1 != null && val1.floatValue() > axisDeadZone) {
+            if (val1 != null && val1 > effectiveDeadZone) {
                 invokeActions(hash1, false);
             }
-            if (val2 != null && val2.floatValue() > axisDeadZone) {
+            if (val2 != null && val2 > effectiveDeadZone) {
                 invokeActions(hash2, false);
             }
 
@@ -328,11 +331,11 @@ public class InputManager implements RawInputListener {
             // Clear the reverse direction's actions in case we
             // crossed center too quickly
             Float otherVal = axisValues.get(otherHash);
-            if (otherVal != null && otherVal.floatValue() > axisDeadZone) {
+            if (otherVal != null && otherVal > effectiveDeadZone) {
                 invokeActions(otherHash, false);
             }
 
-            invokeAnalogsAndActions(hash, -value, true);
+            invokeAnalogsAndActions(hash, -value, effectiveDeadZone, true);
             axisValues.put(hash, -value);
             axisValues.remove(otherHash);
         } else {
@@ -342,11 +345,11 @@ public class InputManager implements RawInputListener {
             // Clear the reverse direction's actions in case we
             // crossed center too quickly
             Float otherVal = axisValues.get(otherHash);
-            if (otherVal != null && otherVal.floatValue() > axisDeadZone) {
+            if (otherVal != null && otherVal > effectiveDeadZone) {
                 invokeActions(otherHash, false);
             }
 
-            invokeAnalogsAndActions(hash, value, true);
+            invokeAnalogsAndActions(hash, value, effectiveDeadZone, true);
             axisValues.put(hash, value);
             axisValues.remove(otherHash);
         }
@@ -355,6 +358,7 @@ public class InputManager implements RawInputListener {
     /**
      * Callback from RawInputListener. Do not use.
      */
+    @Override
     public void onJoyAxisEvent(JoyAxisEvent evt) {
         if (!eventsPermitted) {
             throw new UnsupportedOperationException("JoyInput has raised an event at an illegal time.");
@@ -376,6 +380,7 @@ public class InputManager implements RawInputListener {
     /**
      * Callback from RawInputListener. Do not use.
      */
+    @Override
     public void onJoyButtonEvent(JoyButtonEvent evt) {
         if (!eventsPermitted) {
             throw new UnsupportedOperationException("JoyInput has raised an event at an illegal time.");
@@ -391,15 +396,15 @@ public class InputManager implements RawInputListener {
 
         if (evt.getDX() != 0) {
             float val = Math.abs(evt.getDX()) / 1024f;
-            invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_X, evt.getDX() < 0), val, false);
+            invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_X, evt.getDX() < 0), val, globalAxisDeadZone, false);
         }
         if (evt.getDY() != 0) {
             float val = Math.abs(evt.getDY()) / 1024f;
-            invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_Y, evt.getDY() < 0), val, false);
+            invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_Y, evt.getDY() < 0), val, globalAxisDeadZone, false);
         }
         if (evt.getDeltaWheel() != 0) {
             float val = Math.abs(evt.getDeltaWheel()) / 100f;
-            invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_WHEEL, evt.getDeltaWheel() < 0), val, false);
+            invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_WHEEL, evt.getDeltaWheel() < 0), val, globalAxisDeadZone, false);
         }
     }
 
@@ -419,6 +424,7 @@ public class InputManager implements RawInputListener {
     /**
      * Callback from RawInputListener. Do not use.
      */
+    @Override
     public void onMouseMotionEvent(MouseMotionEvent evt) {
         if (!eventsPermitted) {
             throw new UnsupportedOperationException("MouseInput has raised an event at an illegal time.");
@@ -437,6 +443,7 @@ public class InputManager implements RawInputListener {
     /**
      * Callback from RawInputListener. Do not use.
      */
+    @Override
     public void onMouseButtonEvent(MouseButtonEvent evt) {
         if (!eventsPermitted) {
             throw new UnsupportedOperationException("MouseInput has raised an event at an illegal time.");
@@ -459,6 +466,7 @@ public class InputManager implements RawInputListener {
     /**
      * Callback from RawInputListener. Do not use.
      */
+    @Override
     public void onKeyEvent(KeyInputEvent evt) {
         if (!eventsPermitted) {
             throw new UnsupportedOperationException("KeyInput has raised an event at an illegal time.");
@@ -477,7 +485,7 @@ public class InputManager implements RawInputListener {
      * @param deadZone the deadzone for joystick axes.
      */
     public void setAxisDeadZone(float deadZone) {
-        this.axisDeadZone = deadZone;
+        this.globalAxisDeadZone = deadZone;
     }
 
     /**
@@ -486,7 +494,7 @@ public class InputManager implements RawInputListener {
      * @return the deadzone for joystick axes.
      */
     public float getAxisDeadZone() {
-        return axisDeadZone;
+        return globalAxisDeadZone;
     }
 
     /**
@@ -721,7 +729,6 @@ public class InputManager implements RawInputListener {
      */
     public void addRawInputListener(RawInputListener listener) {
         rawListeners.add(listener);
-        rawListenerArray = null;
     }
 
     /**
@@ -734,7 +741,6 @@ public class InputManager implements RawInputListener {
      */
     public void removeRawInputListener(RawInputListener listener) {
         rawListeners.remove(listener);
-        rawListenerArray = null;
     }
 
     /**
@@ -744,13 +750,6 @@ public class InputManager implements RawInputListener {
      */
     public void clearRawInputListeners() {
         rawListeners.clear();
-        rawListenerArray = null;
-    }
-
-    private RawInputListener[] getRawListenerArray() {
-        if (rawListenerArray == null)
-            rawListenerArray = rawListeners.toArray(new RawInputListener[rawListeners.size()]);
-        return rawListenerArray;
     }
 
     /**
@@ -813,7 +812,7 @@ public class InputManager implements RawInputListener {
 
     private void processQueue() {
         int queueSize = inputQueue.size();
-        RawInputListener[] array = getRawListenerArray();
+        RawInputListener[] array = rawListeners.getArray(); 
 
         for (RawInputListener listener : array) {
             listener.beginInput();

+ 18 - 2
jme3-core/src/main/java/com/jme3/renderer/RenderManager.java

@@ -748,27 +748,43 @@ public class RenderManager {
     }
 
     /**
-     * Sets the light filter to use when rendering Lighted Geometries
+     * Sets the light filter to use when rendering lit Geometries.
      * 
      * @see LightFilter
-     * @param lightFilter The light filter tose. Set it to null if you want all lights to be rendered
+     * @param lightFilter The light filter. Set it to null if you want all lights to be rendered.
      */
     public void setLightFilter(LightFilter lightFilter) {
         this.lightFilter = lightFilter;
     }
 
+    /**
+     * Defines what light mode will be selected when a technique offers several light modes.
+     * @param preferredLightMode The light mode to use.
+     */
     public void setPreferredLightMode(TechniqueDef.LightMode preferredLightMode) {
         this.preferredLightMode = preferredLightMode;
     }
 
+    /**
+     * returns the preferred light mode.
+     * @return the light mode.
+     */
     public TechniqueDef.LightMode getPreferredLightMode() {
         return preferredLightMode;
     }
 
+    /**
+     * returns the number of lights used for each pass when the light mode is single pass.
+     * @return the number of lights.
+     */
     public int getSinglePassLightBatchSize() {
         return singlePassLightBatchSize;
     }
 
+    /**
+     * Sets the number of lights to use for each pass when the light mode is single pass.
+     * @param singlePassLightBatchSize the number of lights.
+     */
     public void setSinglePassLightBatchSize(int singlePassLightBatchSize) {
         if (singlePassLightBatchSize < 1) {
             throw new IllegalArgumentException("batch size cannot be less than 1");

+ 32 - 25
jme3-core/src/main/java/com/jme3/scene/shape/Curve.java

@@ -198,35 +198,42 @@ public class Curve extends Mesh {
      * points
      */
     private void createNurbMesh(int nbSubSegments) {
-        float minKnot = spline.getMinNurbKnot();
-        float maxKnot = spline.getMaxNurbKnot();
-        float deltaU = (maxKnot - minKnot) / nbSubSegments;
+    	if(spline.getControlPoints() != null && spline.getControlPoints().size() > 0) {
+    		if(nbSubSegments == 0) {
+        		nbSubSegments = spline.getControlPoints().size() + 1;
+        	} else {
+        		nbSubSegments = spline.getControlPoints().size() * nbSubSegments + 1;
+        	}
+            float minKnot = spline.getMinNurbKnot();
+            float maxKnot = spline.getMaxNurbKnot();
+            float deltaU = (maxKnot - minKnot) / nbSubSegments;
 
-        float[] array = new float[(nbSubSegments + 1) * 3];
+            float[] array = new float[(nbSubSegments + 1) * 3];
 
-        float u = minKnot;
-        Vector3f interpolationResult = new Vector3f();
-        for (int i = 0; i < array.length; i += 3) {
-            spline.interpolate(u, 0, interpolationResult);
-            array[i] = interpolationResult.x;
-            array[i + 1] = interpolationResult.y;
-            array[i + 2] = interpolationResult.z;
-            u += deltaU;
-        }
+            float u = minKnot;
+            Vector3f interpolationResult = new Vector3f();
+            for (int i = 0; i < array.length; i += 3) {
+                spline.interpolate(u, 0, interpolationResult);
+                array[i] = interpolationResult.x;
+                array[i + 1] = interpolationResult.y;
+                array[i + 2] = interpolationResult.z;
+                u += deltaU;
+            }
 
-        //calculating indexes
-        int i = 0;
-        short[] indices = new short[nbSubSegments << 1];
-        for (int j = 0; j < nbSubSegments; ++j) {
-            indices[i++] = (short) j;
-            indices[i++] = (short) (j + 1);
-        }
+            //calculating indexes
+            int i = 0;
+            short[] indices = new short[nbSubSegments << 1];
+            for (int j = 0; j < nbSubSegments; ++j) {
+                indices[i++] = (short) j;
+                indices[i++] = (short) (j + 1);
+            }
 
-        this.setMode(Mesh.Mode.Lines);
-        this.setBuffer(VertexBuffer.Type.Position, 3, array);
-        this.setBuffer(VertexBuffer.Type.Index, 2, indices);
-        this.updateBound();
-        this.updateCounts();
+            this.setMode(Mesh.Mode.Lines);
+            this.setBuffer(VertexBuffer.Type.Position, 3, array);
+            this.setBuffer(VertexBuffer.Type.Index, 2, indices);
+            this.updateBound();
+            this.updateCounts();
+    	}
     }
 
     private void createLinearMesh() {

+ 2 - 1
jme3-core/src/main/java/com/jme3/texture/image/DefaultImageRaster.java

@@ -51,7 +51,8 @@ public class DefaultImageRaster extends ImageRaster {
     
     private void rangeCheck(int x, int y) {
         if (x < 0 || y < 0 || x >= width || y >= height) {
-            throw new IllegalArgumentException("x and y must be inside the image dimensions");
+            throw new IllegalArgumentException("x and y must be inside the image dimensions:" 
+                                                + x + ", " + y + " in:" + width + ", " + height);
         }
     }
     

+ 5 - 0
jme3-networking/src/main/java/com/jme3/network/base/DefaultClient.java

@@ -389,6 +389,7 @@ public class DefaultClient implements Client
 
     protected void startServices() 
     {
+        log.fine("Starting client services.");
         // Let the services know we are finally started
         services.start();      
     }
@@ -447,6 +448,10 @@ public class DefaultClient implements Client
  
     protected void dispatch( Message m )
     {
+        if( log.isLoggable(Level.FINER) ) {
+            log.log(Level.FINER, "{0} received:{1}", new Object[]{this, m});
+        }
+        
         // Pull off the connection management messages we're
         // interested in and then pass on the rest.
         if( m instanceof ClientRegistrationMessage ) {

+ 4 - 0
jme3-networking/src/main/java/com/jme3/network/base/DefaultServer.java

@@ -326,6 +326,10 @@ public class DefaultServer implements Server
  
     protected void dispatch( HostedConnection source, Message m )
     {
+        if( log.isLoggable(Level.FINER) ) {
+            log.log(Level.FINER, "{0} received:{1}", new Object[]{source, m});
+        }
+        
         if( source == null ) {
             messageListeners.messageReceived( source, m );
         } else {

+ 11 - 3
jme3-networking/src/main/java/com/jme3/network/base/MessageListenerRegistry.java

@@ -50,26 +50,34 @@ import java.util.logging.Logger;
  */
 public class MessageListenerRegistry<S> implements MessageListener<S>
 {
-    static Logger log = Logger.getLogger(MessageListenerRegistry.class.getName());
+    static final Logger log = Logger.getLogger(MessageListenerRegistry.class.getName());
     
-    private List<MessageListener<? super S>> listeners = new CopyOnWriteArrayList<MessageListener<? super S>>();
-    private Map<Class,List<MessageListener<? super S>>> typeListeners 
+    private final List<MessageListener<? super S>> listeners = new CopyOnWriteArrayList<MessageListener<? super S>>();
+    private final Map<Class,List<MessageListener<? super S>>> typeListeners 
                     = new ConcurrentHashMap<Class,List<MessageListener<? super S>>>(); 
 
     public MessageListenerRegistry()
     {
     }
  
+    @Override
     public void messageReceived( S source, Message m )
     {
         boolean delivered = false;
+        boolean trace = log.isLoggable(Level.FINER);
         
         for( MessageListener<? super S> l : listeners ) {
+            if( trace ) {
+                log.log(Level.FINER, "Delivering {0} to:{1}", new Object[]{m, l});
+            }
             l.messageReceived( source, m );
             delivered = true;
         }
         
         for( MessageListener<? super S> l : getListeners(m.getClass(),false) ) {
+            if( trace ) {
+                log.log(Level.FINER, "Delivering {0} to:{1}", new Object[]{m, l});
+            }
             l.messageReceived( source, m );
             delivered = true;
         }

+ 4 - 0
jme3-networking/src/main/java/com/jme3/network/service/rmi/RmiHostedService.java

@@ -89,6 +89,10 @@ public class RmiHostedService extends AbstractHostedService {
         this((short)-1, (byte)MessageConnection.CHANNEL_DEFAULT_RELIABLE, true);
     }
 
+    public RmiHostedService( byte defaultChannel ) {
+        this((short)-1, defaultChannel, true);
+    }
+
     public RmiHostedService( short rmiId, byte defaultChannel, boolean autoHost ) {
         this.rmiId = rmiId;
         this.defaultChannel = defaultChannel;

+ 1 - 0
jme3-networking/src/main/java/com/jme3/network/service/rpc/msg/RpcResponseMessage.java

@@ -84,6 +84,7 @@ public class RpcResponseMessage extends AbstractMessage {
     @Override
     public String toString() {
         return getClass().getSimpleName() + "[#" + msgId + ", result=" + result
+                                          + (error != null ? ", error=" + error : "")
                                           + "]";
     }
 }