@babylonjs/core 7.2.1 → 7.2.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"dracoCompression.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompression.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAoC,cAAc,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAY7H,SAAS,kBAAkB,CAAC,UAAwB,EAAE,QAA6B;IAC/E,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,CAAC,QAAQ,IAAI,kBAAkB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YAC7D,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC;AA6DD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,OAAO,gBAAgB;IAkBzB;;OAEG;IACI,MAAM,KAAK,gBAAgB;QAC9B,MAAM,OAAO,GAAG,gBAAgB,CAAC,aAAa,CAAC,OAAO,CAAC;QACvD,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,aAAa,IAAI,OAAO,WAAW,KAAK,QAAQ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L;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,eAAe,CAAC,IAAmC,EAAE,UAAuC;QACrG,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAC/D,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC;QACpC,IAAI,QAAQ,CAAC,OAAO,EAAE;YAClB,UAAU,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;SACzC;QACD,KAAK,MAAM,SAAS,IAAI,QAAQ,CAAC,UAAU,EAAE;YACzC,MAAM,SAAS,GAAG,YAAY,CAAC,YAAY,CACvC,SAAS,CAAC,IAAI,EACd,SAAS,CAAC,IAAI,EACd,YAAY,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,EACxC,SAAS,CAAC,UAAU,EACpB,SAAS,CAAC,UAAU,EACpB,SAAS,CAAC,UAAU,EACpB,QAAQ,CAAC,aAAa,CACzB,CAAC;YAEF,UAAU,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;SAC7C;QACD,OAAO,UAAU,CAAC;IACtB,CAAC;;AAhVD;;;;;GAKG;AACW,8BAAa,GAAmC;IAC1D,OAAO,EAAE;QACL,OAAO,EAAE,GAAG,KAAK,CAAC,cAAc,6BAA6B;QAC7D,aAAa,EAAE,GAAG,KAAK,CAAC,cAAc,0BAA0B;QAChE,WAAW,EAAE,GAAG,KAAK,CAAC,cAAc,wBAAwB;KAC/D;CACJ,CAAC;AAUF;;GAEG;AACW,kCAAiB,GAAG,gBAAgB,CAAC,oBAAoB,EAAE,CAAC;AAW3D,yBAAQ,GAA+B,IAAI,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { AutoReleaseWorkerPool } from \"../../Misc/workerPool\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IDisposable, Scene } from \"../../scene\";\r\nimport { Geometry } from \"../geometry\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { DecoderModule } from \"draco3dgltf\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { decodeMesh, type AttributeData, type Message, workerFunction, initializeWebWorker } from \"./dracoCompressionWorker\";\r\nimport { DracoDecoderModule } from \"draco3dgltf\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\ninterface MeshData {\r\n indices?: Uint16Array | Uint32Array;\r\n attributes: Array<AttributeData>;\r\n totalVertices: number;\r\n}\r\n\r\nfunction createDecoderAsync(wasmBinary?: ArrayBuffer, jsModule?: DracoDecoderModule): Promise<{ module: DecoderModule }> {\r\n return new Promise((resolve) => {\r\n (jsModule || DracoDecoderModule)({ wasmBinary }).then((module) => {\r\n resolve({ module });\r\n });\r\n });\r\n}\r\n\r\n/**\r\n * Configuration for Draco compression\r\n */\r\nexport interface IDracoCompressionConfiguration {\r\n /**\r\n * Configuration for the decoder.\r\n */\r\n decoder: {\r\n /**\r\n * The url to the WebAssembly module.\r\n */\r\n wasmUrl?: string;\r\n\r\n /**\r\n * The url to the WebAssembly binary.\r\n */\r\n wasmBinaryUrl?: string;\r\n\r\n /**\r\n * The url to the fallback JavaScript module.\r\n */\r\n fallbackUrl?: string;\r\n /**\r\n * Optional worker pool to use for async decoding instead of creating a new worker pool.\r\n */\r\n workerPool?: AutoReleaseWorkerPool;\r\n /**\r\n * Optional ArrayBuffer of the WebAssembly binary\r\n */\r\n wasmBinary?: ArrayBuffer;\r\n\r\n /**\r\n * The decoder module if already available.\r\n */\r\n jsModule?: any /* DecoderModule */;\r\n };\r\n}\r\n\r\n/**\r\n * Options for Draco compression\r\n */\r\nexport interface IDracoCompressionOptions {\r\n /**\r\n * The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n numWorkers?: number;\r\n /**\r\n * Optional ArrayBuffer of the WebAssembly binary.\r\n * If provided it will be used instead of loading the binary from wasmBinaryUrl.\r\n */\r\n wasmBinary?: ArrayBuffer;\r\n /**\r\n * Optional worker pool to use for async decoding.\r\n * If provided, numWorkers will be ignored and the worker pool will be used instead.\r\n * If provided the draco script will not be loaded from the DracoConfiguration.\r\n */\r\n workerPool?: AutoReleaseWorkerPool;\r\n}\r\n\r\n/**\r\n * Draco compression (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco module.\r\n *\r\n * **Encoder**\r\n *\r\n * The encoder is not currently implemented.\r\n *\r\n * **Decoder**\r\n *\r\n * By default, the configuration points to a copy of the Draco decoder files for glTF from the babylon.js preview cdn https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoCompression.Configuration = {\r\n * decoder: {\r\n * wasmUrl: \"<url to the WebAssembly library>\",\r\n * wasmBinaryUrl: \"<url to the WebAssembly binary>\",\r\n * fallbackUrl: \"<url to the fallback JavaScript library>\",\r\n * }\r\n * };\r\n * ```\r\n *\r\n * Draco has two versions, one for WebAssembly and one for JavaScript. The decoder configuration can be set to only support WebAssembly or only support the JavaScript version.\r\n * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.\r\n * Use `DracoCompression.DecoderAvailable` to determine if the decoder configuration is available for the current context.\r\n *\r\n * To decode Draco compressed data, get the default DracoCompression object and call decodeMeshToGeometryAsync:\r\n * ```javascript\r\n * var geometry = await DracoCompression.Default.decodeMeshToGeometryAsync(data);\r\n * ```\r\n *\r\n * @see https://playground.babylonjs.com/#DMZIBD#0\r\n */\r\nexport class DracoCompression implements IDisposable {\r\n private _workerPoolPromise?: Promise<AutoReleaseWorkerPool>;\r\n private _decoderModulePromise?: Promise<{ module: DecoderModule }>;\r\n\r\n /**\r\n * The configuration. Defaults to the following urls:\r\n * - wasmUrl: \"https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js\"\r\n * - wasmBinaryUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.wasm\"\r\n * - fallbackUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.js\"\r\n */\r\n public static Configuration: IDracoCompressionConfiguration = {\r\n decoder: {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_wasm_wrapper_gltf.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.js`,\r\n },\r\n };\r\n\r\n /**\r\n * Returns true if the decoder configuration is available.\r\n */\r\n public static get DecoderAvailable(): boolean {\r\n const decoder = DracoCompression.Configuration.decoder;\r\n return !!((decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\") || decoder.fallbackUrl);\r\n }\r\n\r\n /**\r\n * Default number of workers to create when creating the draco compression object.\r\n */\r\n public static DefaultNumWorkers = DracoCompression.GetDefaultNumWorkers();\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 static _Default: Nullable<DracoCompression> = null;\r\n\r\n /**\r\n * Default instance for the draco compression object.\r\n */\r\n public static get Default(): DracoCompression {\r\n if (!DracoCompression._Default) {\r\n DracoCompression._Default = new DracoCompression();\r\n }\r\n\r\n return DracoCompression._Default;\r\n }\r\n\r\n /**\r\n * Constructor\r\n * @param numWorkers The number of workers for async operations Or an options object. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n constructor(numWorkers: number | IDracoCompressionOptions = DracoCompression.DefaultNumWorkers) {\r\n const decoder = DracoCompression.Configuration.decoder;\r\n // check if the decoder binary and worker pool was injected\r\n // Note - it is expected that the developer checked if WebWorker, WebAssembly and the URL object are available\r\n if (decoder.workerPool || (typeof numWorkers === \"object\" && numWorkers.workerPool)) {\r\n // set the promise accordingly\r\n this._workerPoolPromise = Promise.resolve(decoder.workerPool || (numWorkers as IDracoCompressionOptions).workerPool!);\r\n } else {\r\n // to avoid making big changes to the decider, if wasmBinary is provided use it in the wasmBinaryPromise\r\n const wasmBinaryProvided = decoder.wasmBinary || (typeof numWorkers === \"object\" && numWorkers.wasmBinary);\r\n const numberOfWorkers = typeof numWorkers === \"number\" ? numWorkers : numWorkers.numWorkers;\r\n const useWorkers = numberOfWorkers && typeof Worker === \"function\" && typeof URL === \"function\";\r\n const urlNeeded = useWorkers || (!useWorkers && !decoder.jsModule);\r\n // code maintained here for back-compat with no changes\r\n\r\n const decoderInfo: { url: string | undefined; wasmBinaryPromise: Promise<ArrayBuffer | undefined> } =\r\n decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\"\r\n ? {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(decoder.wasmUrl, true) : \"\",\r\n wasmBinaryPromise: wasmBinaryProvided ? Promise.resolve(wasmBinaryProvided) : Tools.LoadFileAsync(Tools.GetBabylonScriptURL(decoder.wasmBinaryUrl, true)),\r\n }\r\n : {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(decoder.fallbackUrl!) : \"\",\r\n wasmBinaryPromise: Promise.resolve(undefined),\r\n };\r\n if (useWorkers) {\r\n this._workerPoolPromise = decoderInfo.wasmBinaryPromise.then((decoderWasmBinary) => {\r\n const workerContent = `${decodeMesh}(${workerFunction})()`;\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n\r\n return new AutoReleaseWorkerPool(numberOfWorkers as number, () => {\r\n const worker = new Worker(workerBlobUrl);\r\n return initializeWebWorker(worker, decoderWasmBinary!, decoderInfo.url);\r\n });\r\n });\r\n } else {\r\n this._decoderModulePromise = decoderInfo.wasmBinaryPromise.then(async (decoderWasmBinary) => {\r\n if (typeof DracoDecoderModule === \"undefined\") {\r\n if (!decoder.jsModule) {\r\n if (!decoderInfo.url) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n await Tools.LoadBabylonScriptAsync(decoderInfo.url);\r\n }\r\n }\r\n return await createDecoderAsync(decoderWasmBinary as ArrayBuffer, decoder.jsModule);\r\n });\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Stop all async operations and release resources.\r\n */\r\n public dispose(): void {\r\n if (this._workerPoolPromise) {\r\n this._workerPoolPromise.then((workerPool) => {\r\n workerPool.dispose();\r\n });\r\n }\r\n\r\n delete this._workerPoolPromise;\r\n delete this._decoderModulePromise;\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when ready. Call this manually to ensure draco compression is ready before use.\r\n * @returns a promise that resolves when ready\r\n */\r\n public async whenReadyAsync(): Promise<void> {\r\n if (this._workerPoolPromise) {\r\n await this._workerPoolPromise;\r\n return;\r\n }\r\n\r\n if (this._decoderModulePromise) {\r\n await this._decoderModulePromise;\r\n return;\r\n }\r\n }\r\n\r\n private _decodeMeshAsync(\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes?: { [kind: string]: number },\r\n gltfNormalizedOverride?: { [kind: string]: boolean }\r\n ): Promise<MeshData> {\r\n const dataView = data instanceof ArrayBuffer ? new Int8Array(data) : new Int8Array(data.buffer, data.byteOffset, data.byteLength);\r\n\r\n const applyGltfNormalizedOverride = (kind: string, normalized: boolean): boolean => {\r\n if (gltfNormalizedOverride && gltfNormalizedOverride[kind] !== undefined) {\r\n if (normalized !== gltfNormalizedOverride[kind]) {\r\n Logger.Warn(\r\n `Normalized flag from Draco data (${normalized}) does not match normalized flag from glTF accessor (${gltfNormalizedOverride[kind]}). Using flag from glTF accessor.`\r\n );\r\n }\r\n\r\n return gltfNormalizedOverride[kind];\r\n } else {\r\n return normalized;\r\n }\r\n };\r\n\r\n if (this._workerPoolPromise) {\r\n return this._workerPoolPromise.then((workerPool) => {\r\n return new Promise<MeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\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 onComplete();\r\n };\r\n\r\n const onMessage = (event: MessageEvent<Message>) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"decodeMeshDone\": {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve({ indices: resultIndices!, attributes: resultAttributes, totalVertices: message.totalVertices });\r\n onComplete();\r\n break;\r\n }\r\n case \"indices\": {\r\n resultIndices = message.data;\r\n break;\r\n }\r\n case \"attribute\": {\r\n resultAttributes.push({\r\n kind: message.kind,\r\n data: message.data,\r\n size: message.size,\r\n byteOffset: message.byteOffset,\r\n byteStride: message.byteStride,\r\n normalized: applyGltfNormalizedOverride(message.kind, message.normalized),\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n const dataViewCopy = dataView.slice();\r\n worker.postMessage({ id: \"decodeMesh\", dataView: dataViewCopy, attributes: attributes }, [dataViewCopy.buffer]);\r\n });\r\n });\r\n });\r\n }\r\n\r\n if (this._decoderModulePromise) {\r\n return this._decoderModulePromise.then((decoder) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const numPoints = decodeMesh(\r\n decoder.module,\r\n dataView,\r\n attributes,\r\n (indices) => {\r\n resultIndices = indices;\r\n },\r\n (kind, data, size, byteOffset, byteStride, normalized) => {\r\n resultAttributes.push({\r\n kind,\r\n data,\r\n size,\r\n byteOffset,\r\n byteStride,\r\n normalized,\r\n });\r\n }\r\n );\r\n\r\n return { indices: resultIndices!, attributes: resultAttributes, totalVertices: numPoints };\r\n });\r\n }\r\n\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon geometry.\r\n * @param name The name to use when creating the geometry\r\n * @param scene The scene to use when creating the geometry\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded geometry\r\n */\r\n public async decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<Geometry> {\r\n const meshData = await this._decodeMeshAsync(data, attributes);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /** @internal */\r\n public async _decodeMeshToGeometryForGltfAsync(\r\n name: string,\r\n scene: Scene,\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes: { [kind: string]: number },\r\n gltfNormalizedOverride: { [kind: string]: boolean }\r\n ): Promise<Geometry> {\r\n const meshData = await this._decodeMeshAsync(data, attributes, gltfNormalizedOverride);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon vertex data.\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded vertex data\r\n * @deprecated Use {@link decodeMeshToGeometryAsync} for better performance in some cases\r\n */\r\n public async decodeMeshAsync(data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<VertexData> {\r\n const meshData = await this._decodeMeshAsync(data, attributes);\r\n const vertexData = new VertexData();\r\n if (meshData.indices) {\r\n vertexData.indices = meshData.indices;\r\n }\r\n for (const attribute of meshData.attributes) {\r\n const floatData = VertexBuffer.GetFloatData(\r\n attribute.data,\r\n attribute.size,\r\n VertexBuffer.GetDataType(attribute.data),\r\n attribute.byteOffset,\r\n attribute.byteStride,\r\n attribute.normalized,\r\n meshData.totalVertices\r\n );\r\n\r\n vertexData.set(floatData, attribute.kind);\r\n }\r\n return vertexData;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"dracoCompression.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompression.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAoC,cAAc,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAY7H,SAAS,kBAAkB,CAAC,UAAwB,EAAE,QAA6B;IAC/E,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,E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AAC,IAAI,CAAC,CAAC;SAC7C;QACD,OAAO,UAAU,CAAC;IACtB,CAAC;;AAvVD;;;;;GAKG;AACW,8BAAa,GAAmC;IAC1D,OAAO,EAAE;QACL,OAAO,EAAE,GAAG,KAAK,CAAC,cAAc,6BAA6B;QAC7D,aAAa,EAAE,GAAG,KAAK,CAAC,cAAc,0BAA0B;QAChE,WAAW,EAAE,GAAG,KAAK,CAAC,cAAc,wBAAwB;KAC/D;CACJ,CAAC;AAUF;;GAEG;AACW,kCAAiB,GAAG,gBAAgB,CAAC,oBAAoB,EAAE,CAAC;AAW3D,yBAAQ,GAA+B,IAAI,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { AutoReleaseWorkerPool } from \"../../Misc/workerPool\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IDisposable, Scene } from \"../../scene\";\r\nimport { Geometry } from \"../geometry\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { DecoderModule } from \"draco3dgltf\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { decodeMesh, type AttributeData, type Message, workerFunction, initializeWebWorker } from \"./dracoCompressionWorker\";\r\nimport { DracoDecoderModule } from \"draco3dgltf\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\ninterface MeshData {\r\n indices?: Uint16Array | Uint32Array;\r\n attributes: Array<AttributeData>;\r\n totalVertices: number;\r\n}\r\n\r\nfunction createDecoderAsync(wasmBinary?: ArrayBuffer, jsModule?: DracoDecoderModule): Promise<{ module: DecoderModule }> {\r\n return new Promise((resolve) => {\r\n (jsModule || DracoDecoderModule)({ wasmBinary }).then((module) => {\r\n resolve({ module });\r\n });\r\n });\r\n}\r\n\r\n/**\r\n * Configuration for Draco compression\r\n */\r\nexport interface IDracoCompressionConfiguration {\r\n /**\r\n * Configuration for the decoder.\r\n */\r\n decoder: {\r\n /**\r\n * The url to the WebAssembly module.\r\n */\r\n wasmUrl?: string;\r\n\r\n /**\r\n * The url to the WebAssembly binary.\r\n */\r\n wasmBinaryUrl?: string;\r\n\r\n /**\r\n * The url to the fallback JavaScript module.\r\n */\r\n fallbackUrl?: string;\r\n /**\r\n * Optional worker pool to use for async decoding instead of creating a new worker pool.\r\n */\r\n workerPool?: AutoReleaseWorkerPool;\r\n /**\r\n * Optional ArrayBuffer of the WebAssembly binary\r\n */\r\n wasmBinary?: ArrayBuffer;\r\n\r\n /**\r\n * The decoder module if already available.\r\n */\r\n jsModule?: any /* DecoderModule */;\r\n };\r\n}\r\n\r\n/**\r\n * Options for Draco compression\r\n */\r\nexport interface IDracoCompressionOptions {\r\n /**\r\n * The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n numWorkers?: number;\r\n /**\r\n * Optional ArrayBuffer of the WebAssembly binary.\r\n * If provided it will be used instead of loading the binary from wasmBinaryUrl.\r\n */\r\n wasmBinary?: ArrayBuffer;\r\n /**\r\n * Optional worker pool to use for async decoding.\r\n * If provided, numWorkers will be ignored and the worker pool will be used instead.\r\n * If provided the draco script will not be loaded from the DracoConfiguration.\r\n */\r\n workerPool?: AutoReleaseWorkerPool;\r\n}\r\n\r\n/**\r\n * Draco compression (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco module.\r\n *\r\n * **Encoder**\r\n *\r\n * The encoder is not currently implemented.\r\n *\r\n * **Decoder**\r\n *\r\n * By default, the configuration points to a copy of the Draco decoder files for glTF from the babylon.js preview cdn https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoCompression.Configuration = {\r\n * decoder: {\r\n * wasmUrl: \"<url to the WebAssembly library>\",\r\n * wasmBinaryUrl: \"<url to the WebAssembly binary>\",\r\n * fallbackUrl: \"<url to the fallback JavaScript library>\",\r\n * }\r\n * };\r\n * ```\r\n *\r\n * Draco has two versions, one for WebAssembly and one for JavaScript. The decoder configuration can be set to only support WebAssembly or only support the JavaScript version.\r\n * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.\r\n * Use `DracoCompression.DecoderAvailable` to determine if the decoder configuration is available for the current context.\r\n *\r\n * To decode Draco compressed data, get the default DracoCompression object and call decodeMeshToGeometryAsync:\r\n * ```javascript\r\n * var geometry = await DracoCompression.Default.decodeMeshToGeometryAsync(data);\r\n * ```\r\n *\r\n * @see https://playground.babylonjs.com/#DMZIBD#0\r\n */\r\nexport class DracoCompression implements IDisposable {\r\n private _workerPoolPromise?: Promise<AutoReleaseWorkerPool>;\r\n private _decoderModulePromise?: Promise<{ module: DecoderModule }>;\r\n\r\n /**\r\n * The configuration. Defaults to the following urls:\r\n * - wasmUrl: \"https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js\"\r\n * - wasmBinaryUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.wasm\"\r\n * - fallbackUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.js\"\r\n */\r\n public static Configuration: IDracoCompressionConfiguration = {\r\n decoder: {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_wasm_wrapper_gltf.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.js`,\r\n },\r\n };\r\n\r\n /**\r\n * Returns true if the decoder configuration is available.\r\n */\r\n public static get DecoderAvailable(): boolean {\r\n const decoder = DracoCompression.Configuration.decoder;\r\n return !!((decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\") || decoder.fallbackUrl);\r\n }\r\n\r\n /**\r\n * Default number of workers to create when creating the draco compression object.\r\n */\r\n public static DefaultNumWorkers = DracoCompression.GetDefaultNumWorkers();\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 static _Default: Nullable<DracoCompression> = null;\r\n\r\n /**\r\n * Default instance for the draco compression object.\r\n */\r\n public static get Default(): DracoCompression {\r\n if (!DracoCompression._Default) {\r\n DracoCompression._Default = new DracoCompression();\r\n }\r\n\r\n return DracoCompression._Default;\r\n }\r\n\r\n /**\r\n * Constructor\r\n * @param numWorkers The number of workers for async operations Or an options object. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n constructor(numWorkers: number | IDracoCompressionOptions = DracoCompression.DefaultNumWorkers) {\r\n const decoder = DracoCompression.Configuration.decoder;\r\n // check if the decoder binary and worker pool was injected\r\n // Note - it is expected that the developer checked if WebWorker, WebAssembly and the URL object are available\r\n if (decoder.workerPool || (typeof numWorkers === \"object\" && numWorkers.workerPool)) {\r\n // set the promise accordingly\r\n this._workerPoolPromise = Promise.resolve(decoder.workerPool || (numWorkers as IDracoCompressionOptions).workerPool!);\r\n } else {\r\n // to avoid making big changes to the decider, if wasmBinary is provided use it in the wasmBinaryPromise\r\n const wasmBinaryProvided = decoder.wasmBinary || (typeof numWorkers === \"object\" && numWorkers.wasmBinary);\r\n const numberOfWorkers = typeof numWorkers === \"number\" ? numWorkers : numWorkers.numWorkers;\r\n const useWorkers = numberOfWorkers && typeof Worker === \"function\" && typeof URL === \"function\";\r\n const urlNeeded = useWorkers || (!useWorkers && !decoder.jsModule);\r\n // code maintained here for back-compat with no changes\r\n\r\n const decoderInfo: { url: string | undefined; wasmBinaryPromise: Promise<ArrayBuffer | undefined> } =\r\n decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\"\r\n ? {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(decoder.wasmUrl, true) : \"\",\r\n wasmBinaryPromise: wasmBinaryProvided ? Promise.resolve(wasmBinaryProvided) : Tools.LoadFileAsync(Tools.GetBabylonScriptURL(decoder.wasmBinaryUrl, true)),\r\n }\r\n : {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(decoder.fallbackUrl!) : \"\",\r\n wasmBinaryPromise: Promise.resolve(undefined),\r\n };\r\n if (useWorkers) {\r\n this._workerPoolPromise = decoderInfo.wasmBinaryPromise.then((decoderWasmBinary) => {\r\n const workerContent = `${decodeMesh}(${workerFunction})()`;\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n\r\n return new AutoReleaseWorkerPool(numberOfWorkers as number, () => {\r\n const worker = new Worker(workerBlobUrl);\r\n return initializeWebWorker(worker, decoderWasmBinary!, decoderInfo.url);\r\n });\r\n });\r\n } else {\r\n this._decoderModulePromise = decoderInfo.wasmBinaryPromise.then(async (decoderWasmBinary) => {\r\n if (typeof DracoDecoderModule === \"undefined\") {\r\n if (!decoder.jsModule) {\r\n if (!decoderInfo.url) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n await Tools.LoadBabylonScriptAsync(decoderInfo.url);\r\n }\r\n }\r\n return await createDecoderAsync(decoderWasmBinary as ArrayBuffer, decoder.jsModule);\r\n });\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Stop all async operations and release resources.\r\n */\r\n public dispose(): void {\r\n if (this._workerPoolPromise) {\r\n this._workerPoolPromise.then((workerPool) => {\r\n workerPool.dispose();\r\n });\r\n }\r\n\r\n delete this._workerPoolPromise;\r\n delete this._decoderModulePromise;\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when ready. Call this manually to ensure draco compression is ready before use.\r\n * @returns a promise that resolves when ready\r\n */\r\n public async whenReadyAsync(): Promise<void> {\r\n if (this._workerPoolPromise) {\r\n await this._workerPoolPromise;\r\n return;\r\n }\r\n\r\n if (this._decoderModulePromise) {\r\n await this._decoderModulePromise;\r\n return;\r\n }\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to mesh data.\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @param gltfNormalizedOverride A map of attributes from vertex buffer kinds to normalized flags to override the Draco normalization\r\n * @returns A promise that resolves with the decoded mesh data\r\n */\r\n public decodeMeshToMeshDataAsync(\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes?: { [kind: string]: number },\r\n gltfNormalizedOverride?: { [kind: string]: boolean }\r\n ): Promise<MeshData> {\r\n const dataView = data instanceof ArrayBuffer ? new Int8Array(data) : new Int8Array(data.buffer, data.byteOffset, data.byteLength);\r\n\r\n const applyGltfNormalizedOverride = (kind: string, normalized: boolean): boolean => {\r\n if (gltfNormalizedOverride && gltfNormalizedOverride[kind] !== undefined) {\r\n if (normalized !== gltfNormalizedOverride[kind]) {\r\n Logger.Warn(\r\n `Normalized flag from Draco data (${normalized}) does not match normalized flag from glTF accessor (${gltfNormalizedOverride[kind]}). Using flag from glTF accessor.`\r\n );\r\n }\r\n\r\n return gltfNormalizedOverride[kind];\r\n } else {\r\n return normalized;\r\n }\r\n };\r\n\r\n if (this._workerPoolPromise) {\r\n return this._workerPoolPromise.then((workerPool) => {\r\n return new Promise<MeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\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 onComplete();\r\n };\r\n\r\n const onMessage = (event: MessageEvent<Message>) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"decodeMeshDone\": {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve({ indices: resultIndices!, attributes: resultAttributes, totalVertices: message.totalVertices });\r\n onComplete();\r\n break;\r\n }\r\n case \"indices\": {\r\n resultIndices = message.data;\r\n break;\r\n }\r\n case \"attribute\": {\r\n resultAttributes.push({\r\n kind: message.kind,\r\n data: message.data,\r\n size: message.size,\r\n byteOffset: message.byteOffset,\r\n byteStride: message.byteStride,\r\n normalized: applyGltfNormalizedOverride(message.kind, message.normalized),\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n const dataViewCopy = dataView.slice();\r\n worker.postMessage({ id: \"decodeMesh\", dataView: dataViewCopy, attributes: attributes }, [dataViewCopy.buffer]);\r\n });\r\n });\r\n });\r\n }\r\n\r\n if (this._decoderModulePromise) {\r\n return this._decoderModulePromise.then((decoder) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const numPoints = decodeMesh(\r\n decoder.module,\r\n dataView,\r\n attributes,\r\n (indices) => {\r\n resultIndices = indices;\r\n },\r\n (kind, data, size, byteOffset, byteStride, normalized) => {\r\n resultAttributes.push({\r\n kind,\r\n data,\r\n size,\r\n byteOffset,\r\n byteStride,\r\n normalized,\r\n });\r\n }\r\n );\r\n\r\n return { indices: resultIndices!, attributes: resultAttributes, totalVertices: numPoints };\r\n });\r\n }\r\n\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon geometry.\r\n * @param name The name to use when creating the geometry\r\n * @param scene The scene to use when creating the geometry\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded geometry\r\n */\r\n public async decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /** @internal */\r\n public async _decodeMeshToGeometryForGltfAsync(\r\n name: string,\r\n scene: Scene,\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes: { [kind: string]: number },\r\n gltfNormalizedOverride: { [kind: string]: boolean }\r\n ): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes, gltfNormalizedOverride);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon vertex data.\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded vertex data\r\n * @deprecated Use {@link decodeMeshToGeometryAsync} for better performance in some cases\r\n */\r\n public async decodeMeshAsync(data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<VertexData> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes);\r\n const vertexData = new VertexData();\r\n if (meshData.indices) {\r\n vertexData.indices = meshData.indices;\r\n }\r\n for (const attribute of meshData.attributes) {\r\n const floatData = VertexBuffer.GetFloatData(\r\n attribute.data,\r\n attribute.size,\r\n VertexBuffer.GetDataType(attribute.data),\r\n attribute.byteOffset,\r\n attribute.byteStride,\r\n attribute.normalized,\r\n meshData.totalVertices\r\n );\r\n\r\n vertexData.set(floatData, attribute.kind);\r\n }\r\n return vertexData;\r\n }\r\n}\r\n"]}
@@ -253,8 +253,8 @@ export class CylinderDirectedParticleEmitter extends CylinderParticleEmitter {
253
253
  */
254
254
  parse(serializationObject) {
255
255
  super.parse(serializationObject);
256
- this.direction1.copyFrom(serializationObject.direction1);
257
- this.direction2.copyFrom(serializationObject.direction2);
256
+ Vector3.FromArrayToRef(serializationObject.direction1, 0, this.direction1);
257
+ Vector3.FromArrayToRef(serializationObject.direction2, 0, this.direction2);
258
258
  }
259
259
  }
