Skip to content

Instantly share code, notes, and snippets.

@BlueMagnificent
Created April 3, 2019 07:36
Show Gist options
  • Save BlueMagnificent/9f5ace06c360617e692b6a7ef102fb9d to your computer and use it in GitHub Desktop.
Save BlueMagnificent/9f5ace06c360617e692b6a7ef102fb9d to your computer and use it in GitHub Desktop.
Javascript 3D Create Mask Ball
function createMaskBall(){
let pos = {x: 1, y: 30, z: 0};
let radius = 2;
let quat = {x: 0, y: 0, z: 0, w: 1};
let mass = 1;
//threeJS Section
let ball = new THREE.Mesh(new THREE.SphereBufferGeometry(radius), new THREE.MeshPhongMaterial({color: 0x00ff08}));
ball.position.set(pos.x, pos.y, pos.z);
ball.castShadow = true;
ball.receiveShadow = true;
scene.add(ball);
//Ammojs Section
let transform = new Ammo.btTransform();
transform.setIdentity();
transform.setOrigin( new Ammo.btVector3( pos.x, pos.y, pos.z ) );
transform.setRotation( new Ammo.btQuaternion( quat.x, quat.y, quat.z, quat.w ) );
let motionState = new Ammo.btDefaultMotionState( transform );
let colShape = new Ammo.btSphereShape( radius );
colShape.setMargin( 0.05 );
let localInertia = new Ammo.btVector3( 0, 0, 0 );
colShape.calculateLocalInertia( mass, localInertia );
let rbInfo = new Ammo.btRigidBodyConstructionInfo( mass, motionState, colShape, localInertia );
let body = new Ammo.btRigidBody( rbInfo );
physicsWorld.addRigidBody( body, colGroupGreenBall, colGroupRedBall);
ball.userData.physicsBody = body;
rigidBodies.push(ball);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment