@babylonjs/core 5.43.0 → 5.43.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/Audio/sound.d.ts +2 -1
- package/Audio/sound.js +27 -26
- package/Audio/sound.js.map +1 -1
- package/Debug/physicsViewer.d.ts +59 -4
- package/Debug/physicsViewer.js +115 -7
- package/Debug/physicsViewer.js.map +1 -1
- package/Engines/thinEngine.js +2 -2
- package/Engines/thinEngine.js.map +1 -1
- package/Meshes/linesMesh.d.ts +2 -1
- package/Meshes/linesMesh.js +1 -2
- package/Meshes/linesMesh.js.map +1 -1
- package/Physics/joinedPhysicsEngineComponent.d.ts +84 -0
- package/Physics/joinedPhysicsEngineComponent.js +144 -0
- package/Physics/joinedPhysicsEngineComponent.js.map +1 -0
- package/Physics/physicsEngineComponent.d.ts +2 -84
- package/Physics/physicsEngineComponent.js +3 -143
- package/Physics/physicsEngineComponent.js.map +1 -1
- package/Physics/v2/IPhysicsEnginePlugin.d.ts +4 -2
- package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
- package/Physics/v2/physicsBody.d.ts +126 -28
- package/Physics/v2/physicsBody.js +127 -31
- package/Physics/v2/physicsBody.js.map +1 -1
- package/Physics/v2/physicsConstraint.d.ts +26 -7
- package/Physics/v2/physicsConstraint.js +23 -7
- package/Physics/v2/physicsConstraint.js.map +1 -1
- package/Physics/v2/physicsEngine.js +0 -7
- package/Physics/v2/physicsEngine.js.map +1 -1
- package/Physics/v2/physicsEngineComponent.d.ts +4 -3
- package/Physics/v2/physicsEngineComponent.js +6 -5
- package/Physics/v2/physicsEngineComponent.js.map +1 -1
- package/Physics/v2/physicsMaterial.d.ts +38 -11
- package/Physics/v2/physicsMaterial.js +35 -11
- package/Physics/v2/physicsMaterial.js.map +1 -1
- package/Physics/v2/physicsShape.d.ts +24 -15
- package/Physics/v2/physicsShape.js +17 -11
- package/Physics/v2/physicsShape.js.map +1 -1
- package/package.json +1 -1
package/Meshes/linesMesh.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { SubMesh } from "../Meshes/subMesh";
|
|
|
6
6
|
import { Mesh } from "../Meshes/mesh";
|
|
7
7
|
import { InstancedMesh } from "../Meshes/instancedMesh";
|
|
8
8
|
import { Material } from "../Materials/material";
|
|
9
|
+
import type { Effect } from "../Materials/effect";
|
|
9
10
|
import "../Shaders/color.fragment";
|
|
10
11
|
import "../Shaders/color.vertex";
|
|
11
12
|
/**
|
|
@@ -81,7 +82,7 @@ export declare class LinesMesh extends Mesh {
|
|
|
81
82
|
/**
|
|
82
83
|
* @internal
|
|
83
84
|
*/
|
|
84
|
-
_bind(): Mesh;
|
|
85
|
+
_bind(_subMesh: SubMesh, colorEffect: Effect): Mesh;
|
|
85
86
|
/**
|
|
86
87
|
* @internal
|
|
87
88
|
*/
|
package/Meshes/linesMesh.js
CHANGED
|
@@ -124,11 +124,10 @@ export class LinesMesh extends Mesh {
|
|
|
124
124
|
/**
|
|
125
125
|
* @internal
|
|
126
126
|
*/
|
|
127
|
-
_bind() {
|
|
127
|
+
_bind(_subMesh, colorEffect) {
|
|
128
128
|
if (!this._geometry) {
|
|
129
129
|
return this;
|
|
130
130
|
}
|
|
131
|
-
const colorEffect = this._lineMaterial.getEffect();
|
|
132
131
|
// VBOs
|
|
133
132
|
const indexToBind = this.isUnIndexed ? null : this._geometry.getIndexBuffer();
|
|
134
133
|
if (!this._userInstancedBuffersStorage) {
|
package/Meshes/linesMesh.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linesMesh.js","sourceRoot":"","sources":["../../../../lts/core/generated/Meshes/linesMesh.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE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AAI,EAAE,MAAM,CAAC,CAAC;QACpB,IAAI,CAAC,qBAAqB,GAAG,MAAM,CAAC,qBAAqB,CAAC;IAC9D,CAAC;IAED;;OAEG;IACI,YAAY;QACf,OAAO,oBAAoB,CAAC;IAChC,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Color3, Color4 } from \"../Maths/math.color\";\r\nimport type { Node } from \"../node\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { InstancedMesh } from \"../Meshes/instancedMesh\";\r\nimport { Material } from \"../Materials/material\";\r\nimport { ShaderMaterial } from \"../Materials/shaderMaterial\";\r\n\r\nimport \"../Shaders/color.fragment\";\r\nimport \"../Shaders/color.vertex\";\r\n\r\nMesh._LinesMeshParser = (parsedMesh: any, scene: Scene): Mesh => {\r\n return LinesMesh.Parse(parsedMesh, scene);\r\n};\r\n\r\n/**\r\n * Line mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\r\n */\r\nexport class LinesMesh extends Mesh {\r\n /**\r\n * Color of the line (Default: White)\r\n */\r\n public color = new Color3(1, 1, 1);\r\n\r\n /**\r\n * Alpha of the line (Default: 1)\r\n */\r\n public alpha = 1;\r\n\r\n /**\r\n * The intersection Threshold is the margin applied when intersection a segment of the LinesMesh with a Ray.\r\n * This margin is expressed in world space coordinates, so its value may vary.\r\n * Default value is 0.1\r\n */\r\n public intersectionThreshold: number;\r\n\r\n private _lineMaterial: Material;\r\n\r\n private _isShaderMaterial(shader: Material): shader is ShaderMaterial {\r\n return shader.getClassName() === \"ShaderMaterial\";\r\n }\r\n\r\n private _color4: Color4;\r\n\r\n /**\r\n * Creates a new LinesMesh\r\n * @param name defines the name\r\n * @param scene defines the hosting scene\r\n * @param parent defines the parent mesh if any\r\n * @param source defines the optional source LinesMesh used to clone data from\r\n * @param doNotCloneChildren When cloning, skip cloning child meshes of source, default False.\r\n * When false, achieved by calling a clone(), also passing False.\r\n * This will make creation of children, recursive.\r\n * @param useVertexColor defines if this LinesMesh supports vertex color\r\n * @param useVertexAlpha defines if this LinesMesh supports vertex alpha\r\n * @param material material to use to draw the line. If not provided, will create a new one\r\n */\r\n constructor(\r\n name: string,\r\n scene: Nullable<Scene> = null,\r\n parent: Nullable<Node> = null,\r\n source: Nullable<LinesMesh> = null,\r\n doNotCloneChildren?: boolean,\r\n /**\r\n * If vertex color should be applied to the mesh\r\n */\r\n public readonly useVertexColor?: boolean,\r\n /**\r\n * If vertex alpha should be applied to the mesh\r\n */\r\n public readonly useVertexAlpha?: boolean,\r\n material?: Material\r\n ) {\r\n super(name, scene, parent, source, doNotCloneChildren);\r\n\r\n if (source) {\r\n this.color = source.color.clone();\r\n this.alpha = source.alpha;\r\n this.useVertexColor = source.useVertexColor;\r\n this.useVertexAlpha = source.useVertexAlpha;\r\n }\r\n\r\n this.intersectionThreshold = 0.1;\r\n\r\n const defines: string[] = [];\r\n const options = {\r\n attributes: [VertexBuffer.PositionKind],\r\n uniforms: [\"world\", \"viewProjection\"],\r\n needAlphaBlending: true,\r\n defines: defines,\r\n useClipPlane: null,\r\n };\r\n\r\n if (useVertexAlpha === false) {\r\n options.needAlphaBlending = false;\r\n } else {\r\n options.defines.push(\"#define VERTEXALPHA\");\r\n }\r\n\r\n if (!useVertexColor) {\r\n options.uniforms.push(\"color\");\r\n this._color4 = new Color4();\r\n } else {\r\n options.defines.push(\"#define VERTEXCOLOR\");\r\n options.attributes.push(VertexBuffer.ColorKind);\r\n }\r\n\r\n if (material) {\r\n this.material = material;\r\n } else {\r\n this.material = new ShaderMaterial(\"colorShader\", this.getScene(), \"color\", options, false);\r\n this.material.doNotSerialize = true;\r\n }\r\n }\r\n\r\n public isReady() {\r\n if (!this._lineMaterial.isReady(this, !!this._userInstancedBuffersStorage)) {\r\n return false;\r\n }\r\n\r\n return super.isReady();\r\n }\r\n\r\n /**\r\n * Returns the string \"LineMesh\"\r\n */\r\n public getClassName(): string {\r\n return \"LinesMesh\";\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public get material(): Material {\r\n return this._lineMaterial;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public set material(value: Material) {\r\n this._lineMaterial = value;\r\n this._lineMaterial.fillMode = Material.LineListDrawMode;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public get checkCollisions(): boolean {\r\n return false;\r\n }\r\n\r\n public set checkCollisions(value: boolean) {\r\n // Just ignore it\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _bind(): Mesh {\r\n if (!this._geometry) {\r\n return this;\r\n }\r\n const colorEffect = this._lineMaterial.getEffect();\r\n\r\n // VBOs\r\n const indexToBind = this.isUnIndexed ? null : this._geometry.getIndexBuffer();\r\n if (!this._userInstancedBuffersStorage) {\r\n this._geometry._bind(colorEffect, indexToBind);\r\n } else {\r\n this._geometry._bind(colorEffect, indexToBind, this._userInstancedBuffersStorage.vertexBuffers, this._userInstancedBuffersStorage.vertexArrayObjects);\r\n }\r\n\r\n // Color\r\n if (!this.useVertexColor && this._isShaderMaterial(this._lineMaterial)) {\r\n const { r, g, b } = this.color;\r\n this._color4.set(r, g, b, this.alpha);\r\n this._lineMaterial.setColor4(\"color\", this._color4);\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _draw(subMesh: SubMesh, fillMode: number, instancesCount?: number): Mesh {\r\n if (!this._geometry || !this._geometry.getVertexBuffers() || (!this._unIndexed && !this._geometry.getIndexBuffer())) {\r\n return this;\r\n }\r\n\r\n const engine = this.getScene().getEngine();\r\n\r\n // Draw order\r\n\r\n if (this._unIndexed) {\r\n engine.drawArraysType(Material.LineListDrawMode, subMesh.verticesStart, subMesh.verticesCount, instancesCount);\r\n } else {\r\n engine.drawElementsType(Material.LineListDrawMode, subMesh.indexStart, subMesh.indexCount, instancesCount);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Disposes of the line mesh\r\n * @param doNotRecurse If children should be disposed\r\n * @param disposeMaterialAndTextures This parameter is not used by the LineMesh class\r\n * @param doNotDisposeMaterial If the material should not be disposed (default: false, meaning the material is disposed)\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public dispose(doNotRecurse?: boolean, disposeMaterialAndTextures = false, doNotDisposeMaterial?: boolean): void {\r\n if (!doNotDisposeMaterial) {\r\n this._lineMaterial.dispose(false, false, true);\r\n }\r\n super.dispose(doNotRecurse);\r\n }\r\n\r\n /**\r\n * Returns a new LineMesh object cloned from the current one.\r\n * @param name\r\n * @param newParent\r\n * @param doNotCloneChildren\r\n */\r\n public clone(name: string, newParent: Nullable<Node> = null, doNotCloneChildren?: boolean): LinesMesh {\r\n return new LinesMesh(name, this.getScene(), newParent, this, doNotCloneChildren);\r\n }\r\n\r\n /**\r\n * Creates a new InstancedLinesMesh object from the mesh model.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/copies/instances\r\n * @param name defines the name of the new instance\r\n * @returns a new InstancedLinesMesh\r\n */\r\n public createInstance(name: string): InstancedLinesMesh {\r\n const instance = new InstancedLinesMesh(name, this);\r\n\r\n if (this.instancedBuffers) {\r\n instance.instancedBuffers = {};\r\n\r\n for (const key in this.instancedBuffers) {\r\n instance.instancedBuffers[key] = this.instancedBuffers[key];\r\n }\r\n }\r\n\r\n return instance;\r\n }\r\n\r\n /**\r\n * Serializes this ground mesh\r\n * @param serializationObject object to write serialization to\r\n */\r\n public serialize(serializationObject: any): void {\r\n super.serialize(serializationObject);\r\n serializationObject.color = this.color.asArray();\r\n serializationObject.alpha = this.alpha;\r\n }\r\n\r\n /**\r\n * Parses a serialized ground mesh\r\n * @param parsedMesh the serialized mesh\r\n * @param scene the scene to create the ground mesh in\r\n * @returns the created ground mesh\r\n */\r\n public static Parse(parsedMesh: any, scene: Scene): LinesMesh {\r\n const result = new LinesMesh(parsedMesh.name, scene);\r\n\r\n result.color = Color3.FromArray(parsedMesh.color);\r\n result.alpha = parsedMesh.alpha;\r\n\r\n return result;\r\n }\r\n}\r\n\r\n/**\r\n * Creates an instance based on a source LinesMesh\r\n */\r\nexport class InstancedLinesMesh extends InstancedMesh {\r\n /**\r\n * The intersection Threshold is the margin applied when intersection a segment of the LinesMesh with a Ray.\r\n * This margin is expressed in world space coordinates, so its value may vary.\r\n * Initialized with the intersectionThreshold value of the source LinesMesh\r\n */\r\n public intersectionThreshold: number;\r\n\r\n constructor(name: string, source: LinesMesh) {\r\n super(name, source);\r\n this.intersectionThreshold = source.intersectionThreshold;\r\n }\r\n\r\n /**\r\n * Returns the string \"InstancedLinesMesh\".\r\n */\r\n public getClassName(): string {\r\n return \"InstancedLinesMesh\";\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"linesMesh.js","sourceRoot":"","sources":["../../../../lts/core/generated/Meshes/linesMesh.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAG7D,OAAO,2BAA2B,CAAC;AACnC,OAAO,yBAAyB,CAAC;AAEjC,IAAI,CAAC,gBAAgB,GAAG,CAAC,UAAe,EAAE,KAAY,EAAQ,EAAE;IAC5D,OAAO,SAAS,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AAC9C,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,OAAO,SAAU,SAAQ,IAAI;IA0B/B;;;;;;;;;;;;OAYG;IACH,YACI,IAAY,EACZ,QAAyB,IAAI,EAC7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,CAAC,GAAG,CAAC,CAAC;aAC/D;SACJ;QAED,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED;;;OAGG;IACI,SAAS,CAAC,mBAAwB;QACrC,KAAK,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;QACrC,mBAAmB,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACjD,mBAAmB,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IAC3C,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,UAAe,EAAE,KAAY;QAC7C,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAErD,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAClD,MAAM,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;QAEhC,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,aAAa;IAQjD,YAAY,IAAY,EAAE,MAAiB;QACvC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACpB,IAAI,CAAC,qBAAqB,GAAG,MAAM,CAAC,qBAAqB,CAAC;IAC9D,CAAC;IAED;;OAEG;IACI,YAAY;QACf,OAAO,oBAAoB,CAAC;IAChC,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Color3, Color4 } from \"../Maths/math.color\";\r\nimport type { Node } from \"../node\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { InstancedMesh } from \"../Meshes/instancedMesh\";\r\nimport { Material } from \"../Materials/material\";\r\nimport { ShaderMaterial } from \"../Materials/shaderMaterial\";\r\nimport type { Effect } from \"../Materials/effect\";\r\n\r\nimport \"../Shaders/color.fragment\";\r\nimport \"../Shaders/color.vertex\";\r\n\r\nMesh._LinesMeshParser = (parsedMesh: any, scene: Scene): Mesh => {\r\n return LinesMesh.Parse(parsedMesh, scene);\r\n};\r\n\r\n/**\r\n * Line mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\r\n */\r\nexport class LinesMesh extends Mesh {\r\n /**\r\n * Color of the line (Default: White)\r\n */\r\n public color = new Color3(1, 1, 1);\r\n\r\n /**\r\n * Alpha of the line (Default: 1)\r\n */\r\n public alpha = 1;\r\n\r\n /**\r\n * The intersection Threshold is the margin applied when intersection a segment of the LinesMesh with a Ray.\r\n * This margin is expressed in world space coordinates, so its value may vary.\r\n * Default value is 0.1\r\n */\r\n public intersectionThreshold: number;\r\n\r\n private _lineMaterial: Material;\r\n\r\n private _isShaderMaterial(shader: Material): shader is ShaderMaterial {\r\n return shader.getClassName() === \"ShaderMaterial\";\r\n }\r\n\r\n private _color4: Color4;\r\n\r\n /**\r\n * Creates a new LinesMesh\r\n * @param name defines the name\r\n * @param scene defines the hosting scene\r\n * @param parent defines the parent mesh if any\r\n * @param source defines the optional source LinesMesh used to clone data from\r\n * @param doNotCloneChildren When cloning, skip cloning child meshes of source, default False.\r\n * When false, achieved by calling a clone(), also passing False.\r\n * This will make creation of children, recursive.\r\n * @param useVertexColor defines if this LinesMesh supports vertex color\r\n * @param useVertexAlpha defines if this LinesMesh supports vertex alpha\r\n * @param material material to use to draw the line. If not provided, will create a new one\r\n */\r\n constructor(\r\n name: string,\r\n scene: Nullable<Scene> = null,\r\n parent: Nullable<Node> = null,\r\n source: Nullable<LinesMesh> = null,\r\n doNotCloneChildren?: boolean,\r\n /**\r\n * If vertex color should be applied to the mesh\r\n */\r\n public readonly useVertexColor?: boolean,\r\n /**\r\n * If vertex alpha should be applied to the mesh\r\n */\r\n public readonly useVertexAlpha?: boolean,\r\n material?: Material\r\n ) {\r\n super(name, scene, parent, source, doNotCloneChildren);\r\n\r\n if (source) {\r\n this.color = source.color.clone();\r\n this.alpha = source.alpha;\r\n this.useVertexColor = source.useVertexColor;\r\n this.useVertexAlpha = source.useVertexAlpha;\r\n }\r\n\r\n this.intersectionThreshold = 0.1;\r\n\r\n const defines: string[] = [];\r\n const options = {\r\n attributes: [VertexBuffer.PositionKind],\r\n uniforms: [\"world\", \"viewProjection\"],\r\n needAlphaBlending: true,\r\n defines: defines,\r\n useClipPlane: null,\r\n };\r\n\r\n if (useVertexAlpha === false) {\r\n options.needAlphaBlending = false;\r\n } else {\r\n options.defines.push(\"#define VERTEXALPHA\");\r\n }\r\n\r\n if (!useVertexColor) {\r\n options.uniforms.push(\"color\");\r\n this._color4 = new Color4();\r\n } else {\r\n options.defines.push(\"#define VERTEXCOLOR\");\r\n options.attributes.push(VertexBuffer.ColorKind);\r\n }\r\n\r\n if (material) {\r\n this.material = material;\r\n } else {\r\n this.material = new ShaderMaterial(\"colorShader\", this.getScene(), \"color\", options, false);\r\n this.material.doNotSerialize = true;\r\n }\r\n }\r\n\r\n public isReady() {\r\n if (!this._lineMaterial.isReady(this, !!this._userInstancedBuffersStorage)) {\r\n return false;\r\n }\r\n\r\n return super.isReady();\r\n }\r\n\r\n /**\r\n * Returns the string \"LineMesh\"\r\n */\r\n public getClassName(): string {\r\n return \"LinesMesh\";\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public get material(): Material {\r\n return this._lineMaterial;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public set material(value: Material) {\r\n this._lineMaterial = value;\r\n this._lineMaterial.fillMode = Material.LineListDrawMode;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public get checkCollisions(): boolean {\r\n return false;\r\n }\r\n\r\n public set checkCollisions(value: boolean) {\r\n // Just ignore it\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _bind(_subMesh: SubMesh, colorEffect: Effect): Mesh {\r\n if (!this._geometry) {\r\n return this;\r\n }\r\n\r\n // VBOs\r\n const indexToBind = this.isUnIndexed ? null : this._geometry.getIndexBuffer();\r\n if (!this._userInstancedBuffersStorage) {\r\n this._geometry._bind(colorEffect, indexToBind);\r\n } else {\r\n this._geometry._bind(colorEffect, indexToBind, this._userInstancedBuffersStorage.vertexBuffers, this._userInstancedBuffersStorage.vertexArrayObjects);\r\n }\r\n\r\n // Color\r\n if (!this.useVertexColor && this._isShaderMaterial(this._lineMaterial)) {\r\n const { r, g, b } = this.color;\r\n this._color4.set(r, g, b, this.alpha);\r\n this._lineMaterial.setColor4(\"color\", this._color4);\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _draw(subMesh: SubMesh, fillMode: number, instancesCount?: number): Mesh {\r\n if (!this._geometry || !this._geometry.getVertexBuffers() || (!this._unIndexed && !this._geometry.getIndexBuffer())) {\r\n return this;\r\n }\r\n\r\n const engine = this.getScene().getEngine();\r\n\r\n // Draw order\r\n\r\n if (this._unIndexed) {\r\n engine.drawArraysType(Material.LineListDrawMode, subMesh.verticesStart, subMesh.verticesCount, instancesCount);\r\n } else {\r\n engine.drawElementsType(Material.LineListDrawMode, subMesh.indexStart, subMesh.indexCount, instancesCount);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Disposes of the line mesh\r\n * @param doNotRecurse If children should be disposed\r\n * @param disposeMaterialAndTextures This parameter is not used by the LineMesh class\r\n * @param doNotDisposeMaterial If the material should not be disposed (default: false, meaning the material is disposed)\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public dispose(doNotRecurse?: boolean, disposeMaterialAndTextures = false, doNotDisposeMaterial?: boolean): void {\r\n if (!doNotDisposeMaterial) {\r\n this._lineMaterial.dispose(false, false, true);\r\n }\r\n super.dispose(doNotRecurse);\r\n }\r\n\r\n /**\r\n * Returns a new LineMesh object cloned from the current one.\r\n * @param name\r\n * @param newParent\r\n * @param doNotCloneChildren\r\n */\r\n public clone(name: string, newParent: Nullable<Node> = null, doNotCloneChildren?: boolean): LinesMesh {\r\n return new LinesMesh(name, this.getScene(), newParent, this, doNotCloneChildren);\r\n }\r\n\r\n /**\r\n * Creates a new InstancedLinesMesh object from the mesh model.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/copies/instances\r\n * @param name defines the name of the new instance\r\n * @returns a new InstancedLinesMesh\r\n */\r\n public createInstance(name: string): InstancedLinesMesh {\r\n const instance = new InstancedLinesMesh(name, this);\r\n\r\n if (this.instancedBuffers) {\r\n instance.instancedBuffers = {};\r\n\r\n for (const key in this.instancedBuffers) {\r\n instance.instancedBuffers[key] = this.instancedBuffers[key];\r\n }\r\n }\r\n\r\n return instance;\r\n }\r\n\r\n /**\r\n * Serializes this ground mesh\r\n * @param serializationObject object to write serialization to\r\n */\r\n public serialize(serializationObject: any): void {\r\n super.serialize(serializationObject);\r\n serializationObject.color = this.color.asArray();\r\n serializationObject.alpha = this.alpha;\r\n }\r\n\r\n /**\r\n * Parses a serialized ground mesh\r\n * @param parsedMesh the serialized mesh\r\n * @param scene the scene to create the ground mesh in\r\n * @returns the created ground mesh\r\n */\r\n public static Parse(parsedMesh: any, scene: Scene): LinesMesh {\r\n const result = new LinesMesh(parsedMesh.name, scene);\r\n\r\n result.color = Color3.FromArray(parsedMesh.color);\r\n result.alpha = parsedMesh.alpha;\r\n\r\n return result;\r\n }\r\n}\r\n\r\n/**\r\n * Creates an instance based on a source LinesMesh\r\n */\r\nexport class InstancedLinesMesh extends InstancedMesh {\r\n /**\r\n * The intersection Threshold is the margin applied when intersection a segment of the LinesMesh with a Ray.\r\n * This margin is expressed in world space coordinates, so its value may vary.\r\n * Initialized with the intersectionThreshold value of the source LinesMesh\r\n */\r\n public intersectionThreshold: number;\r\n\r\n constructor(name: string, source: LinesMesh) {\r\n super(name, source);\r\n this.intersectionThreshold = source.intersectionThreshold;\r\n }\r\n\r\n /**\r\n * Returns the string \"InstancedLinesMesh\".\r\n */\r\n public getClassName(): string {\r\n return \"InstancedLinesMesh\";\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { Nullable } from "../types";
|
|
2
|
+
import { Observable } from "../Misc/observable";
|
|
3
|
+
import type { Vector3 } from "../Maths/math.vector";
|
|
4
|
+
import type { ISceneComponent } from "../sceneComponent";
|
|
5
|
+
import { Scene } from "../scene";
|
|
6
|
+
import type { IPhysicsEngine } from "./IPhysicsEngine";
|
|
7
|
+
import type { IPhysicsEnginePlugin as IPhysicsEnginePluginV1 } from "./v1/IPhysicsEnginePlugin";
|
|
8
|
+
import type { IPhysicsEnginePluginV2 } from "./v2/IPhysicsEnginePlugin";
|
|
9
|
+
declare module "../scene" {
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
interface Scene {
|
|
14
|
+
/** @internal (Backing field) */
|
|
15
|
+
_physicsEngine: Nullable<IPhysicsEngine>;
|
|
16
|
+
/** @internal */
|
|
17
|
+
_physicsTimeAccumulator: number;
|
|
18
|
+
/**
|
|
19
|
+
* Gets the current physics engine
|
|
20
|
+
* @returns a IPhysicsEngine or null if none attached
|
|
21
|
+
*/
|
|
22
|
+
getPhysicsEngine(): Nullable<IPhysicsEngine>;
|
|
23
|
+
/**
|
|
24
|
+
* Enables physics to the current scene
|
|
25
|
+
* @param gravity defines the scene's gravity for the physics engine. defaults to real earth gravity : (0, -9.81, 0)
|
|
26
|
+
* @param plugin defines the physics engine to be used. defaults to CannonJS.
|
|
27
|
+
* @returns a boolean indicating if the physics engine was initialized
|
|
28
|
+
*/
|
|
29
|
+
enablePhysics(gravity?: Nullable<Vector3>, plugin?: IPhysicsEnginePluginV1 | IPhysicsEnginePluginV2): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Disables and disposes the physics engine associated with the scene
|
|
32
|
+
*/
|
|
33
|
+
disablePhysicsEngine(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Gets a boolean indicating if there is an active physics engine
|
|
36
|
+
* @returns a boolean indicating if there is an active physics engine
|
|
37
|
+
*/
|
|
38
|
+
isPhysicsEnabled(): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Deletes a physics compound impostor
|
|
41
|
+
* @param compound defines the compound to delete
|
|
42
|
+
*/
|
|
43
|
+
deleteCompoundImpostor(compound: any): void;
|
|
44
|
+
/**
|
|
45
|
+
* An event triggered when physic simulation is about to be run
|
|
46
|
+
*/
|
|
47
|
+
onBeforePhysicsObservable: Observable<Scene>;
|
|
48
|
+
/**
|
|
49
|
+
* An event triggered when physic simulation has been done
|
|
50
|
+
*/
|
|
51
|
+
onAfterPhysicsObservable: Observable<Scene>;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Defines the physics engine scene component responsible to manage a physics engine
|
|
56
|
+
*/
|
|
57
|
+
export declare class PhysicsEngineSceneComponent implements ISceneComponent {
|
|
58
|
+
/**
|
|
59
|
+
* The component name helpful to identify the component in the list of scene components.
|
|
60
|
+
*/
|
|
61
|
+
readonly name = "PhysicsEngine";
|
|
62
|
+
/**
|
|
63
|
+
* The scene the component belongs to.
|
|
64
|
+
*/
|
|
65
|
+
scene: Scene;
|
|
66
|
+
/**
|
|
67
|
+
* Creates a new instance of the component for the given scene
|
|
68
|
+
* @param scene Defines the scene to register the component in
|
|
69
|
+
*/
|
|
70
|
+
constructor(scene: Scene);
|
|
71
|
+
/**
|
|
72
|
+
* Registers the component in a given scene
|
|
73
|
+
*/
|
|
74
|
+
register(): void;
|
|
75
|
+
/**
|
|
76
|
+
* Rebuilds the elements related to this component in case of
|
|
77
|
+
* context lost for instance.
|
|
78
|
+
*/
|
|
79
|
+
rebuild(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Disposes the component and the associated resources
|
|
82
|
+
*/
|
|
83
|
+
dispose(): void;
|
|
84
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Logger } from "../Misc/logger.js";
|
|
2
|
+
import { Observable } from "../Misc/observable.js";
|
|
3
|
+
import { SceneComponentConstants } from "../sceneComponent.js";
|
|
4
|
+
import { Scene } from "../scene.js";
|
|
5
|
+
import { PhysicsEngine as PhysicsEngineV1 } from "./v1/physicsEngine.js";
|
|
6
|
+
import { PhysicsEngine as PhysicsEngineV2 } from "./v2/physicsEngine.js";
|
|
7
|
+
/**
|
|
8
|
+
* Gets the current physics engine
|
|
9
|
+
* @returns a IPhysicsEngine or null if none attached
|
|
10
|
+
*/
|
|
11
|
+
Scene.prototype.getPhysicsEngine = function () {
|
|
12
|
+
return this._physicsEngine;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Enables physics to the current scene
|
|
16
|
+
* @param gravity defines the scene's gravity for the physics engine
|
|
17
|
+
* @param plugin defines the physics engine to be used. defaults to CannonJS.
|
|
18
|
+
* @returns a boolean indicating if the physics engine was initialized
|
|
19
|
+
*/
|
|
20
|
+
Scene.prototype.enablePhysics = function (gravity = null, plugin) {
|
|
21
|
+
if (this._physicsEngine) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
// Register the component to the scene
|
|
25
|
+
let component = this._getComponent(SceneComponentConstants.NAME_PHYSICSENGINE);
|
|
26
|
+
if (!component) {
|
|
27
|
+
component = new PhysicsEngineSceneComponent(this);
|
|
28
|
+
this._addComponent(component);
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
if (!plugin || (plugin === null || plugin === void 0 ? void 0 : plugin.getPluginVersion()) === 1) {
|
|
32
|
+
this._physicsEngine = new PhysicsEngineV1(gravity, plugin);
|
|
33
|
+
}
|
|
34
|
+
else if ((plugin === null || plugin === void 0 ? void 0 : plugin.getPluginVersion()) === 2) {
|
|
35
|
+
this._physicsEngine = new PhysicsEngineV2(gravity, plugin);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
throw new Error("Unsupported Physics plugin version.");
|
|
39
|
+
}
|
|
40
|
+
this._physicsTimeAccumulator = 0;
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
Logger.Error(e.message);
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Disables and disposes the physics engine associated with the scene
|
|
50
|
+
*/
|
|
51
|
+
Scene.prototype.disablePhysicsEngine = function () {
|
|
52
|
+
if (!this._physicsEngine) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
this._physicsEngine.dispose();
|
|
56
|
+
this._physicsEngine = null;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Gets a boolean indicating if there is an active physics engine
|
|
60
|
+
* @returns a boolean indicating if there is an active physics engine
|
|
61
|
+
*/
|
|
62
|
+
Scene.prototype.isPhysicsEnabled = function () {
|
|
63
|
+
return this._physicsEngine !== undefined;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Deletes a physics compound impostor
|
|
67
|
+
* @param compound defines the compound to delete
|
|
68
|
+
*/
|
|
69
|
+
Scene.prototype.deleteCompoundImpostor = function (compound) {
|
|
70
|
+
const mesh = compound.parts[0].mesh;
|
|
71
|
+
if (mesh.physicsImpostor) {
|
|
72
|
+
mesh.physicsImpostor.dispose( /*true*/);
|
|
73
|
+
mesh.physicsImpostor = null;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
Scene.prototype._advancePhysicsEngineStep = function (step) {
|
|
80
|
+
if (this._physicsEngine) {
|
|
81
|
+
const subTime = this._physicsEngine.getSubTimeStep();
|
|
82
|
+
if (subTime > 0) {
|
|
83
|
+
this._physicsTimeAccumulator += step;
|
|
84
|
+
while (this._physicsTimeAccumulator > subTime) {
|
|
85
|
+
this.onBeforePhysicsObservable.notifyObservers(this);
|
|
86
|
+
this._physicsEngine._step(subTime / 1000);
|
|
87
|
+
this.onAfterPhysicsObservable.notifyObservers(this);
|
|
88
|
+
this._physicsTimeAccumulator -= subTime;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.onBeforePhysicsObservable.notifyObservers(this);
|
|
93
|
+
this._physicsEngine._step(step / 1000);
|
|
94
|
+
this.onAfterPhysicsObservable.notifyObservers(this);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Defines the physics engine scene component responsible to manage a physics engine
|
|
100
|
+
*/
|
|
101
|
+
export class PhysicsEngineSceneComponent {
|
|
102
|
+
/**
|
|
103
|
+
* Creates a new instance of the component for the given scene
|
|
104
|
+
* @param scene Defines the scene to register the component in
|
|
105
|
+
*/
|
|
106
|
+
constructor(scene) {
|
|
107
|
+
/**
|
|
108
|
+
* The component name helpful to identify the component in the list of scene components.
|
|
109
|
+
*/
|
|
110
|
+
this.name = SceneComponentConstants.NAME_PHYSICSENGINE;
|
|
111
|
+
this.scene = scene;
|
|
112
|
+
this.scene.onBeforePhysicsObservable = new Observable();
|
|
113
|
+
this.scene.onAfterPhysicsObservable = new Observable();
|
|
114
|
+
// Replace the function used to get the deterministic frame time
|
|
115
|
+
this.scene.getDeterministicFrameTime = () => {
|
|
116
|
+
if (this.scene._physicsEngine) {
|
|
117
|
+
return this.scene._physicsEngine.getTimeStep() * 1000;
|
|
118
|
+
}
|
|
119
|
+
return 1000.0 / 60.0;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Registers the component in a given scene
|
|
124
|
+
*/
|
|
125
|
+
register() { }
|
|
126
|
+
/**
|
|
127
|
+
* Rebuilds the elements related to this component in case of
|
|
128
|
+
* context lost for instance.
|
|
129
|
+
*/
|
|
130
|
+
rebuild() {
|
|
131
|
+
// Nothing to do for this component
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Disposes the component and the associated resources
|
|
135
|
+
*/
|
|
136
|
+
dispose() {
|
|
137
|
+
this.scene.onBeforePhysicsObservable.clear();
|
|
138
|
+
this.scene.onAfterPhysicsObservable.clear();
|
|
139
|
+
if (this.scene._physicsEngine) {
|
|
140
|
+
this.scene.disablePhysicsEngine();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=joinedPhysicsEngineComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"joinedPhysicsEngineComponent.js","sourceRoot":"","sources":["../../../../lts/core/generated/Physics/joinedPhysicsEngineComponent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIhD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAIjC,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAuDtE;;;GAGG;AACH,KAAK,CAAC,SAAS,CAAC,gBAAgB,GAAG;IAC/B,OAAO,IAAI,CAAC,cAAc,CAAC;AAC/B,CAAC,CAAC;AAEF;;;;;GAKG;AACH,KAAK,CAAC,SAAS,CAAC,aAAa,GAAG,UAAU,UAA6B,IAAI,EAAE,MAAwD;IACjI,IAAI,IAAI,CAAC,cAAc,EAAE;QACrB,OAAO,IAAI,CAAC;KACf;IAED,sCAAsC;IACtC,IAAI,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,uBAAuB,CAAC,kBAAkB,CAAgC,CAAC;IAC9G,IAAI,CAAC,SAAS,EAAE;QACZ,SAAS,GAAG,IAAI,2BAA2B,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;KACjC;IAED,IAAI;QACA,IAAI,CAAC,MAAM,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,gBAAgB,EAAE,MA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AK,CAAC,cAAc,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC;aACzD;YAED,OAAO,MAAM,GAAG,IAAI,CAAC;QACzB,CAAC,CAAC;IACN,CAAC;IAED;;OAEG;IACI,QAAQ,KAAU,CAAC;IAE1B;;;OAGG;IACI,OAAO;QACV,mCAAmC;IACvC,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,KAAK,CAAC,yBAAyB,CAAC,KAAK,EAAE,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,KAAK,EAAE,CAAC;QAE5C,IAAI,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE;YAC3B,IAAI,CAAC,KAAK,CAAC,oBAAoB,EAAE,CAAC;SACrC;IACL,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { Vector3 } from \"../Maths/math.vector\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { ISceneComponent } from \"../sceneComponent\";\r\nimport { SceneComponentConstants } from \"../sceneComponent\";\r\nimport { Scene } from \"../scene\";\r\nimport type { IPhysicsEngine } from \"./IPhysicsEngine\";\r\nimport type { IPhysicsEnginePlugin as IPhysicsEnginePluginV1 } from \"./v1/IPhysicsEnginePlugin\";\r\nimport type { IPhysicsEnginePluginV2 } from \"./v2/IPhysicsEnginePlugin\";\r\nimport { PhysicsEngine as PhysicsEngineV1 } from \"./v1/physicsEngine\";\r\nimport { PhysicsEngine as PhysicsEngineV2 } from \"./v2/physicsEngine\";\r\n\r\ndeclare module \"../scene\" {\r\n /**\r\n *\r\n */\r\n export interface Scene {\r\n /** @internal (Backing field) */\r\n _physicsEngine: Nullable<IPhysicsEngine>;\r\n /** @internal */\r\n _physicsTimeAccumulator: number;\r\n\r\n /**\r\n * Gets the current physics engine\r\n * @returns a IPhysicsEngine or null if none attached\r\n */\r\n getPhysicsEngine(): Nullable<IPhysicsEngine>;\r\n\r\n /**\r\n * Enables physics to the current scene\r\n * @param gravity defines the scene's gravity for the physics engine. defaults to real earth gravity : (0, -9.81, 0)\r\n * @param plugin defines the physics engine to be used. defaults to CannonJS.\r\n * @returns a boolean indicating if the physics engine was initialized\r\n */\r\n enablePhysics(gravity?: Nullable<Vector3>, plugin?: IPhysicsEnginePluginV1 | IPhysicsEnginePluginV2): boolean;\r\n\r\n /**\r\n * Disables and disposes the physics engine associated with the scene\r\n */\r\n disablePhysicsEngine(): void;\r\n\r\n /**\r\n * Gets a boolean indicating if there is an active physics engine\r\n * @returns a boolean indicating if there is an active physics engine\r\n */\r\n isPhysicsEnabled(): boolean;\r\n\r\n /**\r\n * Deletes a physics compound impostor\r\n * @param compound defines the compound to delete\r\n */\r\n deleteCompoundImpostor(compound: any): void;\r\n\r\n /**\r\n * An event triggered when physic simulation is about to be run\r\n */\r\n onBeforePhysicsObservable: Observable<Scene>;\r\n\r\n /**\r\n * An event triggered when physic simulation has been done\r\n */\r\n onAfterPhysicsObservable: Observable<Scene>;\r\n }\r\n}\r\n\r\n/**\r\n * Gets the current physics engine\r\n * @returns a IPhysicsEngine or null if none attached\r\n */\r\nScene.prototype.getPhysicsEngine = function (): Nullable<IPhysicsEngine> {\r\n return this._physicsEngine;\r\n};\r\n\r\n/**\r\n * Enables physics to the current scene\r\n * @param gravity defines the scene's gravity for the physics engine\r\n * @param plugin defines the physics engine to be used. defaults to CannonJS.\r\n * @returns a boolean indicating if the physics engine was initialized\r\n */\r\nScene.prototype.enablePhysics = function (gravity: Nullable<Vector3> = null, plugin?: IPhysicsEnginePluginV1 | IPhysicsEnginePluginV2): boolean {\r\n if (this._physicsEngine) {\r\n return true;\r\n }\r\n\r\n // Register the component to the scene\r\n let component = this._getComponent(SceneComponentConstants.NAME_PHYSICSENGINE) as PhysicsEngineSceneComponent;\r\n if (!component) {\r\n component = new PhysicsEngineSceneComponent(this);\r\n this._addComponent(component);\r\n }\r\n\r\n try {\r\n if (!plugin || plugin?.getPluginVersion() === 1) {\r\n this._physicsEngine = new PhysicsEngineV1(gravity, plugin as IPhysicsEnginePluginV1);\r\n } else if (plugin?.getPluginVersion() === 2) {\r\n this._physicsEngine = new PhysicsEngineV2(gravity, plugin as IPhysicsEnginePluginV2);\r\n } else {\r\n throw new Error(\"Unsupported Physics plugin version.\");\r\n }\r\n this._physicsTimeAccumulator = 0;\r\n return true;\r\n } catch (e) {\r\n Logger.Error(e.message);\r\n return false;\r\n }\r\n};\r\n\r\n/**\r\n * Disables and disposes the physics engine associated with the scene\r\n */\r\nScene.prototype.disablePhysicsEngine = function (): void {\r\n if (!this._physicsEngine) {\r\n return;\r\n }\r\n\r\n this._physicsEngine.dispose();\r\n this._physicsEngine = null;\r\n};\r\n\r\n/**\r\n * Gets a boolean indicating if there is an active physics engine\r\n * @returns a boolean indicating if there is an active physics engine\r\n */\r\nScene.prototype.isPhysicsEnabled = function (): boolean {\r\n return this._physicsEngine !== undefined;\r\n};\r\n\r\n/**\r\n * Deletes a physics compound impostor\r\n * @param compound defines the compound to delete\r\n */\r\nScene.prototype.deleteCompoundImpostor = function (compound: any): void {\r\n const mesh: AbstractMesh = compound.parts[0].mesh;\r\n\r\n if (mesh.physicsImpostor) {\r\n mesh.physicsImpostor.dispose(/*true*/);\r\n mesh.physicsImpostor = null;\r\n }\r\n};\r\n\r\n/**\r\n * @internal\r\n */\r\nScene.prototype._advancePhysicsEngineStep = function (step: number) {\r\n if (this._physicsEngine) {\r\n const subTime = this._physicsEngine.getSubTimeStep();\r\n if (subTime > 0) {\r\n this._physicsTimeAccumulator += step;\r\n while (this._physicsTimeAccumulator > subTime) {\r\n this.onBeforePhysicsObservable.notifyObservers(this);\r\n this._physicsEngine._step(subTime / 1000);\r\n this.onAfterPhysicsObservable.notifyObservers(this);\r\n this._physicsTimeAccumulator -= subTime;\r\n }\r\n } else {\r\n this.onBeforePhysicsObservable.notifyObservers(this);\r\n this._physicsEngine._step(step / 1000);\r\n this.onAfterPhysicsObservable.notifyObservers(this);\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Defines the physics engine scene component responsible to manage a physics engine\r\n */\r\nexport class PhysicsEngineSceneComponent implements ISceneComponent {\r\n /**\r\n * The component name helpful to identify the component in the list of scene components.\r\n */\r\n public readonly name = SceneComponentConstants.NAME_PHYSICSENGINE;\r\n\r\n /**\r\n * The scene the component belongs to.\r\n */\r\n public scene: Scene;\r\n\r\n /**\r\n * Creates a new instance of the component for the given scene\r\n * @param scene Defines the scene to register the component in\r\n */\r\n constructor(scene: Scene) {\r\n this.scene = scene;\r\n this.scene.onBeforePhysicsObservable = new Observable<Scene>();\r\n this.scene.onAfterPhysicsObservable = new Observable<Scene>();\r\n\r\n // Replace the function used to get the deterministic frame time\r\n this.scene.getDeterministicFrameTime = () => {\r\n if (this.scene._physicsEngine) {\r\n return this.scene._physicsEngine.getTimeStep() * 1000;\r\n }\r\n\r\n return 1000.0 / 60.0;\r\n };\r\n }\r\n\r\n /**\r\n * Registers the component in a given scene\r\n */\r\n public register(): void {}\r\n\r\n /**\r\n * Rebuilds the elements related to this component in case of\r\n * context lost for instance.\r\n */\r\n public rebuild(): void {\r\n // Nothing to do for this component\r\n }\r\n\r\n /**\r\n * Disposes the component and the associated resources\r\n */\r\n public dispose(): void {\r\n this.scene.onBeforePhysicsObservable.clear();\r\n this.scene.onAfterPhysicsObservable.clear();\r\n\r\n if (this.scene._physicsEngine) {\r\n this.scene.disablePhysicsEngine();\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -1,84 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import type { Vector3 } from "../Maths/math.vector";
|
|
4
|
-
import type { ISceneComponent } from "../sceneComponent";
|
|
5
|
-
import { Scene } from "../scene";
|
|
6
|
-
import type { IPhysicsEngine } from "./IPhysicsEngine";
|
|
7
|
-
import type { IPhysicsEnginePlugin as IPhysicsEnginePluginV1 } from "./v1/IPhysicsEnginePlugin";
|
|
8
|
-
import type { IPhysicsEnginePluginV2 } from "./v2/IPhysicsEnginePlugin";
|
|
9
|
-
declare module "../scene" {
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
interface Scene {
|
|
14
|
-
/** @internal (Backing field) */
|
|
15
|
-
_physicsEngine: Nullable<IPhysicsEngine>;
|
|
16
|
-
/** @internal */
|
|
17
|
-
_physicsTimeAccumulator: number;
|
|
18
|
-
/**
|
|
19
|
-
* Gets the current physics engine
|
|
20
|
-
* @returns a IPhysicsEngine or null if none attached
|
|
21
|
-
*/
|
|
22
|
-
getPhysicsEngine(): Nullable<IPhysicsEngine>;
|
|
23
|
-
/**
|
|
24
|
-
* Enables physics to the current scene
|
|
25
|
-
* @param gravity defines the scene's gravity for the physics engine. defaults to real earth gravity : (0, -9.81, 0)
|
|
26
|
-
* @param plugin defines the physics engine to be used. defaults to CannonJS.
|
|
27
|
-
* @returns a boolean indicating if the physics engine was initialized
|
|
28
|
-
*/
|
|
29
|
-
enablePhysics(gravity?: Nullable<Vector3>, plugin?: IPhysicsEnginePluginV1 | IPhysicsEnginePluginV2): boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Disables and disposes the physics engine associated with the scene
|
|
32
|
-
*/
|
|
33
|
-
disablePhysicsEngine(): void;
|
|
34
|
-
/**
|
|
35
|
-
* Gets a boolean indicating if there is an active physics engine
|
|
36
|
-
* @returns a boolean indicating if there is an active physics engine
|
|
37
|
-
*/
|
|
38
|
-
isPhysicsEnabled(): boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Deletes a physics compound impostor
|
|
41
|
-
* @param compound defines the compound to delete
|
|
42
|
-
*/
|
|
43
|
-
deleteCompoundImpostor(compound: any): void;
|
|
44
|
-
/**
|
|
45
|
-
* An event triggered when physic simulation is about to be run
|
|
46
|
-
*/
|
|
47
|
-
onBeforePhysicsObservable: Observable<Scene>;
|
|
48
|
-
/**
|
|
49
|
-
* An event triggered when physic simulation has been done
|
|
50
|
-
*/
|
|
51
|
-
onAfterPhysicsObservable: Observable<Scene>;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Defines the physics engine scene component responsible to manage a physics engine
|
|
56
|
-
*/
|
|
57
|
-
export declare class PhysicsEngineSceneComponent implements ISceneComponent {
|
|
58
|
-
/**
|
|
59
|
-
* The component name helpful to identify the component in the list of scene components.
|
|
60
|
-
*/
|
|
61
|
-
readonly name = "PhysicsEngine";
|
|
62
|
-
/**
|
|
63
|
-
* The scene the component belongs to.
|
|
64
|
-
*/
|
|
65
|
-
scene: Scene;
|
|
66
|
-
/**
|
|
67
|
-
* Creates a new instance of the component for the given scene
|
|
68
|
-
* @param scene Defines the scene to register the component in
|
|
69
|
-
*/
|
|
70
|
-
constructor(scene: Scene);
|
|
71
|
-
/**
|
|
72
|
-
* Registers the component in a given scene
|
|
73
|
-
*/
|
|
74
|
-
register(): void;
|
|
75
|
-
/**
|
|
76
|
-
* Rebuilds the elements related to this component in case of
|
|
77
|
-
* context lost for instance.
|
|
78
|
-
*/
|
|
79
|
-
rebuild(): void;
|
|
80
|
-
/**
|
|
81
|
-
* Disposes the component and the associated resources
|
|
82
|
-
*/
|
|
83
|
-
dispose(): void;
|
|
84
|
-
}
|
|
1
|
+
import "./joinedPhysicsEngineComponent";
|
|
2
|
+
import "./v1/physicsEngineComponent";
|
|
@@ -1,144 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { Scene } from "../scene.js";
|
|
5
|
-
import { PhysicsEngine as PhysicsEngineV1 } from "./v1/physicsEngine.js";
|
|
6
|
-
import { PhysicsEngine as PhysicsEngineV2 } from "./v2/physicsEngine.js";
|
|
7
|
-
/**
|
|
8
|
-
* Gets the current physics engine
|
|
9
|
-
* @returns a IPhysicsEngine or null if none attached
|
|
10
|
-
*/
|
|
11
|
-
Scene.prototype.getPhysicsEngine = function () {
|
|
12
|
-
return this._physicsEngine;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Enables physics to the current scene
|
|
16
|
-
* @param gravity defines the scene's gravity for the physics engine
|
|
17
|
-
* @param plugin defines the physics engine to be used. defaults to CannonJS.
|
|
18
|
-
* @returns a boolean indicating if the physics engine was initialized
|
|
19
|
-
*/
|
|
20
|
-
Scene.prototype.enablePhysics = function (gravity = null, plugin) {
|
|
21
|
-
if (this._physicsEngine) {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
// Register the component to the scene
|
|
25
|
-
let component = this._getComponent(SceneComponentConstants.NAME_PHYSICSENGINE);
|
|
26
|
-
if (!component) {
|
|
27
|
-
component = new PhysicsEngineSceneComponent(this);
|
|
28
|
-
this._addComponent(component);
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
if (!plugin || (plugin === null || plugin === void 0 ? void 0 : plugin.getPluginVersion()) === 1) {
|
|
32
|
-
this._physicsEngine = new PhysicsEngineV1(gravity, plugin);
|
|
33
|
-
}
|
|
34
|
-
else if ((plugin === null || plugin === void 0 ? void 0 : plugin.getPluginVersion()) === 2) {
|
|
35
|
-
this._physicsEngine = new PhysicsEngineV2(gravity, plugin);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
throw new Error("Unsupported Physics plugin version.");
|
|
39
|
-
}
|
|
40
|
-
this._physicsTimeAccumulator = 0;
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
catch (e) {
|
|
44
|
-
Logger.Error(e.message);
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Disables and disposes the physics engine associated with the scene
|
|
50
|
-
*/
|
|
51
|
-
Scene.prototype.disablePhysicsEngine = function () {
|
|
52
|
-
if (!this._physicsEngine) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
this._physicsEngine.dispose();
|
|
56
|
-
this._physicsEngine = null;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Gets a boolean indicating if there is an active physics engine
|
|
60
|
-
* @returns a boolean indicating if there is an active physics engine
|
|
61
|
-
*/
|
|
62
|
-
Scene.prototype.isPhysicsEnabled = function () {
|
|
63
|
-
return this._physicsEngine !== undefined;
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Deletes a physics compound impostor
|
|
67
|
-
* @param compound defines the compound to delete
|
|
68
|
-
*/
|
|
69
|
-
Scene.prototype.deleteCompoundImpostor = function (compound) {
|
|
70
|
-
const mesh = compound.parts[0].mesh;
|
|
71
|
-
if (mesh.physicsImpostor) {
|
|
72
|
-
mesh.physicsImpostor.dispose( /*true*/);
|
|
73
|
-
mesh.physicsImpostor = null;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* @internal
|
|
78
|
-
*/
|
|
79
|
-
Scene.prototype._advancePhysicsEngineStep = function (step) {
|
|
80
|
-
if (this._physicsEngine) {
|
|
81
|
-
const subTime = this._physicsEngine.getSubTimeStep();
|
|
82
|
-
if (subTime > 0) {
|
|
83
|
-
this._physicsTimeAccumulator += step;
|
|
84
|
-
while (this._physicsTimeAccumulator > subTime) {
|
|
85
|
-
this.onBeforePhysicsObservable.notifyObservers(this);
|
|
86
|
-
this._physicsEngine._step(subTime / 1000);
|
|
87
|
-
this.onAfterPhysicsObservable.notifyObservers(this);
|
|
88
|
-
this._physicsTimeAccumulator -= subTime;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
this.onBeforePhysicsObservable.notifyObservers(this);
|
|
93
|
-
this._physicsEngine._step(step / 1000);
|
|
94
|
-
this.onAfterPhysicsObservable.notifyObservers(this);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Defines the physics engine scene component responsible to manage a physics engine
|
|
100
|
-
*/
|
|
101
|
-
export class PhysicsEngineSceneComponent {
|
|
102
|
-
/**
|
|
103
|
-
* Creates a new instance of the component for the given scene
|
|
104
|
-
* @param scene Defines the scene to register the component in
|
|
105
|
-
*/
|
|
106
|
-
constructor(scene) {
|
|
107
|
-
/**
|
|
108
|
-
* The component name helpful to identify the component in the list of scene components.
|
|
109
|
-
*/
|
|
110
|
-
this.name = SceneComponentConstants.NAME_PHYSICSENGINE;
|
|
111
|
-
this.scene = scene;
|
|
112
|
-
this.scene.onBeforePhysicsObservable = new Observable();
|
|
113
|
-
this.scene.onAfterPhysicsObservable = new Observable();
|
|
114
|
-
// Replace the function used to get the deterministic frame time
|
|
115
|
-
this.scene.getDeterministicFrameTime = () => {
|
|
116
|
-
if (this.scene._physicsEngine) {
|
|
117
|
-
return this.scene._physicsEngine.getTimeStep() * 1000;
|
|
118
|
-
}
|
|
119
|
-
return 1000.0 / 60.0;
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Registers the component in a given scene
|
|
124
|
-
*/
|
|
125
|
-
register() { }
|
|
126
|
-
/**
|
|
127
|
-
* Rebuilds the elements related to this component in case of
|
|
128
|
-
* context lost for instance.
|
|
129
|
-
*/
|
|
130
|
-
rebuild() {
|
|
131
|
-
// Nothing to do for this component
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Disposes the component and the associated resources
|
|
135
|
-
*/
|
|
136
|
-
dispose() {
|
|
137
|
-
this.scene.onBeforePhysicsObservable.clear();
|
|
138
|
-
this.scene.onAfterPhysicsObservable.clear();
|
|
139
|
-
if (this.scene._physicsEngine) {
|
|
140
|
-
this.scene.disablePhysicsEngine();
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
1
|
+
// back compat
|
|
2
|
+
import "./joinedPhysicsEngineComponent.js";
|
|
3
|
+
import "./v1/physicsEngineComponent.js";
|
|
144
4
|
//# sourceMappingURL=physicsEngineComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physicsEngineComponent.js","sourceRoot":"","sources":["../../../../lts/core/generated/Physics/physicsEngineComponent.ts"],"names":[],"m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,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,KAAK,EAAE,CAAC;QAE5C,IAAI,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE;YAC3B,IAAI,CAAC,KAAK,CAAC,oBAAoB,EAAE,CAAC;SACrC;IACL,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { Vector3 } from \"../Maths/math.vector\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { ISceneComponent } from \"../sceneComponent\";\r\nimport { SceneComponentConstants } from \"../sceneComponent\";\r\nimport { Scene } from \"../scene\";\r\nimport type { IPhysicsEngine } from \"./IPhysicsEngine\";\r\nimport type { IPhysicsEnginePlugin as IPhysicsEnginePluginV1 } from \"./v1/IPhysicsEnginePlugin\";\r\nimport type { IPhysicsEnginePluginV2 } from \"./v2/IPhysicsEnginePlugin\";\r\nimport { PhysicsEngine as PhysicsEngineV1 } from \"./v1/physicsEngine\";\r\nimport { PhysicsEngine as PhysicsEngineV2 } from \"./v2/physicsEngine\";\r\n\r\ndeclare module \"../scene\" {\r\n /**\r\n *\r\n */\r\n export interface Scene {\r\n /** @internal (Backing field) */\r\n _physicsEngine: Nullable<IPhysicsEngine>;\r\n /** @internal */\r\n _physicsTimeAccumulator: number;\r\n\r\n /**\r\n * Gets the current physics engine\r\n * @returns a IPhysicsEngine or null if none attached\r\n */\r\n getPhysicsEngine(): Nullable<IPhysicsEngine>;\r\n\r\n /**\r\n * Enables physics to the current scene\r\n * @param gravity defines the scene's gravity for the physics engine. defaults to real earth gravity : (0, -9.81, 0)\r\n * @param plugin defines the physics engine to be used. defaults to CannonJS.\r\n * @returns a boolean indicating if the physics engine was initialized\r\n */\r\n enablePhysics(gravity?: Nullable<Vector3>, plugin?: IPhysicsEnginePluginV1 | IPhysicsEnginePluginV2): boolean;\r\n\r\n /**\r\n * Disables and disposes the physics engine associated with the scene\r\n */\r\n disablePhysicsEngine(): void;\r\n\r\n /**\r\n * Gets a boolean indicating if there is an active physics engine\r\n * @returns a boolean indicating if there is an active physics engine\r\n */\r\n isPhysicsEnabled(): boolean;\r\n\r\n /**\r\n * Deletes a physics compound impostor\r\n * @param compound defines the compound to delete\r\n */\r\n deleteCompoundImpostor(compound: any): void;\r\n\r\n /**\r\n * An event triggered when physic simulation is about to be run\r\n */\r\n onBeforePhysicsObservable: Observable<Scene>;\r\n\r\n /**\r\n * An event triggered when physic simulation has been done\r\n */\r\n onAfterPhysicsObservable: Observable<Scene>;\r\n }\r\n}\r\n\r\n/**\r\n * Gets the current physics engine\r\n * @returns a IPhysicsEngine or null if none attached\r\n */\r\nScene.prototype.getPhysicsEngine = function (): Nullable<IPhysicsEngine> {\r\n return this._physicsEngine;\r\n};\r\n\r\n/**\r\n * Enables physics to the current scene\r\n * @param gravity defines the scene's gravity for the physics engine\r\n * @param plugin defines the physics engine to be used. defaults to CannonJS.\r\n * @returns a boolean indicating if the physics engine was initialized\r\n */\r\nScene.prototype.enablePhysics = function (gravity: Nullable<Vector3> = null, plugin?: IPhysicsEnginePluginV1 | IPhysicsEnginePluginV2): boolean {\r\n if (this._physicsEngine) {\r\n return true;\r\n }\r\n\r\n // Register the component to the scene\r\n let component = this._getComponent(SceneComponentConstants.NAME_PHYSICSENGINE) as PhysicsEngineSceneComponent;\r\n if (!component) {\r\n component = new PhysicsEngineSceneComponent(this);\r\n this._addComponent(component);\r\n }\r\n\r\n try {\r\n if (!plugin || plugin?.getPluginVersion() === 1) {\r\n this._physicsEngine = new PhysicsEngineV1(gravity, plugin as IPhysicsEnginePluginV1);\r\n } else if (plugin?.getPluginVersion() === 2) {\r\n this._physicsEngine = new PhysicsEngineV2(gravity, plugin as IPhysicsEnginePluginV2);\r\n } else {\r\n throw new Error(\"Unsupported Physics plugin version.\");\r\n }\r\n this._physicsTimeAccumulator = 0;\r\n return true;\r\n } catch (e) {\r\n Logger.Error(e.message);\r\n return false;\r\n }\r\n};\r\n\r\n/**\r\n * Disables and disposes the physics engine associated with the scene\r\n */\r\nScene.prototype.disablePhysicsEngine = function (): void {\r\n if (!this._physicsEngine) {\r\n return;\r\n }\r\n\r\n this._physicsEngine.dispose();\r\n this._physicsEngine = null;\r\n};\r\n\r\n/**\r\n * Gets a boolean indicating if there is an active physics engine\r\n * @returns a boolean indicating if there is an active physics engine\r\n */\r\nScene.prototype.isPhysicsEnabled = function (): boolean {\r\n return this._physicsEngine !== undefined;\r\n};\r\n\r\n/**\r\n * Deletes a physics compound impostor\r\n * @param compound defines the compound to delete\r\n */\r\nScene.prototype.deleteCompoundImpostor = function (compound: any): void {\r\n const mesh: AbstractMesh = compound.parts[0].mesh;\r\n\r\n if (mesh.physicsImpostor) {\r\n mesh.physicsImpostor.dispose(/*true*/);\r\n mesh.physicsImpostor = null;\r\n }\r\n};\r\n\r\n/**\r\n * @internal\r\n */\r\nScene.prototype._advancePhysicsEngineStep = function (step: number) {\r\n if (this._physicsEngine) {\r\n const subTime = this._physicsEngine.getSubTimeStep();\r\n if (subTime > 0) {\r\n this._physicsTimeAccumulator += step;\r\n while (this._physicsTimeAccumulator > subTime) {\r\n this.onBeforePhysicsObservable.notifyObservers(this);\r\n this._physicsEngine._step(subTime / 1000);\r\n this.onAfterPhysicsObservable.notifyObservers(this);\r\n this._physicsTimeAccumulator -= subTime;\r\n }\r\n } else {\r\n this.onBeforePhysicsObservable.notifyObservers(this);\r\n this._physicsEngine._step(step / 1000);\r\n this.onAfterPhysicsObservable.notifyObservers(this);\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Defines the physics engine scene component responsible to manage a physics engine\r\n */\r\nexport class PhysicsEngineSceneComponent implements ISceneComponent {\r\n /**\r\n * The component name helpful to identify the component in the list of scene components.\r\n */\r\n public readonly name = SceneComponentConstants.NAME_PHYSICSENGINE;\r\n\r\n /**\r\n * The scene the component belongs to.\r\n */\r\n public scene: Scene;\r\n\r\n /**\r\n * Creates a new instance of the component for the given scene\r\n * @param scene Defines the scene to register the component in\r\n */\r\n constructor(scene: Scene) {\r\n this.scene = scene;\r\n this.scene.onBeforePhysicsObservable = new Observable<Scene>();\r\n this.scene.onAfterPhysicsObservable = new Observable<Scene>();\r\n\r\n // Replace the function used to get the deterministic frame time\r\n this.scene.getDeterministicFrameTime = () => {\r\n if (this.scene._physicsEngine) {\r\n return this.scene._physicsEngine.getTimeStep() * 1000;\r\n }\r\n\r\n return 1000.0 / 60.0;\r\n };\r\n }\r\n\r\n /**\r\n * Registers the component in a given scene\r\n */\r\n public register(): void {}\r\n\r\n /**\r\n * Rebuilds the elements related to this component in case of\r\n * context lost for instance.\r\n */\r\n public rebuild(): void {\r\n // Nothing to do for this component\r\n }\r\n\r\n /**\r\n * Disposes the component and the associated resources\r\n */\r\n public dispose(): void {\r\n this.scene.onBeforePhysicsObservable.clear();\r\n this.scene.onAfterPhysicsObservable.clear();\r\n\r\n if (this.scene._physicsEngine) {\r\n this.scene.disablePhysicsEngine();\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"physicsEngineComponent.js","sourceRoot":"","sources":["../../../../lts/core/generated/Physics/physicsEngineComponent.ts"],"names":[],"mappings":"AAAA,cAAc;AAEd,OAAO,gCAAgC,CAAC;AACxC,OAAO,6BAA6B,CAAC","sourcesContent":["// back compat\r\n\r\nimport \"./joinedPhysicsEngineComponent\";\r\nimport \"./v1/physicsEngineComponent\";\r\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Vector3, Quaternion } from "../../Maths/math.vector";
|
|
2
|
-
import type { AbstractMesh } from "../../Meshes/abstractMesh";
|
|
3
2
|
import type { PhysicsRaycastResult } from "../physicsRaycastResult";
|
|
4
3
|
import type { PhysicsBody } from "./physicsBody";
|
|
5
4
|
import type { PhysicsShape } from "./physicsShape";
|
|
@@ -58,7 +57,8 @@ export interface PhysicsShapeParameters {
|
|
|
58
57
|
pointB?: Vector3;
|
|
59
58
|
rotation?: Quaternion;
|
|
60
59
|
extents?: Vector3;
|
|
61
|
-
mesh?:
|
|
60
|
+
mesh?: Mesh;
|
|
61
|
+
includeChildMeshes?: boolean;
|
|
62
62
|
}
|
|
63
63
|
/** @internal */
|
|
64
64
|
export interface PhysicsConstraintParameters {
|
|
@@ -106,6 +106,8 @@ export interface IPhysicsEnginePluginV2 {
|
|
|
106
106
|
getPluginVersion(): number;
|
|
107
107
|
initBody(body: PhysicsBody, position: Vector3, orientation: Quaternion): void;
|
|
108
108
|
initBodyInstances(body: PhysicsBody, mesh: Mesh): void;
|
|
109
|
+
sync(body: PhysicsBody): void;
|
|
110
|
+
syncTransform(body: PhysicsBody, transformNode: TransformNode): void;
|
|
109
111
|
setShape(body: PhysicsBody, shape: PhysicsShape): void;
|
|
110
112
|
getShape(body: PhysicsBody): PhysicsShape;
|
|
111
113
|
setFilterGroup(body: PhysicsBody, group: number): void;
|