260
260
  //# sourceMappingURL=cylinderParticleEmitter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cylinderParticleEmitter.js","sourceRoot":"","sources":["../../../../../dev/core/src/Particles/EmitterTypes/cylinderParticleEmitter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGjD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IAGhC;;;;;;OAMG;IACH;IACI;;OAEG;IACI,SAAS,CAAC;IACjB;;OAEG;IACI,SAAS,CAAC;IACjB;;OAEG;IACI,cAAc,CAAC;IACtB;;OAEG;IACI,sBAAsB,CAAC;QAZvB,WAAM,GAAN,MAAM,CAAI;QAIV,WAAM,GAAN,MAAM,CAAI;QAIV,gBAAW,GAAX,WAAW,CAAI;QAIf,wBAAmB,GAAnB,mBAAmB,CAAI;QAzB1B,gBAAW,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IA0BlC,CAAC;IAEJ;;;;;;;OAOG;IACI,sBAAsB,CAAC,WAAmB,EAAE,iBAA0B,EAAE,QA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;OAGG;IACI,gBAAgB;QACnB,OAAO,0DAA0D,CAAC;IACtE,CAAC;IAED;;;OAGG;IACI,YAAY;QACf,OAAO,iCAAiC,CAAC;IAC7C,CAAC;IAED;;;OAGG;IACI,SAAS;QACZ,MAAM,mBAAmB,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;QAE9C,mBAAmB,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QAC3D,mBAAmB,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QAE3D,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,mBAAwB;QACjC,KAAK,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;QACjC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;QACzD,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC7D,CAAC;CACJ","sourcesContent":["import type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport type { Particle } from \"../../Particles/particle\";\r\nimport type { IParticleEmitterType } from \"./IParticleEmitterType\";\r\nimport { DeepCopier } from \"../../Misc/deepCopier\";\r\nimport type { UniformBufferEffectCommonAccessor } from \"../../Materials/uniformBufferEffectCommonAccessor\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\n/**\r\n * Particle emitter emitting particles from the inside of a cylinder.\r\n * It emits the particles alongside the cylinder radius. The emission direction might be randomized.\r\n */\r\nexport class CylinderParticleEmitter implements IParticleEmitterType {\r\n private _tempVector = Vector3.Zero();\r\n\r\n /**\r\n * Creates a new instance CylinderParticleEmitter\r\n * @param radius the radius of the emission cylinder (1 by default)\r\n * @param height the height of the emission cylinder (1 by default)\r\n * @param radiusRange the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)\r\n * @param directionRandomizer defines how much to randomize the particle direction [0-1]\r\n */\r\n constructor(\r\n /**\r\n * The radius of the emission cylinder.\r\n */\r\n public radius = 1,\r\n /**\r\n * The height of the emission cylinder.\r\n */\r\n public height = 1,\r\n /**\r\n * The range of emission [0-1] 0 Surface only, 1 Entire Radius.\r\n */\r\n public radiusRange = 1,\r\n /**\r\n * How much to randomize the particle direction [0-1].\r\n */\r\n public directionRandomizer = 0\r\n ) {}\r\n\r\n /**\r\n * Called by the particle System when the direction is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param directionToUpdate is the direction vector to update with the result\r\n * @param particle is the particle we are computed the direction for\r\n * @param isLocal defines if the direction should be set in local space\r\n * @param inverseWorldMatrix defines the inverted world matrix to use if isLocal is false\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle, isLocal: boolean, inverseWorldMatrix: Matrix): void {\r\n particle.position.subtractToRef(worldMatrix.getTranslation(), this._tempVector);\r\n\r\n this._tempVector.normalize();\r\n\r\n Vector3.TransformNormalToRef(this._tempVector, inverseWorldMatrix, this._tempVector);\r\n\r\n const randY = Scalar.RandomRange(-this.directionRandomizer / 2, this.directionRandomizer / 2);\r\n\r\n let angle = Math.atan2(this._tempVector.x, this._tempVector.z);\r\n angle += Scalar.RandomRange(-Math.PI / 2, Math.PI / 2) * this.directionRandomizer;\r\n\r\n this._tempVector.y = randY; // set direction y to rand y to mirror normal of cylinder surface\r\n this._tempVector.x = Math.sin(angle);\r\n this._tempVector.z = Math.cos(angle);\r\n this._tempVector.normalize();\r\n\r\n if (isLocal) {\r\n directionToUpdate.copyFrom(this._tempVector);\r\n return;\r\n }\r\n\r\n Vector3.TransformNormalFromFloatsToRef(this._tempVector.x, this._tempVector.y, this._tempVector.z, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the position is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param positionToUpdate is the position vector to update with the result\r\n * @param particle is the particle we are computed the position for\r\n * @param isLocal defines if the position should be set in local space\r\n */\r\n public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const yPos = Scalar.RandomRange(-this.height / 2, this.height / 2);\r\n const angle = Scalar.RandomRange(0, 2 * Math.PI);\r\n\r\n // Pick a properly distributed point within the circle https://programming.guide/random-point-within-circle.html\r\n const radiusDistribution = Scalar.RandomRange((1 - this.radiusRange) * (1 - this.radiusRange), 1);\r\n const positionRadius = Math.sqrt(radiusDistribution) * this.radius;\r\n const xPos = positionRadius * Math.cos(angle);\r\n const zPos = positionRadius * Math.sin(angle);\r\n\r\n if (isLocal) {\r\n positionToUpdate.copyFromFloats(xPos, yPos, zPos);\r\n return;\r\n }\r\n\r\n Vector3.TransformCoordinatesFromFloatsToRef(xPos, yPos, zPos, worldMatrix, positionToUpdate);\r\n }\r\n\r\n /**\r\n * Clones the current emitter and returns a copy of it\r\n * @returns the new emitter\r\n */\r\n public clone(): CylinderParticleEmitter {\r\n const newOne = new CylinderParticleEmitter(this.radius, this.directionRandomizer);\r\n\r\n DeepCopier.DeepCopy(this, newOne);\r\n\r\n return newOne;\r\n }\r\n\r\n /**\r\n * Called by the GPUParticleSystem to setup the update shader\r\n * @param uboOrEffect defines the update shader\r\n */\r\n public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {\r\n uboOrEffect.setFloat(\"radius\", this.radius);\r\n uboOrEffect.setFloat(\"height\", this.height);\r\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\r\n uboOrEffect.setFloat(\"directionRandomizer\", this.directionRandomizer);\r\n }\r\n\r\n /**\r\n * Creates the structure of the ubo for this particle emitter\r\n * @param ubo ubo to create the structure for\r\n */\r\n public buildUniformLayout(ubo: UniformBuffer): void {\r\n ubo.addUniform(\"radius\", 1);\r\n ubo.addUniform(\"height\", 1);\r\n ubo.addUniform(\"radiusRange\", 1);\r\n ubo.addUniform(\"directionRandomizer\", 1);\r\n }\r\n\r\n /**\r\n * Returns a string to use to update the GPU particles update shader\r\n * @returns a string containing the defines string\r\n */\r\n public getEffectDefines(): string {\r\n return \"#define CYLINDEREMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"CylinderParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"CylinderParticleEmitter\";\r\n }\r\n\r\n /**\r\n * Serializes the particle system to a JSON object.\r\n * @returns the JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n serializationObject.type = this.getClassName();\r\n serializationObject.radius = this.radius;\r\n serializationObject.height = this.height;\r\n serializationObject.radiusRange = this.radiusRange;\r\n serializationObject.directionRandomizer = this.directionRandomizer;\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse properties from a JSON object\r\n * @param serializationObject defines the JSON object\r\n */\r\n public parse(serializationObject: any): void {\r\n this.radius = serializationObject.radius;\r\n this.height = serializationObject.height;\r\n this.radiusRange = serializationObject.radiusRange;\r\n this.directionRandomizer = serializationObject.directionRandomizer;\r\n }\r\n}\r\n\r\n/**\r\n * Particle emitter emitting particles from the inside of a cylinder.\r\n * It emits the particles randomly between two vectors.\r\n */\r\nexport class CylinderDirectedParticleEmitter extends CylinderParticleEmitter {\r\n /**\r\n * Creates a new instance CylinderDirectedParticleEmitter\r\n * @param radius the radius of the emission cylinder (1 by default)\r\n * @param height the height of the emission cylinder (1 by default)\r\n * @param radiusRange the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)\r\n * @param direction1 the min limit of the emission direction (up vector by default)\r\n * @param direction2 the max limit of the emission direction (up vector by default)\r\n */\r\n constructor(\r\n radius = 1,\r\n height = 1,\r\n radiusRange = 1,\r\n /**\r\n * The min limit of the emission direction.\r\n */\r\n public direction1 = new Vector3(0, 1, 0),\r\n /**\r\n * The max limit of the emission direction.\r\n */\r\n public direction2 = new Vector3(0, 1, 0)\r\n ) {\r\n super(radius, height, radiusRange);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the direction is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param directionToUpdate is the direction vector to update with the result\r\n * @param _particle is the particle we are computed the direction for\r\n * @param isLocal defines if the direction should be set in local space\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, _particle: Particle, isLocal: boolean): void {\r\n const randX = Scalar.RandomRange(this.direction1.x, this.direction2.x);\r\n const randY = Scalar.RandomRange(this.direction1.y, this.direction2.y);\r\n const randZ = Scalar.RandomRange(this.direction1.z, this.direction2.z);\r\n if (isLocal) {\r\n directionToUpdate.copyFromFloats(randX, randY, randZ);\r\n return;\r\n }\r\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Clones the current emitter and returns a copy of it\r\n * @returns the new emitter\r\n */\r\n public clone(): CylinderDirectedParticleEmitter {\r\n const newOne = new CylinderDirectedParticleEmitter(this.radius, this.height, this.radiusRange, this.direction1, this.direction2);\r\n\r\n DeepCopier.DeepCopy(this, newOne);\r\n\r\n return newOne;\r\n }\r\n\r\n /**\r\n * Called by the GPUParticleSystem to setup the update shader\r\n * @param uboOrEffect defines the update shader\r\n */\r\n public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {\r\n uboOrEffect.setFloat(\"radius\", this.radius);\r\n uboOrEffect.setFloat(\"height\", this.height);\r\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\r\n uboOrEffect.setVector3(\"direction1\", this.direction1);\r\n uboOrEffect.setVector3(\"direction2\", this.direction2);\r\n }\r\n\r\n /**\r\n * Creates the structure of the ubo for this particle emitter\r\n * @param ubo ubo to create the structure for\r\n */\r\n public buildUniformLayout(ubo: UniformBuffer): void {\r\n ubo.addUniform(\"radius\", 1);\r\n ubo.addUniform(\"height\", 1);\r\n ubo.addUniform(\"radiusRange\", 1);\r\n ubo.addUniform(\"direction1\", 3);\r\n ubo.addUniform(\"direction2\", 3);\r\n }\r\n\r\n /**\r\n * Returns a string to use to update the GPU particles update shader\r\n * @returns a string containing the defines string\r\n */\r\n public getEffectDefines(): string {\r\n return \"#define CYLINDEREMITTER\\n#define DIRECTEDCYLINDEREMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"CylinderDirectedParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"CylinderDirectedParticleEmitter\";\r\n }\r\n\r\n /**\r\n * Serializes the particle system to a JSON object.\r\n * @returns the JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.direction1 = this.direction1.asArray();\r\n serializationObject.direction2 = this.direction2.asArray();\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse properties from a JSON object\r\n * @param serializationObject defines the JSON object\r\n */\r\n public parse(serializationObject: any): void {\r\n super.parse(serializationObject);\r\n this.direction1.copyFrom(serializationObject.direction1);\r\n this.direction2.copyFrom(serializationObject.direction2);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"cylinderParticleEmitter.js","sourceRoot":"","sources":["../../../../../dev/core/src/Particles/EmitterTypes/cylinderParticleEmitter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGjD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IAGhC;;;;;;OAMG;IACH;IACI;;OAEG;IACI,SAAS,CAAC;IACjB;;OAEG;IACI,SAAS,CAAC;IACjB;;OAEG;IACI,cAAc,CAAC;IACtB;;OAEG;IACI,sBAAsB,CAAC;QAZvB,WAAM,GAAN,MAAM,CAAI;QAIV,WAAM,GAAN,MAAM,CAAI;QAIV,gBAAW,GAAX,WAAW,CAAI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AAC,aAAa,EAAE,CAAC,CAAC,CAAC;QACjC,GAAG,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;QAChC,GAAG,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;IACpC,CAAC;IAED;;;OAGG;IACI,gBAAgB;QACnB,OAAO,0DAA0D,CAAC;IACtE,CAAC;IAED;;;OAGG;IACI,YAAY;QACf,OAAO,iCAAiC,CAAC;IAC7C,CAAC;IAED;;;OAGG;IACI,SAAS;QACZ,MAAM,mBAAmB,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;QAE9C,mBAAmB,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QAC3D,mBAAmB,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QAE3D,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,mBAAwB;QACjC,KAAK,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;QACjC,OAAO,CAAC,cAAc,CAAC,mBAAmB,CAAC,UAAU,EAAE,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAC3E,OAAO,CAAC,cAAc,CAAC,mBAAmB,CAAC,UAAU,EAAE,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC/E,CAAC;CACJ","sourcesContent":["import type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport type { Particle } from \"../../Particles/particle\";\r\nimport type { IParticleEmitterType } from \"./IParticleEmitterType\";\r\nimport { DeepCopier } from \"../../Misc/deepCopier\";\r\nimport type { UniformBufferEffectCommonAccessor } from \"../../Materials/uniformBufferEffectCommonAccessor\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\n/**\r\n * Particle emitter emitting particles from the inside of a cylinder.\r\n * It emits the particles alongside the cylinder radius. The emission direction might be randomized.\r\n */\r\nexport class CylinderParticleEmitter implements IParticleEmitterType {\r\n private _tempVector = Vector3.Zero();\r\n\r\n /**\r\n * Creates a new instance CylinderParticleEmitter\r\n * @param radius the radius of the emission cylinder (1 by default)\r\n * @param height the height of the emission cylinder (1 by default)\r\n * @param radiusRange the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)\r\n * @param directionRandomizer defines how much to randomize the particle direction [0-1]\r\n */\r\n constructor(\r\n /**\r\n * The radius of the emission cylinder.\r\n */\r\n public radius = 1,\r\n /**\r\n * The height of the emission cylinder.\r\n */\r\n public height = 1,\r\n /**\r\n * The range of emission [0-1] 0 Surface only, 1 Entire Radius.\r\n */\r\n public radiusRange = 1,\r\n /**\r\n * How much to randomize the particle direction [0-1].\r\n */\r\n public directionRandomizer = 0\r\n ) {}\r\n\r\n /**\r\n * Called by the particle System when the direction is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param directionToUpdate is the direction vector to update with the result\r\n * @param particle is the particle we are computed the direction for\r\n * @param isLocal defines if the direction should be set in local space\r\n * @param inverseWorldMatrix defines the inverted world matrix to use if isLocal is false\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle, isLocal: boolean, inverseWorldMatrix: Matrix): void {\r\n particle.position.subtractToRef(worldMatrix.getTranslation(), this._tempVector);\r\n\r\n this._tempVector.normalize();\r\n\r\n Vector3.TransformNormalToRef(this._tempVector, inverseWorldMatrix, this._tempVector);\r\n\r\n const randY = Scalar.RandomRange(-this.directionRandomizer / 2, this.directionRandomizer / 2);\r\n\r\n let angle = Math.atan2(this._tempVector.x, this._tempVector.z);\r\n angle += Scalar.RandomRange(-Math.PI / 2, Math.PI / 2) * this.directionRandomizer;\r\n\r\n this._tempVector.y = randY; // set direction y to rand y to mirror normal of cylinder surface\r\n this._tempVector.x = Math.sin(angle);\r\n this._tempVector.z = Math.cos(angle);\r\n this._tempVector.normalize();\r\n\r\n if (isLocal) {\r\n directionToUpdate.copyFrom(this._tempVector);\r\n return;\r\n }\r\n\r\n Vector3.TransformNormalFromFloatsToRef(this._tempVector.x, this._tempVector.y, this._tempVector.z, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the position is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param positionToUpdate is the position vector to update with the result\r\n * @param particle is the particle we are computed the position for\r\n * @param isLocal defines if the position should be set in local space\r\n */\r\n public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const yPos = Scalar.RandomRange(-this.height / 2, this.height / 2);\r\n const angle = Scalar.RandomRange(0, 2 * Math.PI);\r\n\r\n // Pick a properly distributed point within the circle https://programming.guide/random-point-within-circle.html\r\n const radiusDistribution = Scalar.RandomRange((1 - this.radiusRange) * (1 - this.radiusRange), 1);\r\n const positionRadius = Math.sqrt(radiusDistribution) * this.radius;\r\n const xPos = positionRadius * Math.cos(angle);\r\n const zPos = positionRadius * Math.sin(angle);\r\n\r\n if (isLocal) {\r\n positionToUpdate.copyFromFloats(xPos, yPos, zPos);\r\n return;\r\n }\r\n\r\n Vector3.TransformCoordinatesFromFloatsToRef(xPos, yPos, zPos, worldMatrix, positionToUpdate);\r\n }\r\n\r\n /**\r\n * Clones the current emitter and returns a copy of it\r\n * @returns the new emitter\r\n */\r\n public clone(): CylinderParticleEmitter {\r\n const newOne = new CylinderParticleEmitter(this.radius, this.directionRandomizer);\r\n\r\n DeepCopier.DeepCopy(this, newOne);\r\n\r\n return newOne;\r\n }\r\n\r\n /**\r\n * Called by the GPUParticleSystem to setup the update shader\r\n * @param uboOrEffect defines the update shader\r\n */\r\n public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {\r\n uboOrEffect.setFloat(\"radius\", this.radius);\r\n uboOrEffect.setFloat(\"height\", this.height);\r\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\r\n uboOrEffect.setFloat(\"directionRandomizer\", this.directionRandomizer);\r\n }\r\n\r\n /**\r\n * Creates the structure of the ubo for this particle emitter\r\n * @param ubo ubo to create the structure for\r\n */\r\n public buildUniformLayout(ubo: UniformBuffer): void {\r\n ubo.addUniform(\"radius\", 1);\r\n ubo.addUniform(\"height\", 1);\r\n ubo.addUniform(\"radiusRange\", 1);\r\n ubo.addUniform(\"directionRandomizer\", 1);\r\n }\r\n\r\n /**\r\n * Returns a string to use to update the GPU particles update shader\r\n * @returns a string containing the defines string\r\n */\r\n public getEffectDefines(): string {\r\n return \"#define CYLINDEREMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"CylinderParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"CylinderParticleEmitter\";\r\n }\r\n\r\n /**\r\n * Serializes the particle system to a JSON object.\r\n * @returns the JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n serializationObject.type = this.getClassName();\r\n serializationObject.radius = this.radius;\r\n serializationObject.height = this.height;\r\n serializationObject.radiusRange = this.radiusRange;\r\n serializationObject.directionRandomizer = this.directionRandomizer;\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse properties from a JSON object\r\n * @param serializationObject defines the JSON object\r\n */\r\n public parse(serializationObject: any): void {\r\n this.radius = serializationObject.radius;\r\n this.height = serializationObject.height;\r\n this.radiusRange = serializationObject.radiusRange;\r\n this.directionRandomizer = serializationObject.directionRandomizer;\r\n }\r\n}\r\n\r\n/**\r\n * Particle emitter emitting particles from the inside of a cylinder.\r\n * It emits the particles randomly between two vectors.\r\n */\r\nexport class CylinderDirectedParticleEmitter extends CylinderParticleEmitter {\r\n /**\r\n * Creates a new instance CylinderDirectedParticleEmitter\r\n * @param radius the radius of the emission cylinder (1 by default)\r\n * @param height the height of the emission cylinder (1 by default)\r\n * @param radiusRange the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)\r\n * @param direction1 the min limit of the emission direction (up vector by default)\r\n * @param direction2 the max limit of the emission direction (up vector by default)\r\n */\r\n constructor(\r\n radius = 1,\r\n height = 1,\r\n radiusRange = 1,\r\n /**\r\n * The min limit of the emission direction.\r\n */\r\n public direction1 = new Vector3(0, 1, 0),\r\n /**\r\n * The max limit of the emission direction.\r\n */\r\n public direction2 = new Vector3(0, 1, 0)\r\n ) {\r\n super(radius, height, radiusRange);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the direction is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param directionToUpdate is the direction vector to update with the result\r\n * @param _particle is the particle we are computed the direction for\r\n * @param isLocal defines if the direction should be set in local space\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, _particle: Particle, isLocal: boolean): void {\r\n const randX = Scalar.RandomRange(this.direction1.x, this.direction2.x);\r\n const randY = Scalar.RandomRange(this.direction1.y, this.direction2.y);\r\n const randZ = Scalar.RandomRange(this.direction1.z, this.direction2.z);\r\n if (isLocal) {\r\n directionToUpdate.copyFromFloats(randX, randY, randZ);\r\n return;\r\n }\r\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Clones the current emitter and returns a copy of it\r\n * @returns the new emitter\r\n */\r\n public clone(): CylinderDirectedParticleEmitter {\r\n const newOne = new CylinderDirectedParticleEmitter(this.radius, this.height, this.radiusRange, this.direction1, this.direction2);\r\n\r\n DeepCopier.DeepCopy(this, newOne);\r\n\r\n return newOne;\r\n }\r\n\r\n /**\r\n * Called by the GPUParticleSystem to setup the update shader\r\n * @param uboOrEffect defines the update shader\r\n */\r\n public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {\r\n uboOrEffect.setFloat(\"radius\", this.radius);\r\n uboOrEffect.setFloat(\"height\", this.height);\r\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\r\n uboOrEffect.setVector3(\"direction1\", this.direction1);\r\n uboOrEffect.setVector3(\"direction2\", this.direction2);\r\n }\r\n\r\n /**\r\n * Creates the structure of the ubo for this particle emitter\r\n * @param ubo ubo to create the structure for\r\n */\r\n public buildUniformLayout(ubo: UniformBuffer): void {\r\n ubo.addUniform(\"radius\", 1);\r\n ubo.addUniform(\"height\", 1);\r\n ubo.addUniform(\"radiusRange\", 1);\r\n ubo.addUniform(\"direction1\", 3);\r\n ubo.addUniform(\"direction2\", 3);\r\n }\r\n\r\n /**\r\n * Returns a string to use to update the GPU particles update shader\r\n * @returns a string containing the defines string\r\n */\r\n public getEffectDefines(): string {\r\n return \"#define CYLINDEREMITTER\\n#define DIRECTEDCYLINDEREMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"CylinderDirectedParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"CylinderDirectedParticleEmitter\";\r\n }\r\n\r\n /**\r\n * Serializes the particle system to a JSON object.\r\n * @returns the JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.direction1 = this.direction1.asArray();\r\n serializationObject.direction2 = this.direction2.asArray();\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse properties from a JSON object\r\n * @param serializationObject defines the JSON object\r\n */\r\n public parse(serializationObject: any): void {\r\n super.parse(serializationObject);\r\n Vector3.FromArrayToRef(serializationObject.direction1, 0, this.direction1);\r\n Vector3.FromArrayToRef(serializationObject.direction2, 0, this.direction2);\r\n }\r\n}\r\n"]}
