@babylonjs/core 6.21.0 → 6.21.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.
- package/Audio/soundTrack.js +1 -1
- package/Audio/soundTrack.js.map +1 -1
- package/Buffers/buffer.d.ts +2 -1
- package/Buffers/buffer.js +13 -5
- package/Buffers/buffer.js.map +1 -1
- package/Debug/rayHelper.d.ts +3 -3
- package/Debug/rayHelper.js +2 -2
- package/Debug/rayHelper.js.map +1 -1
- package/Engines/Native/nativeHelpers.d.ts +9 -0
- package/Engines/Native/nativeHelpers.js +296 -0
- package/Engines/Native/nativeHelpers.js.map +1 -0
- package/Engines/Native/nativeInterfaces.d.ts +92 -0
- package/Engines/Native/nativeInterfaces.js.map +1 -1
- package/Engines/engine.d.ts +6 -4
- package/Engines/engine.js +7 -1
- package/Engines/engine.js.map +1 -1
- package/Engines/nativeEngine.d.ts +3 -12
- package/Engines/nativeEngine.js +43 -226
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/thinEngine.js +4 -2
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.js +2 -1
- package/Engines/webgpuEngine.js.map +1 -1
- package/FlowGraph/Blocks/Data/Logic/flowGraphLogicBlocks.d.ts +23 -0
- package/FlowGraph/Blocks/Data/Logic/flowGraphLogicBlocks.js +31 -0
- package/FlowGraph/Blocks/Data/Logic/flowGraphLogicBlocks.js.map +1 -0
- package/FlowGraph/Blocks/Data/Math/flowGraphNumberMathBlocks.d.ts +270 -0
- package/FlowGraph/Blocks/Data/Math/flowGraphNumberMathBlocks.js +347 -0
- package/FlowGraph/Blocks/Data/Math/flowGraphNumberMathBlocks.js.map +1 -0
- package/FlowGraph/Blocks/Data/Math/flowGraphVector2MathBlocks.d.ts +52 -0
- package/FlowGraph/Blocks/Data/Math/flowGraphVector2MathBlocks.js +71 -0
- package/FlowGraph/Blocks/Data/Math/flowGraphVector2MathBlocks.js.map +1 -0
- package/FlowGraph/Blocks/Data/Math/flowGraphVector3MathBlocks.d.ts +66 -0
- package/FlowGraph/Blocks/Data/Math/flowGraphVector3MathBlocks.js +86 -0
- package/FlowGraph/Blocks/Data/Math/flowGraphVector3MathBlocks.js.map +1 -0
- package/FlowGraph/Blocks/Data/Math/flowGraphVector4MathBlocks.d.ts +52 -0
- package/FlowGraph/Blocks/Data/Math/flowGraphVector4MathBlocks.js +71 -0
- package/FlowGraph/Blocks/Data/Math/flowGraphVector4MathBlocks.js.map +1 -0
- package/FlowGraph/Blocks/Data/flowGraphBinaryOperationBlock.d.ts +17 -0
- package/FlowGraph/Blocks/Data/flowGraphBinaryOperationBlock.js +19 -0
- package/FlowGraph/Blocks/Data/flowGraphBinaryOperationBlock.js.map +1 -0
- package/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.d.ts +13 -0
- package/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.js +16 -0
- package/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.js.map +1 -0
- package/FlowGraph/Blocks/Data/flowGraphUnaryOperationBlock.d.ts +15 -0
- package/FlowGraph/Blocks/Data/flowGraphUnaryOperationBlock.js +17 -0
- package/FlowGraph/Blocks/Data/flowGraphUnaryOperationBlock.js.map +1 -0
- package/FlowGraph/Blocks/Data/index.d.ts +4 -1
- package/FlowGraph/Blocks/Data/index.js +4 -1
- package/FlowGraph/Blocks/Data/index.js.map +1 -1
- package/FlowGraph/Blocks/Event/flowGraphSceneTickEventBlock.d.ts +16 -0
- package/FlowGraph/Blocks/Event/flowGraphSceneTickEventBlock.js +29 -0
- package/FlowGraph/Blocks/Event/flowGraphSceneTickEventBlock.js.map +1 -0
- package/FlowGraph/Blocks/Event/index.d.ts +1 -0
- package/FlowGraph/Blocks/Event/index.js +1 -0
- package/FlowGraph/Blocks/Event/index.js.map +1 -1
- package/FlowGraph/Blocks/Execution/Animation/flowGraphPauseAnimationBlock.d.ts +16 -0
- package/FlowGraph/Blocks/Execution/Animation/flowGraphPauseAnimationBlock.js +18 -0
- package/FlowGraph/Blocks/Execution/Animation/flowGraphPauseAnimationBlock.js.map +1 -0
- package/FlowGraph/Blocks/Execution/{flowGraphPlayAnimationBlock.d.ts → Animation/flowGraphPlayAnimationBlock.d.ts} +5 -5
- package/FlowGraph/Blocks/Execution/{flowGraphPlayAnimationBlock.js → Animation/flowGraphPlayAnimationBlock.js} +15 -8
- package/FlowGraph/Blocks/Execution/Animation/flowGraphPlayAnimationBlock.js.map +1 -0
- package/FlowGraph/Blocks/Execution/{flowGraphStopAnimationBlock.d.ts → Animation/flowGraphStopAnimationBlock.d.ts} +4 -4
- package/FlowGraph/Blocks/Execution/{flowGraphStopAnimationBlock.js → Animation/flowGraphStopAnimationBlock.js} +2 -2
- package/FlowGraph/Blocks/Execution/Animation/flowGraphStopAnimationBlock.js.map +1 -0
- package/FlowGraph/Blocks/Execution/Animation/index.d.ts +3 -0
- package/FlowGraph/Blocks/Execution/Animation/index.js +4 -0
- package/FlowGraph/Blocks/Execution/Animation/index.js.map +1 -0
- package/FlowGraph/Blocks/Execution/index.d.ts +1 -2
- package/FlowGraph/Blocks/Execution/index.js +2 -2
- package/FlowGraph/Blocks/Execution/index.js.map +1 -1
- package/FlowGraph/flowGraphDataConnection.d.ts +2 -2
- package/FlowGraph/flowGraphDataConnection.js +3 -3
- package/FlowGraph/flowGraphDataConnection.js.map +1 -1
- package/Gizmos/axisDragGizmo.d.ts +1 -1
- package/Gizmos/axisDragGizmo.js +0 -1
- package/Gizmos/axisDragGizmo.js.map +1 -1
- package/Gizmos/axisScaleGizmo.js +0 -1
- package/Gizmos/axisScaleGizmo.js.map +1 -1
- package/Gizmos/boundingBoxGizmo.d.ts +12 -0
- package/Gizmos/boundingBoxGizmo.js +37 -1
- package/Gizmos/boundingBoxGizmo.js.map +1 -1
- package/Gizmos/gizmo.d.ts +0 -4
- package/Gizmos/gizmo.js +19 -16
- package/Gizmos/gizmo.js.map +1 -1
- package/Gizmos/planeDragGizmo.js +0 -1
- package/Gizmos/planeDragGizmo.js.map +1 -1
- package/Gizmos/planeRotationGizmo.js +0 -1
- package/Gizmos/planeRotationGizmo.js.map +1 -1
- package/Gizmos/scaleGizmo.d.ts +2 -2
- package/Gizmos/scaleGizmo.js +5 -2
- package/Gizmos/scaleGizmo.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js +1 -0
- package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.d.ts +1 -0
- package/Materials/PBR/pbrBaseMaterial.js +12 -2
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/Textures/equiRectangularCubeTexture.js +24 -4
- package/Materials/Textures/equiRectangularCubeTexture.js.map +1 -1
- package/Materials/standardMaterial.d.ts +1 -0
- package/Materials/standardMaterial.js +6 -0
- package/Materials/standardMaterial.js.map +1 -1
- package/Maths/math.vector.d.ts +1 -1
- package/Maths/math.vector.js +1 -1
- package/Maths/math.vector.js.map +1 -1
- package/Meshes/Compression/dracoCompression.d.ts +25 -8
- package/Meshes/Compression/dracoCompression.js +187 -119
- package/Meshes/Compression/dracoCompression.js.map +1 -1
- package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.d.ts +22 -2
- package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.js +62 -4
- package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.js.map +1 -1
- package/Meshes/Node/Blocks/debugBlock.d.ts +2 -1
- package/Meshes/Node/Blocks/debugBlock.js +8 -2
- package/Meshes/Node/Blocks/debugBlock.js.map +1 -1
- package/Meshes/Node/Blocks/randomBlock.d.ts +14 -3
- package/Meshes/Node/Blocks/randomBlock.js +40 -13
- package/Meshes/Node/Blocks/randomBlock.js.map +1 -1
- package/Meshes/Node/nodeGeometryBuildState.d.ts +2 -2
- package/Meshes/Node/nodeGeometryBuildState.js +5 -3
- package/Meshes/Node/nodeGeometryBuildState.js.map +1 -1
- package/Meshes/meshSimplification.d.ts +1 -1
- package/Meshes/meshSimplification.js.map +1 -1
- package/Meshes/subMesh.js +1 -1
- package/Meshes/subMesh.js.map +1 -1
- package/Physics/v2/IPhysicsEnginePlugin.d.ts +8 -0
- package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
- package/Shaders/ShadersInclude/bumpFragmentFunctions.js +14 -2
- package/Shaders/ShadersInclude/bumpFragmentFunctions.js.map +1 -1
- package/package.json +1 -1
- package/FlowGraph/Blocks/Data/flowGraphAddBlock.d.ts +0 -23
- package/FlowGraph/Blocks/Data/flowGraphAddBlock.js +0 -18
- package/FlowGraph/Blocks/Data/flowGraphAddBlock.js.map +0 -1
- package/FlowGraph/Blocks/Execution/flowGraphPlayAnimationBlock.js.map +0 -1
- package/FlowGraph/Blocks/Execution/flowGraphStopAnimationBlock.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { IDisposable } from "../../scene";
|
|
2
|
-
import {
|
|
1
|
+
import type { IDisposable, Scene } from "../../scene";
|
|
2
|
+
import { Geometry } from "../geometry";
|
|
3
|
+
import { VertexData } from "../mesh.vertexData";
|
|
3
4
|
/**
|
|
4
5
|
* Configuration for Draco compression
|
|
5
6
|
*/
|
|
@@ -50,9 +51,9 @@ export interface IDracoCompressionConfiguration {
|
|
|
50
51
|
* Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.
|
|
51
52
|
* Use `DracoCompression.DecoderAvailable` to determine if the decoder configuration is available for the current context.
|
|
52
53
|
*
|
|
53
|
-
* To decode Draco compressed data, get the default DracoCompression object and call
|
|
54
|
+
* To decode Draco compressed data, get the default DracoCompression object and call decodeMeshToGeometryAsync:
|
|
54
55
|
* ```javascript
|
|
55
|
-
* var
|
|
56
|
+
* var geometry = await DracoCompression.Default.decodeMeshToGeometryAsync(data);
|
|
56
57
|
* ```
|
|
57
58
|
*
|
|
58
59
|
* @see https://playground.babylonjs.com/#DMZIBD#0
|
|
@@ -95,16 +96,32 @@ export declare class DracoCompression implements IDisposable {
|
|
|
95
96
|
* @returns a promise that resolves when ready
|
|
96
97
|
*/
|
|
97
98
|
whenReadyAsync(): Promise<void>;
|
|
99
|
+
private _decodeMeshAsync;
|
|
98
100
|
/**
|
|
99
|
-
* Decode Draco compressed mesh data to
|
|
101
|
+
* Decode Draco compressed mesh data to Babylon geometry.
|
|
102
|
+
* @param name The name to use when creating the geometry
|
|
103
|
+
* @param scene The scene to use when creating the geometry
|
|
104
|
+
* @param data The ArrayBuffer or ArrayBufferView for the Draco compression data
|
|
105
|
+
* @param attributes A map of attributes from vertex buffer kinds to Draco unique ids
|
|
106
|
+
* @returns A promise that resolves with the decoded geometry
|
|
107
|
+
*/
|
|
108
|
+
decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: {
|
|
109
|
+
[kind: string]: number;
|
|
110
|
+
}): Promise<Geometry>;
|
|
111
|
+
/** @internal */
|
|
112
|
+
_decodeMeshToGeometryForGltfAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes: {
|
|
113
|
+
[kind: string]: number;
|
|
114
|
+
}, gltfNormalizedOverride: {
|
|
115
|
+
[kind: string]: boolean;
|
|
116
|
+
}): Promise<Geometry>;
|
|
117
|
+
/**
|
|
118
|
+
* Decode Draco compressed mesh data to Babylon vertex data.
|
|
100
119
|
* @param data The ArrayBuffer or ArrayBufferView for the Draco compression data
|
|
101
120
|
* @param attributes A map of attributes from vertex buffer kinds to Draco unique ids
|
|
102
|
-
* @param dividers a list of optional dividers for normalization
|
|
103
121
|
* @returns A promise that resolves with the decoded vertex data
|
|
122
|
+
* @deprecated Use {@link decodeMeshToGeometryAsync} for better performance in some cases
|
|
104
123
|
*/
|
|
105
124
|
decodeMeshAsync(data: ArrayBuffer | ArrayBufferView, attributes?: {
|
|
106
125
|
[kind: string]: number;
|
|
107
|
-
}, dividers?: {
|
|
108
|
-
[kind: string]: number;
|
|
109
126
|
}): Promise<VertexData>;
|
|
110
127
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
2
|
import { Tools } from "../../Misc/tools.js";
|
|
3
3
|
import { AutoReleaseWorkerPool } from "../../Misc/workerPool.js";
|
|
4
|
-
import {
|
|
4
|
+
import { Geometry } from "../geometry.js";
|
|
5
|
+
import { VertexBuffer } from "../buffer.js";
|
|
6
|
+
import { VertexData } from "../mesh.vertexData.js";
|
|
7
|
+
import { Logger } from "../../Misc/logger.js";
|
|
5
8
|
function createDecoderAsync(wasmBinary) {
|
|
6
9
|
return new Promise((resolve) => {
|
|
7
10
|
DracoDecoderModule({ wasmBinary: wasmBinary }).then((module) => {
|
|
@@ -9,73 +12,79 @@ function createDecoderAsync(wasmBinary) {
|
|
|
9
12
|
});
|
|
10
13
|
});
|
|
11
14
|
}
|
|
12
|
-
function decodeMesh(decoderModule,
|
|
13
|
-
|
|
14
|
-
buffer
|
|
15
|
-
|
|
16
|
-
let geometry;
|
|
17
|
-
let status;
|
|
15
|
+
function decodeMesh(decoderModule, data, attributes, onIndicesData, onAttributeData) {
|
|
16
|
+
let decoder = null;
|
|
17
|
+
let buffer = null;
|
|
18
|
+
let geometry = null;
|
|
18
19
|
try {
|
|
20
|
+
decoder = new decoderModule.Decoder();
|
|
21
|
+
buffer = new decoderModule.DecoderBuffer();
|
|
22
|
+
buffer.Init(data, data.byteLength);
|
|
23
|
+
let status;
|
|
19
24
|
const type = decoder.GetEncodedGeometryType(buffer);
|
|
20
25
|
switch (type) {
|
|
21
|
-
case decoderModule.TRIANGULAR_MESH:
|
|
22
|
-
|
|
23
|
-
status = decoder.DecodeBufferToMesh(buffer,
|
|
26
|
+
case decoderModule.TRIANGULAR_MESH: {
|
|
27
|
+
const mesh = new decoderModule.Mesh();
|
|
28
|
+
status = decoder.DecodeBufferToMesh(buffer, mesh);
|
|
29
|
+
if (!status.ok() || mesh.ptr === 0) {
|
|
30
|
+
throw new Error(status.error_msg());
|
|
31
|
+
}
|
|
32
|
+
const numFaces = mesh.num_faces();
|
|
33
|
+
const numIndices = numFaces * 3;
|
|
34
|
+
const byteLength = numIndices * 4;
|
|
35
|
+
const ptr = decoderModule._malloc(byteLength);
|
|
36
|
+
try {
|
|
37
|
+
decoder.GetTrianglesUInt32Array(mesh, byteLength, ptr);
|
|
38
|
+
const indices = new Uint32Array(numIndices);
|
|
39
|
+
indices.set(new Uint32Array(decoderModule.HEAPF32.buffer, ptr, numIndices));
|
|
40
|
+
onIndicesData(indices);
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
decoderModule._free(ptr);
|
|
44
|
+
}
|
|
45
|
+
geometry = mesh;
|
|
24
46
|
break;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
47
|
+
}
|
|
48
|
+
case decoderModule.POINT_CLOUD: {
|
|
49
|
+
const pointCloud = new decoderModule.PointCloud();
|
|
50
|
+
status = decoder.DecodeBufferToPointCloud(buffer, pointCloud);
|
|
51
|
+
if (!status.ok() || !pointCloud.ptr) {
|
|
52
|
+
throw new Error(status.error_msg());
|
|
53
|
+
}
|
|
54
|
+
geometry = pointCloud;
|
|
28
55
|
break;
|
|
29
|
-
default:
|
|
30
|
-
throw new Error(`Invalid geometry type ${type}`);
|
|
31
|
-
}
|
|
32
|
-
if (!status.ok() || !geometry.ptr) {
|
|
33
|
-
throw new Error(status.error_msg());
|
|
34
|
-
}
|
|
35
|
-
if (type === decoderModule.TRIANGULAR_MESH) {
|
|
36
|
-
const numFaces = geometry.num_faces();
|
|
37
|
-
const numIndices = numFaces * 3;
|
|
38
|
-
const byteLength = numIndices * 4;
|
|
39
|
-
const ptr = decoderModule._malloc(byteLength);
|
|
40
|
-
try {
|
|
41
|
-
decoder.GetTrianglesUInt32Array(geometry, byteLength, ptr);
|
|
42
|
-
const indices = new Uint32Array(numIndices);
|
|
43
|
-
indices.set(new Uint32Array(decoderModule.HEAPF32.buffer, ptr, numIndices));
|
|
44
|
-
onIndicesData(indices);
|
|
45
56
|
}
|
|
46
|
-
|
|
47
|
-
|
|
57
|
+
default: {
|
|
58
|
+
throw new Error(`Invalid geometry type ${type}`);
|
|
48
59
|
}
|
|
49
60
|
}
|
|
50
|
-
const
|
|
61
|
+
const numPoints = geometry.num_points();
|
|
62
|
+
const processAttribute = (decoder, geometry, kind, attribute) => {
|
|
63
|
+
const dataType = attribute.data_type();
|
|
51
64
|
const numComponents = attribute.num_components();
|
|
52
|
-
const
|
|
65
|
+
const normalized = attribute.normalized();
|
|
66
|
+
const byteStride = attribute.byte_stride();
|
|
67
|
+
const byteOffset = attribute.byte_offset();
|
|
68
|
+
const dataTypeInfo = {
|
|
69
|
+
[decoderModule.DT_FLOAT32]: { typedArrayConstructor: Float32Array, heap: decoderModule.HEAPF32 },
|
|
70
|
+
[decoderModule.DT_INT8]: { typedArrayConstructor: Int8Array, heap: decoderModule.HEAP8 },
|
|
71
|
+
[decoderModule.DT_INT16]: { typedArrayConstructor: Int16Array, heap: decoderModule.HEAP16 },
|
|
72
|
+
[decoderModule.DT_INT32]: { typedArrayConstructor: Int32Array, heap: decoderModule.HEAP32 },
|
|
73
|
+
[decoderModule.DT_UINT8]: { typedArrayConstructor: Uint8Array, heap: decoderModule.HEAPU8 },
|
|
74
|
+
[decoderModule.DT_UINT16]: { typedArrayConstructor: Uint16Array, heap: decoderModule.HEAPU16 },
|
|
75
|
+
[decoderModule.DT_UINT32]: { typedArrayConstructor: Uint32Array, heap: decoderModule.HEAPU32 },
|
|
76
|
+
};
|
|
77
|
+
const info = dataTypeInfo[dataType];
|
|
78
|
+
if (!info) {
|
|
79
|
+
throw new Error(`Invalid data type ${dataType}`);
|
|
80
|
+
}
|
|
53
81
|
const numValues = numPoints * numComponents;
|
|
54
|
-
const byteLength = numValues *
|
|
82
|
+
const byteLength = numValues * info.typedArrayConstructor.BYTES_PER_ELEMENT;
|
|
55
83
|
const ptr = decoderModule._malloc(byteLength);
|
|
56
84
|
try {
|
|
57
|
-
decoder.GetAttributeDataArrayForAllPoints(geometry, attribute,
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
const babylonData = new Float32Array(numPoints * 4);
|
|
61
|
-
for (let i = 0, j = 0; i < babylonData.length; i += 4, j += numComponents) {
|
|
62
|
-
babylonData[i + 0] = values[j + 0];
|
|
63
|
-
babylonData[i + 1] = values[j + 1];
|
|
64
|
-
babylonData[i + 2] = values[j + 2];
|
|
65
|
-
babylonData[i + 3] = 1;
|
|
66
|
-
}
|
|
67
|
-
onAttributeData(kind, babylonData);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
const babylonData = new Float32Array(numValues);
|
|
71
|
-
babylonData.set(new Float32Array(decoderModule.HEAPF32.buffer, ptr, numValues));
|
|
72
|
-
if (divider !== 1) {
|
|
73
|
-
for (let i = 0; i < babylonData.length; i++) {
|
|
74
|
-
babylonData[i] = babylonData[i] / divider;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
onAttributeData(kind, babylonData);
|
|
78
|
-
}
|
|
85
|
+
decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, dataType, byteLength, ptr);
|
|
86
|
+
const data = new info.typedArrayConstructor(info.heap.buffer, ptr, numValues);
|
|
87
|
+
onAttributeData(kind, data.slice(), byteOffset, byteStride, normalized);
|
|
79
88
|
}
|
|
80
89
|
finally {
|
|
81
90
|
decoderModule._free(ptr);
|
|
@@ -85,32 +94,36 @@ function decodeMesh(decoderModule, dataView, attributes, onIndicesData, onAttrib
|
|
|
85
94
|
for (const kind in attributes) {
|
|
86
95
|
const id = attributes[kind];
|
|
87
96
|
const attribute = decoder.GetAttributeByUniqueId(geometry, id);
|
|
88
|
-
|
|
89
|
-
processAttribute(kind, attribute, divider);
|
|
97
|
+
processAttribute(decoder, geometry, kind, attribute);
|
|
90
98
|
}
|
|
91
99
|
}
|
|
92
100
|
else {
|
|
93
|
-
const
|
|
94
|
-
position:
|
|
95
|
-
normal:
|
|
96
|
-
color:
|
|
97
|
-
uv:
|
|
101
|
+
const dracoAttributeTypes = {
|
|
102
|
+
position: decoderModule.POSITION,
|
|
103
|
+
normal: decoderModule.NORMAL,
|
|
104
|
+
color: decoderModule.COLOR,
|
|
105
|
+
uv: decoderModule.TEX_COORD,
|
|
98
106
|
};
|
|
99
|
-
for (const kind in
|
|
100
|
-
const id = decoder.GetAttributeId(geometry,
|
|
107
|
+
for (const kind in dracoAttributeTypes) {
|
|
108
|
+
const id = decoder.GetAttributeId(geometry, dracoAttributeTypes[kind]);
|
|
101
109
|
if (id !== -1) {
|
|
102
110
|
const attribute = decoder.GetAttribute(geometry, id);
|
|
103
|
-
processAttribute(kind, attribute);
|
|
111
|
+
processAttribute(decoder, geometry, kind, attribute);
|
|
104
112
|
}
|
|
105
113
|
}
|
|
106
114
|
}
|
|
115
|
+
return numPoints;
|
|
107
116
|
}
|
|
108
117
|
finally {
|
|
109
118
|
if (geometry) {
|
|
110
119
|
decoderModule.destroy(geometry);
|
|
111
120
|
}
|
|
112
|
-
|
|
113
|
-
|
|
121
|
+
if (buffer) {
|
|
122
|
+
decoderModule.destroy(buffer);
|
|
123
|
+
}
|
|
124
|
+
if (decoder) {
|
|
125
|
+
decoderModule.destroy(decoder);
|
|
126
|
+
}
|
|
114
127
|
}
|
|
115
128
|
}
|
|
116
129
|
/**
|
|
@@ -119,15 +132,15 @@ function decodeMesh(decoderModule, dataView, attributes, onIndicesData, onAttrib
|
|
|
119
132
|
function worker() {
|
|
120
133
|
let decoderPromise;
|
|
121
134
|
onmessage = (event) => {
|
|
122
|
-
const
|
|
123
|
-
switch (
|
|
135
|
+
const message = event.data;
|
|
136
|
+
switch (message.id) {
|
|
124
137
|
case "init": {
|
|
125
|
-
const decoder =
|
|
138
|
+
const decoder = message.decoder;
|
|
126
139
|
if (decoder.url) {
|
|
127
140
|
importScripts(decoder.url);
|
|
128
141
|
decoderPromise = DracoDecoderModule({ wasmBinary: decoder.wasmBinary });
|
|
129
142
|
}
|
|
130
|
-
postMessage("
|
|
143
|
+
postMessage({ id: "initDone" });
|
|
131
144
|
break;
|
|
132
145
|
}
|
|
133
146
|
case "decodeMesh": {
|
|
@@ -135,12 +148,12 @@ function worker() {
|
|
|
135
148
|
throw new Error("Draco decoder module is not available");
|
|
136
149
|
}
|
|
137
150
|
decoderPromise.then((decoder) => {
|
|
138
|
-
decodeMesh(decoder,
|
|
139
|
-
postMessage({ id: "indices",
|
|
140
|
-
}, (kind, data) => {
|
|
141
|
-
postMessage({ id: kind,
|
|
151
|
+
const numPoints = decodeMesh(decoder, message.dataView, message.attributes, (indices) => {
|
|
152
|
+
postMessage({ id: "indices", data: indices }, [indices.buffer]);
|
|
153
|
+
}, (kind, data, offset, stride, normalized) => {
|
|
154
|
+
postMessage({ id: "attribute", kind, data, offset, stride, normalized }, [data.buffer]);
|
|
142
155
|
});
|
|
143
|
-
postMessage("
|
|
156
|
+
postMessage({ id: "decodeMeshDone", totalVertices: numPoints });
|
|
144
157
|
});
|
|
145
158
|
break;
|
|
146
159
|
}
|
|
@@ -175,9 +188,9 @@ function worker() {
|
|
|
175
188
|
* Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.
|
|
176
189
|
* Use `DracoCompression.DecoderAvailable` to determine if the decoder configuration is available for the current context.
|
|
177
190
|
*
|
|
178
|
-
* To decode Draco compressed data, get the default DracoCompression object and call
|
|
191
|
+
* To decode Draco compressed data, get the default DracoCompression object and call decodeMeshToGeometryAsync:
|
|
179
192
|
* ```javascript
|
|
180
|
-
* var
|
|
193
|
+
* var geometry = await DracoCompression.Default.decodeMeshToGeometryAsync(data);
|
|
181
194
|
* ```
|
|
182
195
|
*
|
|
183
196
|
* @see https://playground.babylonjs.com/#DMZIBD#0
|
|
@@ -233,8 +246,8 @@ export class DracoCompression {
|
|
|
233
246
|
worker.removeEventListener("message", onMessage);
|
|
234
247
|
reject(error);
|
|
235
248
|
};
|
|
236
|
-
const onMessage = (
|
|
237
|
-
if (
|
|
249
|
+
const onMessage = (event) => {
|
|
250
|
+
if (event.data.id === "initDone") {
|
|
238
251
|
worker.removeEventListener("error", onError);
|
|
239
252
|
worker.removeEventListener("message", onMessage);
|
|
240
253
|
resolve(worker);
|
|
@@ -289,52 +302,54 @@ export class DracoCompression {
|
|
|
289
302
|
}
|
|
290
303
|
return Promise.resolve();
|
|
291
304
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
305
|
+
_decodeMeshAsync(engine, data, attributes, gltfNormalizedOverride) {
|
|
306
|
+
const dataView = data instanceof ArrayBuffer ? new Int8Array(data) : new Int8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
307
|
+
const applyGltfNormalizedOverride = (kind, normalized) => {
|
|
308
|
+
if (gltfNormalizedOverride && gltfNormalizedOverride[kind] !== undefined) {
|
|
309
|
+
if (normalized !== gltfNormalizedOverride[kind]) {
|
|
310
|
+
Logger.Warn(`Normalized flag from Draco data (${normalized}) does not match normalized flag from glTF accessor (${gltfNormalizedOverride[kind]}). Using flag from glTF accessor.`);
|
|
311
|
+
}
|
|
312
|
+
return gltfNormalizedOverride[kind];
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
return normalized;
|
|
316
|
+
}
|
|
317
|
+
};
|
|
301
318
|
if (this._workerPoolPromise) {
|
|
302
319
|
return this._workerPoolPromise.then((workerPool) => {
|
|
303
320
|
return new Promise((resolve, reject) => {
|
|
304
321
|
workerPool.push((worker, onComplete) => {
|
|
305
|
-
|
|
322
|
+
let resultIndices = null;
|
|
323
|
+
const resultAttributes = [];
|
|
306
324
|
const onError = (error) => {
|
|
307
325
|
worker.removeEventListener("error", onError);
|
|
308
326
|
worker.removeEventListener("message", onMessage);
|
|
309
327
|
reject(error);
|
|
310
328
|
onComplete();
|
|
311
329
|
};
|
|
312
|
-
const onMessage = (
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
330
|
+
const onMessage = (event) => {
|
|
331
|
+
const message = event.data;
|
|
332
|
+
switch (message.id) {
|
|
333
|
+
case "decodeMeshDone": {
|
|
334
|
+
worker.removeEventListener("error", onError);
|
|
335
|
+
worker.removeEventListener("message", onMessage);
|
|
336
|
+
resolve({ indices: resultIndices, attributes: resultAttributes, totalVertices: message.totalVertices });
|
|
337
|
+
onComplete();
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
case "indices": {
|
|
341
|
+
resultIndices = message.data;
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
case "attribute": {
|
|
345
|
+
resultAttributes.push(new VertexBuffer(engine, message.data, message.kind, false, undefined, message.stride, undefined, message.offset, undefined, undefined, applyGltfNormalizedOverride(message.kind, message.normalized), true));
|
|
346
|
+
break;
|
|
330
347
|
}
|
|
331
|
-
vertexData.set(message.data.value, message.data.id);
|
|
332
348
|
}
|
|
333
349
|
};
|
|
334
350
|
worker.addEventListener("error", onError);
|
|
335
351
|
worker.addEventListener("message", onMessage);
|
|
336
|
-
const dataViewCopy =
|
|
337
|
-
dataViewCopy.set(new Uint8Array(dataView.buffer, dataView.byteOffset, dataView.byteLength));
|
|
352
|
+
const dataViewCopy = dataView.slice();
|
|
338
353
|
worker.postMessage({ id: "decodeMesh", dataView: dataViewCopy, attributes: attributes }, [dataViewCopy.buffer]);
|
|
339
354
|
});
|
|
340
355
|
});
|
|
@@ -342,17 +357,70 @@ export class DracoCompression {
|
|
|
342
357
|
}
|
|
343
358
|
if (this._decoderModulePromise) {
|
|
344
359
|
return this._decoderModulePromise.then((decoder) => {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
360
|
+
let resultIndices = null;
|
|
361
|
+
const resultAttributes = [];
|
|
362
|
+
const numPoints = decodeMesh(decoder.module, dataView, attributes, (indices) => {
|
|
363
|
+
resultIndices = indices;
|
|
364
|
+
}, (kind, data, offset, stride, normalized) => {
|
|
365
|
+
resultAttributes.push(new VertexBuffer(null, data, kind, false, undefined, stride, undefined, offset, undefined, undefined, applyGltfNormalizedOverride(kind, normalized), true));
|
|
366
|
+
});
|
|
367
|
+
return { indices: resultIndices, attributes: resultAttributes, totalVertices: numPoints };
|
|
352
368
|
});
|
|
353
369
|
}
|
|
354
370
|
throw new Error("Draco decoder module is not available");
|
|
355
371
|
}
|
|
372
|
+
/**
|
|
373
|
+
* Decode Draco compressed mesh data to Babylon geometry.
|
|
374
|
+
* @param name The name to use when creating the geometry
|
|
375
|
+
* @param scene The scene to use when creating the geometry
|
|
376
|
+
* @param data The ArrayBuffer or ArrayBufferView for the Draco compression data
|
|
377
|
+
* @param attributes A map of attributes from vertex buffer kinds to Draco unique ids
|
|
378
|
+
* @returns A promise that resolves with the decoded geometry
|
|
379
|
+
*/
|
|
380
|
+
decodeMeshToGeometryAsync(name, scene, data, attributes) {
|
|
381
|
+
return this._decodeMeshAsync(scene.getEngine(), data, attributes).then((meshData) => {
|
|
382
|
+
const geometry = new Geometry(name, scene);
|
|
383
|
+
if (meshData.indices) {
|
|
384
|
+
geometry.setIndices(meshData.indices);
|
|
385
|
+
}
|
|
386
|
+
for (const attribute of meshData.attributes) {
|
|
387
|
+
geometry.setVerticesBuffer(attribute);
|
|
388
|
+
}
|
|
389
|
+
return geometry;
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
/** @internal */
|
|
393
|
+
_decodeMeshToGeometryForGltfAsync(name, scene, data, attributes, gltfNormalizedOverride) {
|
|
394
|
+
return this._decodeMeshAsync(scene.getEngine(), data, attributes, gltfNormalizedOverride).then((meshData) => {
|
|
395
|
+
const geometry = new Geometry(name, scene);
|
|
396
|
+
if (meshData.indices) {
|
|
397
|
+
geometry.setIndices(meshData.indices);
|
|
398
|
+
}
|
|
399
|
+
for (const attribute of meshData.attributes) {
|
|
400
|
+
geometry.setVerticesBuffer(attribute);
|
|
401
|
+
}
|
|
402
|
+
return geometry;
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Decode Draco compressed mesh data to Babylon vertex data.
|
|
407
|
+
* @param data The ArrayBuffer or ArrayBufferView for the Draco compression data
|
|
408
|
+
* @param attributes A map of attributes from vertex buffer kinds to Draco unique ids
|
|
409
|
+
* @returns A promise that resolves with the decoded vertex data
|
|
410
|
+
* @deprecated Use {@link decodeMeshToGeometryAsync} for better performance in some cases
|
|
411
|
+
*/
|
|
412
|
+
decodeMeshAsync(data, attributes) {
|
|
413
|
+
return this._decodeMeshAsync(null, data, attributes).then((meshData) => {
|
|
414
|
+
const vertexData = new VertexData();
|
|
415
|
+
if (meshData.indices) {
|
|
416
|
+
vertexData.indices = meshData.indices;
|
|
417
|
+
}
|
|
418
|
+
for (const attribute of meshData.attributes) {
|
|
419
|
+
vertexData.set(attribute.getFloatData(meshData.totalVertices), attribute.getKind());
|
|
420
|
+
}
|
|
421
|
+
return vertexData;
|
|
422
|
+
});
|
|
423
|
+
}
|
|
356
424
|
}
|
|
357
425
|
/**
|
|
358
426
|
* The configuration. Defaults to the following urls:
|