/** * Sets the current angular velocity of the rigid-body. * @param {Vec3} velocity - The angular velocity to be set. */ set angularVelocity(velocity) { this.activate(); if (!this.isKinematic()) { if (this.body) { ammoVec1.setValue(velocity.x, velocity.y, velocity.z); this.body.setAngularVelocity(ammoVec1); } } else { this._angularVelocity.copy(velocity); } }
createBody() { var shape; if (this.entity && this.entity.collision) { shape = entity.collision.shape; if (entity.trigger) { entity.trigger.destroy(); entity.trigger = null; } } if (shape) { if (this.body) { this.system.removeBody(this.body); Ammo.destroy(this.body); } let isStaticOrKinematic = this.isStaticOrKinematic(); var mass = isStaticOrKinematic ? 0 : this.mass; var localInertia = new Ammo.btVector3(0, 0, 0); if (!isStaticOrKinematic) { shape.calculateLocalInertia(mass, localInertia); } var pos = entity.getPosition(); var rot = entity.getRotation(); ammoQuat.setValue(rot.x, rot.y, rot.z, rot.w); var startTransform = new Ammo.btTransform(); startTransform.setIdentity(); startTransform.getOrigin().setValue(pos.x, pos.y, pos.z); startTransform.setRotation(ammoQuat); var motionState = new Ammo.btDefaultMotionState(startTransform); var bodyInfo = new Ammo.btRigidBodyConstructionInfo(mass, motionState, shape, localInertia); var body = new Ammo.btRigidBody(bodyInfo); body.setRestitution(this.restitution); body.setFriction(this.friction); body.setDamping(this.linearDamping, this.angularDamping); var v = this.linearFactor; ammoVec1.setValue(v.x, v.y, v.z); body.setLinearFactor(ammoVec1); v = this.angularFactor; ammoVec1.setValue(v.x, v.y, v.z); body.setAngularFactor(ammoVec1); if (this.isKinematic()) { body.setCollisionFlags(body.getCollisionFlags() | RigidBody.BodyFlag.KINEMATIC_OBJECT); body.setActivationState(RigidBody.BodyState.DISABLE_DEACTIVATION); } this.body = body; if (this.enabled && this.entity.enabled) { this.enableSimulation(); } } }