@@ -229,18 +229,16 @@ float thickness=thicknessMap.r*vThicknessParam.y+vThicknessParam.x;
229
229
  #if DEBUGMODE>0
230
230
  outParams.thicknessMap=thicknessMap;
231
231
  #endif
232
- #ifdef SS_MASK_FROM_THICKNESS_TEXTURE
233
- #if defined(SS_REFRACTION) && defined(SS_REFRACTION_USE_INTENSITY_FROM_TEXTURE)
232
+ #if defined(SS_REFRACTION) && defined(SS_REFRACTION_USE_INTENSITY_FROM_THICKNESS)
234
233
  #if defined(SS_USE_GLTF_TEXTURES)
235
234
  refractionIntensity*=thicknessMap.r;
236
235
  #else
237
236
  refractionIntensity*=thicknessMap.g;
238
237
  #endif
239
238
  #endif
240
- #if defined(SS_TRANSLUCENCY) && defined(SS_TRANSLUCENCY_USE_INTENSITY_FROM_TEXTURE)
239
+ #if defined(SS_TRANSLUCENCY) && defined(SS_TRANSLUCENCY_USE_INTENSITY_FROM_THICKNESS)
241
240
  translucencyIntensity*=thicknessMap.b;
242
241
  #endif
243
- #endif
244
242
  #else
