@babylonjs/core 5.48.0 → 5.48.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Bones/skeleton.js +1 -1
- package/Bones/skeleton.js.map +1 -1
- package/Debug/physicsViewer.js +4 -0
- package/Debug/physicsViewer.js.map +1 -1
- package/Engines/Native/nativeInterfaces.d.ts +0 -1
- package/Engines/Native/nativeInterfaces.js.map +1 -1
- package/Engines/engine.d.ts +3 -1
- package/Engines/engine.js +14 -5
- package/Engines/engine.js.map +1 -1
- package/Engines/engineStore.d.ts +6 -0
- package/Engines/engineStore.js +6 -0
- package/Engines/engineStore.js.map +1 -1
- package/Engines/nativeEngine.d.ts +3 -2
- package/Engines/nativeEngine.js +9 -5
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/thinEngine.d.ts +4 -3
- package/Engines/thinEngine.js +11 -13
- package/Engines/thinEngine.js.map +1 -1
- package/Helpers/environmentHelper.d.ts +1 -0
- package/Helpers/environmentHelper.js +6 -5
- package/Helpers/environmentHelper.js.map +1 -1
- package/Loading/Plugins/babylonFileLoader.js +1 -0
- package/Loading/Plugins/babylonFileLoader.js.map +1 -1
- package/Materials/Background/backgroundMaterial.js +1 -1
- package/Materials/Background/backgroundMaterial.js.map +1 -1
- package/Materials/Node/Blocks/Input/inputBlock.js +8 -8
- package/Materials/Node/Blocks/Input/inputBlock.js.map +1 -1
- package/Materials/Textures/thinTexture.d.ts +4 -2
- package/Materials/Textures/thinTexture.js +5 -2
- package/Materials/Textures/thinTexture.js.map +1 -1
- package/Materials/material.js +5 -0
- package/Materials/material.js.map +1 -1
- package/Materials/materialHelper.js +1 -1
- package/Materials/materialHelper.js.map +1 -1
- package/Materials/materialPluginBase.js +3 -0
- package/Materials/materialPluginBase.js.map +1 -1
- package/Materials/pushMaterial.d.ts +2 -1
- package/Materials/pushMaterial.js +4 -0
- package/Materials/pushMaterial.js.map +1 -1
- package/Maths/math.color.d.ts +20 -12
- package/Maths/math.color.js +85 -31
- package/Maths/math.color.js.map +1 -1
- package/Misc/decorators.js +2 -2
- package/Misc/decorators.js.map +1 -1
- package/Misc/fileTools.js +3 -0
- package/Misc/fileTools.js.map +1 -1
- package/Misc/khronosTextureContainer2.d.ts +3 -3
- package/Misc/khronosTextureContainer2.js +4 -3
- package/Misc/khronosTextureContainer2.js.map +1 -1
- package/Misc/observable.d.ts +18 -1
- package/Misc/observable.js +28 -2
- package/Misc/observable.js.map +1 -1
- package/Physics/v2/IPhysicsEnginePlugin.d.ts +3 -0
- package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
- package/Physics/v2/physicsAggregate.js +1 -1
- package/Physics/v2/physicsAggregate.js.map +1 -1
- package/Physics/v2/physicsBody.d.ts +12 -0
- package/Physics/v2/physicsBody.js +19 -0
- package/Physics/v2/physicsBody.js.map +1 -1
- package/Physics/v2/physicsShape.d.ts +24 -4
- package/Physics/v2/physicsShape.js +24 -13
- package/Physics/v2/physicsShape.js.map +1 -1
- package/package.json +1 -1
- package/scene.d.ts +1 -1
- package/scene.js +47 -46
- package/scene.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physicsBody.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsBody.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAM9D;;;;GAIG;AACH,MAAM,OAAO,WAAW;IA8BpB;;;;;;;;OAQG;IACH,YAAY,aAA4B,EAAE,KAAY;QAtCtD;;WAEG;QACI,gBAAW,GAAQ,SAAS,CAAC;QACpC;;WAEG;QACI,yBAAoB,GAAe,EAAE,CAAC;QAa7C;;;WAGG;QACH,mBAAc,GAAY,IAAI,CAAC;QAe3B,IAAI,CAAC,KAAK,EAAE;YACR,OAAO;SACV;QACD,MAAM,aAAa,GAAG,KAAK,CAAC,gBAAgB,EAAmB,CAAC;QAChE,IAAI,CAAC,aAAa,EAAE;YA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AAC;YACrF,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,WAAW,CAAC,oBAAoB,CAAC;SAC3C;IACL,CAAC;IAED;;OAEG;IACI,eAAe;QAClB,OAAO;QACP,OAAO,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAChC,CAAC;IAED;;;;;;OAMG;IACI,aAAa,CAAC,SAAsB,EAAE,UAA6B;QACtE,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;IACnE,CAAC;IAED;;;;OAIG;IACI,OAAO;QACV,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;IACzC,CAAC;;AAvWc,gCAAoB,GAAY,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACrD,gCAAoB,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC","sourcesContent":["import type { IPhysicsEnginePluginV2, MassProperties } from \"./IPhysicsEnginePlugin\";\r\nimport type { PhysicsShape } from \"./physicsShape\";\r\nimport { Vector3, Quaternion } from \"../../Maths/math.vector\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { PhysicsEngine } from \"./physicsEngine\";\r\nimport type { Mesh, TransformNode, AbstractMesh } from \"../../Meshes\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { PhysicsConstraint } from \"./physicsConstraint\";\r\n/**\r\n * PhysicsBody is useful for creating a physics body that can be used in a physics engine. It allows\r\n * the user to set the mass and velocity of the body, which can then be used to calculate the\r\n * motion of the body in the physics engine.\r\n */\r\nexport class PhysicsBody {\r\n /**\r\n * V2 Physics plugin private data for single Transform\r\n */\r\n public _pluginData: any = undefined;\r\n /**\r\n * V2 Physics plugin private data for instances\r\n */\r\n public _pluginDataInstances: Array<any> = [];\r\n /**\r\n * The V2 plugin used to create and manage this Physics Body\r\n */\r\n private _physicsPlugin: IPhysicsEnginePluginV2;\r\n /**\r\n * The engine used to create and manage this Physics Body\r\n */\r\n private _physicsEngine: PhysicsEngine;\r\n /**\r\n * The transform node associated with this Physics Body\r\n */\r\n transformNode: TransformNode;\r\n /**\r\n * Disable pre-step that consists in updating Physics Body from Transform Node Translation/Orientation.\r\n * True by default for maximum performance.\r\n */\r\n disablePreStep: boolean = true;\r\n\r\n private static _DEFAULT_OBJECT_SIZE: Vector3 = new Vector3(1, 1, 1);\r\n private static _IDENTITY_QUATERNION = Quaternion.Identity();\r\n\r\n /**\r\n * Constructs a new physics body for the given node.\r\n * @param transformNode - The Transform Node to construct the physics body for.\r\n * @param scene - The scene containing the physics engine.\r\n *\r\n * This code is useful for creating a physics body for a given Transform Node in a scene.\r\n * It checks the version of the physics engine and the physics plugin, and initializes the body accordingly.\r\n * It also sets the node's rotation quaternion if it is not already set. Finally, it adds the body to the physics engine.\r\n */\r\n constructor(transformNode: TransformNode, scene: Scene) {\r\n if (!scene) {\r\n return;\r\n }\r\n const physicsEngine = scene.getPhysicsEngine() as PhysicsEngine;\r\n if (!physicsEngine) {\r\n throw new Error(\"No Physics Engine available.\");\r\n }\r\n this._physicsEngine = physicsEngine;\r\n if (physicsEngine.getPluginVersion() != 2) {\r\n throw new Error(\"Plugin version is incorrect. Expected version 2.\");\r\n }\r\n const physicsPlugin = physicsEngine.getPhysicsPlugin();\r\n if (!physicsPlugin) {\r\n throw new Error(\"No Physics Plugin available.\");\r\n }\r\n\r\n this._physicsPlugin = physicsPlugin as IPhysicsEnginePluginV2;\r\n if (!transformNode.rotationQuaternion) {\r\n transformNode.rotationQuaternion = Quaternion.FromEulerAngles(transformNode.rotation.x, transformNode.rotation.y, transformNode.rotation.z);\r\n }\r\n // instances?\r\n const m = transformNode as Mesh;\r\n if (m.hasThinInstances) {\r\n this._physicsPlugin.initBodyInstances(this, m);\r\n } else {\r\n // single instance\r\n this._physicsPlugin.initBody(this, transformNode.position, transformNode.rotationQuaternion);\r\n }\r\n this.transformNode = transformNode;\r\n transformNode.physicsBody = this;\r\n physicsEngine.addBody(this);\r\n }\r\n\r\n /**\r\n * Sets the shape of the physics body.\r\n * @param shape - The shape of the physics body.\r\n *\r\n * This method is useful for setting the shape of the physics body, which is necessary for the physics engine to accurately simulate the body's behavior.\r\n * The shape is used to calculate the body's mass, inertia, and other properties.\r\n */\r\n public setShape(shape: PhysicsShape): void {\r\n this._physicsPlugin.setShape(this, shape);\r\n }\r\n\r\n /**\r\n * Retrieves the physics shape associated with this object.\r\n *\r\n * @returns The physics shape associated with this object, or `undefined` if no\r\n * shape is associated.\r\n *\r\n * This method is useful for retrieving the physics shape associated with this object,\r\n * which can be used to apply physical forces to the object or to detect collisions.\r\n */\r\n public getShape(): PhysicsShape | undefined {\r\n return this._physicsPlugin.getShape(this);\r\n }\r\n\r\n /**\r\n * Sets the filter group of the physics body.\r\n * @param group - The filter group of the physics body.\r\n *\r\n * This method is useful for setting the filter group of the physics body.\r\n * The filter group is used to determine which bodies should collide with each other.\r\n * This allows for more control over the physics engine and can be used to create more realistic simulations.\r\n */\r\n public setFilterGroup(group: number): void {\r\n this._physicsPlugin.setFilterGroup(this, group);\r\n }\r\n\r\n /**\r\n * Gets the filter group of the physics engine.\r\n *\r\n * @returns The filter group of the physics engine.\r\n *\r\n * This method is useful for getting the filter group of the physics engine,\r\n * which is used to determine which objects will interact with each other.\r\n * This is important for creating realistic physics simulations.\r\n */\r\n public getFilterGroup(): number {\r\n return this._physicsPlugin.getFilterGroup(this);\r\n }\r\n\r\n /**\r\n * Sets the event mask for the physics engine.\r\n *\r\n * @param eventMask - A bitmask that determines which events will be sent to the physics engine.\r\n *\r\n * This method is useful for setting the event mask for the physics engine, which determines which events\r\n * will be sent to the physics engine. This allows the user to control which events the physics engine will respond to.\r\n */\r\n public setEventMask(eventMask: number): void {\r\n this._physicsPlugin.setEventMask(this, eventMask);\r\n }\r\n\r\n /**\r\n * Gets the event mask of the physics engine.\r\n *\r\n * @returns The event mask of the physics engine.\r\n *\r\n * This method is useful for getting the event mask of the physics engine,\r\n * which is used to determine which events the engine will respond to.\r\n * This is important for ensuring that the engine is responding to the correct events and not\r\n * wasting resources on unnecessary events.\r\n */\r\n public getEventMask(): number {\r\n return this._physicsPlugin.getEventMask(this);\r\n }\r\n\r\n /**\r\n * Sets the mass properties of the physics object.\r\n *\r\n * @param massProps - The mass properties to set.\r\n *\r\n * This method is useful for setting the mass properties of a physics object, such as its mass,\r\n * inertia, and center of mass. This is important for accurately simulating the physics of the object in the physics engine.\r\n */\r\n public setMassProperties(massProps: MassProperties): void {\r\n this._physicsPlugin.setMassProperties(this, massProps);\r\n }\r\n\r\n /**\r\n * Retrieves the mass properties of the object.\r\n *\r\n * @returns The mass properties of the object, or `undefined` if the physics\r\n * plugin does not support mass properties.\r\n *\r\n * This method is useful for physics simulations, as it allows the user to\r\n * retrieve the mass properties of the object, such as its mass, center of mass,\r\n * and moment of inertia. This information is necessary for accurate physics\r\n * simulations.\r\n */\r\n public getMassProperties(): MassProperties | undefined {\r\n return this._physicsPlugin.getMassProperties(this);\r\n }\r\n\r\n /**\r\n * Sets the linear damping of the physics body.\r\n *\r\n * @param damping - The linear damping value.\r\n *\r\n * This method is useful for controlling the linear damping of the physics body,\r\n * which is the rate at which the body's velocity decreases over time. This is useful for simulating\r\n * the effects of air resistance or other forms of friction.\r\n */\r\n public setLinearDamping(damping: number): void {\r\n this._physicsPlugin.setLinearDamping(this, damping);\r\n }\r\n\r\n /**\r\n * Gets the linear damping of the physics body.\r\n * @returns The linear damping of the physics body.\r\n *\r\n * This method is useful for retrieving the linear damping of the physics body, which is the amount of\r\n * resistance the body has to linear motion. This is useful for simulating realistic physics behavior\r\n * in a game.\r\n */\r\n public getLinearDamping(): number {\r\n return this._physicsPlugin.getLinearDamping(this);\r\n }\r\n\r\n /**\r\n * Sets the angular damping of the physics body.\r\n * @param damping The angular damping of the body.\r\n *\r\n * This method is useful for controlling the angular velocity of a physics body.\r\n * By setting the damping, the body's angular velocity will be reduced over time, simulating the effect of friction.\r\n * This can be used to create realistic physical behavior in a physics engine.\r\n */\r\n public setAngularDamping(damping: number): void {\r\n this._physicsPlugin.setAngularDamping(this, damping);\r\n }\r\n\r\n /**\r\n * Gets the angular damping of the physics body.\r\n *\r\n * @returns The angular damping of the physics body.\r\n *\r\n * This method is useful for getting the angular damping of the physics body,\r\n * which is the rate of reduction of the angular velocity over time.\r\n * This is important for simulating realistic physics behavior in a game.\r\n */\r\n public getAngularDamping(): number {\r\n return this._physicsPlugin.getAngularDamping(this);\r\n }\r\n\r\n /**\r\n * Sets the linear velocity of the physics object.\r\n * @param linVel - The linear velocity to set.\r\n *\r\n * This method is useful for setting the linear velocity of a physics object,\r\n * which is necessary for simulating realistic physics in a game engine.\r\n * By setting the linear velocity, the physics object will move in the direction and speed specified by the vector.\r\n * This allows for realistic physics simulations, such as simulating the motion of a ball rolling down a hill.\r\n */\r\n public setLinearVelocity(linVel: Vector3): void {\r\n this._physicsPlugin.setLinearVelocity(this, linVel);\r\n }\r\n\r\n /**\r\n * Gets the linear velocity of the physics body and stores it in the given vector3.\r\n * @param linVel - The vector3 to store the linear velocity in.\r\n *\r\n * This method is useful for getting the linear velocity of a physics body in a physics engine.\r\n * This can be used to determine the speed and direction of the body, which can be used to calculate the motion of the body.*/\r\n public getLinearVelocityToRef(linVel: Vector3): void {\r\n return this._physicsPlugin.getLinearVelocityToRef(this, linVel);\r\n }\r\n\r\n /**\r\n * Sets the angular velocity of the physics object.\r\n * @param angVel - The angular velocity to set.\r\n *\r\n * This method is useful for setting the angular velocity of a physics object, which is necessary for\r\n * simulating realistic physics behavior. The angular velocity is used to determine the rate of rotation of the object,\r\n * which is important for simulating realistic motion.\r\n */\r\n public setAngularVelocity(angVel: Vector3): void {\r\n this._physicsPlugin.setAngularVelocity(this, angVel);\r\n }\r\n\r\n /**\r\n * Gets the angular velocity of the physics body and stores it in the given vector3.\r\n * @param angVel - The vector3 to store the angular velocity in.\r\n *\r\n * This method is useful for getting the angular velocity of a physics body, which can be used to determine the body's\r\n * rotational speed. This information can be used to create realistic physics simulations.\r\n */\r\n public getAngularVelocityToRef(angVel: Vector3): void {\r\n return this._physicsPlugin.getAngularVelocityToRef(this, angVel);\r\n }\r\n\r\n /**\r\n * Applies an impulse to the physics object.\r\n *\r\n * @param impulse The impulse vector.\r\n * @param location The location of the impulse.\r\n *\r\n * This method is useful for applying an impulse to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyImpulse(impulse: Vector3, location: Vector3): void {\r\n this._physicsPlugin.applyImpulse(this, impulse, location);\r\n }\r\n\r\n /**\r\n * Applies a force to the physics object.\r\n *\r\n * @param force The force vector.\r\n * @param location The location of the force.\r\n *\r\n * This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyForce(force: Vector3, location: Vector3): void {\r\n this._physicsPlugin.applyForce(this, force, location);\r\n }\r\n\r\n /**\r\n * Retrieves the geometry of the body from the physics plugin.\r\n *\r\n * @returns The geometry of the body.\r\n *\r\n * This method is useful for retrieving the geometry of the body from the physics plugin, which can be used for various physics calculations.\r\n */\r\n public getGeometry(): {} {\r\n return this._physicsPlugin.getBodyGeometry(this);\r\n }\r\n\r\n /**\r\n * Register a collision callback that is called when the body collides\r\n * Filtering by body is inefficient. It's more preferable to register a collision callback for the entire world\r\n * and do the filtering on the user side.\r\n */\r\n public registerOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void {\r\n return this._physicsPlugin.registerOnBodyCollide(this, func);\r\n }\r\n\r\n /**\r\n * Unregister a collision callback that is called when the body collides\r\n */\r\n public unregisterOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void {\r\n return this._physicsPlugin.unregisterOnBodyCollide(this, func);\r\n }\r\n\r\n /**\r\n * Gets the object extents\r\n * @returns the object extents\r\n */\r\n public getObjectExtents(): Vector3 {\r\n const tmAbstractMesh = this.transformNode as AbstractMesh;\r\n if (tmAbstractMesh.getBoundingInfo) {\r\n const q = this.transformNode.rotationQuaternion;\r\n const scaling = this.transformNode.scaling.clone();\r\n //reset rotation\r\n this.transformNode.rotationQuaternion = PhysicsBody._IDENTITY_QUATERNION;\r\n //calculate the world matrix with no rotation\r\n const worldMatrix = this.transformNode.computeWorldMatrix && this.transformNode.computeWorldMatrix(true);\r\n if (worldMatrix) {\r\n worldMatrix.decompose(scaling, undefined, undefined);\r\n }\r\n const boundingInfo = tmAbstractMesh.getBoundingInfo();\r\n // get the global scaling of the object\r\n const size = boundingInfo.boundingBox.extendSize.scale(2).multiplyInPlace(scaling);\r\n size.x = Math.abs(size.x);\r\n size.y = Math.abs(size.y);\r\n size.z = Math.abs(size.z);\r\n //bring back the rotation\r\n this.transformNode.rotationQuaternion = q;\r\n //calculate the world matrix with the new rotation\r\n this.transformNode.computeWorldMatrix && this.transformNode.computeWorldMatrix(true);\r\n return size;\r\n } else {\r\n return PhysicsBody._DEFAULT_OBJECT_SIZE;\r\n }\r\n }\r\n\r\n /**\r\n * @returns geometric center of the associated mesh\r\n */\r\n public getObjectCenter(): Vector3 {\r\n // TODO\r\n return new Vector3(0, 0, 0);\r\n }\r\n\r\n /**\r\n * Adds a constraint to the physics engine.\r\n *\r\n * @param childBody - The body to which the constraint will be applied.\r\n * @param constraint - The constraint to be applied.\r\n *\r\n */\r\n public addConstraint(childBody: PhysicsBody, constraint: PhysicsConstraint): void {\r\n this._physicsPlugin.addConstraint(this, childBody, constraint);\r\n }\r\n\r\n /**\r\n * Disposes the body from the physics engine.\r\n *\r\n * This method is useful for cleaning up the physics engine when a body is no longer needed. Disposing the body will free up resources and prevent memory leaks.\r\n */\r\n public dispose() {\r\n this._physicsEngine.removeBody(this);\r\n this._physicsPlugin.removeBody(this);\r\n this._physicsPlugin.disposeBody(this);\r\n this._pluginData = null;\r\n this._pluginDataInstances.length = 0;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"physicsBody.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsBody.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAM9D;;;;GAIG;AACH,MAAM,OAAO,WAAW;IA8BpB;;;;;;;;OAQG;IACH,YAAY,aAA4B,EAAE,KAAY;QAtCtD;;WAEG;QACI,gBAAW,GAAQ,SAAS,CAAC;QACpC;;WAEG;QACI,yBAAoB,GAAe,EAAE,CAAC;QAa7C;;;WAGG;QACH,mBAAc,GAAY,IAAI,CAAC;QAe3B,IAAI,CAAC,KAAK,EAAE;YACR,OAAO;SACV;QACD,MAAM,aAAa,GAAG,KAAK,CAAC,gBAAgB,EAAmB,CAAC;QAChE,IAAI,CAAC,aAAa,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACnD;QACD,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,aAAa,CAAC,gBAAgB,EAAE,IAAI,CAAC,EAAE;YACvC,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;SACvE;QACD,MAAM,aAAa,GAAG,aAAa,CAAC,gBAAgB,EAAE,CAAC;QACvD,IAAI,CAAC,aAAa,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACnD;QAED,IAAI,CAAC,cAAc,GAAG,aAAuC,CAAC;QAC9D,IAAI,CAAC,aAAa,CAAC,kBAAkB,EAAE;YACnC,aAAa,CAAC,kBAAkB,GAAG,UAAU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P,OAAO,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAChC,CAAC;IAED;;;;;;OAMG;IACI,aAAa,CAAC,SAAsB,EAAE,UAA6B;QACtE,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;IACnE,CAAC;IAED;;;;OAIG;IACI,OAAO;QACV,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;IACzC,CAAC;;AA5Xc,gCAAoB,GAAY,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACrD,gCAAoB,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC","sourcesContent":["import type { IPhysicsEnginePluginV2, MassProperties } from \"./IPhysicsEnginePlugin\";\r\nimport type { PhysicsShape } from \"./physicsShape\";\r\nimport { Vector3, Quaternion } from \"../../Maths/math.vector\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { PhysicsEngine } from \"./physicsEngine\";\r\nimport type { Mesh, TransformNode, AbstractMesh } from \"../../Meshes\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { PhysicsConstraint } from \"./physicsConstraint\";\r\n/**\r\n * PhysicsBody is useful for creating a physics body that can be used in a physics engine. It allows\r\n * the user to set the mass and velocity of the body, which can then be used to calculate the\r\n * motion of the body in the physics engine.\r\n */\r\nexport class PhysicsBody {\r\n /**\r\n * V2 Physics plugin private data for single Transform\r\n */\r\n public _pluginData: any = undefined;\r\n /**\r\n * V2 Physics plugin private data for instances\r\n */\r\n public _pluginDataInstances: Array<any> = [];\r\n /**\r\n * The V2 plugin used to create and manage this Physics Body\r\n */\r\n private _physicsPlugin: IPhysicsEnginePluginV2;\r\n /**\r\n * The engine used to create and manage this Physics Body\r\n */\r\n private _physicsEngine: PhysicsEngine;\r\n /**\r\n * The transform node associated with this Physics Body\r\n */\r\n transformNode: TransformNode;\r\n /**\r\n * Disable pre-step that consists in updating Physics Body from Transform Node Translation/Orientation.\r\n * True by default for maximum performance.\r\n */\r\n disablePreStep: boolean = true;\r\n\r\n private static _DEFAULT_OBJECT_SIZE: Vector3 = new Vector3(1, 1, 1);\r\n private static _IDENTITY_QUATERNION = Quaternion.Identity();\r\n\r\n /**\r\n * Constructs a new physics body for the given node.\r\n * @param transformNode - The Transform Node to construct the physics body for.\r\n * @param scene - The scene containing the physics engine.\r\n *\r\n * This code is useful for creating a physics body for a given Transform Node in a scene.\r\n * It checks the version of the physics engine and the physics plugin, and initializes the body accordingly.\r\n * It also sets the node's rotation quaternion if it is not already set. Finally, it adds the body to the physics engine.\r\n */\r\n constructor(transformNode: TransformNode, scene: Scene) {\r\n if (!scene) {\r\n return;\r\n }\r\n const physicsEngine = scene.getPhysicsEngine() as PhysicsEngine;\r\n if (!physicsEngine) {\r\n throw new Error(\"No Physics Engine available.\");\r\n }\r\n this._physicsEngine = physicsEngine;\r\n if (physicsEngine.getPluginVersion() != 2) {\r\n throw new Error(\"Plugin version is incorrect. Expected version 2.\");\r\n }\r\n const physicsPlugin = physicsEngine.getPhysicsPlugin();\r\n if (!physicsPlugin) {\r\n throw new Error(\"No Physics Plugin available.\");\r\n }\r\n\r\n this._physicsPlugin = physicsPlugin as IPhysicsEnginePluginV2;\r\n if (!transformNode.rotationQuaternion) {\r\n transformNode.rotationQuaternion = Quaternion.FromEulerAngles(transformNode.rotation.x, transformNode.rotation.y, transformNode.rotation.z);\r\n }\r\n // instances?\r\n const m = transformNode as Mesh;\r\n if (m.hasThinInstances) {\r\n this._physicsPlugin.initBodyInstances(this, m);\r\n } else {\r\n // single instance\r\n this._physicsPlugin.initBody(this, transformNode.position, transformNode.rotationQuaternion);\r\n }\r\n this.transformNode = transformNode;\r\n transformNode.physicsBody = this;\r\n physicsEngine.addBody(this);\r\n }\r\n\r\n /**\r\n * If a physics body is connected to an instanced node, update the number physic instances to match the number of node instances.\r\n */\r\n public updateBodyInstances() {\r\n const m = this.transformNode as Mesh;\r\n if (m.hasThinInstances) {\r\n this._physicsPlugin.updateBodyInstances(this, m);\r\n }\r\n }\r\n\r\n /**\r\n * Sets the shape of the physics body.\r\n * @param shape - The shape of the physics body.\r\n *\r\n * This method is useful for setting the shape of the physics body, which is necessary for the physics engine to accurately simulate the body's behavior.\r\n * The shape is used to calculate the body's mass, inertia, and other properties.\r\n */\r\n public setShape(shape: PhysicsShape): void {\r\n this._physicsPlugin.setShape(this, shape);\r\n }\r\n\r\n /**\r\n * Retrieves the physics shape associated with this object.\r\n *\r\n * @returns The physics shape associated with this object, or `undefined` if no\r\n * shape is associated.\r\n *\r\n * This method is useful for retrieving the physics shape associated with this object,\r\n * which can be used to apply physical forces to the object or to detect collisions.\r\n */\r\n public getShape(): PhysicsShape | undefined {\r\n return this._physicsPlugin.getShape(this);\r\n }\r\n\r\n /**\r\n * Sets the filter group of the physics body.\r\n * @param group - The filter group of the physics body.\r\n *\r\n * This method is useful for setting the filter group of the physics body.\r\n * The filter group is used to determine which bodies should collide with each other.\r\n * This allows for more control over the physics engine and can be used to create more realistic simulations.\r\n */\r\n public setFilterGroup(group: number): void {\r\n this._physicsPlugin.setFilterGroup(this, group);\r\n }\r\n\r\n /**\r\n * Gets the filter group of the physics engine.\r\n *\r\n * @returns The filter group of the physics engine.\r\n *\r\n * This method is useful for getting the filter group of the physics engine,\r\n * which is used to determine which objects will interact with each other.\r\n * This is important for creating realistic physics simulations.\r\n */\r\n public getFilterGroup(): number {\r\n return this._physicsPlugin.getFilterGroup(this);\r\n }\r\n\r\n /**\r\n * Sets the event mask for the physics engine.\r\n *\r\n * @param eventMask - A bitmask that determines which events will be sent to the physics engine.\r\n *\r\n * This method is useful for setting the event mask for the physics engine, which determines which events\r\n * will be sent to the physics engine. This allows the user to control which events the physics engine will respond to.\r\n */\r\n public setEventMask(eventMask: number): void {\r\n this._physicsPlugin.setEventMask(this, eventMask);\r\n }\r\n\r\n /**\r\n * Gets the event mask of the physics engine.\r\n *\r\n * @returns The event mask of the physics engine.\r\n *\r\n * This method is useful for getting the event mask of the physics engine,\r\n * which is used to determine which events the engine will respond to.\r\n * This is important for ensuring that the engine is responding to the correct events and not\r\n * wasting resources on unnecessary events.\r\n */\r\n public getEventMask(): number {\r\n return this._physicsPlugin.getEventMask(this);\r\n }\r\n\r\n /**\r\n * Sets the mass properties of the physics object.\r\n *\r\n * @param massProps - The mass properties to set.\r\n *\r\n * This method is useful for setting the mass properties of a physics object, such as its mass,\r\n * inertia, and center of mass. This is important for accurately simulating the physics of the object in the physics engine.\r\n */\r\n public setMassProperties(massProps: MassProperties): void {\r\n this._physicsPlugin.setMassProperties(this, massProps);\r\n }\r\n\r\n /**\r\n * Retrieves the mass properties of the object.\r\n *\r\n * @returns The mass properties of the object, or `undefined` if the physics\r\n * plugin does not support mass properties.\r\n *\r\n * This method is useful for physics simulations, as it allows the user to\r\n * retrieve the mass properties of the object, such as its mass, center of mass,\r\n * and moment of inertia. This information is necessary for accurate physics\r\n * simulations.\r\n */\r\n public getMassProperties(): MassProperties | undefined {\r\n return this._physicsPlugin.getMassProperties(this);\r\n }\r\n\r\n /**\r\n * Sets the linear damping of the physics body.\r\n *\r\n * @param damping - The linear damping value.\r\n *\r\n * This method is useful for controlling the linear damping of the physics body,\r\n * which is the rate at which the body's velocity decreases over time. This is useful for simulating\r\n * the effects of air resistance or other forms of friction.\r\n */\r\n public setLinearDamping(damping: number): void {\r\n this._physicsPlugin.setLinearDamping(this, damping);\r\n }\r\n\r\n /**\r\n * Gets the linear damping of the physics body.\r\n * @returns The linear damping of the physics body.\r\n *\r\n * This method is useful for retrieving the linear damping of the physics body, which is the amount of\r\n * resistance the body has to linear motion. This is useful for simulating realistic physics behavior\r\n * in a game.\r\n */\r\n public getLinearDamping(): number {\r\n return this._physicsPlugin.getLinearDamping(this);\r\n }\r\n\r\n /**\r\n * Sets the angular damping of the physics body.\r\n * @param damping The angular damping of the body.\r\n *\r\n * This method is useful for controlling the angular velocity of a physics body.\r\n * By setting the damping, the body's angular velocity will be reduced over time, simulating the effect of friction.\r\n * This can be used to create realistic physical behavior in a physics engine.\r\n */\r\n public setAngularDamping(damping: number): void {\r\n this._physicsPlugin.setAngularDamping(this, damping);\r\n }\r\n\r\n /**\r\n * Gets the angular damping of the physics body.\r\n *\r\n * @returns The angular damping of the physics body.\r\n *\r\n * This method is useful for getting the angular damping of the physics body,\r\n * which is the rate of reduction of the angular velocity over time.\r\n * This is important for simulating realistic physics behavior in a game.\r\n */\r\n public getAngularDamping(): number {\r\n return this._physicsPlugin.getAngularDamping(this);\r\n }\r\n\r\n /**\r\n * Sets the linear velocity of the physics object.\r\n * @param linVel - The linear velocity to set.\r\n *\r\n * This method is useful for setting the linear velocity of a physics object,\r\n * which is necessary for simulating realistic physics in a game engine.\r\n * By setting the linear velocity, the physics object will move in the direction and speed specified by the vector.\r\n * This allows for realistic physics simulations, such as simulating the motion of a ball rolling down a hill.\r\n */\r\n public setLinearVelocity(linVel: Vector3): void {\r\n this._physicsPlugin.setLinearVelocity(this, linVel);\r\n }\r\n\r\n /**\r\n * Gets the linear velocity of the physics body and stores it in the given vector3.\r\n * @param linVel - The vector3 to store the linear velocity in.\r\n *\r\n * This method is useful for getting the linear velocity of a physics body in a physics engine.\r\n * This can be used to determine the speed and direction of the body, which can be used to calculate the motion of the body.*/\r\n public getLinearVelocityToRef(linVel: Vector3): void {\r\n return this._physicsPlugin.getLinearVelocityToRef(this, linVel);\r\n }\r\n\r\n /**\r\n * Sets the angular velocity of the physics object.\r\n * @param angVel - The angular velocity to set.\r\n *\r\n * This method is useful for setting the angular velocity of a physics object, which is necessary for\r\n * simulating realistic physics behavior. The angular velocity is used to determine the rate of rotation of the object,\r\n * which is important for simulating realistic motion.\r\n */\r\n public setAngularVelocity(angVel: Vector3): void {\r\n this._physicsPlugin.setAngularVelocity(this, angVel);\r\n }\r\n\r\n /**\r\n * Gets the angular velocity of the physics body and stores it in the given vector3.\r\n * @param angVel - The vector3 to store the angular velocity in.\r\n *\r\n * This method is useful for getting the angular velocity of a physics body, which can be used to determine the body's\r\n * rotational speed. This information can be used to create realistic physics simulations.\r\n */\r\n public getAngularVelocityToRef(angVel: Vector3): void {\r\n return this._physicsPlugin.getAngularVelocityToRef(this, angVel);\r\n }\r\n\r\n /**\r\n * Applies an impulse to the physics object.\r\n *\r\n * @param impulse The impulse vector.\r\n * @param location The location of the impulse.\r\n *\r\n * This method is useful for applying an impulse to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyImpulse(impulse: Vector3, location: Vector3): void {\r\n this._physicsPlugin.applyImpulse(this, impulse, location);\r\n }\r\n\r\n /**\r\n * Applies a force to the physics object.\r\n *\r\n * @param force The force vector.\r\n * @param location The location of the force.\r\n *\r\n * This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyForce(force: Vector3, location: Vector3): void {\r\n this._physicsPlugin.applyForce(this, force, location);\r\n }\r\n\r\n /**\r\n * Retrieves the geometry of the body from the physics plugin.\r\n *\r\n * @returns The geometry of the body.\r\n *\r\n * This method is useful for retrieving the geometry of the body from the physics plugin, which can be used for various physics calculations.\r\n */\r\n public getGeometry(): {} {\r\n return this._physicsPlugin.getBodyGeometry(this);\r\n }\r\n\r\n /**\r\n * Register a collision callback that is called when the body collides\r\n * Filtering by body is inefficient. It's more preferable to register a collision callback for the entire world\r\n * and do the filtering on the user side.\r\n */\r\n public registerOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void {\r\n return this._physicsPlugin.registerOnBodyCollide(this, func);\r\n }\r\n\r\n /**\r\n * Unregister a collision callback that is called when the body collides\r\n */\r\n public unregisterOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void {\r\n return this._physicsPlugin.unregisterOnBodyCollide(this, func);\r\n }\r\n\r\n /**\r\n * Enable or disable collision callback for this PhysicsBody.\r\n * `registerOnCollide` method will enable collision callback and `unregisterOnCollide` will disable them.\r\n * Registering a collision callback on the plugin and enabling collision per body is faster than\r\n * registering callback per PhysicsBody.\r\n * @param enabled true if PhysicsBody's collision will rise a collision event and call the callback\r\n */\r\n public setCollisionCallbackEnabled(enabled: boolean): void {\r\n return this._physicsPlugin.setCollisionCallbackEnabled(this, enabled);\r\n }\r\n\r\n /**\r\n * Gets the object extents\r\n * @returns the object extents\r\n */\r\n public getObjectExtents(): Vector3 {\r\n const tmAbstractMesh = this.transformNode as AbstractMesh;\r\n if (tmAbstractMesh.getBoundingInfo) {\r\n const q = this.transformNode.rotationQuaternion;\r\n const scaling = this.transformNode.scaling.clone();\r\n //reset rotation\r\n this.transformNode.rotationQuaternion = PhysicsBody._IDENTITY_QUATERNION;\r\n //calculate the world matrix with no rotation\r\n const worldMatrix = this.transformNode.computeWorldMatrix && this.transformNode.computeWorldMatrix(true);\r\n if (worldMatrix) {\r\n worldMatrix.decompose(scaling, undefined, undefined);\r\n }\r\n const boundingInfo = tmAbstractMesh.getBoundingInfo();\r\n // get the global scaling of the object\r\n const size = boundingInfo.boundingBox.extendSize.scale(2).multiplyInPlace(scaling);\r\n size.x = Math.abs(size.x);\r\n size.y = Math.abs(size.y);\r\n size.z = Math.abs(size.z);\r\n //bring back the rotation\r\n this.transformNode.rotationQuaternion = q;\r\n //calculate the world matrix with the new rotation\r\n this.transformNode.computeWorldMatrix && this.transformNode.computeWorldMatrix(true);\r\n return size;\r\n } else {\r\n return PhysicsBody._DEFAULT_OBJECT_SIZE;\r\n }\r\n }\r\n\r\n /**\r\n * @returns geometric center of the associated mesh\r\n */\r\n public getObjectCenter(): Vector3 {\r\n // TODO\r\n return new Vector3(0, 0, 0);\r\n }\r\n\r\n /**\r\n * Adds a constraint to the physics engine.\r\n *\r\n * @param childBody - The body to which the constraint will be applied.\r\n * @param constraint - The constraint to be applied.\r\n *\r\n */\r\n public addConstraint(childBody: PhysicsBody, constraint: PhysicsConstraint): void {\r\n this._physicsPlugin.addConstraint(this, childBody, constraint);\r\n }\r\n\r\n /**\r\n * Disposes the body from the physics engine.\r\n *\r\n * This method is useful for cleaning up the physics engine when a body is no longer needed. Disposing the body will free up resources and prevent memory leaks.\r\n */\r\n public dispose() {\r\n this._physicsEngine.removeBody(this);\r\n this._physicsPlugin.removeBody(this);\r\n this._physicsPlugin.disposeBody(this);\r\n this._pluginData = null;\r\n this._pluginDataInstances.length = 0;\r\n }\r\n}\r\n"]}
|
|
@@ -7,6 +7,23 @@ import type { Vector3 } from "../../Maths/math.vector";
|
|
|
7
7
|
import type { Quaternion } from "../../Maths/math.vector";
|
|
8
8
|
import type { Mesh } from "../../Meshes/mesh";
|
|
9
9
|
import type { Scene } from "../../scene";
|
|
10
|
+
/**
|
|
11
|
+
* Options for creating a physics shape
|
|
12
|
+
*/
|
|
13
|
+
export interface PhysicShapeOptions {
|
|
14
|
+
/**
|
|
15
|
+
* The type of the shape. This can be one of the following: SPHERE, BOX, CAPSULE, CYLINDER, CONVEX_HULL, MESH, HEIGHTFIELD, CONTAINER
|
|
16
|
+
*/
|
|
17
|
+
type?: ShapeType;
|
|
18
|
+
/**
|
|
19
|
+
* The parameters of the shape. Varies depending of the shape type.
|
|
20
|
+
*/
|
|
21
|
+
parameters?: PhysicsShapeParameters;
|
|
22
|
+
/**
|
|
23
|
+
* Reference to an already existing physics shape in the plugin.
|
|
24
|
+
*/
|
|
25
|
+
pluginData?: any;
|
|
26
|
+
}
|
|
10
27
|
/**
|
|
11
28
|
* PhysicsShape class.
|
|
12
29
|
* This class is useful for creating a physics shape that can be used in a physics engine.
|
|
@@ -24,15 +41,18 @@ export declare class PhysicsShape {
|
|
|
24
41
|
private _type;
|
|
25
42
|
/**
|
|
26
43
|
* Constructs a new physics shape.
|
|
27
|
-
* @param
|
|
28
|
-
*
|
|
44
|
+
* @param options The options for the physics shape. These are:
|
|
45
|
+
* * type: The type of the shape. This can be one of the following: SPHERE, BOX, CAPSULE, CYLINDER, CONVEX_HULL, MESH, HEIGHTFIELD, CONTAINER
|
|
46
|
+
* * parameters: The parameters of the shape.
|
|
47
|
+
* * pluginData: The plugin data of the shape. This is used if you already have a reference to the object on the plugin side.
|
|
48
|
+
* You need to specify either type or pluginData.
|
|
29
49
|
* @param scene The scene the shape belongs to.
|
|
30
50
|
*
|
|
31
51
|
* This code is useful for creating a new physics shape with the given type, options, and scene.
|
|
32
52
|
* It also checks that the physics engine and plugin version are correct.
|
|
33
53
|
* If not, it throws an error. This ensures that the shape is created with the correct parameters and is compatible with the physics engine.
|
|
34
54
|
*/
|
|
35
|
-
constructor(
|
|
55
|
+
constructor(options: PhysicShapeOptions, scene: Scene);
|
|
36
56
|
/**
|
|
37
57
|
*
|
|
38
58
|
*/
|
|
@@ -104,7 +124,7 @@ export declare class PhysicsShapeSphere extends PhysicsShape {
|
|
|
104
124
|
*/
|
|
105
125
|
constructor(center: Vector3, radius: number, scene: Scene);
|
|
106
126
|
}
|
|
107
|
-
|
|
127
|
+
/**
|
|
108
128
|
* Helper object to create a capsule shape
|
|
109
129
|
*/
|
|
110
130
|
export declare class PhysicsShapeCapsule extends PhysicsShape {
|
|
@@ -7,20 +7,23 @@ import { ShapeType } from "./IPhysicsEnginePlugin.js";
|
|
|
7
7
|
export class PhysicsShape {
|
|
8
8
|
/**
|
|
9
9
|
* Constructs a new physics shape.
|
|
10
|
-
* @param
|
|
11
|
-
*
|
|
10
|
+
* @param options The options for the physics shape. These are:
|
|
11
|
+
* * type: The type of the shape. This can be one of the following: SPHERE, BOX, CAPSULE, CYLINDER, CONVEX_HULL, MESH, HEIGHTFIELD, CONTAINER
|
|
12
|
+
* * parameters: The parameters of the shape.
|
|
13
|
+
* * pluginData: The plugin data of the shape. This is used if you already have a reference to the object on the plugin side.
|
|
14
|
+
* You need to specify either type or pluginData.
|
|
12
15
|
* @param scene The scene the shape belongs to.
|
|
13
16
|
*
|
|
14
17
|
* This code is useful for creating a new physics shape with the given type, options, and scene.
|
|
15
18
|
* It also checks that the physics engine and plugin version are correct.
|
|
16
19
|
* If not, it throws an error. This ensures that the shape is created with the correct parameters and is compatible with the physics engine.
|
|
17
20
|
*/
|
|
18
|
-
constructor(
|
|
21
|
+
constructor(options, scene) {
|
|
22
|
+
var _a;
|
|
19
23
|
/**
|
|
20
24
|
* V2 Physics plugin private data for single shape
|
|
21
25
|
*/
|
|
22
26
|
this._pluginData = undefined;
|
|
23
|
-
this._type = type;
|
|
24
27
|
if (!scene) {
|
|
25
28
|
return;
|
|
26
29
|
}
|
|
@@ -36,7 +39,15 @@ export class PhysicsShape {
|
|
|
36
39
|
throw new Error("No Physics Plugin available.");
|
|
37
40
|
}
|
|
38
41
|
this._physicsPlugin = physicsPlugin;
|
|
39
|
-
|
|
42
|
+
if (options.pluginData !== undefined && options.pluginData !== null) {
|
|
43
|
+
this._pluginData = options.pluginData;
|
|
44
|
+
this._type = this._physicsPlugin.getShapeType(this);
|
|
45
|
+
}
|
|
46
|
+
else if (options.type !== undefined && options.type !== null) {
|
|
47
|
+
this._type = options.type;
|
|
48
|
+
const parameters = (_a = options.parameters) !== null && _a !== void 0 ? _a : {};
|
|
49
|
+
this._physicsPlugin.initShape(this, options.type, parameters);
|
|
50
|
+
}
|
|
40
51
|
}
|
|
41
52
|
/**
|
|
42
53
|
*
|
|
@@ -132,10 +143,10 @@ export class PhysicsShapeSphere extends PhysicsShape {
|
|
|
132
143
|
* @param scene scene to attach to
|
|
133
144
|
*/
|
|
134
145
|
constructor(center, radius, scene) {
|
|
135
|
-
super(ShapeType.SPHERE, { center: center, radius: radius }, scene);
|
|
146
|
+
super({ type: ShapeType.SPHERE, parameters: { center: center, radius: radius } }, scene);
|
|
136
147
|
}
|
|
137
148
|
}
|
|
138
|
-
|
|
149
|
+
/**
|
|
139
150
|
* Helper object to create a capsule shape
|
|
140
151
|
*/
|
|
141
152
|
export class PhysicsShapeCapsule extends PhysicsShape {
|
|
@@ -147,7 +158,7 @@ export class PhysicsShapeCapsule extends PhysicsShape {
|
|
|
147
158
|
* @param scene scene to attach to
|
|
148
159
|
*/
|
|
149
160
|
constructor(pointA, pointB, radius, scene) {
|
|
150
|
-
super(ShapeType.CAPSULE, { pointA: pointA, pointB: pointB, radius: radius }, scene);
|
|
161
|
+
super({ type: ShapeType.CAPSULE, parameters: { pointA: pointA, pointB: pointB, radius: radius } }, scene);
|
|
151
162
|
}
|
|
152
163
|
}
|
|
153
164
|
/**
|
|
@@ -162,7 +173,7 @@ export class PhysicsShapeCylinder extends PhysicsShape {
|
|
|
162
173
|
* @param scene scene to attach to
|
|
163
174
|
*/
|
|
164
175
|
constructor(pointA, pointB, radius, scene) {
|
|
165
|
-
super(ShapeType.CYLINDER, { pointA: pointA, pointB: pointB, radius: radius }, scene);
|
|
176
|
+
super({ type: ShapeType.CYLINDER, parameters: { pointA: pointA, pointB: pointB, radius: radius } }, scene);
|
|
166
177
|
}
|
|
167
178
|
}
|
|
168
179
|
/**
|
|
@@ -177,7 +188,7 @@ export class PhysicsShapeBox extends PhysicsShape {
|
|
|
177
188
|
* @param scene scene to attach to
|
|
178
189
|
*/
|
|
179
190
|
constructor(center, rotation, extents, scene) {
|
|
180
|
-
super(ShapeType.BOX, { center: center, rotation: rotation, extents: extents }, scene);
|
|
191
|
+
super({ type: ShapeType.BOX, parameters: { center: center, rotation: rotation, extents: extents } }, scene);
|
|
181
192
|
}
|
|
182
193
|
}
|
|
183
194
|
/**
|
|
@@ -190,7 +201,7 @@ export class PhysicsShapeConvexHull extends PhysicsShape {
|
|
|
190
201
|
* @param scene scene to attach to
|
|
191
202
|
*/
|
|
192
203
|
constructor(mesh, scene) {
|
|
193
|
-
super(ShapeType.CONVEX_HULL, { mesh: mesh }, scene);
|
|
204
|
+
super({ type: ShapeType.CONVEX_HULL, parameters: { mesh: mesh } }, scene);
|
|
194
205
|
}
|
|
195
206
|
}
|
|
196
207
|
/**
|
|
@@ -203,7 +214,7 @@ export class PhysicsShapeMesh extends PhysicsShape {
|
|
|
203
214
|
* @param scene scene to attach to
|
|
204
215
|
*/
|
|
205
216
|
constructor(mesh, scene) {
|
|
206
|
-
super(ShapeType.MESH, { mesh: mesh }, scene);
|
|
217
|
+
super({ type: ShapeType.MESH, parameters: { mesh: mesh } }, scene);
|
|
207
218
|
}
|
|
208
219
|
}
|
|
209
220
|
/**
|
|
@@ -215,7 +226,7 @@ export class PhysicsShapeContainer extends PhysicsShape {
|
|
|
215
226
|
* @param scene scene to attach to
|
|
216
227
|
*/
|
|
217
228
|
constructor(scene) {
|
|
218
|
-
super(ShapeType.CONTAINER, {}, scene);
|
|
229
|
+
super({ type: ShapeType.CONTAINER, parameters: {} }, scene);
|
|
219
230
|
}
|
|
220
231
|
}
|
|
221
232
|
//# sourceMappingURL=physicsShape.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physicsShape.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsShape.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAQnD;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAYrB;;;;;;;;;OASG;IACH,YAAY,IAAY,EAAE,UAAkC,EAAE,EAAE,KAAY;QArB5E;;WAEG;QACI,gBAAW,GAAQ,SAAS,CAAC;QAmBhC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,KAAK,EAAE;YACR,OAAO;SACV;QAED,MAAM,aAAa,GAAG,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAC/C,IAAI,CAAC,aAAa,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC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,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,CAAC;IACzF,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,YAAY;IAC7C;;;;;;OAMG;IACH,YAAY,MAAe,EAAE,QAAoB,EAAE,OAAgB,EAAE,KAAY;QAC7E,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;IAC1F,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,YAAY;IACpD;;;;OAIG;IACH,YAAY,IAAU,EAAE,KAAY;QAChC,KAAK,CAAC,SAAS,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,YAAY;IAC9C;;;;OAIG;IACH,YAAY,IAAU,EAAE,KAAY;QAChC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC;IACjD,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,YAAY;IACnD;;;OAGG;IACH,YAAY,KAAY;QACpB,KAAK,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;IAC1C,CAAC;CACJ","sourcesContent":["import type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { BoundingBox } from \"../../Culling/boundingBox\";\r\nimport { ShapeType } from \"./IPhysicsEnginePlugin\";\r\nimport type { IPhysicsEnginePluginV2, PhysicsShapeParameters } from \"./IPhysicsEnginePlugin\";\r\nimport type { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport type { Vector3 } from \"../../Maths/math.vector\";\r\nimport type { Quaternion } from \"../../Maths/math.vector\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { Scene } from \"../../scene\";\r\n\r\n/**\r\n * PhysicsShape class.\r\n * This class is useful for creating a physics shape that can be used in a physics engine.\r\n * A Physic Shape determine how collision are computed. It must be attached to a body.\r\n */\r\nexport class PhysicsShape {\r\n /**\r\n * V2 Physics plugin private data for single shape\r\n */\r\n public _pluginData: any = undefined;\r\n /**\r\n * The V2 plugin used to create and manage this Physics Body\r\n */\r\n private _physicsPlugin: IPhysicsEnginePluginV2;\r\n\r\n private _type: ShapeType;\r\n\r\n /**\r\n * Constructs a new physics shape.\r\n * @param type The type of the shape.\r\n * @param options The options of the shape.\r\n * @param scene The scene the shape belongs to.\r\n *\r\n * This code is useful for creating a new physics shape with the given type, options, and scene.\r\n * It also checks that the physics engine and plugin version are correct.\r\n * If not, it throws an error. This ensures that the shape is created with the correct parameters and is compatible with the physics engine.\r\n */\r\n constructor(type: number, options: PhysicsShapeParameters = {}, scene: Scene) {\r\n this._type = type;\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n const physicsEngine = scene.getPhysicsEngine();\r\n if (!physicsEngine) {\r\n throw new Error(\"No Physics Engine available.\");\r\n }\r\n if (physicsEngine.getPluginVersion() != 2) {\r\n throw new Error(\"Plugin version is incorrect. Expected version 2.\");\r\n }\r\n const physicsPlugin = physicsEngine.getPhysicsPlugin();\r\n if (!physicsPlugin) {\r\n throw new Error(\"No Physics Plugin available.\");\r\n }\r\n\r\n this._physicsPlugin = physicsPlugin as IPhysicsEnginePluginV2;\r\n this._physicsPlugin.initShape(this, type, options);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public get type(): ShapeType {\r\n return this._type;\r\n }\r\n\r\n /**\r\n *\r\n * @param layer\r\n */\r\n public setFilterLayer(layer: number): void {\r\n this._physicsPlugin.setFilterLayer(this, layer);\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public getFilterLayer(): number {\r\n return this._physicsPlugin.getFilterLayer(this);\r\n }\r\n\r\n /**\r\n *\r\n * @param materialId\r\n */\r\n public setMaterial(material: PhysicsMaterial): void {\r\n this._physicsPlugin.setMaterial(this, material);\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public getMaterial(): PhysicsMaterial | undefined {\r\n return this._physicsPlugin.getMaterial(this);\r\n }\r\n\r\n /**\r\n *\r\n * @param density\r\n */\r\n public setDensity(density: number): void {\r\n this._physicsPlugin.setDensity(this, density);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public getDensity(): number {\r\n return this._physicsPlugin.getDensity(this);\r\n }\r\n\r\n /**\r\n *\r\n * @param newChild\r\n * @param childTransform\r\n */\r\n public addChild(newChild: PhysicsShape, childTransform: TransformNode): void {\r\n this._physicsPlugin.addChild(this, newChild, childTransform);\r\n }\r\n\r\n /**\r\n *\r\n * @param childIndex\r\n */\r\n public removeChild(childIndex: number): void {\r\n this._physicsPlugin.removeChild(this, childIndex);\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public getNumChildren(): number {\r\n return this._physicsPlugin.getNumChildren(this);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public getBoundingBox(): BoundingBox {\r\n return this._physicsPlugin.getBoundingBox(this);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public dispose() {\r\n this._physicsPlugin.disposeShape(this);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a sphere shape\r\n */\r\nexport class PhysicsShapeSphere extends PhysicsShape {\r\n /** @internal */\r\n /**\r\n * Constructor for the Sphere Shape\r\n * @param center local center of the sphere\r\n * @param radius radius\r\n * @param scene scene to attach to\r\n */\r\n constructor(center: Vector3, radius: number, scene: Scene) {\r\n super(ShapeType.SPHERE, { center: center, radius: radius }, scene);\r\n }\r\n}\r\n\r\n/***\r\n * Helper object to create a capsule shape\r\n */\r\nexport class PhysicsShapeCapsule extends PhysicsShape {\r\n /**\r\n *\r\n * @param pointA Starting point that defines the capsule segment\r\n * @param pointB ending point of that same segment\r\n * @param radius radius\r\n * @param scene scene to attach to\r\n */\r\n constructor(pointA: Vector3, pointB: Vector3, radius: number, scene: Scene) {\r\n super(ShapeType.CAPSULE, { pointA: pointA, pointB: pointB, radius: radius }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a cylinder shape\r\n */\r\nexport class PhysicsShapeCylinder extends PhysicsShape {\r\n /**\r\n *\r\n * @param pointA Starting point that defines the cylinder segment\r\n * @param pointB ending point of that same segment\r\n * @param radius radius\r\n * @param scene scene to attach to\r\n */\r\n constructor(pointA: Vector3, pointB: Vector3, radius: number, scene: Scene) {\r\n super(ShapeType.CYLINDER, { pointA: pointA, pointB: pointB, radius: radius }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a box shape\r\n */\r\nexport class PhysicsShapeBox extends PhysicsShape {\r\n /**\r\n *\r\n * @param center local center of the sphere\r\n * @param rotation local orientation\r\n * @param extents size of the box in each direction\r\n * @param scene scene to attach to\r\n */\r\n constructor(center: Vector3, rotation: Quaternion, extents: Vector3, scene: Scene) {\r\n super(ShapeType.BOX, { center: center, rotation: rotation, extents: extents }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a convex hull shape\r\n */\r\nexport class PhysicsShapeConvexHull extends PhysicsShape {\r\n /**\r\n *\r\n * @param mesh the mesh to be used as topology infos for the convex hull\r\n * @param scene scene to attach to\r\n */\r\n constructor(mesh: Mesh, scene: Scene) {\r\n super(ShapeType.CONVEX_HULL, { mesh: mesh }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a mesh shape\r\n */\r\nexport class PhysicsShapeMesh extends PhysicsShape {\r\n /**\r\n *\r\n * @param mesh the mesh topology that will be used to create the shape\r\n * @param scene scene to attach to\r\n */\r\n constructor(mesh: Mesh, scene: Scene) {\r\n super(ShapeType.MESH, { mesh: mesh }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * A shape container holds a variable number of shapes. Use AddChild to append to newly created parent container.\r\n */\r\nexport class PhysicsShapeContainer extends PhysicsShape {\r\n /**\r\n * Constructor of the Shape container\r\n * @param scene scene to attach to\r\n */\r\n constructor(scene: Scene) {\r\n super(ShapeType.CONTAINER, {}, scene);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"physicsShape.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsShape.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AA0BnD;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAYrB;;;;;;;;;;;;OAYG;IACH,YAAY,OAA2B,EAAE,KAAY;;QAxBrD;;WAEG;QACI,gBAAW,GAAQ,SAAS,CAAC;QAsBhC,IAAI,CAAC,KAAK,EAAE;YACR,OAAO;SACV;QACD,MAAM,aAAa,GAAG,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAC/C,IAAI,CAAC,aAAa,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACnD;QACD,IAAI,aAAa,CAAC,gBAAgB,EAAE,IAAI,CAAC,EAAE;YACvC,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;SACvE;QACD,MAAM,aAAa,GAAG,aAAa,CAAC,gBAAgB,EAAE,CAAC;QACvD,IAAI,CAAC,aAAa,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACnD;QACD,IAAI,CAAC,cAAc,GAAG,aAAuC,CAAC;QAE9D,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,IAAI,OAAO,CAAC,UAAU,KAAK,IAAI,EAAE;YACjE,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;YACtC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;SACvD;aAAM,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,I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EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;IAC/G,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,YAAY;IAC7C;;;;;;OAMG;IACH,YAAY,MAAe,EAAE,QAAoB,EAAE,OAAgB,EAAE,KAAY;QAC7E,KAAK,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,GAAG,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;IAChH,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,YAAY;IACpD;;;;OAIG;IACH,YAAY,IAAU,EAAE,KAAY;QAChC,KAAK,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,WAAW,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;IAC9E,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,YAAY;IAC9C;;;;OAIG;IACH,YAAY,IAAU,EAAE,KAAY;QAChC,KAAK,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;IACvE,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,YAAY;IACnD;;;OAGG;IACH,YAAY,KAAY;QACpB,KAAK,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,SAAS,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;IAChE,CAAC;CACJ","sourcesContent":["import type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { BoundingBox } from \"../../Culling/boundingBox\";\r\nimport { ShapeType } from \"./IPhysicsEnginePlugin\";\r\nimport type { IPhysicsEnginePluginV2, PhysicsShapeParameters } from \"./IPhysicsEnginePlugin\";\r\nimport type { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport type { Vector3 } from \"../../Maths/math.vector\";\r\nimport type { Quaternion } from \"../../Maths/math.vector\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { Scene } from \"../../scene\";\r\n\r\n/**\r\n * Options for creating a physics shape\r\n */\r\nexport interface PhysicShapeOptions {\r\n /**\r\n * The type of the shape. This can be one of the following: SPHERE, BOX, CAPSULE, CYLINDER, CONVEX_HULL, MESH, HEIGHTFIELD, CONTAINER\r\n */\r\n type?: ShapeType;\r\n /**\r\n * The parameters of the shape. Varies depending of the shape type.\r\n */\r\n parameters?: PhysicsShapeParameters;\r\n /**\r\n * Reference to an already existing physics shape in the plugin.\r\n */\r\n pluginData?: any;\r\n}\r\n\r\n/**\r\n * PhysicsShape class.\r\n * This class is useful for creating a physics shape that can be used in a physics engine.\r\n * A Physic Shape determine how collision are computed. It must be attached to a body.\r\n */\r\nexport class PhysicsShape {\r\n /**\r\n * V2 Physics plugin private data for single shape\r\n */\r\n public _pluginData: any = undefined;\r\n /**\r\n * The V2 plugin used to create and manage this Physics Body\r\n */\r\n private _physicsPlugin: IPhysicsEnginePluginV2;\r\n\r\n private _type: ShapeType;\r\n\r\n /**\r\n * Constructs a new physics shape.\r\n * @param options The options for the physics shape. These are:\r\n * * type: The type of the shape. This can be one of the following: SPHERE, BOX, CAPSULE, CYLINDER, CONVEX_HULL, MESH, HEIGHTFIELD, CONTAINER\r\n * * parameters: The parameters of the shape.\r\n * * pluginData: The plugin data of the shape. This is used if you already have a reference to the object on the plugin side.\r\n * You need to specify either type or pluginData.\r\n * @param scene The scene the shape belongs to.\r\n *\r\n * This code is useful for creating a new physics shape with the given type, options, and scene.\r\n * It also checks that the physics engine and plugin version are correct.\r\n * If not, it throws an error. This ensures that the shape is created with the correct parameters and is compatible with the physics engine.\r\n */\r\n constructor(options: PhysicShapeOptions, scene: Scene) {\r\n if (!scene) {\r\n return;\r\n }\r\n const physicsEngine = scene.getPhysicsEngine();\r\n if (!physicsEngine) {\r\n throw new Error(\"No Physics Engine available.\");\r\n }\r\n if (physicsEngine.getPluginVersion() != 2) {\r\n throw new Error(\"Plugin version is incorrect. Expected version 2.\");\r\n }\r\n const physicsPlugin = physicsEngine.getPhysicsPlugin();\r\n if (!physicsPlugin) {\r\n throw new Error(\"No Physics Plugin available.\");\r\n }\r\n this._physicsPlugin = physicsPlugin as IPhysicsEnginePluginV2;\r\n\r\n if (options.pluginData !== undefined && options.pluginData !== null) {\r\n this._pluginData = options.pluginData;\r\n this._type = this._physicsPlugin.getShapeType(this);\r\n } else if (options.type !== undefined && options.type !== null) {\r\n this._type = options.type;\r\n const parameters = options.parameters ?? {};\r\n this._physicsPlugin.initShape(this, options.type, parameters);\r\n }\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public get type(): ShapeType {\r\n return this._type;\r\n }\r\n\r\n /**\r\n *\r\n * @param layer\r\n */\r\n public setFilterLayer(layer: number): void {\r\n this._physicsPlugin.setFilterLayer(this, layer);\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public getFilterLayer(): number {\r\n return this._physicsPlugin.getFilterLayer(this);\r\n }\r\n\r\n /**\r\n *\r\n * @param materialId\r\n */\r\n public setMaterial(material: PhysicsMaterial): void {\r\n this._physicsPlugin.setMaterial(this, material);\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public getMaterial(): PhysicsMaterial | undefined {\r\n return this._physicsPlugin.getMaterial(this);\r\n }\r\n\r\n /**\r\n *\r\n * @param density\r\n */\r\n public setDensity(density: number): void {\r\n this._physicsPlugin.setDensity(this, density);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public getDensity(): number {\r\n return this._physicsPlugin.getDensity(this);\r\n }\r\n\r\n /**\r\n *\r\n * @param newChild\r\n * @param childTransform\r\n */\r\n public addChild(newChild: PhysicsShape, childTransform: TransformNode): void {\r\n this._physicsPlugin.addChild(this, newChild, childTransform);\r\n }\r\n\r\n /**\r\n *\r\n * @param childIndex\r\n */\r\n public removeChild(childIndex: number): void {\r\n this._physicsPlugin.removeChild(this, childIndex);\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public getNumChildren(): number {\r\n return this._physicsPlugin.getNumChildren(this);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public getBoundingBox(): BoundingBox {\r\n return this._physicsPlugin.getBoundingBox(this);\r\n }\r\n\r\n /**\r\n *\r\n */\r\n public dispose() {\r\n this._physicsPlugin.disposeShape(this);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a sphere shape\r\n */\r\nexport class PhysicsShapeSphere extends PhysicsShape {\r\n /** @internal */\r\n /**\r\n * Constructor for the Sphere Shape\r\n * @param center local center of the sphere\r\n * @param radius radius\r\n * @param scene scene to attach to\r\n */\r\n constructor(center: Vector3, radius: number, scene: Scene) {\r\n super({ type: ShapeType.SPHERE, parameters: { center: center, radius: radius } }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a capsule shape\r\n */\r\nexport class PhysicsShapeCapsule extends PhysicsShape {\r\n /**\r\n *\r\n * @param pointA Starting point that defines the capsule segment\r\n * @param pointB ending point of that same segment\r\n * @param radius radius\r\n * @param scene scene to attach to\r\n */\r\n constructor(pointA: Vector3, pointB: Vector3, radius: number, scene: Scene) {\r\n super({ type: ShapeType.CAPSULE, parameters: { pointA: pointA, pointB: pointB, radius: radius } }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a cylinder shape\r\n */\r\nexport class PhysicsShapeCylinder extends PhysicsShape {\r\n /**\r\n *\r\n * @param pointA Starting point that defines the cylinder segment\r\n * @param pointB ending point of that same segment\r\n * @param radius radius\r\n * @param scene scene to attach to\r\n */\r\n constructor(pointA: Vector3, pointB: Vector3, radius: number, scene: Scene) {\r\n super({ type: ShapeType.CYLINDER, parameters: { pointA: pointA, pointB: pointB, radius: radius } }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a box shape\r\n */\r\nexport class PhysicsShapeBox extends PhysicsShape {\r\n /**\r\n *\r\n * @param center local center of the sphere\r\n * @param rotation local orientation\r\n * @param extents size of the box in each direction\r\n * @param scene scene to attach to\r\n */\r\n constructor(center: Vector3, rotation: Quaternion, extents: Vector3, scene: Scene) {\r\n super({ type: ShapeType.BOX, parameters: { center: center, rotation: rotation, extents: extents } }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a convex hull shape\r\n */\r\nexport class PhysicsShapeConvexHull extends PhysicsShape {\r\n /**\r\n *\r\n * @param mesh the mesh to be used as topology infos for the convex hull\r\n * @param scene scene to attach to\r\n */\r\n constructor(mesh: Mesh, scene: Scene) {\r\n super({ type: ShapeType.CONVEX_HULL, parameters: { mesh: mesh } }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * Helper object to create a mesh shape\r\n */\r\nexport class PhysicsShapeMesh extends PhysicsShape {\r\n /**\r\n *\r\n * @param mesh the mesh topology that will be used to create the shape\r\n * @param scene scene to attach to\r\n */\r\n constructor(mesh: Mesh, scene: Scene) {\r\n super({ type: ShapeType.MESH, parameters: { mesh: mesh } }, scene);\r\n }\r\n}\r\n\r\n/**\r\n * A shape container holds a variable number of shapes. Use AddChild to append to newly created parent container.\r\n */\r\nexport class PhysicsShapeContainer extends PhysicsShape {\r\n /**\r\n * Constructor of the Shape container\r\n * @param scene scene to attach to\r\n */\r\n constructor(scene: Scene) {\r\n super({ type: ShapeType.CONTAINER, parameters: {} }, scene);\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
package/scene.d.ts
CHANGED
|
@@ -1263,7 +1263,7 @@ export declare class Scene extends AbstractScene implements IAnimatable, IClipPl
|
|
|
1263
1263
|
get isLoading(): boolean;
|
|
1264
1264
|
/**
|
|
1265
1265
|
* Registers a function to be executed when the scene is ready
|
|
1266
|
-
* @param
|
|
1266
|
+
* @param func - the function to be executed
|
|
1267
1267
|
* @param checkRenderTargets true to also check that the meshes rendered as part of a render target are ready (default: false)
|
|
1268
1268
|
*/
|
|
1269
1269
|
executeWhenReady(func: () => void, checkRenderTargets?: boolean): void;
|
package/scene.js
CHANGED
|
@@ -1647,7 +1647,7 @@ export class Scene extends AbstractScene {
|
|
|
1647
1647
|
}
|
|
1648
1648
|
/**
|
|
1649
1649
|
* Registers a function to be executed when the scene is ready
|
|
1650
|
-
* @param
|
|
1650
|
+
* @param func - the function to be executed
|
|
1651
1651
|
* @param checkRenderTargets true to also check that the meshes rendered as part of a render target are ready (default: false)
|
|
1652
1652
|
*/
|
|
1653
1653
|
executeWhenReady(func, checkRenderTargets = false) {
|
|
@@ -3803,51 +3803,6 @@ export class Scene extends AbstractScene {
|
|
|
3803
3803
|
catch (e) {
|
|
3804
3804
|
console.error("An error occurred while calling onDisposeObservable!", e);
|
|
3805
3805
|
}
|
|
3806
|
-
this.onDisposeObservable.clear();
|
|
3807
|
-
this.onBeforeRenderObservable.clear();
|
|
3808
|
-
this.onAfterRenderObservable.clear();
|
|
3809
|
-
this.onBeforeRenderTargetsRenderObservable.clear();
|
|
3810
|
-
this.onAfterRenderTargetsRenderObservable.clear();
|
|
3811
|
-
this.onAfterStepObservable.clear();
|
|
3812
|
-
this.onBeforeStepObservable.clear();
|
|
3813
|
-
this.onBeforeActiveMeshesEvaluationObservable.clear();
|
|
3814
|
-
this.onAfterActiveMeshesEvaluationObservable.clear();
|
|
3815
|
-
this.onBeforeParticlesRenderingObservable.clear();
|
|
3816
|
-
this.onAfterParticlesRenderingObservable.clear();
|
|
3817
|
-
this.onBeforeDrawPhaseObservable.clear();
|
|
3818
|
-
this.onAfterDrawPhaseObservable.clear();
|
|
3819
|
-
this.onBeforeAnimationsObservable.clear();
|
|
3820
|
-
this.onAfterAnimationsObservable.clear();
|
|
3821
|
-
this.onDataLoadedObservable.clear();
|
|
3822
|
-
this.onBeforeRenderingGroupObservable.clear();
|
|
3823
|
-
this.onAfterRenderingGroupObservable.clear();
|
|
3824
|
-
this.onMeshImportedObservable.clear();
|
|
3825
|
-
this.onBeforeCameraRenderObservable.clear();
|
|
3826
|
-
this.onAfterCameraRenderObservable.clear();
|
|
3827
|
-
this.onReadyObservable.clear();
|
|
3828
|
-
this.onNewCameraAddedObservable.clear();
|
|
3829
|
-
this.onCameraRemovedObservable.clear();
|
|
3830
|
-
this.onNewLightAddedObservable.clear();
|
|
3831
|
-
this.onLightRemovedObservable.clear();
|
|
3832
|
-
this.onNewGeometryAddedObservable.clear();
|
|
3833
|
-
this.onGeometryRemovedObservable.clear();
|
|
3834
|
-
this.onNewTransformNodeAddedObservable.clear();
|
|
3835
|
-
this.onTransformNodeRemovedObservable.clear();
|
|
3836
|
-
this.onNewMeshAddedObservable.clear();
|
|
3837
|
-
this.onMeshRemovedObservable.clear();
|
|
3838
|
-
this.onNewSkeletonAddedObservable.clear();
|
|
3839
|
-
this.onSkeletonRemovedObservable.clear();
|
|
3840
|
-
this.onNewMaterialAddedObservable.clear();
|
|
3841
|
-
this.onNewMultiMaterialAddedObservable.clear();
|
|
3842
|
-
this.onMaterialRemovedObservable.clear();
|
|
3843
|
-
this.onMultiMaterialRemovedObservable.clear();
|
|
3844
|
-
this.onNewTextureAddedObservable.clear();
|
|
3845
|
-
this.onTextureRemovedObservable.clear();
|
|
3846
|
-
this.onPrePointerObservable.clear();
|
|
3847
|
-
this.onPointerObservable.clear();
|
|
3848
|
-
this.onPreKeyboardObservable.clear();
|
|
3849
|
-
this.onKeyboardObservable.clear();
|
|
3850
|
-
this.onActiveCameraChanged.clear();
|
|
3851
3806
|
this.detachControl();
|
|
3852
3807
|
// Detach cameras
|
|
3853
3808
|
const canvas = this._engine.getInputElement();
|
|
@@ -3907,6 +3862,52 @@ export class Scene extends AbstractScene {
|
|
|
3907
3862
|
this._engine._virtualScenes.splice(index, 1);
|
|
3908
3863
|
}
|
|
3909
3864
|
this._engine.wipeCaches(true);
|
|
3865
|
+
this.onDisposeObservable.clear();
|
|
3866
|
+
this.onBeforeRenderObservable.clear();
|
|
3867
|
+
this.onAfterRenderObservable.clear();
|
|
3868
|
+
this.onBeforeRenderTargetsRenderObservable.clear();
|
|
3869
|
+
this.onAfterRenderTargetsRenderObservable.clear();
|
|
3870
|
+
this.onAfterStepObservable.clear();
|
|
3871
|
+
this.onBeforeStepObservable.clear();
|
|
3872
|
+
this.onBeforeActiveMeshesEvaluationObservable.clear();
|
|
3873
|
+
this.onAfterActiveMeshesEvaluationObservable.clear();
|
|
3874
|
+
this.onBeforeParticlesRenderingObservable.clear();
|
|
3875
|
+
this.onAfterParticlesRenderingObservable.clear();
|
|
3876
|
+
this.onBeforeDrawPhaseObservable.clear();
|
|
3877
|
+
this.onAfterDrawPhaseObservable.clear();
|
|
3878
|
+
this.onBeforeAnimationsObservable.clear();
|
|
3879
|
+
this.onAfterAnimationsObservable.clear();
|
|
3880
|
+
this.onDataLoadedObservable.clear();
|
|
3881
|
+
this.onBeforeRenderingGroupObservable.clear();
|
|
3882
|
+
this.onAfterRenderingGroupObservable.clear();
|
|
3883
|
+
this.onMeshImportedObservable.clear();
|
|
3884
|
+
this.onBeforeCameraRenderObservable.clear();
|
|
3885
|
+
this.onAfterCameraRenderObservable.clear();
|
|
3886
|
+
this.onAfterRenderCameraObservable.clear();
|
|
3887
|
+
this.onReadyObservable.clear();
|
|
3888
|
+
this.onNewCameraAddedObservable.clear();
|
|
3889
|
+
this.onCameraRemovedObservable.clear();
|
|
3890
|
+
this.onNewLightAddedObservable.clear();
|
|
3891
|
+
this.onLightRemovedObservable.clear();
|
|
3892
|
+
this.onNewGeometryAddedObservable.clear();
|
|
3893
|
+
this.onGeometryRemovedObservable.clear();
|
|
3894
|
+
this.onNewTransformNodeAddedObservable.clear();
|
|
3895
|
+
this.onTransformNodeRemovedObservable.clear();
|
|
3896
|
+
this.onNewMeshAddedObservable.clear();
|
|
3897
|
+
this.onMeshRemovedObservable.clear();
|
|
3898
|
+
this.onNewSkeletonAddedObservable.clear();
|
|
3899
|
+
this.onSkeletonRemovedObservable.clear();
|
|
3900
|
+
this.onNewMaterialAddedObservable.clear();
|
|
3901
|
+
this.onNewMultiMaterialAddedObservable.clear();
|
|
3902
|
+
this.onMaterialRemovedObservable.clear();
|
|
3903
|
+
this.onMultiMaterialRemovedObservable.clear();
|
|
3904
|
+
this.onNewTextureAddedObservable.clear();
|
|
3905
|
+
this.onTextureRemovedObservable.clear();
|
|
3906
|
+
this.onPrePointerObservable.clear();
|
|
3907
|
+
this.onPointerObservable.clear();
|
|
3908
|
+
this.onPreKeyboardObservable.clear();
|
|
3909
|
+
this.onKeyboardObservable.clear();
|
|
3910
|
+
this.onActiveCameraChanged.clear();
|
|
3910
3911
|
this._isDisposed = true;
|
|
3911
3912
|
}
|
|
3912
3913
|
_disposeList(items, callback) {
|