RESOLVED: AWPConvexHullShape seems to always to be 4 units from ground.

Software: Away3D 4.x

John Brookes, Moderator
Posted: 18 September 2011 03:26 PM   Total Posts: 732

Not sure if its a bug or feature wink


Using AWPConvexHullShape and noticed no matter what model I used it always has an extra height from the ground of 4 units.

See the red sphere
http://www.shrewballooba.co.uk/convex/


Im sure I read somewhere that bullet uses 4 units as a distance between objects and the ground.
But why does it only show with convex hull?

package
{
 import away3d
.containers.Scene3D;
 
import away3d.containers.View3D;
 
import away3d.debug.AwayStats;
 
import away3d.library.AssetLibrary;
 
import away3d.lights.DirectionalLight;
 
import away3d.events.LoaderEvent;
 
import away3d.materials.ColorMaterial;
 
import away3d.primitives.Plane;
 
import away3d.primitives.Sphere;
 
import awayphysics.collision.shapes.AWPCompoundShape;
 
import awayphysics.collision.shapes.AWPConvexHullShape;
 
import awayphysics.collision.shapes.AWPSphereShape;
 
import awayphysics.collision.shapes.AWPStaticPlaneShape;
 
import awayphysics.dynamics.AWPDynamicsWorld;
 
import awayphysics.dynamics.AWPRigidBody;
 
import flash.display.StageAlign;
 
import flash.display.StageScaleMode;
 
import flash.events.MouseEvent;
 
import flash.geom.Matrix3D;
 
import flash.geom.Vector3D;

 
import flash.display.Sprite;
 
import flash.events.Event;
 
 
import uk.co.shrewballooba.away4.camera.HoverDragController;

// [SWF(width="800", height="450", frameRate="60", backgroundColor="#000000")]
 
public class AWPConvexHullShapeTest extends Sprite
 {
  
private var timeStep Number 1.0 60;
  private var 
view View3D;
  private var 
camController:HoverDragController;
  private var 
physicsWorld:AWPDynamicsWorld;
  private var 
scene:Scene3D;
  private var 
light:DirectionalLight;
  
  
  public function 
AWPConvexHullShapeTest()
  
{
   
if (stageinit();
   else 
addEventListener(Event.ADDED_TO_STAGEinit);
  
}
  
  
private function init(e:Event null):void 
  {
   removeEventListener
(Event.ADDED_TO_STAGEinit); 
   
// entry point
   
stage.scaleMode StageScaleMode.NO_SCALE;
   
stage.align StageAlign.TOP_LEFT;
   
   
view = new View3D();
   
view.antiAlias 8;
   
view.backgroundColor 0xfcfcfc
   view
.camera.= -2000;
   
view.camera.lens.far 8000;
   
addChild(view);
   
   
scene view.scene;
   
   
   
camController = new HoverDragController(view.camerastage);
   
camController.radius 200;
   
   
physicsWorld AWPDynamicsWorld.getInstance();
   
physicsWorld.initWithDbvtBroadphase();
   
   
   
addChild(new AwayStats(view));
   
   
   
light = new DirectionalLight();
   
scene.addChild(light);
   
initObjects();
  
}
  
  
  
private function initObjects():void 
  {
   
var material:ColorMaterial = new ColorMaterial(0x252525);
   
material.bothSides true;
   
material.lights [light];
   
   var 
ground Plane = new Plane(material5000050000);
   
scene.addChild(ground);

   
   var 
groundShape AWPStaticPlaneShape = new AWPStaticPlaneShape(new Vector3D(00, -1));
   var 
groundRigidbody AWPRigidBody = new AWPRigidBody(groundShapeground0);
   
physicsWorld.addRigidBody(groundRigidbody);

   
// set ground rotation
   
var rot Matrix3D = new Matrix3D();
   
rot.appendRotation(90, new Vector3D(100));
   
groundRigidbody.rotation rot;
   
groundRigidbody.friction 0.03
   
   
   
//AWPConvexHullShape center sphere with issue
   
var redmat:ColorMaterial = new ColorMaterial(0xff4a2f);
   
redmat.lights [light];
   var 
s:Sphere = new Sphere(redmat25);
   
scene.addChild(s);
  
// s.geometry.scale(new Vector3D(1, 0.25, 1));
   
var sShape:AWPConvexHullShape = new AWPConvexHullShape(s);
   var 
sRb:AWPRigidBody = new AWPRigidBody(sShapes1);
   
physicsWorld.addRigidBody(sRb);
   
   
//Just checking sphere shape doesnt do same
   
var greenmat:ColorMaterial = new ColorMaterial(0x3dff2f);
   
greenmat.lights [light];
   var 
s2:Sphere = new Sphere(greenmat25);
   
scene.addChild(s2);
   var 
sShape2:AWPSphereShape = new AWPSphereShape(25);
   var 
sRb2:AWPRigidBody = new AWPRigidBody(sShape2s21);
   
sRb2.position = new Vector3D(80500);
   
physicsWorld.addRigidBody(sRb2);
   
   
//Using compound shape to fix AWPConvexHullShape issue
   
var bluemat:ColorMaterial = new ColorMaterial(0x3d4aff);
   
bluemat.lights [light];
   var 
s3:Sphere = new Sphere(bluemat25);
  
// s3.geometry.scale(new Vector3D(1, 0.25, 1));
   
scene.addChild(s3);
   var 
compoundShape:AWPCompoundShape = new AWPCompoundShape();
   var 
sShape3:AWPConvexHullShape = new AWPConvexHullShape(s3);
   
compoundShape.addChildShape(sShape3, new Vector3D(040), new Matrix3D());
   var 
sRb3:AWPRigidBody = new AWPRigidBody(compoundShapes31);
   
sRb3.position = new Vector3D(-80500);
   
physicsWorld.addRigidBody(sRb3);
   
   
   
this.addEventListener(Event.ENTER_FRAMEhandleEnterFrame);
  
}
  
  
private function handleEnterFrame(Event) : void
  {
   physicsWorld
.step(timeStep);
   
view.render();
  
}
 }

ps I used sphere is just for quick demo any model does the same thing.

   

Yang Li, Administrator
Posted: 19 September 2011 01:53 AM   Total Posts: 80   [ # 1 ]

Hi, look this post: http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=6575&p=22850&hilit=margin+collision+margin#p22850

the collision margin is different, convex hull shape is extend with margin, but other shapes is embed. So the ConvexHullShape is always 0.04 meters larger than other shapes.

   

John Brookes, Moderator
Posted: 19 September 2011 09:17 AM   Total Posts: 732   [ # 2 ]

Ahh thanks. Good to know.


“To compensate for this you can scale the graphics object, or shrink the btConvexHull.”

Note only thing that works (for me) is to up scale the geometry (vertices) of the object after adding the physics.

So to get an exact match to the original,
scale down the geometry of the model
add the physics
scale up the geometry

Then it looks the same and doesn’t have the extra gap.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X