AWPBvhTriangleMeshShape surface is not smooth

Software: Away3D 4.x

Whypay, Newbie
Posted: 22 November 2013 08:46 PM   Total Posts: 12

Hi there,

I am creating a ball game, where a ball follows a way. The way is a AWPBvhTriangleMeshShape. But unfortunately, the ball jumps up and changes its direction when it is rolling over edges - even if the surface is flat.

I have created a project to reproduce this behaviour. There is a PlaneGeometry and a SphereGeometry. When moving the ball, it starts to jump at the edges of the plane surface.


I have uploaded a movie of the project, where you can see the ball jumps up: http://de.tinypic.com/r/2ibymh5/5

Is this a bug or is there a solution to get rid of this problem? I really need the AWPBvhTriangleMeshShape, as the way is not a straight one.


Here is the code, woul’d be very happy is someone coul’d help me out.

package
{
 import flash
.display.Sprite;
 
import flash.events.Event;
 
import flash.events.KeyboardEvent;
 
import flash.geom.Vector3D;
 
import flash.text.TextField;
 
import flash.text.TextFormat;
 
import flash.ui.Keyboard;
 
 
import away3d.containers.View3D;
 
import away3d.debug.AwayStats;
 
import away3d.entities.Mesh;
 
import away3d.lights.PointLight;
 
import away3d.materials.ColorMaterial;
 
import away3d.materials.lightpickers.StaticLightPicker;
 
import away3d.primitives.PlaneGeometry;
 
import away3d.primitives.SphereGeometry;
 
 
import awayphysics.collision.shapes.AWPBvhTriangleMeshShape;
 
import awayphysics.collision.shapes.AWPSphereShape;
 
import awayphysics.debug.AWPDebugDraw;
 
import awayphysics.dynamics.AWPDynamicsWorld;
 
import awayphysics.dynamics.AWPRigidBody;
 
 
[SWF(backgroundColor="#000000"frameRate="60"width="600"height="400")]
 
public class BvhTriangleMesh extends Sprite
 {
  
private var _view View3D;
  private var 
_light PointLight;
  private var 
_lightPicker:StaticLightPicker;
  private var 
_physicsWorld AWPDynamicsWorld;
  private var 
_debugDraw:AWPDebugDraw;
  private var 
_timeStep Number 1.0 60;
  private var 
_bodySphere:AWPRigidBody;
  private var 
_text:TextField;
  private var 
_textFormat:TextFormat;
  
  public function 
BvhTriangleMesh()
  
{
   
if (stageinit();
   else 
addEventListener(Event.ADDED_TO_STAGEinit);
  
}
  
  
  
private function init():void{
   removeEventListener
(Event.ADDED_TO_STAGEinit);
   
   
   
_view = new View3D();
   
this.addChild(_view);
   
this.addChild(new AwayStats(_view));
   
   
_light = new PointLight();
   
_light.5000;
   
_view.scene.addChild(_light);
   
   
_lightPicker = new StaticLightPicker([_light]);

   
_view.camera.lens.far 20000;
   
_view.camera.2000;
   
_view.camera.= -2000;
   
_view.camera.rotationX 40;
   
   
   
// init the physics world
   
_physicsWorld AWPDynamicsWorld.getInstance();
   
_physicsWorld.initWithDbvtBroadphase();
   
   
_debugDraw = new AWPDebugDraw(_view_physicsWorld); 
   
_debugDraw.debugMode AWPDebugDraw.DBG_NoDebug;
   
_debugDraw.debugMode AWPDebugDraw.DBG_DrawCollisionShapes;
   
   
addObjects();
   
   
stage.addEventListener(Event.ENTER_FRAMEonEnterFrame);
   
stage.addEventListener(KeyboardEvent.KEY_DOWNonDownHandler);
  
}
  
  
  
private function addObjects():void{
   
   
var material ColorMaterial = new ColorMaterial(0xfa6c16);
   
material.lightPicker _lightPicker;
   
   var 
mesh Mesh;
   
   
//Create plane:
   
var iSeg:uint 3;
   
mesh = new Mesh(new PlaneGeometry(2000020000iSegiSeg), material);
   
_view.scene.addChild(mesh);
   var 
triangleShape AWPBvhTriangleMeshShape = new AWPBvhTriangleMeshShape(mesh.geometry);
   var 
planeBody:AWPRigidBody = new AWPRigidBody(triangleShapemesh0);
   
planeBody.position = new Vector3D(000);
   
planeBody.restitution 0.5;
   
   
_physicsWorld.addRigidBody(planeBody);
   
   
   
   
//Creat shpere:
   
var sphereShape:AWPSphereShape = new AWPSphereShape(100);
   
mesh = new Mesh(new SphereGeometry(100), material);
   
_view.scene.addChild(mesh);
   
_bodySphere = new AWPRigidBody(sphereShapemesh1);
   
_bodySphere.friction .9;
   
_bodySphere.restitution 0.9;
   
_bodySphere.position = new Vector3D(-10006000);
   
_physicsWorld.addRigidBody(_bodySphere);
   
   
_textFormat = new TextFormat('Arial'200xfffffftrue);
   
_text = new TextField();
   
_text.this.width/2;
   
_text.20;
   
_text.width 400;
   
this.addChild(_text);
   
   
  
}
  
  
  
private function onEnterFrame(Event):void{
   _physicsWorld
.step(_timeStep);
   
_debugDraw.debugDrawWorld();
   
_view.render();
   
   
_view.camera.position _bodySphere.position.add(new Vector3D(02000, -2500));
   
_view.camera.lookAt(_bodySphere.position);
   
   
   
_text.text "ball.y: " _bodySphere.position.y.toFixed(3);
   
_text.setTextFormat(_textFormat);
   
  
}
  
  
private function onDownHandler(event KeyboardEvent):void{
   
var fForce:Number 1;
   
   if(
event.keyCode==Keyboard.UP_bodySphere.applyCentralImpulse(new Vector3D(0,0,fForce));
   if(
event.keyCode==Keyboard.DOWN_bodySphere.applyCentralImpulse(new Vector3D(0,0,-fForce));
   if(
event.keyCode==Keyboard.LEFT_bodySphere.applyCentralImpulse(new Vector3D(-fForce,0,0));
   if(
event.keyCode==Keyboard.RIGHT_bodySphere.applyCentralImpulse(new Vector3D(fForce,0,0));
  
}
 }

 

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X