@babylonjs/core 5.45.0 → 5.45.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/Engines/thinEngine.js +2 -2
- package/Engines/thinEngine.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/perturbNormalBlock.d.ts +7 -0
- package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js +30 -1
- package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js.map +1 -1
- package/Materials/Textures/texture.d.ts +2 -2
- package/Materials/Textures/texture.js +2 -2
- package/Materials/Textures/texture.js.map +1 -1
- package/Materials/clipPlaneMaterialHelper.js +22 -19
- package/Materials/clipPlaneMaterialHelper.js.map +1 -1
- package/Misc/khronosTextureContainer2.js +3 -5
- package/Misc/khronosTextureContainer2.js.map +1 -1
- package/Physics/v2/IPhysicsEnginePlugin.d.ts +6 -0
- package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
- package/Physics/v2/physicsAggregate.d.ts +21 -19
- package/Physics/v2/physicsAggregate.js +18 -4
- package/Physics/v2/physicsAggregate.js.map +1 -1
- package/Physics/v2/physicsBody.d.ts +15 -0
- package/Physics/v2/physicsBody.js +17 -0
- package/Physics/v2/physicsBody.js.map +1 -1
- package/Physics/v2/physicsShape.d.ts +30 -44
- package/Physics/v2/physicsShape.js +30 -44
- package/Physics/v2/physicsShape.js.map +1 -1
- package/Shaders/ShadersInclude/bumpFragment.js +1 -0
- package/Shaders/ShadersInclude/bumpFragment.js.map +1 -1
- package/Shaders/ShadersInclude/bumpFragmentMainFunctions.js +1 -1
- package/Shaders/ShadersInclude/bumpFragmentMainFunctions.js.map +1 -1
- package/Shaders/sprites.fragment.js +1 -1
- package/Shaders/sprites.fragment.js.map +1 -1
- package/assetContainer.js +1 -1
- package/assetContainer.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"khronosTextureContainer2.js","sourceRoot":"","sources":["../../../../lts/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EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;gBACpE,CAAC,CAAC,CAAC;gBACP,MAAM;SACb;IACL,CAAC,CAAC;AACN,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { AutoReleaseWorkerPool } from \"./workerPool\";\r\nimport { Tools } from \"./tools\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { ICompressedFormatCapabilities, IDecodedData, IKTX2DecoderOptions } from \"core/Materials/Textures/ktx2decoderTypes\";\r\nimport { EngineFormat, TranscodeTarget } from \"core/Materials/Textures/ktx2decoderTypes\";\r\n\r\ndeclare let KTX2DECODER: any;\r\n\r\nfunction getAbsoluteUrlOrNull(url: Nullable<string>): Nullable<string> {\r\n return url ? Tools.GetAbsoluteUrl(url) : null;\r\n}\r\n\r\nfunction applyConfig(urls: typeof KhronosTextureContainer2.URLConfig): void {\r\n if (urls.wasmUASTCToASTC !== null) {\r\n KTX2DECODER.LiteTranscoder_UASTC_ASTC.WasmModuleURL = urls.wasmUASTCToASTC;\r\n }\r\n\r\n if (urls.wasmUASTCToBC7 !== null) {\r\n KTX2DECODER.LiteTranscoder_UASTC_BC7.WasmModuleURL = urls.wasmUASTCToBC7;\r\n }\r\n\r\n if (urls.wasmUASTCToRGBA_UNORM !== null) {\r\n KTX2DECODER.LiteTranscoder_UASTC_RGBA_UNORM.WasmModuleURL = urls.wasmUASTCToRGBA_UNORM;\r\n }\r\n\r\n if (urls.wasmUASTCToRGBA_SRGB !== null) {\r\n KTX2DECODER.LiteTranscoder_UASTC_RGBA_SRGB.WasmModuleURL = urls.wasmUASTCToRGBA_SRGB;\r\n }\r\n\r\n if (urls.wasmUASTCToR8_UNORM !== null) {\r\n KTX2DECODER.LiteTranscoder_UASTC_R8_UNORM.WasmModuleURL = urls.wasmUASTCToR8_UNORM;\r\n }\r\n\r\n if (urls.wasmUASTCToRG8_UNORM !== null) {\r\n KTX2DECODER.LiteTranscoder_UASTC_RG8_UNORM.WasmModuleURL = urls.wasmUASTCToRG8_UNORM;\r\n }\r\n\r\n if (urls.jsMSCTranscoder !== null) {\r\n KTX2DECODER.MSCTranscoder.JSModuleURL = urls.jsMSCTranscoder;\r\n }\r\n\r\n if (urls.wasmMSCTranscoder !== null) {\r\n KTX2DECODER.MSCTranscoder.WasmModuleURL = urls.wasmMSCTranscoder;\r\n }\r\n\r\n if (urls.wasmZSTDDecoder !== null) {\r\n KTX2DECODER.ZSTDDecoder.WasmModuleURL = urls.wasmZSTDDecoder;\r\n }\r\n}\r\n\r\n/**\r\n * Class that defines the default KTX2 decoder options.\r\n *\r\n * This class is useful for providing options to the KTX2 decoder to control how the source data is transcoded.\r\n */\r\nexport class DefaultKTX2DecoderOptions {\r\n private _isDirty = true;\r\n\r\n /**\r\n * Gets the dirty flag\r\n */\r\n public get isDirty() {\r\n return this._isDirty;\r\n }\r\n\r\n private _useRGBAIfASTCBC7NotAvailableWhenUASTC?: boolean;\r\n /**\r\n * force a (uncompressed) RGBA transcoded format if transcoding a UASTC source format and ASTC + BC7 are not available as a compressed transcoded format\r\n */\r\n public get useRGBAIfASTCBC7NotAvailableWhenUASTC() {\r\n return this._useRGBAIfASTCBC7NotAvailableWhenUASTC;\r\n }\r\n\r\n public set useRGBAIfASTCBC7NotAvailableWhenUASTC(value: boolean | undefined) {\r\n if (this._useRGBAIfASTCBC7NotAvailableWhenUASTC === value) {\r\n return;\r\n }\r\n this._useRGBAIfASTCBC7NotAvailableWhenUASTC = value;\r\n this._isDirty = true;\r\n }\r\n\r\n private _useRGBAIfOnlyBC1BC3AvailableWhenUASTC = true;\r\n /**\r\n * force a (uncompressed) RGBA transcoded format if transcoding a UASTC source format and only BC1 or BC3 are available as a compressed transcoded format.\r\n * This property is true by default to favor speed over memory, because currently transcoding from UASTC to BC1/3 is slow because the transcoder transcodes\r\n * to uncompressed and then recompresses the texture\r\n */\r\n public get useRGBAIfOnlyBC1BC3AvailableWhenUASTC() {\r\n return this._useRGBAIfOnlyBC1BC3AvailableWhenUASTC;\r\n }\r\n\r\n public set useRGBAIfOnlyBC1BC3AvailableWhenUASTC(value: boolean) {\r\n if (this._useRGBAIfOnlyBC1BC3AvailableWhenUASTC === value) {\r\n return;\r\n }\r\n this._useRGBAIfOnlyBC1BC3AvailableWhenUASTC = value;\r\n this._isDirty = true;\r\n }\r\n\r\n private _forceRGBA?: boolean;\r\n /**\r\n * force to always use (uncompressed) RGBA for transcoded format\r\n */\r\n public get forceRGBA() {\r\n return this._forceRGBA;\r\n }\r\n\r\n public set forceRGBA(value: boolean | undefined) {\r\n if (this._forceRGBA === value) {\r\n return;\r\n }\r\n this._forceRGBA = value;\r\n this._isDirty = true;\r\n }\r\n\r\n private _forceR8?: boolean;\r\n /**\r\n * force to always use (uncompressed) R8 for transcoded format\r\n */\r\n public get forceR8() {\r\n return this._forceR8;\r\n }\r\n\r\n public set forceR8(value: boolean | undefined) {\r\n if (this._forceR8 === value) {\r\n return;\r\n }\r\n this._forceR8 = value;\r\n this._isDirty = true;\r\n }\r\n\r\n private _forceRG8?: boolean;\r\n /**\r\n * force to always use (uncompressed) RG8 for transcoded format\r\n */\r\n public get forceRG8() {\r\n return this._forceRG8;\r\n }\r\n\r\n public set forceRG8(value: boolean | undefined) {\r\n if (this._forceRG8 === value) {\r\n return;\r\n }\r\n this._forceRG8 = value;\r\n this._isDirty = true;\r\n }\r\n\r\n private _bypassTranscoders?: string[];\r\n /**\r\n * list of transcoders to bypass when looking for a suitable transcoder. The available transcoders are:\r\n * UniversalTranscoder_UASTC_ASTC\r\n * UniversalTranscoder_UASTC_BC7\r\n * UniversalTranscoder_UASTC_RGBA_UNORM\r\n * UniversalTranscoder_UASTC_RGBA_SRGB\r\n * UniversalTranscoder_UASTC_R8_UNORM\r\n * UniversalTranscoder_UASTC_RG8_UNORM\r\n * MSCTranscoder\r\n */\r\n public get bypassTranscoders() {\r\n return this._bypassTranscoders;\r\n }\r\n\r\n public set bypassTranscoders(value: string[] | undefined) {\r\n if (this._bypassTranscoders === value) {\r\n return;\r\n }\r\n this._bypassTranscoders = value;\r\n this._isDirty = true;\r\n }\r\n\r\n private _ktx2DecoderOptions: IKTX2DecoderOptions = {};\r\n\r\n /** @internal */\r\n public _getKTX2DecoderOptions(): IKTX2DecoderOptions {\r\n if (!this._isDirty) {\r\n return this._ktx2DecoderOptions;\r\n }\r\n\r\n this._isDirty = false;\r\n\r\n const options: IKTX2DecoderOptions = {\r\n useRGBAIfASTCBC7NotAvailableWhenUASTC: this._useRGBAIfASTCBC7NotAvailableWhenUASTC,\r\n forceRGBA: this._forceRGBA,\r\n forceR8: this._forceR8,\r\n forceRG8: this._forceRG8,\r\n bypassTranscoders: this._bypassTranscoders,\r\n };\r\n\r\n if (this.useRGBAIfOnlyBC1BC3AvailableWhenUASTC) {\r\n options.transcodeFormatDecisionTree = {\r\n UASTC: {\r\n transcodeFormat: [TranscodeTarget.BC1_RGB, TranscodeTarget.BC3_RGBA],\r\n yes: {\r\n transcodeFormat: TranscodeTarget.RGBA32,\r\n engineFormat: EngineFormat.RGBA8Format,\r\n roundToMultiple4: false,\r\n },\r\n },\r\n };\r\n }\r\n\r\n this._ktx2DecoderOptions = options;\r\n\r\n return options;\r\n }\r\n}\r\n\r\n/**\r\n * Class for loading KTX2 files\r\n */\r\nexport class KhronosTextureContainer2 {\r\n private static _WorkerPoolPromise?: Promise<AutoReleaseWorkerPool>;\r\n private static _DecoderModulePromise?: Promise<any>;\r\n\r\n /**\r\n * URLs to use when loading the KTX2 decoder module as well as its dependencies\r\n * If a url is null, the default url is used (pointing to https://preview.babylonjs.com)\r\n * Note that jsDecoderModule can't be null and that the other dependencies will only be loaded if necessary\r\n * Urls you can change:\r\n * URLConfig.jsDecoderModule\r\n * URLConfig.wasmUASTCToASTC\r\n * URLConfig.wasmUASTCToBC7\r\n * URLConfig.wasmUASTCToRGBA_UNORM\r\n * URLConfig.wasmUASTCToRGBA_SRGB\r\n * URLConfig.wasmUASTCToR8_UNORM\r\n * URLConfig.wasmUASTCToRG8_UNORM\r\n * URLConfig.jsMSCTranscoder\r\n * URLConfig.wasmMSCTranscoder\r\n * URLConfig.wasmZSTDDecoder\r\n * You can see their default values in this PG: https://playground.babylonjs.com/#EIJH8L#29\r\n */\r\n public static URLConfig: {\r\n jsDecoderModule: string;\r\n wasmUASTCToASTC: Nullable<string>;\r\n wasmUASTCToBC7: Nullable<string>;\r\n wasmUASTCToRGBA_UNORM: Nullable<string>;\r\n wasmUASTCToRGBA_SRGB: Nullable<string>;\r\n wasmUASTCToR8_UNORM: Nullable<string>;\r\n wasmUASTCToRG8_UNORM: Nullable<string>;\r\n jsMSCTranscoder: Nullable<string>;\r\n wasmMSCTranscoder: Nullable<string>;\r\n wasmZSTDDecoder: Nullable<string>;\r\n } = {\r\n jsDecoderModule: \"https://preview.babylonjs.com/babylon.ktx2Decoder.js\",\r\n wasmUASTCToASTC: null,\r\n wasmUASTCToBC7: null,\r\n wasmUASTCToRGBA_UNORM: null,\r\n wasmUASTCToRGBA_SRGB: null,\r\n wasmUASTCToR8_UNORM: null,\r\n wasmUASTCToRG8_UNORM: null,\r\n jsMSCTranscoder: null,\r\n wasmMSCTranscoder: null,\r\n wasmZSTDDecoder: null,\r\n };\r\n\r\n /**\r\n * Default number of workers used to handle data decoding\r\n */\r\n public static DefaultNumWorkers = KhronosTextureContainer2.GetDefaultNumWorkers();\r\n\r\n /**\r\n * Default configuration for the KTX2 decoder.\r\n * The options defined in this way have priority over those passed when creating a KTX2 texture with new Texture(...).\r\n */\r\n public static DefaultDecoderOptions = new DefaultKTX2DecoderOptions();\r\n\r\n private static GetDefaultNumWorkers(): number {\r\n if (typeof navigator !== \"object\" || !navigator.hardwareConcurrency) {\r\n return 1;\r\n }\r\n\r\n // Use 50% of the available logical processors but capped at 4.\r\n return Math.min(Math.floor(navigator.hardwareConcurrency * 0.5), 4);\r\n }\r\n\r\n private _engine: ThinEngine;\r\n\r\n private static _Initialize(numWorkers: number): void {\r\n if (KhronosTextureContainer2._WorkerPoolPromise || KhronosTextureContainer2._DecoderModulePromise) {\r\n return;\r\n }\r\n\r\n const urls = {\r\n jsDecoderModule: Tools.GetAbsoluteUrl(this.URLConfig.jsDecoderModule),\r\n wasmUASTCToASTC: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToASTC),\r\n wasmUASTCToBC7: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToBC7),\r\n wasmUASTCToRGBA_UNORM: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToRGBA_UNORM),\r\n wasmUASTCToRGBA_SRGB: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToRGBA_SRGB),\r\n wasmUASTCToR8_UNORM: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToR8_UNORM),\r\n wasmUASTCToRG8_UNORM: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToRG8_UNORM),\r\n jsMSCTranscoder: getAbsoluteUrlOrNull(this.URLConfig.jsMSCTranscoder),\r\n wasmMSCTranscoder: getAbsoluteUrlOrNull(this.URLConfig.wasmMSCTranscoder),\r\n wasmZSTDDecoder: getAbsoluteUrlOrNull(this.URLConfig.wasmZSTDDecoder),\r\n };\r\n\r\n if (numWorkers && typeof Worker === \"function\" && typeof URL !== \"undefined\") {\r\n KhronosTextureContainer2._WorkerPoolPromise = new Promise((resolve) => {\r\n const workerContent = `${applyConfig}(${workerFunc})()`;\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n resolve(\r\n new AutoReleaseWorkerPool(\r\n numWorkers,\r\n () =>\r\n new Promise((resolve, reject) => {\r\n const worker = new Worker(workerBlobUrl);\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n };\r\n\r\n const onMessage = (message: MessageEvent) => {\r\n if (message.data.action === \"init\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(worker);\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n worker.postMessage({\r\n action: \"init\",\r\n urls: urls,\r\n });\r\n })\r\n )\r\n );\r\n });\r\n } else if (typeof KTX2DECODER === \"undefined\") {\r\n KhronosTextureContainer2._DecoderModulePromise = Tools.LoadScriptAsync(urls.jsDecoderModule).then(() => {\r\n KTX2DECODER.MSCTranscoder.UseFromWorkerThread = false;\r\n KTX2DECODER.WASMMemoryManager.LoadBinariesFromCurrentThread = true;\r\n applyConfig(urls);\r\n return new KTX2DECODER.KTX2Decoder();\r\n });\r\n } else {\r\n KTX2DECODER.MSCTranscoder.UseFromWorkerThread = false;\r\n KTX2DECODER.WASMMemoryManager.LoadBinariesFromCurrentThread = true;\r\n KhronosTextureContainer2._DecoderModulePromise = Promise.resolve(new KTX2DECODER.KTX2Decoder());\r\n }\r\n }\r\n\r\n /**\r\n * Constructor\r\n * @param engine The engine to use\r\n * @param numWorkers The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n public constructor(engine: ThinEngine, numWorkers = KhronosTextureContainer2.DefaultNumWorkers) {\r\n this._engine = engine;\r\n\r\n KhronosTextureContainer2._Initialize(numWorkers);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public uploadAsync(data: ArrayBufferView, internalTexture: InternalTexture, options?: IKTX2DecoderOptions & IDecodedData): Promise<void> {\r\n const caps = this._engine.getCaps();\r\n\r\n const compressedTexturesCaps: ICompressedFormatCapabilities = {\r\n astc: !!caps.astc,\r\n bptc: !!caps.bptc,\r\n s3tc: !!caps.s3tc,\r\n pvrtc: !!caps.pvrtc,\r\n etc2: !!caps.etc2,\r\n etc1: !!caps.etc1,\r\n };\r\n\r\n if (KhronosTextureContainer2._WorkerPoolPromise) {\r\n return KhronosTextureContainer2._WorkerPoolPromise.then((workerPool) => {\r\n return new Promise((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (message: MessageEvent) => {\r\n if (message.data.action === \"decoded\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n if (!message.data.success) {\r\n reject({ message: message.data.msg });\r\n } else {\r\n try {\r\n this._createTexture(message.data.decodedData, internalTexture, options);\r\n resolve();\r\n } catch (err) {\r\n reject({ message: err });\r\n }\r\n }\r\n onComplete();\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n const dataCopy = new Uint8Array(data.byteLength);\r\n dataCopy.set(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));\r\n\r\n if (KhronosTextureContainer2.DefaultDecoderOptions.isDirty) {\r\n worker.postMessage({ action: \"setDefaultDecoderOptions\", options: KhronosTextureContainer2.DefaultDecoderOptions._getKTX2DecoderOptions() }, [\r\n dataCopy.buffer,\r\n ]);\r\n }\r\n\r\n worker.postMessage({ action: \"decode\", data: dataCopy, caps: compressedTexturesCaps, options }, [dataCopy.buffer]);\r\n });\r\n });\r\n });\r\n } else if (KhronosTextureContainer2._DecoderModulePromise) {\r\n return KhronosTextureContainer2._DecoderModulePromise.then((decoder) => {\r\n return new Promise((resolve, reject) => {\r\n decoder\r\n .decode(data, caps)\r\n .then((data: IDecodedData) => {\r\n this._createTexture(data, internalTexture);\r\n resolve();\r\n })\r\n .catch((reason: any) => {\r\n reject({ message: reason });\r\n });\r\n });\r\n });\r\n }\r\n\r\n throw new Error(\"KTX2 decoder module is not available\");\r\n }\r\n\r\n protected _createTexture(data: IDecodedData, internalTexture: InternalTexture, options?: IKTX2DecoderOptions & IDecodedData): void {\r\n const oglTexture2D = 3553; // gl.TEXTURE_2D\r\n\r\n this._engine._bindTextureDirectly(oglTexture2D, internalTexture);\r\n\r\n if (options) {\r\n // return back some information about the decoded data\r\n options.transcodedFormat = data.transcodedFormat;\r\n options.isInGammaSpace = data.isInGammaSpace;\r\n options.hasAlpha = data.hasAlpha;\r\n options.transcoderName = data.transcoderName;\r\n }\r\n\r\n let isUncompressedFormat = true;\r\n\r\n switch (data.transcodedFormat) {\r\n case 0x8058 /* RGBA8 */:\r\n internalTexture.type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n internalTexture.format = Constants.TEXTUREFORMAT_RGBA;\r\n break;\r\n case 0x8229 /* R8 */:\r\n internalTexture.type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n internalTexture.format = Constants.TEXTUREFORMAT_R;\r\n break;\r\n case 0x822b /* RG8 */:\r\n internalTexture.type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n internalTexture.format = Constants.TEXTUREFORMAT_RG;\r\n break;\r\n default:\r\n internalTexture.format = data.transcodedFormat;\r\n isUncompressedFormat = false;\r\n break;\r\n }\r\n\r\n internalTexture._gammaSpace = data.isInGammaSpace;\r\n internalTexture.generateMipMaps = data.mipmaps.length > 1;\r\n\r\n if (data.errors) {\r\n throw new Error(\"KTX2 container - could not transcode the data. \" + data.errors);\r\n }\r\n\r\n for (let t = 0; t < data.mipmaps.length; ++t) {\r\n const mipmap = data.mipmaps[t];\r\n\r\n if (!mipmap || !mipmap.data) {\r\n throw new Error(\"KTX2 container - could not transcode one of the image\");\r\n }\r\n\r\n if (isUncompressedFormat) {\r\n // uncompressed RGBA / R8 / RG8\r\n internalTexture.width = mipmap.width; // need to set width/height so that the call to _uploadDataToTextureDirectly uses the right dimensions\r\n internalTexture.height = mipmap.height;\r\n\r\n this._engine._uploadDataToTextureDirectly(internalTexture, mipmap.data, 0, t, undefined, true);\r\n } else {\r\n this._engine._uploadCompressedDataToTextureDirectly(internalTexture, data.transcodedFormat, mipmap.width, mipmap.height, mipmap.data, 0, t);\r\n }\r\n }\r\n\r\n internalTexture._extension = \".ktx2\";\r\n internalTexture.width = data.mipmaps[0].width;\r\n internalTexture.height = data.mipmaps[0].height;\r\n internalTexture.isReady = true;\r\n\r\n this._engine._bindTextureDirectly(oglTexture2D, null);\r\n }\r\n\r\n /**\r\n * Checks if the given data starts with a KTX2 file identifier.\r\n * @param data the data to check\r\n * @returns true if the data is a KTX2 file or false otherwise\r\n */\r\n public static IsValid(data: ArrayBufferView): boolean {\r\n if (data.byteLength >= 12) {\r\n // '«', 'K', 'T', 'X', ' ', '2', '0', '»', '\\r', '\\n', '\\x1A', '\\n'\r\n const identifier = new Uint8Array(data.buffer, data.byteOffset, 12);\r\n if (\r\n identifier[0] === 0xab &&\r\n identifier[1] === 0x4b &&\r\n identifier[2] === 0x54 &&\r\n identifier[3] === 0x58 &&\r\n identifier[4] === 0x20 &&\r\n identifier[5] === 0x32 &&\r\n identifier[6] === 0x30 &&\r\n identifier[7] === 0xbb &&\r\n identifier[8] === 0x0d &&\r\n identifier[9] === 0x0a &&\r\n identifier[10] === 0x1a &&\r\n identifier[11] === 0x0a\r\n ) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n}\r\n\r\ndeclare function importScripts(...urls: string[]): void;\r\ndeclare function postMessage(message: any, transfer?: any[]): void;\r\n\r\nfunction workerFunc(): void {\r\n let ktx2Decoder: any;\r\n\r\n onmessage = (event) => {\r\n if (!event.data) {\r\n return;\r\n }\r\n switch (event.data.action) {\r\n case \"init\": {\r\n const urls = event.data.urls;\r\n importScripts(urls.jsDecoderModule);\r\n applyConfig(urls);\r\n ktx2Decoder = new KTX2DECODER.KTX2Decoder();\r\n postMessage({ action: \"init\" });\r\n break;\r\n }\r\n case \"setDefaultDecoderOptions\": {\r\n KTX2DECODER.KTX2Decoder.DefaultDecoderOptions = event.data.options;\r\n break;\r\n }\r\n case \"decode\":\r\n ktx2Decoder\r\n .decode(event.data.data, event.data.caps, event.data.options)\r\n .then((data: IDecodedData) => {\r\n const buffers = [];\r\n for (let mip = 0; mip < data.mipmaps.length; ++mip) {\r\n const mipmap = data.mipmaps[mip];\r\n if (mipmap && mipmap.data) {\r\n buffers.push(mipmap.data.buffer);\r\n }\r\n }\r\n postMessage({ action: \"decoded\", success: true, decodedData: data }, buffers);\r\n })\r\n .catch((reason: any) => {\r\n postMessage({ action: \"decoded\", success: false, msg: reason });\r\n });\r\n break;\r\n }\r\n };\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"khronosTextureContainer2.js","sourceRoot":"","sources":["../../../../lts/core/generated/Misc/khronosTextureContainer2.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,kDAAiD;AAIzF,SAAS,oBAAoB,CAAC,GAAqB;IAC/C,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAClD,CAAC;AAED,SAAS,WAAW,CAAC,IAA+C;IAChE,IAAI,IAAI,CAAC,eAAe,KAAK,IAAI,EAAE;QAC/B,WAAW,CAAC,yBAAyB,CAAC,aAAa,GAAG,IAAI,CAAC,eAAe,CAAC;KAC9E;IAED,IAAI,IAAI,CAAC,cAAc,KAAK,IAAI,EAAE;QAC9B,WAAW,CAAC,wBAAwB,CAAC,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC;KAC5E;IAED,IAAI,IAAI,CAAC,qBAAqB,KAAK,IAAI,EAAE;QACrC,WAAW,CAAC,+BAA+B,CAAC,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAAC;KAC1F;IAED,IAAI,IAAI,CAAC,oBAAoB,KAAK,IAAI,EAAE;QACpC,WAAW,C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vB,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;yBACpC;qBACJ;oBACD,WAAW,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;gBAClF,CAAC,CAAC;qBACD,KAAK,CAAC,CAAC,MAAW,EAAE,EAAE;oBACnB,WAAW,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;gBACpE,CAAC,CAAC,CAAC;gBACP,MAAM;SACb;IACL,CAAC,CAAC;AACN,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { AutoReleaseWorkerPool } from \"./workerPool\";\r\nimport { Tools } from \"./tools\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { ICompressedFormatCapabilities, IDecodedData, IKTX2DecoderOptions } from \"core/Materials/Textures/ktx2decoderTypes\";\r\nimport { EngineFormat, TranscodeTarget } from \"core/Materials/Textures/ktx2decoderTypes\";\r\n\r\ndeclare let KTX2DECODER: any;\r\n\r\nfunction getAbsoluteUrlOrNull(url: Nullable<string>): Nullable<string> {\r\n return url ? Tools.GetAbsoluteUrl(url) : null;\r\n}\r\n\r\nfunction applyConfig(urls: typeof KhronosTextureContainer2.URLConfig): void {\r\n if (urls.wasmUASTCToASTC !== null) {\r\n KTX2DECODER.LiteTranscoder_UASTC_ASTC.WasmModuleURL = urls.wasmUASTCToASTC;\r\n }\r\n\r\n if (urls.wasmUASTCToBC7 !== null) {\r\n KTX2DECODER.LiteTranscoder_UASTC_BC7.WasmModuleURL = urls.wasmUASTCToBC7;\r\n }\r\n\r\n if (urls.wasmUASTCToRGBA_UNORM !== null) {\r\n KTX2DECODER.LiteTranscoder_UASTC_RGBA_UNORM.WasmModuleURL = urls.wasmUASTCToRGBA_UNORM;\r\n }\r\n\r\n if (urls.wasmUASTCToRGBA_SRGB !== null) {\r\n KTX2DECODER.LiteTranscoder_UASTC_RGBA_SRGB.WasmModuleURL = urls.wasmUASTCToRGBA_SRGB;\r\n }\r\n\r\n if (urls.wasmUASTCToR8_UNORM !== null) {\r\n KTX2DECODER.LiteTranscoder_UASTC_R8_UNORM.WasmModuleURL = urls.wasmUASTCToR8_UNORM;\r\n }\r\n\r\n if (urls.wasmUASTCToRG8_UNORM !== null) {\r\n KTX2DECODER.LiteTranscoder_UASTC_RG8_UNORM.WasmModuleURL = urls.wasmUASTCToRG8_UNORM;\r\n }\r\n\r\n if (urls.jsMSCTranscoder !== null) {\r\n KTX2DECODER.MSCTranscoder.JSModuleURL = urls.jsMSCTranscoder;\r\n }\r\n\r\n if (urls.wasmMSCTranscoder !== null) {\r\n KTX2DECODER.MSCTranscoder.WasmModuleURL = urls.wasmMSCTranscoder;\r\n }\r\n\r\n if (urls.wasmZSTDDecoder !== null) {\r\n KTX2DECODER.ZSTDDecoder.WasmModuleURL = urls.wasmZSTDDecoder;\r\n }\r\n}\r\n\r\n/**\r\n * Class that defines the default KTX2 decoder options.\r\n *\r\n * This class is useful for providing options to the KTX2 decoder to control how the source data is transcoded.\r\n */\r\nexport class DefaultKTX2DecoderOptions {\r\n private _isDirty = true;\r\n\r\n /**\r\n * Gets the dirty flag\r\n */\r\n public get isDirty() {\r\n return this._isDirty;\r\n }\r\n\r\n private _useRGBAIfASTCBC7NotAvailableWhenUASTC?: boolean;\r\n /**\r\n * force a (uncompressed) RGBA transcoded format if transcoding a UASTC source format and ASTC + BC7 are not available as a compressed transcoded format\r\n */\r\n public get useRGBAIfASTCBC7NotAvailableWhenUASTC() {\r\n return this._useRGBAIfASTCBC7NotAvailableWhenUASTC;\r\n }\r\n\r\n public set useRGBAIfASTCBC7NotAvailableWhenUASTC(value: boolean | undefined) {\r\n if (this._useRGBAIfASTCBC7NotAvailableWhenUASTC === value) {\r\n return;\r\n }\r\n this._useRGBAIfASTCBC7NotAvailableWhenUASTC = value;\r\n this._isDirty = true;\r\n }\r\n\r\n private _useRGBAIfOnlyBC1BC3AvailableWhenUASTC = true;\r\n /**\r\n * force a (uncompressed) RGBA transcoded format if transcoding a UASTC source format and only BC1 or BC3 are available as a compressed transcoded format.\r\n * This property is true by default to favor speed over memory, because currently transcoding from UASTC to BC1/3 is slow because the transcoder transcodes\r\n * to uncompressed and then recompresses the texture\r\n */\r\n public get useRGBAIfOnlyBC1BC3AvailableWhenUASTC() {\r\n return this._useRGBAIfOnlyBC1BC3AvailableWhenUASTC;\r\n }\r\n\r\n public set useRGBAIfOnlyBC1BC3AvailableWhenUASTC(value: boolean) {\r\n if (this._useRGBAIfOnlyBC1BC3AvailableWhenUASTC === value) {\r\n return;\r\n }\r\n this._useRGBAIfOnlyBC1BC3AvailableWhenUASTC = value;\r\n this._isDirty = true;\r\n }\r\n\r\n private _forceRGBA?: boolean;\r\n /**\r\n * force to always use (uncompressed) RGBA for transcoded format\r\n */\r\n public get forceRGBA() {\r\n return this._forceRGBA;\r\n }\r\n\r\n public set forceRGBA(value: boolean | undefined) {\r\n if (this._forceRGBA === value) {\r\n return;\r\n }\r\n this._forceRGBA = value;\r\n this._isDirty = true;\r\n }\r\n\r\n private _forceR8?: boolean;\r\n /**\r\n * force to always use (uncompressed) R8 for transcoded format\r\n */\r\n public get forceR8() {\r\n return this._forceR8;\r\n }\r\n\r\n public set forceR8(value: boolean | undefined) {\r\n if (this._forceR8 === value) {\r\n return;\r\n }\r\n this._forceR8 = value;\r\n this._isDirty = true;\r\n }\r\n\r\n private _forceRG8?: boolean;\r\n /**\r\n * force to always use (uncompressed) RG8 for transcoded format\r\n */\r\n public get forceRG8() {\r\n return this._forceRG8;\r\n }\r\n\r\n public set forceRG8(value: boolean | undefined) {\r\n if (this._forceRG8 === value) {\r\n return;\r\n }\r\n this._forceRG8 = value;\r\n this._isDirty = true;\r\n }\r\n\r\n private _bypassTranscoders?: string[];\r\n /**\r\n * list of transcoders to bypass when looking for a suitable transcoder. The available transcoders are:\r\n * UniversalTranscoder_UASTC_ASTC\r\n * UniversalTranscoder_UASTC_BC7\r\n * UniversalTranscoder_UASTC_RGBA_UNORM\r\n * UniversalTranscoder_UASTC_RGBA_SRGB\r\n * UniversalTranscoder_UASTC_R8_UNORM\r\n * UniversalTranscoder_UASTC_RG8_UNORM\r\n * MSCTranscoder\r\n */\r\n public get bypassTranscoders() {\r\n return this._bypassTranscoders;\r\n }\r\n\r\n public set bypassTranscoders(value: string[] | undefined) {\r\n if (this._bypassTranscoders === value) {\r\n return;\r\n }\r\n this._bypassTranscoders = value;\r\n this._isDirty = true;\r\n }\r\n\r\n private _ktx2DecoderOptions: IKTX2DecoderOptions = {};\r\n\r\n /** @internal */\r\n public _getKTX2DecoderOptions(): IKTX2DecoderOptions {\r\n if (!this._isDirty) {\r\n return this._ktx2DecoderOptions;\r\n }\r\n\r\n this._isDirty = false;\r\n\r\n const options: IKTX2DecoderOptions = {\r\n useRGBAIfASTCBC7NotAvailableWhenUASTC: this._useRGBAIfASTCBC7NotAvailableWhenUASTC,\r\n forceRGBA: this._forceRGBA,\r\n forceR8: this._forceR8,\r\n forceRG8: this._forceRG8,\r\n bypassTranscoders: this._bypassTranscoders,\r\n };\r\n\r\n if (this.useRGBAIfOnlyBC1BC3AvailableWhenUASTC) {\r\n options.transcodeFormatDecisionTree = {\r\n UASTC: {\r\n transcodeFormat: [TranscodeTarget.BC1_RGB, TranscodeTarget.BC3_RGBA],\r\n yes: {\r\n transcodeFormat: TranscodeTarget.RGBA32,\r\n engineFormat: EngineFormat.RGBA8Format,\r\n roundToMultiple4: false,\r\n },\r\n },\r\n };\r\n }\r\n\r\n this._ktx2DecoderOptions = options;\r\n\r\n return options;\r\n }\r\n}\r\n\r\n/**\r\n * Class for loading KTX2 files\r\n */\r\nexport class KhronosTextureContainer2 {\r\n private static _WorkerPoolPromise?: Promise<AutoReleaseWorkerPool>;\r\n private static _DecoderModulePromise?: Promise<any>;\r\n\r\n /**\r\n * URLs to use when loading the KTX2 decoder module as well as its dependencies\r\n * If a url is null, the default url is used (pointing to https://preview.babylonjs.com)\r\n * Note that jsDecoderModule can't be null and that the other dependencies will only be loaded if necessary\r\n * Urls you can change:\r\n * URLConfig.jsDecoderModule\r\n * URLConfig.wasmUASTCToASTC\r\n * URLConfig.wasmUASTCToBC7\r\n * URLConfig.wasmUASTCToRGBA_UNORM\r\n * URLConfig.wasmUASTCToRGBA_SRGB\r\n * URLConfig.wasmUASTCToR8_UNORM\r\n * URLConfig.wasmUASTCToRG8_UNORM\r\n * URLConfig.jsMSCTranscoder\r\n * URLConfig.wasmMSCTranscoder\r\n * URLConfig.wasmZSTDDecoder\r\n * You can see their default values in this PG: https://playground.babylonjs.com/#EIJH8L#29\r\n */\r\n public static URLConfig: {\r\n jsDecoderModule: string;\r\n wasmUASTCToASTC: Nullable<string>;\r\n wasmUASTCToBC7: Nullable<string>;\r\n wasmUASTCToRGBA_UNORM: Nullable<string>;\r\n wasmUASTCToRGBA_SRGB: Nullable<string>;\r\n wasmUASTCToR8_UNORM: Nullable<string>;\r\n wasmUASTCToRG8_UNORM: Nullable<string>;\r\n jsMSCTranscoder: Nullable<string>;\r\n wasmMSCTranscoder: Nullable<string>;\r\n wasmZSTDDecoder: Nullable<string>;\r\n } = {\r\n jsDecoderModule: \"https://preview.babylonjs.com/babylon.ktx2Decoder.js\",\r\n wasmUASTCToASTC: null,\r\n wasmUASTCToBC7: null,\r\n wasmUASTCToRGBA_UNORM: null,\r\n wasmUASTCToRGBA_SRGB: null,\r\n wasmUASTCToR8_UNORM: null,\r\n wasmUASTCToRG8_UNORM: null,\r\n jsMSCTranscoder: null,\r\n wasmMSCTranscoder: null,\r\n wasmZSTDDecoder: null,\r\n };\r\n\r\n /**\r\n * Default number of workers used to handle data decoding\r\n */\r\n public static DefaultNumWorkers = KhronosTextureContainer2.GetDefaultNumWorkers();\r\n\r\n /**\r\n * Default configuration for the KTX2 decoder.\r\n * The options defined in this way have priority over those passed when creating a KTX2 texture with new Texture(...).\r\n */\r\n public static DefaultDecoderOptions = new DefaultKTX2DecoderOptions();\r\n\r\n private static GetDefaultNumWorkers(): number {\r\n if (typeof navigator !== \"object\" || !navigator.hardwareConcurrency) {\r\n return 1;\r\n }\r\n\r\n // Use 50% of the available logical processors but capped at 4.\r\n return Math.min(Math.floor(navigator.hardwareConcurrency * 0.5), 4);\r\n }\r\n\r\n private _engine: ThinEngine;\r\n\r\n private static _Initialize(numWorkers: number): void {\r\n if (KhronosTextureContainer2._WorkerPoolPromise || KhronosTextureContainer2._DecoderModulePromise) {\r\n return;\r\n }\r\n\r\n const urls = {\r\n jsDecoderModule: Tools.GetAbsoluteUrl(this.URLConfig.jsDecoderModule),\r\n wasmUASTCToASTC: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToASTC),\r\n wasmUASTCToBC7: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToBC7),\r\n wasmUASTCToRGBA_UNORM: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToRGBA_UNORM),\r\n wasmUASTCToRGBA_SRGB: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToRGBA_SRGB),\r\n wasmUASTCToR8_UNORM: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToR8_UNORM),\r\n wasmUASTCToRG8_UNORM: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToRG8_UNORM),\r\n jsMSCTranscoder: getAbsoluteUrlOrNull(this.URLConfig.jsMSCTranscoder),\r\n wasmMSCTranscoder: getAbsoluteUrlOrNull(this.URLConfig.wasmMSCTranscoder),\r\n wasmZSTDDecoder: getAbsoluteUrlOrNull(this.URLConfig.wasmZSTDDecoder),\r\n };\r\n\r\n if (numWorkers && typeof Worker === \"function\" && typeof URL !== \"undefined\") {\r\n KhronosTextureContainer2._WorkerPoolPromise = new Promise((resolve) => {\r\n const workerContent = `${applyConfig}(${workerFunc})()`;\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n resolve(\r\n new AutoReleaseWorkerPool(\r\n numWorkers,\r\n () =>\r\n new Promise((resolve, reject) => {\r\n const worker = new Worker(workerBlobUrl);\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n };\r\n\r\n const onMessage = (message: MessageEvent) => {\r\n if (message.data.action === \"init\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(worker);\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n worker.postMessage({\r\n action: \"init\",\r\n urls: urls,\r\n });\r\n })\r\n )\r\n );\r\n });\r\n } else if (typeof KTX2DECODER === \"undefined\") {\r\n KhronosTextureContainer2._DecoderModulePromise = Tools.LoadScriptAsync(urls.jsDecoderModule).then(() => {\r\n KTX2DECODER.MSCTranscoder.UseFromWorkerThread = false;\r\n KTX2DECODER.WASMMemoryManager.LoadBinariesFromCurrentThread = true;\r\n applyConfig(urls);\r\n return new KTX2DECODER.KTX2Decoder();\r\n });\r\n } else {\r\n KTX2DECODER.MSCTranscoder.UseFromWorkerThread = false;\r\n KTX2DECODER.WASMMemoryManager.LoadBinariesFromCurrentThread = true;\r\n KhronosTextureContainer2._DecoderModulePromise = Promise.resolve(new KTX2DECODER.KTX2Decoder());\r\n }\r\n }\r\n\r\n /**\r\n * Constructor\r\n * @param engine The engine to use\r\n * @param numWorkers The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n public constructor(engine: ThinEngine, numWorkers = KhronosTextureContainer2.DefaultNumWorkers) {\r\n this._engine = engine;\r\n\r\n KhronosTextureContainer2._Initialize(numWorkers);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public uploadAsync(data: ArrayBufferView, internalTexture: InternalTexture, options?: IKTX2DecoderOptions & IDecodedData): Promise<void> {\r\n const caps = this._engine.getCaps();\r\n\r\n const compressedTexturesCaps: ICompressedFormatCapabilities = {\r\n astc: !!caps.astc,\r\n bptc: !!caps.bptc,\r\n s3tc: !!caps.s3tc,\r\n pvrtc: !!caps.pvrtc,\r\n etc2: !!caps.etc2,\r\n etc1: !!caps.etc1,\r\n };\r\n\r\n if (KhronosTextureContainer2._WorkerPoolPromise) {\r\n return KhronosTextureContainer2._WorkerPoolPromise.then((workerPool) => {\r\n return new Promise((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (message: MessageEvent) => {\r\n if (message.data.action === \"decoded\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n if (!message.data.success) {\r\n reject({ message: message.data.msg });\r\n } else {\r\n try {\r\n this._createTexture(message.data.decodedData, internalTexture, options);\r\n resolve();\r\n } catch (err) {\r\n reject({ message: err });\r\n }\r\n }\r\n onComplete();\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n if (KhronosTextureContainer2.DefaultDecoderOptions.isDirty) {\r\n worker.postMessage({ action: \"setDefaultDecoderOptions\", options: KhronosTextureContainer2.DefaultDecoderOptions._getKTX2DecoderOptions() });\r\n }\r\n\r\n const dataCopy = new Uint8Array(data.byteLength);\r\n dataCopy.set(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));\r\n\r\n worker.postMessage({ action: \"decode\", data: dataCopy, caps: compressedTexturesCaps, options }, [dataCopy.buffer]);\r\n });\r\n });\r\n });\r\n } else if (KhronosTextureContainer2._DecoderModulePromise) {\r\n return KhronosTextureContainer2._DecoderModulePromise.then((decoder) => {\r\n return new Promise((resolve, reject) => {\r\n decoder\r\n .decode(data, caps)\r\n .then((data: IDecodedData) => {\r\n this._createTexture(data, internalTexture);\r\n resolve();\r\n })\r\n .catch((reason: any) => {\r\n reject({ message: reason });\r\n });\r\n });\r\n });\r\n }\r\n\r\n throw new Error(\"KTX2 decoder module is not available\");\r\n }\r\n\r\n protected _createTexture(data: IDecodedData, internalTexture: InternalTexture, options?: IKTX2DecoderOptions & IDecodedData): void {\r\n const oglTexture2D = 3553; // gl.TEXTURE_2D\r\n\r\n this._engine._bindTextureDirectly(oglTexture2D, internalTexture);\r\n\r\n if (options) {\r\n // return back some information about the decoded data\r\n options.transcodedFormat = data.transcodedFormat;\r\n options.isInGammaSpace = data.isInGammaSpace;\r\n options.hasAlpha = data.hasAlpha;\r\n options.transcoderName = data.transcoderName;\r\n }\r\n\r\n let isUncompressedFormat = true;\r\n\r\n switch (data.transcodedFormat) {\r\n case 0x8058 /* RGBA8 */:\r\n internalTexture.type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n internalTexture.format = Constants.TEXTUREFORMAT_RGBA;\r\n break;\r\n case 0x8229 /* R8 */:\r\n internalTexture.type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n internalTexture.format = Constants.TEXTUREFORMAT_R;\r\n break;\r\n case 0x822b /* RG8 */:\r\n internalTexture.type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n internalTexture.format = Constants.TEXTUREFORMAT_RG;\r\n break;\r\n default:\r\n internalTexture.format = data.transcodedFormat;\r\n isUncompressedFormat = false;\r\n break;\r\n }\r\n\r\n internalTexture._gammaSpace = data.isInGammaSpace;\r\n internalTexture.generateMipMaps = data.mipmaps.length > 1;\r\n\r\n if (data.errors) {\r\n throw new Error(\"KTX2 container - could not transcode the data. \" + data.errors);\r\n }\r\n\r\n for (let t = 0; t < data.mipmaps.length; ++t) {\r\n const mipmap = data.mipmaps[t];\r\n\r\n if (!mipmap || !mipmap.data) {\r\n throw new Error(\"KTX2 container - could not transcode one of the image\");\r\n }\r\n\r\n if (isUncompressedFormat) {\r\n // uncompressed RGBA / R8 / RG8\r\n internalTexture.width = mipmap.width; // need to set width/height so that the call to _uploadDataToTextureDirectly uses the right dimensions\r\n internalTexture.height = mipmap.height;\r\n\r\n this._engine._uploadDataToTextureDirectly(internalTexture, mipmap.data, 0, t, undefined, true);\r\n } else {\r\n this._engine._uploadCompressedDataToTextureDirectly(internalTexture, data.transcodedFormat, mipmap.width, mipmap.height, mipmap.data, 0, t);\r\n }\r\n }\r\n\r\n internalTexture._extension = \".ktx2\";\r\n internalTexture.width = data.mipmaps[0].width;\r\n internalTexture.height = data.mipmaps[0].height;\r\n internalTexture.isReady = true;\r\n\r\n this._engine._bindTextureDirectly(oglTexture2D, null);\r\n }\r\n\r\n /**\r\n * Checks if the given data starts with a KTX2 file identifier.\r\n * @param data the data to check\r\n * @returns true if the data is a KTX2 file or false otherwise\r\n */\r\n public static IsValid(data: ArrayBufferView): boolean {\r\n if (data.byteLength >= 12) {\r\n // '«', 'K', 'T', 'X', ' ', '2', '0', '»', '\\r', '\\n', '\\x1A', '\\n'\r\n const identifier = new Uint8Array(data.buffer, data.byteOffset, 12);\r\n if (\r\n identifier[0] === 0xab &&\r\n identifier[1] === 0x4b &&\r\n identifier[2] === 0x54 &&\r\n identifier[3] === 0x58 &&\r\n identifier[4] === 0x20 &&\r\n identifier[5] === 0x32 &&\r\n identifier[6] === 0x30 &&\r\n identifier[7] === 0xbb &&\r\n identifier[8] === 0x0d &&\r\n identifier[9] === 0x0a &&\r\n identifier[10] === 0x1a &&\r\n identifier[11] === 0x0a\r\n ) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n}\r\n\r\ndeclare function importScripts(...urls: string[]): void;\r\ndeclare function postMessage(message: any, transfer?: any[]): void;\r\n\r\nfunction workerFunc(): void {\r\n let ktx2Decoder: any;\r\n\r\n onmessage = (event) => {\r\n if (!event.data) {\r\n return;\r\n }\r\n switch (event.data.action) {\r\n case \"init\": {\r\n const urls = event.data.urls;\r\n importScripts(urls.jsDecoderModule);\r\n applyConfig(urls);\r\n ktx2Decoder = new KTX2DECODER.KTX2Decoder();\r\n postMessage({ action: \"init\" });\r\n break;\r\n }\r\n case \"setDefaultDecoderOptions\": {\r\n KTX2DECODER.KTX2Decoder.DefaultDecoderOptions = event.data.options;\r\n break;\r\n }\r\n case \"decode\":\r\n ktx2Decoder\r\n .decode(event.data.data, event.data.caps, event.data.options)\r\n .then((data: IDecodedData) => {\r\n const buffers = [];\r\n for (let mip = 0; mip < data.mipmaps.length; ++mip) {\r\n const mipmap = data.mipmaps[mip];\r\n if (mipmap && mipmap.data) {\r\n buffers.push(mipmap.data.buffer);\r\n }\r\n }\r\n postMessage({ action: \"decoded\", success: true, decodedData: data }, buffers);\r\n })\r\n .catch((reason: any) => {\r\n postMessage({ action: \"decoded\", success: false, msg: reason });\r\n });\r\n break;\r\n }\r\n };\r\n}\r\n"]}
|
|
@@ -7,6 +7,7 @@ import type { BoundingBox } from "../../Culling/boundingBox";
|
|
|
7
7
|
import type { TransformNode } from "../../Meshes/transformNode";
|
|
8
8
|
import type { PhysicsMaterial } from "./physicsMaterial";
|
|
9
9
|
import type { Mesh } from "../../Meshes/mesh";
|
|
10
|
+
import type { Nullable } from "../../types.js";
|
|
10
11
|
/** @internal */
|
|
11
12
|
export declare enum ConstraintAxisLimitMode {
|
|
12
13
|
FREE = 0,
|
|
@@ -104,8 +105,11 @@ export interface IPhysicsEnginePluginV2 {
|
|
|
104
105
|
getTimeStep(): number;
|
|
105
106
|
executeStep(delta: number, bodies: Array<PhysicsBody>): void;
|
|
106
107
|
getPluginVersion(): number;
|
|
108
|
+
registerOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;
|
|
109
|
+
unregisterOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;
|
|
107
110
|
initBody(body: PhysicsBody, position: Vector3, orientation: Quaternion): void;
|
|
108
111
|
initBodyInstances(body: PhysicsBody, mesh: Mesh): void;
|
|
112
|
+
removeBody(body: PhysicsBody): void;
|
|
109
113
|
sync(body: PhysicsBody): void;
|
|
110
114
|
syncTransform(body: PhysicsBody, transformNode: TransformNode): void;
|
|
111
115
|
setShape(body: PhysicsBody, shape: PhysicsShape): void;
|
|
@@ -127,6 +131,8 @@ export interface IPhysicsEnginePluginV2 {
|
|
|
127
131
|
getAngularVelocityToRef(body: PhysicsBody, angVel: Vector3): void;
|
|
128
132
|
getBodyGeometry(body: PhysicsBody): {};
|
|
129
133
|
disposeBody(body: PhysicsBody): void;
|
|
134
|
+
registerOnBodyCollide(body: PhysicsBody, func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;
|
|
135
|
+
unregisterOnBodyCollide(body: PhysicsBody, func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;
|
|
130
136
|
initShape(shape: PhysicsShape, type: ShapeType, options: PhysicsShapeParameters): void;
|
|
131
137
|
setFilterLayer(shape: PhysicsShape, layer: number): void;
|
|
132
138
|
getFilterLayer(shape: PhysicsShape): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IPhysicsEnginePlugin.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/IPhysicsEnginePlugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"IPhysicsEnginePlugin.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/IPhysicsEnginePlugin.ts"],"names":[],"mappings":"AAWA,gBAAgB;AAChB,MAAM,CAAN,IAAY,uBAKX;AALD,WAAY,uBAAuB;IAC/B,qEAAI,CAAA;IACJ,2EAAO,CAAA;IACP,yEAAM,CAAA;IACN,qEAAI,CAAA;AACR,CAAC,EALW,uBAAuB,KAAvB,uBAAuB,QAKlC;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,cAQX;AARD,WAAY,cAAc;IACtB,2DAAQ,CAAA;IACR,2DAAQ,CAAA;IACR,2DAAQ,CAAA;IACR,6DAAS,CAAA;IACT,6DAAS,CAAA;IACT,6DAAS,CAAA;IACT,yEAAe,CAAA;AACnB,CAAC,EARW,cAAc,KAAd,cAAc,QAQzB;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,cAMX;AAND,WAAY,cAAc;IACtB,yEAAe,CAAA;IACf,2DAAQ,CAAA;IACR,qDAAK,CAAA;IACL,uDAAM,CAAA;IACN,mDAAI,CAAA;AACR,CAAC,EANW,cAAc,KAAd,cAAc,QAMzB;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,SASX;AATD,WAAY,SAAS;IACjB,6CAAM,CAAA;IACN,+CAAO,CAAA;IACP,iDAAQ,CAAA;IACR,uCAAG,CAAA;IACH,uDAAW,CAAA;IACX,mDAAS,CAAA;IACT,yCAAI,CAAA;IACJ,uDAAW,CAAA;AACf,CAAC,EATW,SAAS,KAAT,SAAS,QASpB;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC3B,6DAAI,CAAA;IACJ,qEAAQ,CAAA;IACR,qEAAQ,CAAA;AACZ,CAAC,EAJW,mBAAmB,KAAnB,mBAAmB,QAI9B","sourcesContent":["import type { Vector3, Quaternion } from \"../../Maths/math.vector\";\r\nimport type { PhysicsRaycastResult } from \"../physicsRaycastResult\";\r\nimport type { PhysicsBody } from \"./physicsBody\";\r\nimport type { PhysicsShape } from \"./physicsShape\";\r\nimport type { PhysicsConstraint } from \"./physicsConstraint\";\r\nimport type { BoundingBox } from \"../../Culling/boundingBox\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\n/** @internal */\r\nexport enum ConstraintAxisLimitMode {\r\n FREE,\r\n LIMITED,\r\n LOCKED,\r\n NONE,\r\n}\r\n\r\n/** @internal */\r\nexport enum ConstraintAxis {\r\n LINEAR_X,\r\n LINEAR_Y,\r\n LINEAR_Z,\r\n ANGULAR_X,\r\n ANGULAR_Y,\r\n ANGULAR_Z,\r\n LINEAR_DISTANCE,\r\n}\r\n\r\n/** @internal */\r\nexport enum ConstraintType {\r\n BALL_AND_SOCKET,\r\n DISTANCE,\r\n HINGE,\r\n SLIDER,\r\n LOCK,\r\n}\r\n\r\n/** @internal */\r\nexport enum ShapeType {\r\n SPHERE,\r\n CAPSULE,\r\n CYLINDER,\r\n BOX,\r\n CONVEX_HULL,\r\n CONTAINER,\r\n MESH,\r\n HEIGHTFIELD,\r\n}\r\n\r\n/** @internal */\r\nexport enum ConstraintMotorType {\r\n NONE,\r\n VELOCITY,\r\n POSITION,\r\n}\r\n\r\n/** @internal */\r\nexport interface PhysicsShapeParameters {\r\n center?: Vector3;\r\n radius?: number;\r\n pointA?: Vector3;\r\n pointB?: Vector3;\r\n rotation?: Quaternion;\r\n extents?: Vector3;\r\n mesh?: Mesh;\r\n includeChildMeshes?: boolean;\r\n}\r\n\r\n/** @internal */\r\nexport interface PhysicsConstraintParameters {\r\n pivotA?: Vector3;\r\n pivotB?: Vector3;\r\n axisA?: Vector3;\r\n axisB?: Vector3;\r\n}\r\n\r\n/**\r\n *\r\n */\r\n/** @internal */\r\nexport interface MassProperties {\r\n /**\r\n *\r\n */\r\n centerOfMass: Vector3;\r\n /**\r\n *\r\n */\r\n mass: number;\r\n /**\r\n *\r\n */\r\n intertia: Vector3;\r\n /**\r\n *\r\n */\r\n inertiaOrientation: Quaternion;\r\n}\r\n\r\n/** @internal */\r\nexport interface IPhysicsEnginePluginV2 {\r\n /**\r\n *\r\n */\r\n world: any;\r\n /**\r\n *\r\n */\r\n name: string;\r\n setGravity(gravity: Vector3): void;\r\n setTimeStep(timeStep: number): void;\r\n getTimeStep(): number;\r\n executeStep(delta: number, bodies: Array<PhysicsBody>): void; //not forgetting pre and post events\r\n getPluginVersion(): number;\r\n registerOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;\r\n unregisterOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;\r\n\r\n // body\r\n initBody(body: PhysicsBody, position: Vector3, orientation: Quaternion): void;\r\n initBodyInstances(body: PhysicsBody, mesh: Mesh): void;\r\n removeBody(body: PhysicsBody): void;\r\n sync(body: PhysicsBody): void;\r\n syncTransform(body: PhysicsBody, transformNode: TransformNode): void;\r\n setShape(body: PhysicsBody, shape: PhysicsShape): void;\r\n getShape(body: PhysicsBody): PhysicsShape;\r\n setFilterGroup(body: PhysicsBody, group: number): void;\r\n getFilterGroup(body: PhysicsBody): number;\r\n setEventMask(body: PhysicsBody, eventMask: number): void;\r\n getEventMask(body: PhysicsBody): number;\r\n setMassProperties(body: PhysicsBody, massProps: MassProperties): void;\r\n getMassProperties(body: PhysicsBody): MassProperties;\r\n setLinearDamping(body: PhysicsBody, damping: number): void;\r\n getLinearDamping(body: PhysicsBody): number;\r\n setAngularDamping(body: PhysicsBody, damping: number): void;\r\n getAngularDamping(body: PhysicsBody): number;\r\n setLinearVelocity(body: PhysicsBody, linVel: Vector3): void;\r\n getLinearVelocityToRef(body: PhysicsBody, linVel: Vector3): void;\r\n applyImpulse(body: PhysicsBody, location: Vector3, impulse: Vector3): void;\r\n setAngularVelocity(body: PhysicsBody, angVel: Vector3): void;\r\n getAngularVelocityToRef(body: PhysicsBody, angVel: Vector3): void;\r\n getBodyGeometry(body: PhysicsBody): {};\r\n disposeBody(body: PhysicsBody): void;\r\n registerOnBodyCollide(body: PhysicsBody, func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;\r\n unregisterOnBodyCollide(body: PhysicsBody, func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;\r\n\r\n // shape\r\n initShape(shape: PhysicsShape, type: ShapeType, options: PhysicsShapeParameters): void;\r\n setFilterLayer(shape: PhysicsShape, layer: number): void;\r\n getFilterLayer(shape: PhysicsShape): number;\r\n setMaterial(shape: PhysicsShape, material: PhysicsMaterial): void;\r\n getMaterial(shape: PhysicsShape): PhysicsMaterial;\r\n setDensity(shape: PhysicsShape, density: number): void;\r\n getDensity(shape: PhysicsShape): number;\r\n addChild(shape: PhysicsShape, newChild: PhysicsShape, childTransform: TransformNode): void;\r\n removeChild(shape: PhysicsShape, childIndex: number): void;\r\n getNumChildren(shape: PhysicsShape): number;\r\n getBoundingBox(shape: PhysicsShape): BoundingBox;\r\n disposeShape(shape: PhysicsShape): void;\r\n\r\n // material\r\n initMaterial(material: PhysicsMaterial): void;\r\n setFriction(material: PhysicsMaterial, friction: number): void;\r\n getFriction(material: PhysicsMaterial): number;\r\n setRestitution(material: PhysicsMaterial, restitution: number): void;\r\n getRestitution(material: PhysicsMaterial): number;\r\n disposeMaterial(material: PhysicsMaterial): void;\r\n\r\n // constraint\r\n initConstraint(constraint: PhysicsConstraint, type: ConstraintType, options: PhysicsConstraintParameters): void;\r\n setParentBody(constraint: PhysicsConstraint, body: PhysicsBody): void;\r\n getParentBody(constraint: PhysicsConstraint): PhysicsBody;\r\n setChildBody(constraint: PhysicsConstraint, body: PhysicsBody): void;\r\n getChildBody(constraint: PhysicsConstraint): PhysicsBody;\r\n setAnchorInParent(constraint: PhysicsConstraint, pivot: Vector3, axisX: Vector3, axisY: Vector3): void;\r\n setAnchorInChild(constraint: PhysicsConstraint, pivot: Vector3, axisX: Vector3, axisY: Vector3): void;\r\n setEnabled(constraint: PhysicsConstraint, isEnabled: boolean): void;\r\n getEnabled(constraint: PhysicsConstraint): boolean;\r\n setCollisionsEnabled(constraint: PhysicsConstraint, isEnabled: boolean): void;\r\n getCollisionsEnabled(constraint: PhysicsConstraint): boolean;\r\n setAxisFriction(constraint: PhysicsConstraint, axis: ConstraintAxis, friction: number): void;\r\n getAxisFriction(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n setAxisMode(constraint: PhysicsConstraint, axis: ConstraintAxis, limitMode: ConstraintAxisLimitMode): void;\r\n getAxisMode(constraint: PhysicsConstraint, axis: ConstraintAxis): ConstraintAxisLimitMode;\r\n setAxisMinLimit(constraint: PhysicsConstraint, axis: ConstraintAxis, minLimit: number): void;\r\n getAxisMinLimit(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n setAxisMaxLimit(constraint: PhysicsConstraint, axis: ConstraintAxis, limit: number): void;\r\n getAxisMaxLimit(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n setAxisMotorType(constraint: PhysicsConstraint, axis: ConstraintAxis, motorType: ConstraintMotorType): void;\r\n getAxisMotorType(constraint: PhysicsConstraint, axis: ConstraintAxis): ConstraintMotorType;\r\n setAxisMotorTarget(constraint: PhysicsConstraint, axis: ConstraintAxis, target: number): void;\r\n getAxisMotorTarget(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n setAxisMotorMaxForce(constraint: PhysicsConstraint, axis: ConstraintAxis, maxForce: number): void;\r\n getAxisMotorMaxForce(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n disposeConstraint(constraint: PhysicsConstraint): void;\r\n\r\n // raycast\r\n raycast(from: Vector3, to: Vector3, result: PhysicsRaycastResult): void;\r\n\r\n dispose(): void;\r\n}\r\n"]}
|
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PhysicsBody } from "./physicsBody";
|
|
2
2
|
import { PhysicsMaterial } from "./physicsMaterial";
|
|
3
|
-
import
|
|
3
|
+
import { PhysicsShape } from "./physicsShape";
|
|
4
4
|
import type { Scene } from "../../scene";
|
|
5
5
|
import type { TransformNode } from "../../Meshes/transformNode";
|
|
6
6
|
/**
|
|
7
7
|
* The interface for the physics aggregate parameters
|
|
8
8
|
*/
|
|
9
|
-
/** @internal */
|
|
10
9
|
export interface PhysicsAggregateParameters {
|
|
11
|
-
/** @internal */
|
|
12
10
|
/**
|
|
13
|
-
* The mass of the physics
|
|
11
|
+
* The mass of the physics aggregate
|
|
14
12
|
*/
|
|
15
13
|
mass: number;
|
|
16
14
|
/**
|
|
17
|
-
* The friction of the physics
|
|
15
|
+
* The friction of the physics aggregate
|
|
18
16
|
*/
|
|
19
17
|
friction?: number;
|
|
20
18
|
/**
|
|
21
|
-
* The coefficient of restitution of the physics
|
|
19
|
+
* The coefficient of restitution of the physics aggregate
|
|
22
20
|
*/
|
|
23
21
|
restitution?: number;
|
|
24
22
|
/**
|
|
25
|
-
* The native options of the physics
|
|
23
|
+
* The native options of the physics aggregate
|
|
26
24
|
*/
|
|
27
25
|
nativeOptions?: any;
|
|
28
26
|
/**
|
|
@@ -34,11 +32,11 @@ export interface PhysicsAggregateParameters {
|
|
|
34
32
|
*/
|
|
35
33
|
disableBidirectionalTransformation?: boolean;
|
|
36
34
|
/**
|
|
37
|
-
* The pressure inside the physics
|
|
35
|
+
* The pressure inside the physics aggregate, soft object only
|
|
38
36
|
*/
|
|
39
37
|
pressure?: number;
|
|
40
38
|
/**
|
|
41
|
-
* The stiffness the physics
|
|
39
|
+
* The stiffness the physics aggregate, soft object only
|
|
42
40
|
*/
|
|
43
41
|
stiffness?: number;
|
|
44
42
|
/**
|
|
@@ -73,42 +71,46 @@ export interface PhysicsAggregateParameters {
|
|
|
73
71
|
shape?: any;
|
|
74
72
|
}
|
|
75
73
|
/**
|
|
76
|
-
*
|
|
74
|
+
* Helper class to create and interact with a PhysicsAggregate.
|
|
75
|
+
* This is a transition object that works like Physics Plugin V1 Impostors.
|
|
76
|
+
* This helper instanciate all mandatory physics objects to get a body/shape and material.
|
|
77
|
+
* It's less efficient that handling body and shapes independently but for prototyping or
|
|
78
|
+
* a small numbers of physics objects, it's good enough.
|
|
77
79
|
*/
|
|
78
80
|
export declare class PhysicsAggregate {
|
|
79
81
|
/**
|
|
80
|
-
* The physics-enabled object used as the physics
|
|
82
|
+
* The physics-enabled object used as the physics aggregate
|
|
81
83
|
*/
|
|
82
84
|
transformNode: TransformNode;
|
|
83
85
|
/**
|
|
84
|
-
* The type of the physics
|
|
86
|
+
* The type of the physics aggregate
|
|
85
87
|
*/
|
|
86
88
|
type: number;
|
|
87
89
|
private _options;
|
|
88
90
|
private _scene?;
|
|
89
91
|
/**
|
|
90
|
-
*
|
|
92
|
+
* The body that is associated with this aggregate
|
|
91
93
|
*/
|
|
92
94
|
body: PhysicsBody;
|
|
93
95
|
/**
|
|
94
|
-
*
|
|
96
|
+
* The shape that is associated with this aggregate
|
|
95
97
|
*/
|
|
96
98
|
shape: PhysicsShape;
|
|
97
99
|
/**
|
|
98
|
-
*
|
|
100
|
+
* The material that is associated with this aggregate
|
|
99
101
|
*/
|
|
100
102
|
material: PhysicsMaterial;
|
|
101
103
|
constructor(
|
|
102
104
|
/**
|
|
103
|
-
* The physics-enabled object used as the physics
|
|
105
|
+
* The physics-enabled object used as the physics aggregate
|
|
104
106
|
*/
|
|
105
107
|
transformNode: TransformNode,
|
|
106
108
|
/**
|
|
107
|
-
* The type of the physics
|
|
109
|
+
* The type of the physics aggregate
|
|
108
110
|
*/
|
|
109
111
|
type: number, _options?: PhysicsAggregateParameters, _scene?: Scene | undefined);
|
|
110
112
|
/**
|
|
111
|
-
*
|
|
113
|
+
* Releases the body, shape and material
|
|
112
114
|
*/
|
|
113
115
|
dispose(): void;
|
|
114
116
|
}
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
+
import { PhysicsBody } from "./physicsBody.js";
|
|
1
2
|
import { PhysicsMaterial } from "./physicsMaterial.js";
|
|
3
|
+
import { PhysicsShape } from "./physicsShape.js";
|
|
2
4
|
import { Logger } from "../../Misc/logger.js";
|
|
3
5
|
/**
|
|
4
|
-
*
|
|
6
|
+
* Helper class to create and interact with a PhysicsAggregate.
|
|
7
|
+
* This is a transition object that works like Physics Plugin V1 Impostors.
|
|
8
|
+
* This helper instanciate all mandatory physics objects to get a body/shape and material.
|
|
9
|
+
* It's less efficient that handling body and shapes independently but for prototyping or
|
|
10
|
+
* a small numbers of physics objects, it's good enough.
|
|
5
11
|
*/
|
|
6
12
|
export class PhysicsAggregate {
|
|
7
13
|
constructor(
|
|
8
14
|
/**
|
|
9
|
-
* The physics-enabled object used as the physics
|
|
15
|
+
* The physics-enabled object used as the physics aggregate
|
|
10
16
|
*/
|
|
11
17
|
transformNode,
|
|
12
18
|
/**
|
|
13
|
-
* The type of the physics
|
|
19
|
+
* The type of the physics aggregate
|
|
14
20
|
*/
|
|
15
21
|
type, _options = { mass: 0 }, _scene) {
|
|
16
22
|
this.transformNode = transformNode;
|
|
@@ -32,10 +38,18 @@ export class PhysicsAggregate {
|
|
|
32
38
|
if (!this._scene) {
|
|
33
39
|
return;
|
|
34
40
|
}
|
|
41
|
+
//default options params
|
|
42
|
+
this._options.mass = _options.mass === void 0 ? 0 : _options.mass;
|
|
43
|
+
this._options.friction = _options.friction === void 0 ? 0.2 : _options.friction;
|
|
44
|
+
this._options.restitution = _options.restitution === void 0 ? 0.2 : _options.restitution;
|
|
45
|
+
this.shape = new PhysicsShape(type, this._options, this._scene);
|
|
46
|
+
this.body = new PhysicsBody(transformNode, this._scene);
|
|
35
47
|
this.material = new PhysicsMaterial(this._options.friction ? this._options.friction : 0, this._options.restitution ? this._options.restitution : 0, this._scene);
|
|
48
|
+
this.body.setShape(this.shape);
|
|
49
|
+
this.shape.setMaterial(this.material);
|
|
36
50
|
}
|
|
37
51
|
/**
|
|
38
|
-
*
|
|
52
|
+
* Releases the body, shape and material
|
|
39
53
|
*/
|
|
40
54
|
dispose() {
|
|
41
55
|
this.body.dispose();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physicsAggregate.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsAggregate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"physicsAggregate.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsAggregate.ts"],"names":[],"mappings":"AAA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CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAChF,IAAI,CAAC,QAAQ,CAAC,WAAW,GAAG,QAAQ,CAAC,WAAW,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC;QACzF,IAAI,CAAC,KAAK,GAAG,IAAI,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,QAAe,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACvE,IAAI,CAAC,IAAI,GAAG,IAAI,WAAW,CAAC,aAAa,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACxD,IAAI,CAAC,QAAQ,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACjK,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACpB,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QACxB,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACJ","sourcesContent":["import { PhysicsBody } from \"./physicsBody\";\r\nimport { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport { PhysicsShape } from \"./physicsShape\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\n\r\n/**\r\n * The interface for the physics aggregate parameters\r\n */\r\nexport interface PhysicsAggregateParameters {\r\n /**\r\n * The mass of the physics aggregate\r\n */\r\n mass: number;\r\n /**\r\n * The friction of the physics aggregate\r\n */\r\n friction?: number;\r\n /**\r\n * The coefficient of restitution of the physics aggregate\r\n */\r\n restitution?: number;\r\n /**\r\n * The native options of the physics aggregate\r\n */\r\n nativeOptions?: any;\r\n /**\r\n * Specifies if the parent should be ignored\r\n */\r\n ignoreParent?: boolean;\r\n /**\r\n * Specifies if bi-directional transformations should be disabled\r\n */\r\n disableBidirectionalTransformation?: boolean;\r\n /**\r\n * The pressure inside the physics aggregate, soft object only\r\n */\r\n pressure?: number;\r\n /**\r\n * The stiffness the physics aggregate, soft object only\r\n */\r\n stiffness?: number;\r\n /**\r\n * The number of iterations used in maintaining consistent vertex velocities, soft object only\r\n */\r\n velocityIterations?: number;\r\n /**\r\n * The number of iterations used in maintaining consistent vertex positions, soft object only\r\n */\r\n positionIterations?: number;\r\n /**\r\n * The number used to fix points on a cloth (0, 1, 2, 4, 8) or rope (0, 1, 2) only\r\n * 0 None, 1, back left or top, 2, back right or bottom, 4, front left, 8, front right\r\n * Add to fix multiple points\r\n */\r\n fixedPoints?: number;\r\n /**\r\n * The collision margin around a soft object\r\n */\r\n margin?: number;\r\n /**\r\n * The collision margin around a soft object\r\n */\r\n damping?: number;\r\n /**\r\n * The path for a rope based on an extrusion\r\n */\r\n path?: any;\r\n /**\r\n * The shape of an extrusion used for a rope based on an extrusion\r\n */\r\n shape?: any;\r\n}\r\n/**\r\n * Helper class to create and interact with a PhysicsAggregate.\r\n * This is a transition object that works like Physics Plugin V1 Impostors.\r\n * This helper instanciate all mandatory physics objects to get a body/shape and material.\r\n * It's less efficient that handling body and shapes independently but for prototyping or\r\n * a small numbers of physics objects, it's good enough.\r\n */\r\nexport class PhysicsAggregate {\r\n /**\r\n * The body that is associated with this aggregate\r\n */\r\n public body: PhysicsBody;\r\n\r\n /**\r\n * The shape that is associated with this aggregate\r\n */\r\n public shape: PhysicsShape;\r\n\r\n /**\r\n * The material that is associated with this aggregate\r\n */\r\n public material: PhysicsMaterial;\r\n\r\n constructor(\r\n /**\r\n * The physics-enabled object used as the physics aggregate\r\n */\r\n public transformNode: TransformNode,\r\n /**\r\n * The type of the physics aggregate\r\n */\r\n public type: number,\r\n private _options: PhysicsAggregateParameters = { mass: 0 },\r\n private _scene?: Scene\r\n ) {\r\n //sanity check!\r\n if (!this.transformNode) {\r\n Logger.Error(\"No object was provided. A physics object is obligatory\");\r\n return;\r\n }\r\n if (this.transformNode.parent && this._options.mass !== 0) {\r\n Logger.Warn(\"A physics impostor has been created for an object which has a parent. Babylon physics currently works in local space so unexpected issues may occur.\");\r\n }\r\n\r\n // Legacy support for old syntax.\r\n if (!this._scene && transformNode.getScene) {\r\n this._scene = transformNode.getScene();\r\n }\r\n\r\n if (!this._scene) {\r\n return;\r\n }\r\n\r\n //default options params\r\n this._options.mass = _options.mass === void 0 ? 0 : _options.mass;\r\n this._options.friction = _options.friction === void 0 ? 0.2 : _options.friction;\r\n this._options.restitution = _options.restitution === void 0 ? 0.2 : _options.restitution;\r\n this.shape = new PhysicsShape(type, this._options as any, this._scene);\r\n this.body = new PhysicsBody(transformNode, this._scene);\r\n this.material = new PhysicsMaterial(this._options.friction ? this._options.friction : 0, this._options.restitution ? this._options.restitution : 0, this._scene);\r\n this.body.setShape(this.shape);\r\n this.shape.setMaterial(this.material);\r\n }\r\n\r\n /**\r\n * Releases the body, shape and material\r\n */\r\n public dispose(): void {\r\n this.body.dispose();\r\n this.material.dispose();\r\n this.shape.dispose();\r\n }\r\n}\r\n"]}
|
|
@@ -3,6 +3,7 @@ import type { PhysicsShape } from "./physicsShape";
|
|
|
3
3
|
import type { Vector3 } from "../../Maths/math.vector";
|
|
4
4
|
import type { Scene } from "../../scene";
|
|
5
5
|
import type { TransformNode } from "../../Meshes";
|
|
6
|
+
import type { Nullable } from "../../types.js";
|
|
6
7
|
/**
|
|
7
8
|
* PhysicsBody is useful for creating a physics body that can be used in a physics engine. It allows
|
|
8
9
|
* the user to set the mass and velocity of the body, which can then be used to calculate the
|
|
@@ -21,6 +22,10 @@ export declare class PhysicsBody {
|
|
|
21
22
|
* The V2 plugin used to create and manage this Physics Body
|
|
22
23
|
*/
|
|
23
24
|
private _physicsPlugin;
|
|
25
|
+
/**
|
|
26
|
+
* The engine used to create and manage this Physics Body
|
|
27
|
+
*/
|
|
28
|
+
private _physicsEngine;
|
|
24
29
|
/**
|
|
25
30
|
* The transform node associated with this Physics Body
|
|
26
31
|
*/
|
|
@@ -208,6 +213,16 @@ export declare class PhysicsBody {
|
|
|
208
213
|
* This method is useful for retrieving the geometry of the body from the physics plugin, which can be used for various physics calculations.
|
|
209
214
|
*/
|
|
210
215
|
getGeometry(): {};
|
|
216
|
+
/**
|
|
217
|
+
* Register a collision callback that is called when the body collides
|
|
218
|
+
* Filtering by body is inefficient. It's more preferable to register a collision callback for the entire world
|
|
219
|
+
* and do the filtering on the user side.
|
|
220
|
+
*/
|
|
221
|
+
registerOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;
|
|
222
|
+
/**
|
|
223
|
+
* Unregister a collision callback that is called when the body collides
|
|
224
|
+
*/
|
|
225
|
+
unregisterOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;
|
|
211
226
|
/**
|
|
212
227
|
* Disposes the body from the physics engine.
|
|
213
228
|
*
|
|
@@ -35,6 +35,7 @@ export class PhysicsBody {
|
|
|
35
35
|
if (!physicsEngine) {
|
|
36
36
|
throw new Error("No Physics Engine available.");
|
|
37
37
|
}
|
|
38
|
+
this._physicsEngine = physicsEngine;
|
|
38
39
|
if (physicsEngine.getPluginVersion() != 2) {
|
|
39
40
|
throw new Error("Plugin version is incorrect. Expected version 2.");
|
|
40
41
|
}
|
|
@@ -263,12 +264,28 @@ export class PhysicsBody {
|
|
|
263
264
|
getGeometry() {
|
|
264
265
|
return this._physicsPlugin.getBodyGeometry(this);
|
|
265
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Register a collision callback that is called when the body collides
|
|
269
|
+
* Filtering by body is inefficient. It's more preferable to register a collision callback for the entire world
|
|
270
|
+
* and do the filtering on the user side.
|
|
271
|
+
*/
|
|
272
|
+
registerOnCollide(func) {
|
|
273
|
+
return this._physicsPlugin.registerOnBodyCollide(this, func);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Unregister a collision callback that is called when the body collides
|
|
277
|
+
*/
|
|
278
|
+
unregisterOnCollide(func) {
|
|
279
|
+
return this._physicsPlugin.unregisterOnBodyCollide(this, func);
|
|
280
|
+
}
|
|
266
281
|
/**
|
|
267
282
|
* Disposes the body from the physics engine.
|
|
268
283
|
*
|
|
269
284
|
* 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.
|
|
270
285
|
*/
|
|
271
286
|
dispose() {
|
|
287
|
+
this._physicsEngine.removeBody(this);
|
|
288
|
+
this._physicsPlugin.removeBody(this);
|
|
272
289
|
this._physicsPlugin.disposeBody(this);
|
|
273
290
|
}
|
|
274
291
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physicsBody.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsBody.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAKrD;;;;GAIG;AACH,MAAM,OAAO,WAAW;IAuBpB;;;;;;;;OAQG;IACH,YAAY,aAA4B,EAAE,KAAY;QA/BtD;;WAEG;QACI,gBAAW,GAAQ,SAAS,CAAC;QACpC;;WAEG;QACI,yBAAoB,GAAe,EAAE,CAAC;QAS7C;;;WAGG;QACH,mBAAc,GAAY,IAAI,CAAC;QAY3B,IAAI,CAAC,KAAK,EAAE;YACR,OAAO;SACV;QACD,MAAM,aAAa,GAAG,KAAK,CAAC,gB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cAAc,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC;IAED;;;;;;;;OAQG;IACI,iBAAiB,CAAC,MAAe;QACpC,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;IAED;;;;;kIAK8H;IACvH,sBAAsB,CAAC,MAAe;QACzC,OAAO,IAAI,CAAC,cAAc,CAAC,sBAAsB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACpE,CAAC;IAED;;;;;;;OAOG;IACI,kBAAkB,CAAC,MAAe;QACrC,IAAI,CAAC,cAAc,CAAC,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;IAED;;;;;;OAMG;IACI,uBAAuB,CAAC,MAAe;QAC1C,OAAO,IAAI,CAAC,cAAc,CAAC,uBAAuB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACrE,CAAC;IAED;;;;;;;;OAQG;IACI,YAAY,CAAC,QAAiB,EAAE,OAAgB;QACnD,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IAED;;;;;;OAMG;IACI,WAAW;QACd,OAAO,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAED;;;;OAIG;IACI,OAAO;QACV,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;CACJ","sourcesContent":["import type { IPhysicsEnginePluginV2, MassProperties } from \"./IPhysicsEnginePlugin\";\r\nimport type { PhysicsShape } from \"./physicsShape\";\r\nimport type { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Quaternion } from \"../../Maths/math.vector\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { PhysicsEngine } from \"./physicsEngine\";\r\nimport type { Mesh, TransformNode } from \"../../Meshes\";\r\n\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 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 /**\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 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 location The location of the impulse.\r\n * @param impulse The impulse vector.\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(location: Vector3, impulse: Vector3): void {\r\n this._physicsPlugin.applyImpulse(this, location, impulse);\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 * 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._physicsPlugin.disposeBody(this);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"physicsBody.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsBody.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAMrD;;;;GAIG;AACH,MAAM,OAAO,WAAW;IA2BpB;;;;;;;;OAQG;IACH,YAAY,aAA4B,EAAE,KAAY;QAnCtD;;WAEG;QACI,gBAAW,GAAQ,SAAS,CAAC;QACpC;;WAEG;QACI,yBAAoB,GAAe,EAAE,CAAC;QAa7C;;;WAGG;QACH,mBAAc,GAAY,IA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,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;IAC1C,CAAC;CACJ","sourcesContent":["import type { IPhysicsEnginePluginV2, MassProperties } from \"./IPhysicsEnginePlugin\";\r\nimport type { PhysicsShape } from \"./physicsShape\";\r\nimport type { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Quaternion } from \"../../Maths/math.vector\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { PhysicsEngine } from \"./physicsEngine\";\r\nimport type { Mesh, TransformNode } from \"../../Meshes\";\r\nimport type { Nullable } from \"core/types\";\r\n\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 /**\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 location The location of the impulse.\r\n * @param impulse The impulse vector.\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(location: Vector3, impulse: Vector3): void {\r\n this._physicsPlugin.applyImpulse(this, location, impulse);\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 * 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 }\r\n}\r\n"]}
|