playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
200 lines (199 loc) • 7.02 kB
JavaScript
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
import { PhysicsBody } from "./physics-body.js";
import { PhysicsJoint } from "./physics-joint.js";
class PhysicsWorld {
/**
* Create a new PhysicsWorld instance.
*
* @param {object} [options] - The world options.
* @param {PhysicsContactListener} [options.contactListener] - The contact listener.
*/
constructor(options = {}) {
/**
* The listener driven during {@link PhysicsWorld#step}. Set once at construction.
*
* @type {PhysicsContactListener|null}
*/
__publicField(this, "contactListener", null);
/**
* The backend-native world object - btDiscreteDynamicsWorld when the Ammo backend is
* active, null otherwise.
*
* @type {object|null}
*/
__publicField(this, "nativeWorld", null);
this.contactListener = options.contactListener ?? null;
}
/**
* Destroys the world and all native resources it owns. The world is unusable afterwards.
*/
destroy() {
}
/**
* Applies gravity if it differs from the current world gravity. Safe (and expected) to be
* called every frame - backends deduplicate.
*
* @param {Vec3} gravity - The world space gravity.
*/
setGravity(gravity) {
}
/**
* Advances the simulation. Contact passes are driven from inside this call on backends
* that support substep granularity.
*
* @param {number} dt - The elapsed time in seconds.
* @param {number} maxSubSteps - The maximum number of fixed substeps to take.
* @param {number} fixedTimeStep - The duration of a fixed substep in seconds.
*/
step(dt, maxSubSteps, fixedTimeStep) {
}
/**
* Runs a deferred contact pass on backends that could not report contacts from inside
* {@link PhysicsWorld#step}. Called by the system after dynamic transform sync. No-op on
* backends that report during step.
*/
flushContacts() {
}
/**
* Creates a body outside the simulation. Add it with {@link PhysicsWorld#addBody}.
*
* @param {PhysicsBodyDesc} desc - The body descriptor.
* @returns {PhysicsBody} The new body.
*/
createBody(desc) {
const body = new PhysicsBody();
body.entity = desc.entity ?? null;
return body;
}
/**
* Destroys a body. It must not currently be in the simulation.
*
* @param {PhysicsBody} body - The body to destroy.
*/
destroyBody(body) {
}
/**
* Adds a body to the simulation and applies the backend's activation policy for the body's
* type (kinematic bodies never deactivate, all others enter the active state).
*
* @param {PhysicsBody} body - The body to add.
* @param {number} [group] - The collision group bits. Used together with mask.
* @param {number} [mask] - The collision mask bits.
*/
addBody(body, group, mask) {
}
/**
* Removes a body from the simulation. The body becomes inert until re-added.
*
* @param {PhysicsBody} body - The body to remove.
*/
removeBody(body) {
}
/**
* Creates a collision shape from a typed descriptor. The returned handle is opaque - it is
* owned by this world and must only be passed back to this world.
*
* @param {PhysicsShapeDesc} desc - The shape descriptor.
* @returns {object} The opaque shape handle.
*/
createShape(desc) {
return {};
}
/**
* Destroys a shape handle created by {@link PhysicsWorld#createShape}.
*
* @param {object} shape - The shape handle.
*/
destroyShape(shape) {
}
/**
* Adds a child shape to a 'compound' shape at a local pose.
*
* @param {object} compound - The compound shape handle.
* @param {object} child - The child shape handle.
* @param {Vec3} position - The child position in the compound's local space.
* @param {Quat} rotation - The child rotation in the compound's local space.
*/
addCompoundChild(compound, child, position, rotation) {
}
/**
* Updates the local pose of a child within a 'compound' shape. Adds the child if it is not
* present.
*
* @param {object} compound - The compound shape handle.
* @param {object} child - The child shape handle.
* @param {Vec3} position - The child position in the compound's local space.
* @param {Quat} rotation - The child rotation in the compound's local space.
*/
updateCompoundChild(compound, child, position, rotation) {
}
/**
* Removes a child from a 'compound' shape. No-op if the child is not present.
*
* @param {object} compound - The compound shape handle.
* @param {object} child - The child shape handle.
*/
removeCompoundChild(compound, child) {
}
/**
* Returns the number of children in a 'compound' shape.
*
* @param {object} compound - The compound shape handle.
* @returns {number} The child count.
*/
getCompoundChildCount(compound) {
return 0;
}
/**
* Creates a joint between two bodies (or one body and the world) and adds it to the
* simulation.
*
* @param {PhysicsJointDesc} desc - The joint descriptor.
* @returns {PhysicsJoint} The new joint.
*/
createJoint(desc) {
return new PhysicsJoint();
}
/**
* Removes a joint from the simulation and destroys it.
*
* @param {PhysicsJoint} joint - The joint to destroy.
*/
destroyJoint(joint) {
}
/**
* Raycast the world and return the first hit.
*
* @param {Vec3} start - The world space start point.
* @param {Vec3} end - The world space end point.
* @param {object} [options] - The raycast options.
* @param {number} [options.filterCollisionGroup] - Collision group to apply to the raycast.
* @param {number} [options.filterCollisionMask] - Collision mask to apply to the raycast.
* @returns {RaycastResult|null} The hit, or null if there was none.
*/
raycastFirst(start, end, options) {
return null;
}
/**
* Raycast the world and return all hits, in backend order.
*
* @param {Vec3} start - The world space start point.
* @param {Vec3} end - The world space end point.
* @param {object} [options] - The raycast options.
* @param {number} [options.filterCollisionGroup] - Collision group to apply to the raycast.
* @param {number} [options.filterCollisionMask] - Collision mask to apply to the raycast.
* @param {any[]} [options.filterTags] - Tags filters. Defined the same way as a
* {@link Tags#has} query but within an array. Hits filtered here are never allocated.
* @param {Function} [options.filterCallback] - Custom function to use to filter entities.
* Must return true to proceed with result. Takes the entity to evaluate as argument.
* @returns {RaycastResult[]} The hits (0 length if there were none).
*/
raycastAll(start, end, options) {
return [];
}
}
export {
PhysicsWorld
};