245
243
  float thickness=vThicknessParam.y;
246
244
  #endif
@@ -251,7 +249,7 @@ refractionIntensity*=refractionIntensityMap.r;
251
249
  refractionIntensity*=refractionIntensityMap.g;
252
250
  #endif
253
251
  #endif
254
- #ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE
252
+ #if defined(SS_TRANSLUCENCY) && defined(SS_TRANSLUCENCYINTENSITY_TEXTURE)
255
253
  translucencyIntensity*=translucencyIntensityMap.b;
256
254
  #endif
257
255
  #ifdef SS_TRANSLUCENCY
@@ -1 +1 @@
1
- {"version":3,"file":"pbrBlockSubSurface.js","sourceRoot":"","sources":["../../../../../dev/core/src/Shaders/ShadersInclude/pbrBlockSubSurface.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,MAAM,IAAI,GAAG,oBAAoB,CAAC;AAClC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4Xd,CAAC;AACF,aAAa;AACb,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAChD,gBAAgB;AAChB,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockSubSurface\";\nconst shader = `struct subSurfaceOutParams\n{vec3 specularEnvironmentReflectance;\n#ifdef SS_REFRACTION\nvec3 finalRefraction;vec3 surfaceAlbedo;\n#ifdef SS_LINKREFRACTIONTOTRANSPARENCY\nfloat alpha;\n#endif\n#ifdef REFLECTION\nfloat refractionFactorForIrradiance;\n#endif\n#endif\n#ifdef SS_TRANSLUCENCY\nvec3 transmittance;float translucencyIntensity;\n#ifdef REFLECTION\nvec3 refractionIrradiance;\n#endif\n#endif\n#if DEBUGMODE>0\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nvec4 thicknessMap;\n#endif\n#ifdef SS_REFRACTION\nvec4 environmentRefraction;vec3 refractionTransmittance;\n#endif\n#endif\n};\n#ifdef SUBSURFACE\n#ifdef SS_REFRACTION\n#define pbr_inline\n#define inline\nvec4 sampleEnvironmentRefraction(\nin float ior\n,in float thickness\n,in float refractionLOD\n,in vec3 normalW\n,in vec3 vPositionW\n,in vec3 viewDirectionW\n,in mat4 view\n,in vec4 vRefractionInfos\n,in mat4 refractionMatrix\n,in vec4 vRefractionMicrosurfaceInfos\n,in float alphaG\n#ifdef SS_REFRACTIONMAP_3D\n,in samplerCube refractionSampler\n#ifndef LODBASEDMICROSFURACE\n,in samplerCube refractionSamplerLow\n,in samplerCube refractionSamplerHigh\n#endif\n#else\n,in sampler2D refractionSampler\n#ifndef LODBASEDMICROSFURACE\n,in sampler2D refractionSamplerLow\n,in sampler2D refractionSamplerHigh\n#endif\n#endif\n#ifdef ANISOTROPIC\n,in anisotropicOutParams anisotropicOut\n#endif\n#ifdef REALTIME_FILTERING\n,in vec2 vRefractionFilteringInfo\n#endif\n#ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC\n,in vec3 refractionPosition\n,in vec3 refractionSize\n#endif\n) {vec4 environmentRefraction=vec4(0.,0.,0.,0.);\n#ifdef ANISOTROPIC\nvec3 refractionVector=refract(-viewDirectionW,anisotropicOut.anisotropicNormal,ior);\n#else\nvec3 refractionVector=refract(-viewDirectionW,normalW,ior);\n#endif\n#ifdef SS_REFRACTIONMAP_OPPOSITEZ\nrefractionVector.z*=-1.0;\n#endif\n#ifdef SS_REFRACTIONMAP_3D\n#ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC\nrefractionVector=parallaxCorrectNormal(vPositionW,refractionVector,refractionSize,refractionPosition);\n#endif\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;vec3 refractionCoords=refractionVector;refractionCoords=vec3(refractionMatrix*vec4(refractionCoords,0));\n#else\n#ifdef SS_USE_THICKNESS_AS_DEPTH\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*thickness,1.0)));\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\n#endif\nvec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;refractionCoords.y=1.0-refractionCoords.y;\n#endif\n#ifdef LODBASEDMICROSFURACE\nrefractionLOD=refractionLOD*vRefractionMicrosurfaceInfos.y+vRefractionMicrosurfaceInfos.z;\n#ifdef SS_LODINREFRACTIONALPHA\nfloat automaticRefractionLOD=UNPACK_LOD(sampleRefraction(refractionSampler,refractionCoords).a);float requestedRefractionLOD=max(automaticRefractionLOD,refractionLOD);\n#else\nfloat requestedRefractionLOD=refractionLOD;\n#endif\n#if defined(REALTIME_FILTERING) && defined(SS_REFRACTIONMAP_3D)\nenvironmentRefraction=vec4(radiance(alphaG,refractionSampler,refractionCoords,vRefractionFilteringInfo),1.0);\n#else\nenvironmentRefraction=sampleRefractionLod(refractionSampler,refractionCoords,requestedRefractionLOD);\n#endif\n#else\nfloat lodRefractionNormalized=saturate(refractionLOD/log2(vRefractionMicrosurfaceInfos.x));float lodRefractionNormalizedDoubled=lodRefractionNormalized*2.0;vec4 environmentRefractionMid=sampleRefraction(refractionSampler,refractionCoords);if (lodRefractionNormalizedDoubled<1.0){environmentRefraction=mix(\nsampleRefraction(refractionSamplerHigh,refractionCoords),\nenvironmentRefractionMid,\nlodRefractionNormalizedDoubled\n);} else {environmentRefraction=mix(\nenvironmentRefractionMid,\nsampleRefraction(refractionSamplerLow,refractionCoords),\nlodRefractionNormalizedDoubled-1.0\n);}\n#endif\n#ifdef SS_RGBDREFRACTION\nenvironmentRefraction.rgb=fromRGBD(environmentRefraction);\n#endif\n#ifdef SS_GAMMAREFRACTION\nenvironmentRefraction.rgb=toLinearSpace(environmentRefraction.rgb);\n#endif\nreturn environmentRefraction;}\n#endif\n#define pbr_inline\n#define inline\nvoid subSurfaceBlock(\nin vec3 vSubSurfaceIntensity,\nin vec2 vThicknessParam,\nin vec4 vTintColor,\nin vec3 normalW,\nin vec3 specularEnvironmentReflectance,\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nin vec4 thicknessMap,\n#endif\n#ifdef SS_REFRACTIONINTENSITY_TEXTURE\nin vec4 refractionIntensityMap,\n#endif\n#ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE\nin vec4 translucencyIntensityMap,\n#endif\n#ifdef REFLECTION\n#ifdef SS_TRANSLUCENCY\nin mat4 reflectionMatrix,\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)\nin vec3 irradianceVector_,\n#endif\n#if defined(REALTIME_FILTERING)\nin samplerCube reflectionSampler,\nin vec2 vReflectionFilteringInfo,\n#endif\n#endif\n#ifdef USEIRRADIANCEMAP\n#ifdef REFLECTIONMAP_3D\nin samplerCube irradianceSampler,\n#else\nin sampler2D irradianceSampler,\n#endif\n#endif\n#endif\n#endif\n#if defined(SS_REFRACTION) || defined(SS_TRANSLUCENCY)\nin vec3 surfaceAlbedo,\n#endif\n#ifdef SS_REFRACTION\nin vec3 vPositionW,\nin vec3 viewDirectionW,\nin mat4 view,\nin vec4 vRefractionInfos,\nin mat4 refractionMatrix,\nin vec4 vRefractionMicrosurfaceInfos,\nin vec4 vLightingIntensity,\n#ifdef SS_LINKREFRACTIONTOTRANSPARENCY\nin float alpha,\n#endif\n#ifdef SS_LODINREFRACTIONALPHA\nin float NdotVUnclamped,\n#endif\n#ifdef SS_LINEARSPECULARREFRACTION\nin float roughness,\n#endif\nin float alphaG,\n#ifdef SS_REFRACTIONMAP_3D\nin samplerCube refractionSampler,\n#ifndef LODBASEDMICROSFURACE\nin samplerCube refractionSamplerLow,\nin samplerCube refractionSamplerHigh,\n#endif\n#else\nin sampler2D refractionSampler,\n#ifndef LODBASEDMICROSFURACE\nin sampler2D refractionSamplerLow,\nin sampler2D refractionSamplerHigh,\n#endif\n#endif\n#ifdef ANISOTROPIC\nin anisotropicOutParams anisotropicOut,\n#endif\n#ifdef REALTIME_FILTERING\nin vec2 vRefractionFilteringInfo,\n#endif\n#ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC\nin vec3 refractionPosition,\nin vec3 refractionSize,\n#endif\n#ifdef SS_DISPERSION\nin float dispersion,\n#endif\n#endif\n#ifdef SS_TRANSLUCENCY\nin vec3 vDiffusionDistance,\n#endif\nout subSurfaceOutParams outParams\n)\n{outParams.specularEnvironmentReflectance=specularEnvironmentReflectance;\n#ifdef SS_REFRACTION\nfloat refractionIntensity=vSubSurfaceIntensity.x;\n#ifdef SS_LINKREFRACTIONTOTRANSPARENCY\nrefractionIntensity*=(1.0-alpha);outParams.alpha=1.0;\n#endif\n#endif\n#ifdef SS_TRANSLUCENCY\nfloat translucencyIntensity=vSubSurfaceIntensity.y;\n#endif\n#ifdef SS_THICKNESSANDMASK_TEXTURE\n#if defined(SS_USE_GLTF_TEXTURES)\nfloat thickness=thicknessMap.g*vThicknessParam.y+vThicknessParam.x;\n#else\nfloat thickness=thicknessMap.r*vThicknessParam.y+vThicknessParam.x;\n#endif\n#if DEBUGMODE>0\noutParams.thicknessMap=thicknessMap;\n#endif\n#ifdef SS_MASK_FROM_THICKNESS_TEXTURE\n#if defined(SS_REFRACTION) && defined(SS_REFRACTION_USE_INTENSITY_FROM_TEXTURE)\n#if defined(SS_USE_GLTF_TEXTURES)\nrefractionIntensity*=thicknessMap.r;\n#else\nrefractionIntensity*=thicknessMap.g;\n#endif\n#endif\n#if defined(SS_TRANSLUCENCY) && defined(SS_TRANSLUCENCY_USE_INTENSITY_FROM_TEXTURE)\ntranslucencyIntensity*=thicknessMap.b;\n#endif\n#endif\n#else\nfloat thickness=vThicknessParam.y;\n#endif\n#if defined(SS_REFRACTION) && defined(SS_REFRACTIONINTENSITY_TEXTURE)\n#ifdef SS_USE_GLTF_TEXTURES\nrefractionIntensity*=refractionIntensityMap.r;\n#else\nrefractionIntensity*=refractionIntensityMap.g;\n#endif\n#endif\n#ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE\ntranslucencyIntensity*=translucencyIntensityMap.b;\n#endif\n#ifdef SS_TRANSLUCENCY\nthickness=maxEps(thickness);vec3 transmittance=transmittanceBRDF_Burley(vTintColor.rgb,vDiffusionDistance,thickness);transmittance*=translucencyIntensity;outParams.transmittance=transmittance;outParams.translucencyIntensity=translucencyIntensity;\n#endif\n#ifdef SS_REFRACTION\nvec4 environmentRefraction=vec4(0.,0.,0.,0.);\n#ifdef SS_HAS_THICKNESS\nfloat ior=vRefractionInfos.y;\n#else\nfloat ior=vRefractionMicrosurfaceInfos.w;\n#endif\n#ifdef SS_LODINREFRACTIONALPHA\nfloat refractionAlphaG=alphaG;refractionAlphaG=mix(alphaG,0.0,clamp(ior*3.0-2.0,0.0,1.0));float refractionLOD=getLodFromAlphaG(vRefractionMicrosurfaceInfos.x,refractionAlphaG,NdotVUnclamped);\n#elif defined(SS_LINEARSPECULARREFRACTION)\nfloat refractionRoughness=alphaG;refractionRoughness=mix(alphaG,0.0,clamp(ior*3.0-2.0,0.0,1.0));float refractionLOD=getLinearLodFromRoughness(vRefractionMicrosurfaceInfos.x,refractionRoughness);\n#else\nfloat refractionAlphaG=alphaG;refractionAlphaG=mix(alphaG,0.0,clamp(ior*3.0-2.0,0.0,1.0));float refractionLOD=getLodFromAlphaG(vRefractionMicrosurfaceInfos.x,refractionAlphaG);\n#endif\nfloat refraction_ior=vRefractionInfos.y;\n#ifdef SS_DISPERSION\nfloat realIOR=1.0/refraction_ior;float iorDispersionSpread=0.04*dispersion*(realIOR-1.0);vec3 iors=vec3(1.0/(realIOR-iorDispersionSpread),refraction_ior,1.0/(realIOR+iorDispersionSpread));for (int i=0; i<3; i++) {refraction_ior=iors[i];\n#endif\nvec4 envSample=sampleEnvironmentRefraction(refraction_ior,thickness,refractionLOD,normalW,vPositionW,viewDirectionW,view,vRefractionInfos,refractionMatrix,vRefractionMicrosurfaceInfos,alphaG\n#ifdef SS_REFRACTIONMAP_3D\n,refractionSampler\n#ifndef LODBASEDMICROSFURACE\n,refractionSamplerLow\n,refractionSamplerHigh\n#endif\n#else\n,refractionSampler\n#ifndef LODBASEDMICROSFURACE\n,refractionSamplerLow\n,refractionSamplerHigh\n#endif\n#endif\n#ifdef ANISOTROPIC\n,anisotropicOut\n#endif\n#ifdef REALTIME_FILTERING\n,vRefractionFilteringInfo\n#endif\n#ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC\n,refractionPosition\n,refractionSize\n#endif\n);\n#ifdef SS_DISPERSION\nenvironmentRefraction[i]=envSample[i];}\n#else\nenvironmentRefraction=envSample;\n#endif\nenvironmentRefraction.rgb*=vRefractionInfos.x;\n#endif\n#ifdef SS_REFRACTION\nvec3 refractionTransmittance=vec3(refractionIntensity);\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nvec3 volumeAlbedo=computeColorAtDistanceInMedia(vTintColor.rgb,vTintColor.w);refractionTransmittance*=cocaLambert(volumeAlbedo,thickness);\n#elif defined(SS_LINKREFRACTIONTOTRANSPARENCY)\nfloat maxChannel=max(max(surfaceAlbedo.r,surfaceAlbedo.g),surfaceAlbedo.b);vec3 volumeAlbedo=saturate(maxChannel*surfaceAlbedo);environmentRefraction.rgb*=volumeAlbedo;\n#else\nvec3 volumeAlbedo=computeColorAtDistanceInMedia(vTintColor.rgb,vTintColor.w);refractionTransmittance*=cocaLambert(volumeAlbedo,vThicknessParam.y);\n#endif\n#ifdef SS_ALBEDOFORREFRACTIONTINT\nenvironmentRefraction.rgb*=surfaceAlbedo.rgb;\n#endif\noutParams.surfaceAlbedo=surfaceAlbedo*(1.-refractionIntensity);\n#ifdef REFLECTION\noutParams.refractionFactorForIrradiance=(1.-refractionIntensity);\n#endif\n#ifdef UNUSED_MULTIPLEBOUNCES\nvec3 bounceSpecularEnvironmentReflectance=(2.0*specularEnvironmentReflectance)/(1.0+specularEnvironmentReflectance);outParams.specularEnvironmentReflectance=mix(bounceSpecularEnvironmentReflectance,specularEnvironmentReflectance,refractionIntensity);\n#endif\nrefractionTransmittance*=1.0-outParams.specularEnvironmentReflectance;\n#if DEBUGMODE>0\noutParams.refractionTransmittance=refractionTransmittance;\n#endif\noutParams.finalRefraction=environmentRefraction.rgb*refractionTransmittance*vLightingIntensity.z;\n#if DEBUGMODE>0\noutParams.environmentRefraction=environmentRefraction;\n#endif\n#endif\n#if defined(REFLECTION) && defined(SS_TRANSLUCENCY)\n#if defined(NORMAL) && defined(USESPHERICALINVERTEX) || !defined(USESPHERICALFROMREFLECTIONMAP)\nvec3 irradianceVector=vec3(reflectionMatrix*vec4(normalW,0)).xyz;\n#ifdef REFLECTIONMAP_OPPOSITEZ\nirradianceVector.z*=-1.0;\n#endif\n#ifdef INVERTCUBICMAP\nirradianceVector.y*=-1.0;\n#endif\n#else\nvec3 irradianceVector=irradianceVector_;\n#endif\n#if defined(USESPHERICALFROMREFLECTIONMAP)\n#if defined(REALTIME_FILTERING)\nvec3 refractionIrradiance=irradiance(reflectionSampler,-irradianceVector,vReflectionFilteringInfo);\n#else\nvec3 refractionIrradiance=computeEnvironmentIrradiance(-irradianceVector);\n#endif\n#elif defined(USEIRRADIANCEMAP)\n#ifdef REFLECTIONMAP_3D\nvec3 irradianceCoords=irradianceVector;\n#else\nvec2 irradianceCoords=irradianceVector.xy;\n#ifdef REFLECTIONMAP_PROJECTION\nirradianceCoords/=irradianceVector.z;\n#endif\nirradianceCoords.y=1.0-irradianceCoords.y;\n#endif\nvec4 refractionIrradiance=sampleReflection(irradianceSampler,-irradianceCoords);\n#ifdef RGBDREFLECTION\nrefractionIrradiance.rgb=fromRGBD(refractionIrradiance);\n#endif\n#ifdef GAMMAREFLECTION\nrefractionIrradiance.rgb=toLinearSpace(refractionIrradiance.rgb);\n#endif\n#else\nvec4 refractionIrradiance=vec4(0.);\n#endif\nrefractionIrradiance.rgb*=transmittance;\n#ifdef SS_ALBEDOFORTRANSLUCENCYTINT\nrefractionIrradiance.rgb*=surfaceAlbedo.rgb;\n#endif\noutParams.refractionIrradiance=refractionIrradiance.rgb;\n#endif\n}\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockSubSurface = { name, shader };\n"]}
1
+ {"version":3,"file":"pbrBlockSubSurface.js","sourceRoot":"","sources":["../../../../../dev/core/src/Shaders/ShadersInclude/pbrBlockSubSurface.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,MAAM,IAAI,GAAG,oBAAoB,CAAC;AAClC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0Xd,CAAC;AACF,aAAa;AACb,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAChD,gBAAgB;AAChB,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockSubSurface\";\nconst shader = `struct subSurfaceOutParams\n{vec3 specularEnvironmentReflectance;\n#ifdef SS_REFRACTION\nvec3 finalRefraction;vec3 surfaceAlbedo;\n#ifdef SS_LINKREFRACTIONTOTRANSPARENCY\nfloat alpha;\n#endif\n#ifdef REFLECTION\nfloat refractionFactorForIrradiance;\n#endif\n#endif\n#ifdef SS_TRANSLUCENCY\nvec3 transmittance;float translucencyIntensity;\n#ifdef REFLECTION\nvec3 refractionIrradiance;\n#endif\n#endif\n#if DEBUGMODE>0\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nvec4 thicknessMap;\n#endif\n#ifdef SS_REFRACTION\nvec4 environmentRefraction;vec3 refractionTransmittance;\n#endif\n#endif\n};\n#ifdef SUBSURFACE\n#ifdef SS_REFRACTION\n#define pbr_inline\n#define inline\nvec4 sampleEnvironmentRefraction(\nin float ior\n,in float thickness\n,in float refractionLOD\n,in vec3 normalW\n,in vec3 vPositionW\n,in vec3 viewDirectionW\n,in mat4 view\n,in vec4 vRefractionInfos\n,in mat4 refractionMatrix\n,in vec4 vRefractionMicrosurfaceInfos\n,in float alphaG\n#ifdef SS_REFRACTIONMAP_3D\n,in samplerCube refractionSampler\n#ifndef LODBASEDMICROSFURACE\n,in samplerCube refractionSamplerLow\n,in samplerCube refractionSamplerHigh\n#endif\n#else\n,in sampler2D refractionSampler\n#ifndef LODBASEDMICROSFURACE\n,in sampler2D refractionSamplerLow\n,in sampler2D refractionSamplerHigh\n#endif\n#endif\n#ifdef ANISOTROPIC\n,in anisotropicOutParams anisotropicOut\n#endif\n#ifdef REALTIME_FILTERING\n,in vec2 vRefractionFilteringInfo\n#endif\n#ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC\n,in vec3 refractionPosition\n,in vec3 refractionSize\n#endif\n) {vec4 environmentRefraction=vec4(0.,0.,0.,0.);\n#ifdef ANISOTROPIC\nvec3 refractionVector=refract(-viewDirectionW,anisotropicOut.anisotropicNormal,ior);\n#else\nvec3 refractionVector=refract(-viewDirectionW,normalW,ior);\n#endif\n#ifdef SS_REFRACTIONMAP_OPPOSITEZ\nrefractionVector.z*=-1.0;\n#endif\n#ifdef SS_REFRACTIONMAP_3D\n#ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC\nrefractionVector=parallaxCorrectNormal(vPositionW,refractionVector,refractionSize,refractionPosition);\n#endif\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;vec3 refractionCoords=refractionVector;refractionCoords=vec3(refractionMatrix*vec4(refractionCoords,0));\n#else\n#ifdef SS_USE_THICKNESS_AS_DEPTH\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*thickness,1.0)));\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\n#endif\nvec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;refractionCoords.y=1.0-refractionCoords.y;\n#endif\n#ifdef LODBASEDMICROSFURACE\nrefractionLOD=refractionLOD*vRefractionMicrosurfaceInfos.y+vRefractionMicrosurfaceInfos.z;\n#ifdef SS_LODINREFRACTIONALPHA\nfloat automaticRefractionLOD=UNPACK_LOD(sampleRefraction(refractionSampler,refractionCoords).a);float requestedRefractionLOD=max(automaticRefractionLOD,refractionLOD);\n#else\nfloat requestedRefractionLOD=refractionLOD;\n#endif\n#if defined(REALTIME_FILTERING) && defined(SS_REFRACTIONMAP_3D)\nenvironmentRefraction=vec4(radiance(alphaG,refractionSampler,refractionCoords,vRefractionFilteringInfo),1.0);\n#else\nenvironmentRefraction=sampleRefractionLod(refractionSampler,refractionCoords,requestedRefractionLOD);\n#endif\n#else\nfloat lodRefractionNormalized=saturate(refractionLOD/log2(vRefractionMicrosurfaceInfos.x));float lodRefractionNormalizedDoubled=lodRefractionNormalized*2.0;vec4 environmentRefractionMid=sampleRefraction(refractionSampler,refractionCoords);if (lodRefractionNormalizedDoubled<1.0){environmentRefraction=mix(\nsampleRefraction(refractionSamplerHigh,refractionCoords),\nenvironmentRefractionMid,\nlodRefractionNormalizedDoubled\n);} else {environmentRefraction=mix(\nenvironmentRefractionMid,\nsampleRefraction(refractionSamplerLow,refractionCoords),\nlodRefractionNormalizedDoubled-1.0\n);}\n#endif\n#ifdef SS_RGBDREFRACTION\nenvironmentRefraction.rgb=fromRGBD(environmentRefraction);\n#endif\n#ifdef SS_GAMMAREFRACTION\nenvironmentRefraction.rgb=toLinearSpace(environmentRefraction.rgb);\n#endif\nreturn environmentRefraction;}\n#endif\n#define pbr_inline\n#define inline\nvoid subSurfaceBlock(\nin vec3 vSubSurfaceIntensity,\nin vec2 vThicknessParam,\nin vec4 vTintColor,\nin vec3 normalW,\nin vec3 specularEnvironmentReflectance,\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nin vec4 thicknessMap,\n#endif\n#ifdef SS_REFRACTIONINTENSITY_TEXTURE\nin vec4 refractionIntensityMap,\n#endif\n#ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE\nin vec4 translucencyIntensityMap,\n#endif\n#ifdef REFLECTION\n#ifdef SS_TRANSLUCENCY\nin mat4 reflectionMatrix,\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)\nin vec3 irradianceVector_,\n#endif\n#if defined(REALTIME_FILTERING)\nin samplerCube reflectionSampler,\nin vec2 vReflectionFilteringInfo,\n#endif\n#endif\n#ifdef USEIRRADIANCEMAP\n#ifdef REFLECTIONMAP_3D\nin samplerCube irradianceSampler,\n#else\nin sampler2D irradianceSampler,\n#endif\n#endif\n#endif\n#endif\n#if defined(SS_REFRACTION) || defined(SS_TRANSLUCENCY)\nin vec3 surfaceAlbedo,\n#endif\n#ifdef SS_REFRACTION\nin vec3 vPositionW,\nin vec3 viewDirectionW,\nin mat4 view,\nin vec4 vRefractionInfos,\nin mat4 refractionMatrix,\nin vec4 vRefractionMicrosurfaceInfos,\nin vec4 vLightingIntensity,\n#ifdef SS_LINKREFRACTIONTOTRANSPARENCY\nin float alpha,\n#endif\n#ifdef SS_LODINREFRACTIONALPHA\nin float NdotVUnclamped,\n#endif\n#ifdef SS_LINEARSPECULARREFRACTION\nin float roughness,\n#endif\nin float alphaG,\n#ifdef SS_REFRACTIONMAP_3D\nin samplerCube refractionSampler,\n#ifndef LODBASEDMICROSFURACE\nin samplerCube refractionSamplerLow,\nin samplerCube refractionSamplerHigh,\n#endif\n#else\nin sampler2D refractionSampler,\n#ifndef LODBASEDMICROSFURACE\nin sampler2D refractionSamplerLow,\nin sampler2D refractionSamplerHigh,\n#endif\n#endif\n#ifdef ANISOTROPIC\nin anisotropicOutParams anisotropicOut,\n#endif\n#ifdef REALTIME_FILTERING\nin vec2 vRefractionFilteringInfo,\n#endif\n#ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC\nin vec3 refractionPosition,\nin vec3 refractionSize,\n#endif\n#ifdef SS_DISPERSION\nin float dispersion,\n#endif\n#endif\n#ifdef SS_TRANSLUCENCY\nin vec3 vDiffusionDistance,\n#endif\nout subSurfaceOutParams outParams\n)\n{outParams.specularEnvironmentReflectance=specularEnvironmentReflectance;\n#ifdef SS_REFRACTION\nfloat refractionIntensity=vSubSurfaceIntensity.x;\n#ifdef SS_LINKREFRACTIONTOTRANSPARENCY\nrefractionIntensity*=(1.0-alpha);outParams.alpha=1.0;\n#endif\n#endif\n#ifdef SS_TRANSLUCENCY\nfloat translucencyIntensity=vSubSurfaceIntensity.y;\n#endif\n#ifdef SS_THICKNESSANDMASK_TEXTURE\n#if defined(SS_USE_GLTF_TEXTURES)\nfloat thickness=thicknessMap.g*vThicknessParam.y+vThicknessParam.x;\n#else\nfloat thickness=thicknessMap.r*vThicknessParam.y+vThicknessParam.x;\n#endif\n#if DEBUGMODE>0\noutParams.thicknessMap=thicknessMap;\n#endif\n#if defined(SS_REFRACTION) && defined(SS_REFRACTION_USE_INTENSITY_FROM_THICKNESS)\n#if defined(SS_USE_GLTF_TEXTURES)\nrefractionIntensity*=thicknessMap.r;\n#else\nrefractionIntensity*=thicknessMap.g;\n#endif\n#endif\n#if defined(SS_TRANSLUCENCY) && defined(SS_TRANSLUCENCY_USE_INTENSITY_FROM_THICKNESS)\ntranslucencyIntensity*=thicknessMap.b;\n#endif\n#else\nfloat thickness=vThicknessParam.y;\n#endif\n#if defined(SS_REFRACTION) && defined(SS_REFRACTIONINTENSITY_TEXTURE)\n#ifdef SS_USE_GLTF_TEXTURES\nrefractionIntensity*=refractionIntensityMap.r;\n#else\nrefractionIntensity*=refractionIntensityMap.g;\n#endif\n#endif\n#if defined(SS_TRANSLUCENCY) && defined(SS_TRANSLUCENCYINTENSITY_TEXTURE)\ntranslucencyIntensity*=translucencyIntensityMap.b;\n#endif\n#ifdef SS_TRANSLUCENCY\nthickness=maxEps(thickness);vec3 transmittance=transmittanceBRDF_Burley(vTintColor.rgb,vDiffusionDistance,thickness);transmittance*=translucencyIntensity;outParams.transmittance=transmittance;outParams.translucencyIntensity=translucencyIntensity;\n#endif\n#ifdef SS_REFRACTION\nvec4 environmentRefraction=vec4(0.,0.,0.,0.);\n#ifdef SS_HAS_THICKNESS\nfloat ior=vRefractionInfos.y;\n#else\nfloat ior=vRefractionMicrosurfaceInfos.w;\n#endif\n#ifdef SS_LODINREFRACTIONALPHA\nfloat refractionAlphaG=alphaG;refractionAlphaG=mix(alphaG,0.0,clamp(ior*3.0-2.0,0.0,1.0));float refractionLOD=getLodFromAlphaG(vRefractionMicrosurfaceInfos.x,refractionAlphaG,NdotVUnclamped);\n#elif defined(SS_LINEARSPECULARREFRACTION)\nfloat refractionRoughness=alphaG;refractionRoughness=mix(alphaG,0.0,clamp(ior*3.0-2.0,0.0,1.0));float refractionLOD=getLinearLodFromRoughness(vRefractionMicrosurfaceInfos.x,refractionRoughness);\n#else\nfloat refractionAlphaG=alphaG;refractionAlphaG=mix(alphaG,0.0,clamp(ior*3.0-2.0,0.0,1.0));float refractionLOD=getLodFromAlphaG(vRefractionMicrosurfaceInfos.x,refractionAlphaG);\n#endif\nfloat refraction_ior=vRefractionInfos.y;\n#ifdef SS_DISPERSION\nfloat realIOR=1.0/refraction_ior;float iorDispersionSpread=0.04*dispersion*(realIOR-1.0);vec3 iors=vec3(1.0/(realIOR-iorDispersionSpread),refraction_ior,1.0/(realIOR+iorDispersionSpread));for (int i=0; i<3; i++) {refraction_ior=iors[i];\n#endif\nvec4 envSample=sampleEnvironmentRefraction(refraction_ior,thickness,refractionLOD,normalW,vPositionW,viewDirectionW,view,vRefractionInfos,refractionMatrix,vRefractionMicrosurfaceInfos,alphaG\n#ifdef SS_REFRACTIONMAP_3D\n,refractionSampler\n#ifndef LODBASEDMICROSFURACE\n,refractionSamplerLow\n,refractionSamplerHigh\n#endif\n#else\n,refractionSampler\n#ifndef LODBASEDMICROSFURACE\n,refractionSamplerLow\n,refractionSamplerHigh\n#endif\n#endif\n#ifdef ANISOTROPIC\n,anisotropicOut\n#endif\n#ifdef REALTIME_FILTERING\n,vRefractionFilteringInfo\n#endif\n#ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC\n,refractionPosition\n,refractionSize\n#endif\n);\n#ifdef SS_DISPERSION\nenvironmentRefraction[i]=envSample[i];}\n#else\nenvironmentRefraction=envSample;\n#endif\nenvironmentRefraction.rgb*=vRefractionInfos.x;\n#endif\n#ifdef SS_REFRACTION\nvec3 refractionTransmittance=vec3(refractionIntensity);\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nvec3 volumeAlbedo=computeColorAtDistanceInMedia(vTintColor.rgb,vTintColor.w);refractionTransmittance*=cocaLambert(volumeAlbedo,thickness);\n#elif defined(SS_LINKREFRACTIONTOTRANSPARENCY)\nfloat maxChannel=max(max(surfaceAlbedo.r,surfaceAlbedo.g),surfaceAlbedo.b);vec3 volumeAlbedo=saturate(maxChannel*surfaceAlbedo);environmentRefraction.rgb*=volumeAlbedo;\n#else\nvec3 volumeAlbedo=computeColorAtDistanceInMedia(vTintColor.rgb,vTintColor.w);refractionTransmittance*=cocaLambert(volumeAlbedo,vThicknessParam.y);\n#endif\n#ifdef SS_ALBEDOFORREFRACTIONTINT\nenvironmentRefraction.rgb*=surfaceAlbedo.rgb;\n#endif\noutParams.surfaceAlbedo=surfaceAlbedo*(1.-refractionIntensity);\n#ifdef REFLECTION\noutParams.refractionFactorForIrradiance=(1.-refractionIntensity);\n#endif\n#ifdef UNUSED_MULTIPLEBOUNCES\nvec3 bounceSpecularEnvironmentReflectance=(2.0*specularEnvironmentReflectance)/(1.0+specularEnvironmentReflectance);outParams.specularEnvironmentReflectance=mix(bounceSpecularEnvironmentReflectance,specularEnvironmentReflectance,refractionIntensity);\n#endif\nrefractionTransmittance*=1.0-outParams.specularEnvironmentReflectance;\n#if DEBUGMODE>0\noutParams.refractionTransmittance=refractionTransmittance;\n#endif\noutParams.finalRefraction=environmentRefraction.rgb*refractionTransmittance*vLightingIntensity.z;\n#if DEBUGMODE>0\noutParams.environmentRefraction=environmentRefraction;\n#endif\n#endif\n#if defined(REFLECTION) && defined(SS_TRANSLUCENCY)\n#if defined(NORMAL) && defined(USESPHERICALINVERTEX) || !defined(USESPHERICALFROMREFLECTIONMAP)\nvec3 irradianceVector=vec3(reflectionMatrix*vec4(normalW,0)).xyz;\n#ifdef REFLECTIONMAP_OPPOSITEZ\nirradianceVector.z*=-1.0;\n#endif\n#ifdef INVERTCUBICMAP\nirradianceVector.y*=-1.0;\n#endif\n#else\nvec3 irradianceVector=irradianceVector_;\n#endif\n#if defined(USESPHERICALFROMREFLECTIONMAP)\n#if defined(REALTIME_FILTERING)\nvec3 refractionIrradiance=irradiance(reflectionSampler,-irradianceVector,vReflectionFilteringInfo);\n#else\nvec3 refractionIrradiance=computeEnvironmentIrradiance(-irradianceVector);\n#endif\n#elif defined(USEIRRADIANCEMAP)\n#ifdef REFLECTIONMAP_3D\nvec3 irradianceCoords=irradianceVector;\n#else\nvec2 irradianceCoords=irradianceVector.xy;\n#ifdef REFLECTIONMAP_PROJECTION\nirradianceCoords/=irradianceVector.z;\n#endif\nirradianceCoords.y=1.0-irradianceCoords.y;\n#endif\nvec4 refractionIrradiance=sampleReflection(irradianceSampler,-irradianceCoords);\n#ifdef RGBDREFLECTION\nrefractionIrradiance.rgb=fromRGBD(refractionIrradiance);\n#endif\n#ifdef GAMMAREFLECTION\nrefractionIrradiance.rgb=toLinearSpace(refractionIrradiance.rgb);\n#endif\n#else\nvec4 refractionIrradiance=vec4(0.);\n#endif\nrefractionIrradiance.rgb*=transmittance;\n#ifdef SS_ALBEDOFORTRANSLUCENCYTINT\nrefractionIrradiance.rgb*=surfaceAlbedo.rgb;\n#endif\noutParams.refractionIrradiance=refractionIrradiance.rgb;\n#endif\n}\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockSubSurface = { name, shader };\n"]}