diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CollisionShape.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CollisionShape.java index ea6f11be9..acdd6ed04 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CollisionShape.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CollisionShape.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2018 jMonkeyEngine + * Copyright (c) 2009-2019 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -49,6 +49,11 @@ import java.util.logging.Logger; */ public abstract class CollisionShape implements Savable { + /** + * default margin for new non-sphere/non-capsule shapes (in physics-space + * units, >0, default=0.04) + */ + private static float defaultMargin = 0.04f; /** * unique identifier of the btCollisionShape *

@@ -63,7 +68,7 @@ public abstract class CollisionShape implements Savable { /** * copy of collision margin (in physics-space units, >0, default=0) */ - protected float margin = 0.0f; + protected float margin = defaultMargin; public CollisionShape() { } @@ -135,6 +140,27 @@ public abstract class CollisionShape implements Savable { private native float getMargin(long objectId); + /** + * Alter the default margin for new shapes that are neither capsules nor + * spheres. + * + * @param margin the desired margin distance (in physics-space units, >0, + * default=0.04) + */ + public static void setDefaultMargin(float margin) { + defaultMargin = margin; + } + + /** + * Read the default margin for new shapes. + * + * @return margin the default margin distance (in physics-space units, + * >0) + */ + public static float getDefaultMargin() { + return defaultMargin; + } + /** * Alter the collision margin of this shape. CAUTION: Margin is applied * differently, depending on the type of shape. Generally the collision @@ -145,7 +171,7 @@ public abstract class CollisionShape implements Savable { * compound shapes) changes can have unintended consequences. * * @param margin the desired margin distance (in physics-space units, >0, - * default=0) + * default=0.04) */ public void setMargin(float margin) { setMargin(objectId, margin); diff --git a/jme3-jbullet/src/main/java/com/jme3/bullet/collision/shapes/CollisionShape.java b/jme3-jbullet/src/main/java/com/jme3/bullet/collision/shapes/CollisionShape.java index 2a4ad596d..b251e0ea6 100644 --- a/jme3-jbullet/src/main/java/com/jme3/bullet/collision/shapes/CollisionShape.java +++ b/jme3-jbullet/src/main/java/com/jme3/bullet/collision/shapes/CollisionShape.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2012 jMonkeyEngine + * Copyright (c) 2009-2019 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -44,9 +44,17 @@ import java.io.IOException; */ public abstract class CollisionShape implements Savable { + /** + * default margin for new shapes (in physics-space units, >0, + * default=0.04) + */ + private static float defaultMargin = 0.04f; protected com.bulletphysics.collision.shapes.CollisionShape cShape; protected Vector3f scale = new Vector3f(1, 1, 1); - protected float margin = 0.0f; + /** + * copy of collision margin (in physics-space units, >0, default=0) + */ + protected float margin = defaultMargin; public CollisionShape() { } @@ -88,6 +96,26 @@ public abstract class CollisionShape implements Savable { return cShape.getMargin(); } + /** + * Alter the default margin for new shapes. + * + * @param margin the desired margin distance (in physics-space units, >0, + * default=0.04) + */ + public static void setDefaultMargin(float margin) { + defaultMargin = margin; + } + + /** + * Read the default margin for new shapes. + * + * @return margin the default margin distance (in physics-space units, + * >0) + */ + public static float getDefaultMargin() { + return defaultMargin; + } + public void setMargin(float margin) { cShape.setMargin(margin); this.margin = margin;