UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

111 lines (110 loc) 3.08 kB
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 { ComponentSystem } from "../system.js"; import { JointComponent } from "./component.js"; const _properties = [ "type", "enableCollision", "breakImpulse", "enableLimits", "limits", "motorSpeed", "maxMotorForce", "swingLimitY", "swingLimitZ", "twistLimit", "linearMotionX", "linearMotionY", "linearMotionZ", "linearLimitsX", "linearLimitsY", "linearLimitsZ", "linearStiffness", "linearDamping", "linearEquilibrium", "angularMotionX", "angularMotionY", "angularMotionZ", "angularLimitsX", "angularLimitsY", "angularLimitsZ", "angularStiffness", "angularDamping", "angularEquilibrium", // entity references are assigned last so the constraint is created with full configuration "entityA", "entityB" ]; class JointComponentSystem extends ComponentSystem { /** * Create a new JointComponentSystem instance. * * @param {AppBase} app - The application. * @ignore */ constructor(app) { super(app); /** * Joints waiting for their rigid bodies to enter the simulation. * * @type {Set<JointComponent>} * @private */ __publicField(this, "_pending", /* @__PURE__ */ new Set()); /** * Joints with an active constraint and a finite break impulse. * * @type {Set<JointComponent>} * @private */ __publicField(this, "_breakable", /* @__PURE__ */ new Set()); this.id = "joint"; this.ComponentType = JointComponent; this.on("beforeremove", this.onBeforeRemove, this); this.app.systems.on("update", this.onUpdate, this); this.app.systems.on("postUpdate", this.onPostUpdate, this); } initializeComponentData(component, data, properties) { for (let i = 0; i < _properties.length; i++) { const property = _properties[i]; if (data[property] !== void 0) { component[property] = data[property]; } } component._initialized = true; super.initializeComponentData(component, data); } cloneComponent(entity, clone) { const c = entity.joint; const data = { enabled: c.enabled }; for (let i = 0; i < _properties.length; i++) { const property = _properties[i]; data[property] = c[property]; } return this.addComponent(clone, data); } onBeforeRemove(entity, component) { component.onBeforeRemove(); } onUpdate(dt) { for (const component of this._pending) { component._tryCreateConstraint(); } } onPostUpdate(dt) { for (const component of this._breakable) { component._checkBroken(); } } destroy() { super.destroy(); this.app.systems.off("update", this.onUpdate, this); this.app.systems.off("postUpdate", this.onPostUpdate, this); } } export { JointComponentSystem };