@babylonjs/core 7.40.1 → 7.40.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Materials/Node/Blocks/Vertex/morphTargetsBlock.d.ts +10 -2
- package/Materials/Node/Blocks/Vertex/morphTargetsBlock.js +48 -2
- package/Materials/Node/Blocks/Vertex/morphTargetsBlock.js.map +1 -1
- package/Materials/Node/Blocks/meshAttributeExistsBlock.js +3 -0
- package/Materials/Node/Blocks/meshAttributeExistsBlock.js.map +1 -1
- package/Materials/Node/nodeMaterial.d.ts +2 -0
- package/Materials/Node/nodeMaterial.js +2 -0
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.d.ts +1 -0
- package/Materials/PBR/pbrBaseMaterial.js +1 -0
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/effect.functions.js +1 -1
- package/Materials/effect.functions.js.map +1 -1
- package/Materials/materialHelper.functions.js +2 -0
- package/Materials/materialHelper.functions.js.map +1 -1
- package/Materials/shaderMaterial.js +4 -0
- package/Materials/shaderMaterial.js.map +1 -1
- package/Materials/standardMaterial.d.ts +1 -0
- package/Materials/standardMaterial.js +1 -0
- package/Materials/standardMaterial.js.map +1 -1
- package/Meshes/Compression/dracoCodec.d.ts +83 -0
- package/Meshes/Compression/dracoCodec.js +107 -0
- package/Meshes/Compression/dracoCodec.js.map +1 -0
- package/Meshes/Compression/dracoCompression.d.ts +17 -63
- package/Meshes/Compression/dracoCompression.js +22 -200
- package/Meshes/Compression/dracoCompression.js.map +1 -1
- package/Meshes/Compression/dracoDecoder.d.ts +103 -0
- package/Meshes/Compression/dracoDecoder.js +216 -0
- package/Meshes/Compression/dracoDecoder.js.map +1 -0
- package/Meshes/Compression/index.d.ts +1 -0
- package/Meshes/Compression/index.js +1 -0
- package/Meshes/Compression/index.js.map +1 -1
- package/Meshes/mesh.js +23 -0
- package/Meshes/mesh.js.map +1 -1
- package/Misc/screenshotTools.d.ts +3 -3
- package/Misc/screenshotTools.js +3 -3
- package/Misc/screenshotTools.js.map +1 -1
- package/Morph/morphTarget.d.ts +15 -0
- package/Morph/morphTarget.js +35 -0
- package/Morph/morphTarget.js.map +1 -1
- package/Morph/morphTargetManager.d.ts +9 -0
- package/Morph/morphTargetManager.js +23 -0
- package/Morph/morphTargetManager.js.map +1 -1
- package/Shaders/ShadersInclude/morphTargetsVertex.js +7 -1
- package/Shaders/ShadersInclude/morphTargetsVertex.js.map +1 -1
- package/Shaders/ShadersInclude/morphTargetsVertexDeclaration.js +3 -0
- package/Shaders/ShadersInclude/morphTargetsVertexDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/samplerVertexImplementation.js +1 -1
- package/Shaders/ShadersInclude/samplerVertexImplementation.js.map +1 -1
- package/Shaders/default.vertex.js +10 -1
- package/Shaders/default.vertex.js.map +1 -1
- package/Shaders/depth.vertex.js +4 -1
- package/Shaders/depth.vertex.js.map +1 -1
- package/Shaders/geometry.vertex.js +9 -6
- package/Shaders/geometry.vertex.js.map +1 -1
- package/Shaders/glowMapGeneration.vertex.js +6 -3
- package/Shaders/glowMapGeneration.vertex.js.map +1 -1
- package/Shaders/outline.vertex.js +4 -1
- package/Shaders/outline.vertex.js.map +1 -1
- package/Shaders/pbr.vertex.js +10 -1
- package/Shaders/pbr.vertex.js.map +1 -1
- package/Shaders/shadowMap.vertex.js +4 -1
- package/Shaders/shadowMap.vertex.js.map +1 -1
- package/Shaders/volumetricLightScatteringPass.vertex.js +4 -1
- package/Shaders/volumetricLightScatteringPass.vertex.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/morphTargetsVertex.js +7 -1
- package/ShadersWGSL/ShadersInclude/morphTargetsVertex.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/morphTargetsVertexDeclaration.js +3 -0
- package/ShadersWGSL/ShadersInclude/morphTargetsVertexDeclaration.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/samplerVertexImplementation.js +1 -1
- package/ShadersWGSL/ShadersInclude/samplerVertexImplementation.js.map +1 -1
- package/ShadersWGSL/default.vertex.js +10 -1
- package/ShadersWGSL/default.vertex.js.map +1 -1
- package/ShadersWGSL/depth.vertex.js +4 -1
- package/ShadersWGSL/depth.vertex.js.map +1 -1
- package/ShadersWGSL/geometry.vertex.js +9 -6
- package/ShadersWGSL/geometry.vertex.js.map +1 -1
- package/ShadersWGSL/glowMapGeneration.vertex.js +6 -3
- package/ShadersWGSL/glowMapGeneration.vertex.js.map +1 -1
- package/ShadersWGSL/glowMapMerge.fragment.js +3 -2
- package/ShadersWGSL/glowMapMerge.fragment.js.map +1 -1
- package/ShadersWGSL/outline.vertex.js +4 -1
- package/ShadersWGSL/outline.vertex.js.map +1 -1
- package/ShadersWGSL/pbr.vertex.js +10 -1
- package/ShadersWGSL/pbr.vertex.js.map +1 -1
- package/ShadersWGSL/shadowMap.vertex.js +4 -1
- package/ShadersWGSL/shadowMap.vertex.js.map +1 -1
- package/XR/features/WebXRNearInteraction.d.ts +4 -0
- package/XR/features/WebXRNearInteraction.js +15 -8
- package/XR/features/WebXRNearInteraction.js.map +1 -1
- package/assets/Draco/draco_encoder.js +38 -0
- package/assets/Draco/draco_encoder.wasm +0 -0
- package/assets/Draco/draco_encoder_wasm_wrapper.js +96 -0
- package/package.json +1 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { WorkerPool } from "../../Misc/workerPool";
|
|
2
|
+
import type { IDisposable } from "../../scene";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for using a Draco codec.
|
|
5
|
+
*/
|
|
6
|
+
export interface IDracoCodecConfiguration {
|
|
7
|
+
/**
|
|
8
|
+
* The url to the WebAssembly module.
|
|
9
|
+
*/
|
|
10
|
+
wasmUrl?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The url to the WebAssembly binary.
|
|
13
|
+
*/
|
|
14
|
+
wasmBinaryUrl?: string;
|
|
15
|
+
/**
|
|
16
|
+
* The url to the fallback JavaScript module.
|
|
17
|
+
*/
|
|
18
|
+
fallbackUrl?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.
|
|
21
|
+
*/
|
|
22
|
+
numWorkers?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Optional worker pool to use for async encoding/decoding.
|
|
25
|
+
* If provided, the worker pool will be used as is: no Draco scripts will be loaded, and numWorkers will be ignored.
|
|
26
|
+
*/
|
|
27
|
+
workerPool?: WorkerPool;
|
|
28
|
+
/**
|
|
29
|
+
* Optional ArrayBuffer of the WebAssembly binary.
|
|
30
|
+
* If provided it will be used instead of loading the binary from wasmBinaryUrl.
|
|
31
|
+
*/
|
|
32
|
+
wasmBinary?: ArrayBuffer;
|
|
33
|
+
/**
|
|
34
|
+
* The codec module if already available.
|
|
35
|
+
*/
|
|
36
|
+
jsModule?: any;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export declare function _GetDefaultNumWorkers(): number;
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
export declare function _IsConfigurationAvailable(config: IDracoCodecConfiguration): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Base class for a Draco codec.
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
export declare abstract class DracoCodec implements IDisposable {
|
|
51
|
+
protected _workerPoolPromise?: Promise<WorkerPool>;
|
|
52
|
+
protected _modulePromise?: Promise<{
|
|
53
|
+
module: any; /** DecoderModule | EncoderModule */
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Checks if the default codec JS module is in scope.
|
|
57
|
+
*/
|
|
58
|
+
protected abstract _isModuleAvailable(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Creates the JS Module for the corresponding wasm.
|
|
61
|
+
*/
|
|
62
|
+
protected abstract _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: any): Promise<{
|
|
63
|
+
module: any; /** DecoderModule | EncoderModule */
|
|
64
|
+
}>;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the worker content.
|
|
67
|
+
*/
|
|
68
|
+
protected abstract _getWorkerContent(): string;
|
|
69
|
+
/**
|
|
70
|
+
* Constructor
|
|
71
|
+
* @param configuration The configuration for the DracoCodec instance.
|
|
72
|
+
*/
|
|
73
|
+
constructor(configuration: IDracoCodecConfiguration);
|
|
74
|
+
/**
|
|
75
|
+
* Returns a promise that resolves when ready. Call this manually to ensure the draco codec is ready before use.
|
|
76
|
+
* @returns a promise that resolves when ready
|
|
77
|
+
*/
|
|
78
|
+
whenReadyAsync(): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Stop all async operations and release resources.
|
|
81
|
+
*/
|
|
82
|
+
dispose(): void;
|
|
83
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Tools } from "../../Misc/tools.js";
|
|
2
|
+
import { AutoReleaseWorkerPool } from "../../Misc/workerPool.js";
|
|
3
|
+
import { initializeWebWorker } from "./dracoCompressionWorker.js";
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export function _GetDefaultNumWorkers() {
|
|
8
|
+
if (typeof navigator !== "object" || !navigator.hardwareConcurrency) {
|
|
9
|
+
return 1;
|
|
10
|
+
}
|
|
11
|
+
// Use 50% of the available logical processors but capped at 4.
|
|
12
|
+
return Math.min(Math.floor(navigator.hardwareConcurrency * 0.5), 4);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export function _IsConfigurationAvailable(config) {
|
|
18
|
+
return !!((config.wasmUrl && (config.wasmBinary || config.wasmBinaryUrl) && typeof WebAssembly === "object") || config.fallbackUrl);
|
|
19
|
+
// TODO: Account for jsModule
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Base class for a Draco codec.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export class DracoCodec {
|
|
26
|
+
/**
|
|
27
|
+
* Constructor
|
|
28
|
+
* @param configuration The configuration for the DracoCodec instance.
|
|
29
|
+
*/
|
|
30
|
+
constructor(configuration) {
|
|
31
|
+
// check if the codec binary and worker pool was injected
|
|
32
|
+
// Note - it is expected that the developer checked if WebWorker, WebAssembly and the URL object are available
|
|
33
|
+
if (configuration.workerPool) {
|
|
34
|
+
// Set the promise accordingly
|
|
35
|
+
this._workerPoolPromise = Promise.resolve(configuration.workerPool);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
// to avoid making big changes to the code here, if wasmBinary is provided use it in the wasmBinaryPromise
|
|
39
|
+
const wasmBinaryProvided = configuration.wasmBinary;
|
|
40
|
+
const numberOfWorkers = configuration.numWorkers ?? _GetDefaultNumWorkers();
|
|
41
|
+
const useWorkers = numberOfWorkers && typeof Worker === "function" && typeof URL === "function";
|
|
42
|
+
const urlNeeded = useWorkers || !configuration.jsModule;
|
|
43
|
+
// code maintained here for back-compat with no changes
|
|
44
|
+
const codecInfo = configuration.wasmUrl && configuration.wasmBinaryUrl && typeof WebAssembly === "object"
|
|
45
|
+
? {
|
|
46
|
+
url: urlNeeded ? Tools.GetBabylonScriptURL(configuration.wasmUrl, true) : "",
|
|
47
|
+
wasmBinaryPromise: wasmBinaryProvided
|
|
48
|
+
? Promise.resolve(wasmBinaryProvided)
|
|
49
|
+
: Tools.LoadFileAsync(Tools.GetBabylonScriptURL(configuration.wasmBinaryUrl, true)),
|
|
50
|
+
}
|
|
51
|
+
: {
|
|
52
|
+
url: urlNeeded ? Tools.GetBabylonScriptURL(configuration.fallbackUrl) : "",
|
|
53
|
+
wasmBinaryPromise: Promise.resolve(undefined),
|
|
54
|
+
};
|
|
55
|
+
// If using workers, initialize a worker pool with either the wasm or url?
|
|
56
|
+
if (useWorkers) {
|
|
57
|
+
this._workerPoolPromise = codecInfo.wasmBinaryPromise.then((wasmBinary) => {
|
|
58
|
+
const workerContent = this._getWorkerContent();
|
|
59
|
+
const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
|
|
60
|
+
return new AutoReleaseWorkerPool(numberOfWorkers, () => {
|
|
61
|
+
const worker = new Worker(workerBlobUrl);
|
|
62
|
+
return initializeWebWorker(worker, wasmBinary, codecInfo.url);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this._modulePromise = codecInfo.wasmBinaryPromise.then(async (wasmBinary) => {
|
|
68
|
+
if (!this._isModuleAvailable()) {
|
|
69
|
+
if (!configuration.jsModule) {
|
|
70
|
+
if (!codecInfo.url) {
|
|
71
|
+
throw new Error("Draco codec module is not available");
|
|
72
|
+
}
|
|
73
|
+
await Tools.LoadBabylonScriptAsync(codecInfo.url);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return this._createModuleAsync(wasmBinary, configuration.jsModule);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Returns a promise that resolves when ready. Call this manually to ensure the draco codec is ready before use.
|
|
82
|
+
* @returns a promise that resolves when ready
|
|
83
|
+
*/
|
|
84
|
+
async whenReadyAsync() {
|
|
85
|
+
if (this._workerPoolPromise) {
|
|
86
|
+
await this._workerPoolPromise;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (this._modulePromise) {
|
|
90
|
+
await this._modulePromise;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Stop all async operations and release resources.
|
|
96
|
+
*/
|
|
97
|
+
dispose() {
|
|
98
|
+
if (this._workerPoolPromise) {
|
|
99
|
+
this._workerPoolPromise.then((workerPool) => {
|
|
100
|
+
workerPool.dispose();
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
delete this._workerPoolPromise;
|
|
104
|
+
delete this._modulePromise;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=dracoCodec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dracoCodec.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCodec.ts"],"names":[],"mappings":"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","sourcesContent":["import { Tools } from \"../../Misc/tools\";\r\nimport { AutoReleaseWorkerPool } from \"../../Misc/workerPool\";\r\nimport type { WorkerPool } from \"../../Misc/workerPool\";\r\nimport type { IDisposable } from \"../../scene\";\r\nimport { initializeWebWorker } from \"./dracoCompressionWorker\";\r\n\r\n/**\r\n * Configuration for using a Draco codec.\r\n */\r\nexport interface IDracoCodecConfiguration {\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 /**\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 /**\r\n * Optional worker pool to use for async encoding/decoding.\r\n * If provided, the worker pool will be used as is: no Draco scripts will be loaded, and numWorkers will be ignored.\r\n */\r\n workerPool?: WorkerPool;\r\n\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 /**\r\n * The codec module if already available.\r\n */\r\n jsModule?: any /* DracoDecoderModule | DracoEncoderModule */;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _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/**\r\n * @internal\r\n */\r\nexport function _IsConfigurationAvailable(config: IDracoCodecConfiguration): boolean {\r\n return !!((config.wasmUrl && (config.wasmBinary || config.wasmBinaryUrl) && typeof WebAssembly === \"object\") || config.fallbackUrl);\r\n // TODO: Account for jsModule\r\n}\r\n\r\n/**\r\n * Base class for a Draco codec.\r\n * @internal\r\n */\r\nexport abstract class DracoCodec implements IDisposable {\r\n protected _workerPoolPromise?: Promise<WorkerPool>;\r\n protected _modulePromise?: Promise<{ module: any /** DecoderModule | EncoderModule */ }>;\r\n\r\n /**\r\n * Checks if the default codec JS module is in scope.\r\n */\r\n protected abstract _isModuleAvailable(): boolean;\r\n\r\n /**\r\n * Creates the JS Module for the corresponding wasm.\r\n */\r\n protected abstract _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: any): Promise<{ module: any /** DecoderModule | EncoderModule */ }>;\r\n\r\n /**\r\n * Returns the worker content.\r\n */\r\n protected abstract _getWorkerContent(): string;\r\n\r\n /**\r\n * Constructor\r\n * @param configuration The configuration for the DracoCodec instance.\r\n */\r\n constructor(configuration: IDracoCodecConfiguration) {\r\n // check if the codec 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 (configuration.workerPool) {\r\n // Set the promise accordingly\r\n this._workerPoolPromise = Promise.resolve(configuration.workerPool);\r\n return;\r\n }\r\n\r\n // to avoid making big changes to the code here, if wasmBinary is provided use it in the wasmBinaryPromise\r\n const wasmBinaryProvided = configuration.wasmBinary;\r\n const numberOfWorkers = configuration.numWorkers ?? _GetDefaultNumWorkers();\r\n const useWorkers = numberOfWorkers && typeof Worker === \"function\" && typeof URL === \"function\";\r\n const urlNeeded = useWorkers || !configuration.jsModule;\r\n // code maintained here for back-compat with no changes\r\n\r\n const codecInfo: { url: string | undefined; wasmBinaryPromise: Promise<ArrayBuffer | undefined> } =\r\n configuration.wasmUrl && configuration.wasmBinaryUrl && typeof WebAssembly === \"object\"\r\n ? {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(configuration.wasmUrl, true) : \"\",\r\n wasmBinaryPromise: wasmBinaryProvided\r\n ? Promise.resolve(wasmBinaryProvided)\r\n : Tools.LoadFileAsync(Tools.GetBabylonScriptURL(configuration.wasmBinaryUrl, true)),\r\n }\r\n : {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(configuration.fallbackUrl!) : \"\",\r\n wasmBinaryPromise: Promise.resolve(undefined),\r\n };\r\n // If using workers, initialize a worker pool with either the wasm or url?\r\n if (useWorkers) {\r\n this._workerPoolPromise = codecInfo.wasmBinaryPromise.then((wasmBinary) => {\r\n const workerContent = this._getWorkerContent();\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, wasmBinary, codecInfo.url);\r\n });\r\n });\r\n } else {\r\n this._modulePromise = codecInfo.wasmBinaryPromise.then(async (wasmBinary) => {\r\n if (!this._isModuleAvailable()) {\r\n if (!configuration.jsModule) {\r\n if (!codecInfo.url) {\r\n throw new Error(\"Draco codec module is not available\");\r\n }\r\n await Tools.LoadBabylonScriptAsync(codecInfo.url);\r\n }\r\n }\r\n return this._createModuleAsync(wasmBinary as ArrayBuffer, configuration.jsModule);\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when ready. Call this manually to ensure the draco codec 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._modulePromise) {\r\n await this._modulePromise;\r\n return;\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._modulePromise;\r\n }\r\n}\r\n"]}
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import type { Nullable } from "../../types";
|
|
4
|
-
import type { IDisposable, Scene } from "../../scene";
|
|
5
|
-
import { Geometry } from "../geometry";
|
|
1
|
+
import type { IDracoCodecConfiguration } from "./dracoCodec";
|
|
2
|
+
import type { MeshData } from "./dracoDecoder";
|
|
6
3
|
import { VertexData } from "../mesh.vertexData";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
totalVertices: number;
|
|
12
|
-
}
|
|
4
|
+
import type { Nullable } from "../../types.js";
|
|
5
|
+
import type { Geometry } from "../geometry";
|
|
6
|
+
import type { BoundingInfo } from "../../Culling/boundingInfo";
|
|
7
|
+
import type { Scene } from "../../scene";
|
|
13
8
|
/**
|
|
14
9
|
* Configuration for Draco compression
|
|
15
10
|
*/
|
|
@@ -17,52 +12,12 @@ export interface IDracoCompressionConfiguration {
|
|
|
17
12
|
/**
|
|
18
13
|
* Configuration for the decoder.
|
|
19
14
|
*/
|
|
20
|
-
decoder:
|
|
21
|
-
/**
|
|
22
|
-
* The url to the WebAssembly module.
|
|
23
|
-
*/
|
|
24
|
-
wasmUrl?: string;
|
|
25
|
-
/**
|
|
26
|
-
* The url to the WebAssembly binary.
|
|
27
|
-
*/
|
|
28
|
-
wasmBinaryUrl?: string;
|
|
29
|
-
/**
|
|
30
|
-
* The url to the fallback JavaScript module.
|
|
31
|
-
*/
|
|
32
|
-
fallbackUrl?: string;
|
|
33
|
-
/**
|
|
34
|
-
* Optional worker pool to use for async decoding instead of creating a new worker pool.
|
|
35
|
-
*/
|
|
36
|
-
workerPool?: AutoReleaseWorkerPool;
|
|
37
|
-
/**
|
|
38
|
-
* Optional ArrayBuffer of the WebAssembly binary
|
|
39
|
-
*/
|
|
40
|
-
wasmBinary?: ArrayBuffer;
|
|
41
|
-
/**
|
|
42
|
-
* The decoder module if already available.
|
|
43
|
-
*/
|
|
44
|
-
jsModule?: any;
|
|
45
|
-
};
|
|
15
|
+
decoder: IDracoCodecConfiguration;
|
|
46
16
|
}
|
|
47
17
|
/**
|
|
48
18
|
* Options for Draco compression
|
|
49
19
|
*/
|
|
50
|
-
export interface IDracoCompressionOptions {
|
|
51
|
-
/**
|
|
52
|
-
* The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.
|
|
53
|
-
*/
|
|
54
|
-
numWorkers?: number;
|
|
55
|
-
/**
|
|
56
|
-
* Optional ArrayBuffer of the WebAssembly binary.
|
|
57
|
-
* If provided it will be used instead of loading the binary from wasmBinaryUrl.
|
|
58
|
-
*/
|
|
59
|
-
wasmBinary?: ArrayBuffer;
|
|
60
|
-
/**
|
|
61
|
-
* Optional worker pool to use for async decoding.
|
|
62
|
-
* If provided, numWorkers will be ignored and the worker pool will be used instead.
|
|
63
|
-
* If provided the draco script will not be loaded from the DracoConfiguration.
|
|
64
|
-
*/
|
|
65
|
-
workerPool?: AutoReleaseWorkerPool;
|
|
20
|
+
export interface IDracoCompressionOptions extends Pick<IDracoCodecConfiguration, "numWorkers" | "wasmBinary" | "workerPool"> {
|
|
66
21
|
}
|
|
67
22
|
/**
|
|
68
23
|
* Draco compression (https://google.github.io/draco/)
|
|
@@ -99,9 +54,8 @@ export interface IDracoCompressionOptions {
|
|
|
99
54
|
*
|
|
100
55
|
* @see https://playground.babylonjs.com/#DMZIBD#0
|
|
101
56
|
*/
|
|
102
|
-
export declare class DracoCompression
|
|
103
|
-
private
|
|
104
|
-
private _decoderModulePromise?;
|
|
57
|
+
export declare class DracoCompression {
|
|
58
|
+
private _decoder;
|
|
105
59
|
/**
|
|
106
60
|
* The configuration. Defaults to the following urls:
|
|
107
61
|
* - wasmUrl: "https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js"
|
|
@@ -117,10 +71,9 @@ export declare class DracoCompression implements IDisposable {
|
|
|
117
71
|
* Default number of workers to create when creating the draco compression object.
|
|
118
72
|
*/
|
|
119
73
|
static DefaultNumWorkers: number;
|
|
120
|
-
|
|
121
|
-
private static _Default;
|
|
74
|
+
protected static _Default: Nullable<DracoCompression>;
|
|
122
75
|
/**
|
|
123
|
-
* Default instance for the
|
|
76
|
+
* Default instance for the DracoCompression.
|
|
124
77
|
*/
|
|
125
78
|
static get Default(): DracoCompression;
|
|
126
79
|
/**
|
|
@@ -131,10 +84,12 @@ export declare class DracoCompression implements IDisposable {
|
|
|
131
84
|
*/
|
|
132
85
|
static ResetDefault(skipDispose?: boolean): void;
|
|
133
86
|
/**
|
|
134
|
-
*
|
|
135
|
-
* @param
|
|
87
|
+
* Creates a new DracoCompression object.
|
|
88
|
+
* @param numWorkersOrOptions Overrides for the Configuration. Either:
|
|
89
|
+
* - The number of workers for async operations or a config object. Specify `0` to disable web workers and run synchronously in the current context.
|
|
90
|
+
* - An options object
|
|
136
91
|
*/
|
|
137
|
-
constructor(
|
|
92
|
+
constructor(numWorkersOrOptions?: number | IDracoCompressionOptions);
|
|
138
93
|
/**
|
|
139
94
|
* Stop all async operations and release resources.
|
|
140
95
|
*/
|
|
@@ -184,4 +139,3 @@ export declare class DracoCompression implements IDisposable {
|
|
|
184
139
|
[kind: string]: number;
|
|
185
140
|
}): Promise<VertexData>;
|
|
186
141
|
}
|
|
187
|
-
export {};
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Geometry } from "../geometry.js";
|
|
1
|
+
import { _GetDefaultNumWorkers, _IsConfigurationAvailable } from "./dracoCodec.js";
|
|
2
|
+
import { DracoDecoder } from "./dracoDecoder.js";
|
|
4
3
|
import { VertexBuffer } from "../buffer.js";
|
|
5
4
|
import { VertexData } from "../mesh.vertexData.js";
|
|
6
|
-
import { Logger } from "../../Misc/logger.js";
|
|
7
|
-
import { decodeMesh, workerFunction, initializeWebWorker } from "./dracoCompressionWorker.js";
|
|
8
|
-
function createDecoderAsync(wasmBinary, jsModule) {
|
|
9
|
-
return new Promise((resolve) => {
|
|
10
|
-
(jsModule || DracoDecoderModule)({ wasmBinary }).then((module) => {
|
|
11
|
-
resolve({ module });
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
5
|
/**
|
|
16
6
|
* Draco compression (https://google.github.io/draco/)
|
|
17
7
|
*
|
|
@@ -52,23 +42,13 @@ export class DracoCompression {
|
|
|
52
42
|
* Returns true if the decoder configuration is available.
|
|
53
43
|
*/
|
|
54
44
|
static get DecoderAvailable() {
|
|
55
|
-
|
|
56
|
-
return !!((decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === "object") || decoder.fallbackUrl);
|
|
57
|
-
}
|
|
58
|
-
static GetDefaultNumWorkers() {
|
|
59
|
-
if (typeof navigator !== "object" || !navigator.hardwareConcurrency) {
|
|
60
|
-
return 1;
|
|
61
|
-
}
|
|
62
|
-
// Use 50% of the available logical processors but capped at 4.
|
|
63
|
-
return Math.min(Math.floor(navigator.hardwareConcurrency * 0.5), 4);
|
|
45
|
+
return _IsConfigurationAvailable(DracoCompression.Configuration.decoder);
|
|
64
46
|
}
|
|
65
47
|
/**
|
|
66
|
-
* Default instance for the
|
|
48
|
+
* Default instance for the DracoCompression.
|
|
67
49
|
*/
|
|
68
50
|
static get Default() {
|
|
69
|
-
|
|
70
|
-
DracoCompression._Default = new DracoCompression();
|
|
71
|
-
}
|
|
51
|
+
DracoCompression._Default ?? (DracoCompression._Default = new DracoCompression());
|
|
72
52
|
return DracoCompression._Default;
|
|
73
53
|
}
|
|
74
54
|
/**
|
|
@@ -86,83 +66,29 @@ export class DracoCompression {
|
|
|
86
66
|
}
|
|
87
67
|
}
|
|
88
68
|
/**
|
|
89
|
-
*
|
|
90
|
-
* @param
|
|
69
|
+
* Creates a new DracoCompression object.
|
|
70
|
+
* @param numWorkersOrOptions Overrides for the Configuration. Either:
|
|
71
|
+
* - The number of workers for async operations or a config object. Specify `0` to disable web workers and run synchronously in the current context.
|
|
72
|
+
* - An options object
|
|
91
73
|
*/
|
|
92
|
-
constructor(
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// set the promise accordingly
|
|
98
|
-
this._workerPoolPromise = Promise.resolve(decoder.workerPool || numWorkers.workerPool);
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
// to avoid making big changes to the decider, if wasmBinary is provided use it in the wasmBinaryPromise
|
|
102
|
-
const wasmBinaryProvided = decoder.wasmBinary || (typeof numWorkers === "object" && numWorkers.wasmBinary);
|
|
103
|
-
const numberOfWorkers = typeof numWorkers === "number" ? numWorkers : numWorkers.numWorkers;
|
|
104
|
-
const useWorkers = numberOfWorkers && typeof Worker === "function" && typeof URL === "function";
|
|
105
|
-
const urlNeeded = useWorkers || (!useWorkers && !decoder.jsModule);
|
|
106
|
-
// code maintained here for back-compat with no changes
|
|
107
|
-
const decoderInfo = decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === "object"
|
|
108
|
-
? {
|
|
109
|
-
url: urlNeeded ? Tools.GetBabylonScriptURL(decoder.wasmUrl, true) : "",
|
|
110
|
-
wasmBinaryPromise: wasmBinaryProvided ? Promise.resolve(wasmBinaryProvided) : Tools.LoadFileAsync(Tools.GetBabylonScriptURL(decoder.wasmBinaryUrl, true)),
|
|
111
|
-
}
|
|
112
|
-
: {
|
|
113
|
-
url: urlNeeded ? Tools.GetBabylonScriptURL(decoder.fallbackUrl) : "",
|
|
114
|
-
wasmBinaryPromise: Promise.resolve(undefined),
|
|
115
|
-
};
|
|
116
|
-
if (useWorkers) {
|
|
117
|
-
this._workerPoolPromise = decoderInfo.wasmBinaryPromise.then((decoderWasmBinary) => {
|
|
118
|
-
const workerContent = `${decodeMesh}(${workerFunction})()`;
|
|
119
|
-
const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
|
|
120
|
-
return new AutoReleaseWorkerPool(numberOfWorkers, () => {
|
|
121
|
-
const worker = new Worker(workerBlobUrl);
|
|
122
|
-
return initializeWebWorker(worker, decoderWasmBinary, decoderInfo.url);
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
this._decoderModulePromise = decoderInfo.wasmBinaryPromise.then(async (decoderWasmBinary) => {
|
|
128
|
-
if (typeof DracoDecoderModule === "undefined") {
|
|
129
|
-
if (!decoder.jsModule) {
|
|
130
|
-
if (!decoderInfo.url) {
|
|
131
|
-
throw new Error("Draco decoder module is not available");
|
|
132
|
-
}
|
|
133
|
-
await Tools.LoadBabylonScriptAsync(decoderInfo.url);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return await createDecoderAsync(decoderWasmBinary, decoder.jsModule);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
74
|
+
constructor(numWorkersOrOptions = DracoCompression.DefaultNumWorkers) {
|
|
75
|
+
const configuration = typeof numWorkersOrOptions === "number"
|
|
76
|
+
? { ...DracoCompression.Configuration.decoder, numWorkers: numWorkersOrOptions }
|
|
77
|
+
: { ...DracoCompression.Configuration.decoder, ...numWorkersOrOptions };
|
|
78
|
+
this._decoder = new DracoDecoder(configuration);
|
|
140
79
|
}
|
|
141
80
|
/**
|
|
142
81
|
* Stop all async operations and release resources.
|
|
143
82
|
*/
|
|
144
83
|
dispose() {
|
|
145
|
-
|
|
146
|
-
this._workerPoolPromise.then((workerPool) => {
|
|
147
|
-
workerPool.dispose();
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
delete this._workerPoolPromise;
|
|
151
|
-
delete this._decoderModulePromise;
|
|
84
|
+
this._decoder.dispose();
|
|
152
85
|
}
|
|
153
86
|
/**
|
|
154
87
|
* Returns a promise that resolves when ready. Call this manually to ensure draco compression is ready before use.
|
|
155
88
|
* @returns a promise that resolves when ready
|
|
156
89
|
*/
|
|
157
90
|
async whenReadyAsync() {
|
|
158
|
-
|
|
159
|
-
await this._workerPoolPromise;
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
if (this._decoderModulePromise) {
|
|
163
|
-
await this._decoderModulePromise;
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
91
|
+
return this._decoder.whenReadyAsync();
|
|
166
92
|
}
|
|
167
93
|
/**
|
|
168
94
|
* Decode Draco compressed mesh data to mesh data.
|
|
@@ -172,85 +98,7 @@ export class DracoCompression {
|
|
|
172
98
|
* @returns A promise that resolves with the decoded mesh data
|
|
173
99
|
*/
|
|
174
100
|
decodeMeshToMeshDataAsync(data, attributes, gltfNormalizedOverride) {
|
|
175
|
-
|
|
176
|
-
const applyGltfNormalizedOverride = (kind, normalized) => {
|
|
177
|
-
if (gltfNormalizedOverride && gltfNormalizedOverride[kind] !== undefined) {
|
|
178
|
-
if (normalized !== gltfNormalizedOverride[kind]) {
|
|
179
|
-
Logger.Warn(`Normalized flag from Draco data (${normalized}) does not match normalized flag from glTF accessor (${gltfNormalizedOverride[kind]}). Using flag from glTF accessor.`);
|
|
180
|
-
}
|
|
181
|
-
return gltfNormalizedOverride[kind];
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
return normalized;
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
if (this._workerPoolPromise) {
|
|
188
|
-
return this._workerPoolPromise.then((workerPool) => {
|
|
189
|
-
return new Promise((resolve, reject) => {
|
|
190
|
-
workerPool.push((worker, onComplete) => {
|
|
191
|
-
let resultIndices = null;
|
|
192
|
-
const resultAttributes = [];
|
|
193
|
-
const onError = (error) => {
|
|
194
|
-
worker.removeEventListener("error", onError);
|
|
195
|
-
worker.removeEventListener("message", onMessage);
|
|
196
|
-
reject(error);
|
|
197
|
-
onComplete();
|
|
198
|
-
};
|
|
199
|
-
const onMessage = (event) => {
|
|
200
|
-
const message = event.data;
|
|
201
|
-
switch (message.id) {
|
|
202
|
-
case "decodeMeshDone": {
|
|
203
|
-
worker.removeEventListener("error", onError);
|
|
204
|
-
worker.removeEventListener("message", onMessage);
|
|
205
|
-
resolve({ indices: resultIndices, attributes: resultAttributes, totalVertices: message.totalVertices });
|
|
206
|
-
onComplete();
|
|
207
|
-
break;
|
|
208
|
-
}
|
|
209
|
-
case "indices": {
|
|
210
|
-
resultIndices = message.data;
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
case "attribute": {
|
|
214
|
-
resultAttributes.push({
|
|
215
|
-
kind: message.kind,
|
|
216
|
-
data: message.data,
|
|
217
|
-
size: message.size,
|
|
218
|
-
byteOffset: message.byteOffset,
|
|
219
|
-
byteStride: message.byteStride,
|
|
220
|
-
normalized: applyGltfNormalizedOverride(message.kind, message.normalized),
|
|
221
|
-
});
|
|
222
|
-
break;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
worker.addEventListener("error", onError);
|
|
227
|
-
worker.addEventListener("message", onMessage);
|
|
228
|
-
const dataViewCopy = dataView.slice();
|
|
229
|
-
worker.postMessage({ id: "decodeMesh", dataView: dataViewCopy, attributes: attributes }, [dataViewCopy.buffer]);
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
if (this._decoderModulePromise) {
|
|
235
|
-
return this._decoderModulePromise.then((decoder) => {
|
|
236
|
-
let resultIndices = null;
|
|
237
|
-
const resultAttributes = [];
|
|
238
|
-
const numPoints = decodeMesh(decoder.module, dataView, attributes, (indices) => {
|
|
239
|
-
resultIndices = indices;
|
|
240
|
-
}, (kind, data, size, byteOffset, byteStride, normalized) => {
|
|
241
|
-
resultAttributes.push({
|
|
242
|
-
kind,
|
|
243
|
-
data,
|
|
244
|
-
size,
|
|
245
|
-
byteOffset,
|
|
246
|
-
byteStride,
|
|
247
|
-
normalized,
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
return { indices: resultIndices, attributes: resultAttributes, totalVertices: numPoints };
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
throw new Error("Draco decoder module is not available");
|
|
101
|
+
return this._decoder.decodeMeshToMeshDataAsync(data, attributes, gltfNormalizedOverride);
|
|
254
102
|
}
|
|
255
103
|
/**
|
|
256
104
|
* Decode Draco compressed mesh data to Babylon geometry.
|
|
@@ -261,31 +109,11 @@ export class DracoCompression {
|
|
|
261
109
|
* @returns A promise that resolves with the decoded geometry
|
|
262
110
|
*/
|
|
263
111
|
async decodeMeshToGeometryAsync(name, scene, data, attributes) {
|
|
264
|
-
|
|
265
|
-
const geometry = new Geometry(name, scene);
|
|
266
|
-
if (meshData.indices) {
|
|
267
|
-
geometry.setIndices(meshData.indices);
|
|
268
|
-
}
|
|
269
|
-
for (const attribute of meshData.attributes) {
|
|
270
|
-
geometry.setVerticesBuffer(new VertexBuffer(scene.getEngine(), attribute.data, attribute.kind, false, undefined, attribute.byteStride, undefined, attribute.byteOffset, attribute.size, undefined, attribute.normalized, true), meshData.totalVertices);
|
|
271
|
-
}
|
|
272
|
-
return geometry;
|
|
112
|
+
return this._decoder.decodeMeshToGeometryAsync(name, scene, data, attributes);
|
|
273
113
|
}
|
|
274
114
|
/** @internal */
|
|
275
115
|
async _decodeMeshToGeometryForGltfAsync(name, scene, data, attributes, gltfNormalizedOverride, boundingInfo) {
|
|
276
|
-
|
|
277
|
-
const geometry = new Geometry(name, scene);
|
|
278
|
-
if (boundingInfo) {
|
|
279
|
-
geometry._boundingInfo = boundingInfo;
|
|
280
|
-
geometry.useBoundingInfoFromGeometry = true;
|
|
281
|
-
}
|
|
282
|
-
if (meshData.indices) {
|
|
283
|
-
geometry.setIndices(meshData.indices);
|
|
284
|
-
}
|
|
285
|
-
for (const attribute of meshData.attributes) {
|
|
286
|
-
geometry.setVerticesBuffer(new VertexBuffer(scene.getEngine(), attribute.data, attribute.kind, false, undefined, attribute.byteStride, undefined, attribute.byteOffset, attribute.size, undefined, attribute.normalized, true), meshData.totalVertices);
|
|
287
|
-
}
|
|
288
|
-
return geometry;
|
|
116
|
+
return this._decoder._decodeMeshToGeometryForGltfAsync(name, scene, data, attributes, gltfNormalizedOverride, boundingInfo);
|
|
289
117
|
}
|
|
290
118
|
/**
|
|
291
119
|
* Decode Draco compressed mesh data to Babylon vertex data.
|
|
@@ -295,7 +123,7 @@ export class DracoCompression {
|
|
|
295
123
|
* @deprecated Use {@link decodeMeshToGeometryAsync} for better performance in some cases
|
|
296
124
|
*/
|
|
297
125
|
async decodeMeshAsync(data, attributes) {
|
|
298
|
-
const meshData = await this.decodeMeshToMeshDataAsync(data, attributes);
|
|
126
|
+
const meshData = await this._decoder.decodeMeshToMeshDataAsync(data, attributes);
|
|
299
127
|
const vertexData = new VertexData();
|
|
300
128
|
if (meshData.indices) {
|
|
301
129
|
vertexData.indices = meshData.indices;
|
|
@@ -313,16 +141,10 @@ export class DracoCompression {
|
|
|
313
141
|
* - wasmBinaryUrl: "https://cdn.babylonjs.com/draco_decoder_gltf.wasm"
|
|
314
142
|
* - fallbackUrl: "https://cdn.babylonjs.com/draco_decoder_gltf.js"
|
|
315
143
|
*/
|
|
316
|
-
DracoCompression.Configuration = {
|
|
317
|
-
decoder: {
|
|
318
|
-
wasmUrl: `${Tools._DefaultCdnUrl}/draco_wasm_wrapper_gltf.js`,
|
|
319
|
-
wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.wasm`,
|
|
320
|
-
fallbackUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.js`,
|
|
321
|
-
},
|
|
322
|
-
};
|
|
144
|
+
DracoCompression.Configuration = { decoder: { ...DracoDecoder.DefaultConfiguration } }; // Use copy
|
|
323
145
|
/**
|
|
324
146
|
* Default number of workers to create when creating the draco compression object.
|
|
325
147
|
*/
|
|
326
|
-
DracoCompression.DefaultNumWorkers =
|
|
148
|
+
DracoCompression.DefaultNumWorkers = _GetDefaultNumWorkers();
|
|
327
149
|
DracoCompression._Default = null;
|
|
328
150
|
//# sourceMappingURL=dracoCompression.js.map
|