@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.
Files changed (134) hide show
  1. package/Audio/soundTrack.js +1 -1
  2. package/Audio/soundTrack.js.map +1 -1
  3. package/Buffers/buffer.d.ts +2 -1
  4. package/Buffers/buffer.js +13 -5
  5. package/Buffers/buffer.js.map +1 -1
  6. package/Debug/rayHelper.d.ts +3 -3
  7. package/Debug/rayHelper.js +2 -2
  8. package/Debug/rayHelper.js.map +1 -1
  9. package/Engines/Native/nativeHelpers.d.ts +9 -0
  10. package/Engines/Native/nativeHelpers.js +296 -0
  11. package/Engines/Native/nativeHelpers.js.map +1 -0
  12. package/Engines/Native/nativeInterfaces.d.ts +92 -0
  13. package/Engines/Native/nativeInterfaces.js.map +1 -1
  14. package/Engines/engine.d.ts +6 -4
  15. package/Engines/engine.js +7 -1
  16. package/Engines/engine.js.map +1 -1
  17. package/Engines/nativeEngine.d.ts +3 -12
  18. package/Engines/nativeEngine.js +43 -226
  19. package/Engines/nativeEngine.js.map +1 -1
  20. package/Engines/thinEngine.js +4 -2
  21. package/Engines/thinEngine.js.map +1 -1
  22. package/Engines/webgpuEngine.js +2 -1
  23. package/Engines/webgpuEngine.js.map +1 -1
  24. package/FlowGraph/Blocks/Data/Logic/flowGraphLogicBlocks.d.ts +23 -0
  25. package/FlowGraph/Blocks/Data/Logic/flowGraphLogicBlocks.js +31 -0
  26. package/FlowGraph/Blocks/Data/Logic/flowGraphLogicBlocks.js.map +1 -0
  27. package/FlowGraph/Blocks/Data/Math/flowGraphNumberMathBlocks.d.ts +270 -0
  28. package/FlowGraph/Blocks/Data/Math/flowGraphNumberMathBlocks.js +347 -0
  29. package/FlowGraph/Blocks/Data/Math/flowGraphNumberMathBlocks.js.map +1 -0
  30. package/FlowGraph/Blocks/Data/Math/flowGraphVector2MathBlocks.d.ts +52 -0
  31. package/FlowGraph/Blocks/Data/Math/flowGraphVector2MathBlocks.js +71 -0
  32. package/FlowGraph/Blocks/Data/Math/flowGraphVector2MathBlocks.js.map +1 -0
  33. package/FlowGraph/Blocks/Data/Math/flowGraphVector3MathBlocks.d.ts +66 -0
  34. package/FlowGraph/Blocks/Data/Math/flowGraphVector3MathBlocks.js +86 -0
  35. package/FlowGraph/Blocks/Data/Math/flowGraphVector3MathBlocks.js.map +1 -0
  36. package/FlowGraph/Blocks/Data/Math/flowGraphVector4MathBlocks.d.ts +52 -0
  37. package/FlowGraph/Blocks/Data/Math/flowGraphVector4MathBlocks.js +71 -0
  38. package/FlowGraph/Blocks/Data/Math/flowGraphVector4MathBlocks.js.map +1 -0
  39. package/FlowGraph/Blocks/Data/flowGraphBinaryOperationBlock.d.ts +17 -0
  40. package/FlowGraph/Blocks/Data/flowGraphBinaryOperationBlock.js +19 -0
  41. package/FlowGraph/Blocks/Data/flowGraphBinaryOperationBlock.js.map +1 -0
  42. package/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.d.ts +13 -0
  43. package/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.js +16 -0
  44. package/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.js.map +1 -0
  45. package/FlowGraph/Blocks/Data/flowGraphUnaryOperationBlock.d.ts +15 -0
  46. package/FlowGraph/Blocks/Data/flowGraphUnaryOperationBlock.js +17 -0
  47. package/FlowGraph/Blocks/Data/flowGraphUnaryOperationBlock.js.map +1 -0
  48. package/FlowGraph/Blocks/Data/index.d.ts +4 -1
  49. package/FlowGraph/Blocks/Data/index.js +4 -1
  50. package/FlowGraph/Blocks/Data/index.js.map +1 -1
  51. package/FlowGraph/Blocks/Event/flowGraphSceneTickEventBlock.d.ts +16 -0
  52. package/FlowGraph/Blocks/Event/flowGraphSceneTickEventBlock.js +29 -0
  53. package/FlowGraph/Blocks/Event/flowGraphSceneTickEventBlock.js.map +1 -0
  54. package/FlowGraph/Blocks/Event/index.d.ts +1 -0
  55. package/FlowGraph/Blocks/Event/index.js +1 -0
  56. package/FlowGraph/Blocks/Event/index.js.map +1 -1
  57. package/FlowGraph/Blocks/Execution/Animation/flowGraphPauseAnimationBlock.d.ts +16 -0
  58. package/FlowGraph/Blocks/Execution/Animation/flowGraphPauseAnimationBlock.js +18 -0
  59. package/FlowGraph/Blocks/Execution/Animation/flowGraphPauseAnimationBlock.js.map +1 -0
  60. package/FlowGraph/Blocks/Execution/{flowGraphPlayAnimationBlock.d.ts → Animation/flowGraphPlayAnimationBlock.d.ts} +5 -5
  61. package/FlowGraph/Blocks/Execution/{flowGraphPlayAnimationBlock.js → Animation/flowGraphPlayAnimationBlock.js} +15 -8
  62. package/FlowGraph/Blocks/Execution/Animation/flowGraphPlayAnimationBlock.js.map +1 -0
  63. package/FlowGraph/Blocks/Execution/{flowGraphStopAnimationBlock.d.ts → Animation/flowGraphStopAnimationBlock.d.ts} +4 -4
  64. package/FlowGraph/Blocks/Execution/{flowGraphStopAnimationBlock.js → Animation/flowGraphStopAnimationBlock.js} +2 -2
  65. package/FlowGraph/Blocks/Execution/Animation/flowGraphStopAnimationBlock.js.map +1 -0
  66. package/FlowGraph/Blocks/Execution/Animation/index.d.ts +3 -0
  67. package/FlowGraph/Blocks/Execution/Animation/index.js +4 -0
  68. package/FlowGraph/Blocks/Execution/Animation/index.js.map +1 -0
  69. package/FlowGraph/Blocks/Execution/index.d.ts +1 -2
  70. package/FlowGraph/Blocks/Execution/index.js +2 -2
  71. package/FlowGraph/Blocks/Execution/index.js.map +1 -1
  72. package/FlowGraph/flowGraphDataConnection.d.ts +2 -2
  73. package/FlowGraph/flowGraphDataConnection.js +3 -3
  74. package/FlowGraph/flowGraphDataConnection.js.map +1 -1
  75. package/Gizmos/axisDragGizmo.d.ts +1 -1
  76. package/Gizmos/axisDragGizmo.js +0 -1
  77. package/Gizmos/axisDragGizmo.js.map +1 -1
  78. package/Gizmos/axisScaleGizmo.js +0 -1
  79. package/Gizmos/axisScaleGizmo.js.map +1 -1
  80. package/Gizmos/boundingBoxGizmo.d.ts +12 -0
  81. package/Gizmos/boundingBoxGizmo.js +37 -1
  82. package/Gizmos/boundingBoxGizmo.js.map +1 -1
  83. package/Gizmos/gizmo.d.ts +0 -4
  84. package/Gizmos/gizmo.js +19 -16
  85. package/Gizmos/gizmo.js.map +1 -1
  86. package/Gizmos/planeDragGizmo.js +0 -1
  87. package/Gizmos/planeDragGizmo.js.map +1 -1
  88. package/Gizmos/planeRotationGizmo.js +0 -1
  89. package/Gizmos/planeRotationGizmo.js.map +1 -1
  90. package/Gizmos/scaleGizmo.d.ts +2 -2
  91. package/Gizmos/scaleGizmo.js +5 -2
  92. package/Gizmos/scaleGizmo.js.map +1 -1
  93. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js +1 -0
  94. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js.map +1 -1
  95. package/Materials/PBR/pbrBaseMaterial.d.ts +1 -0
  96. package/Materials/PBR/pbrBaseMaterial.js +12 -2
  97. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  98. package/Materials/Textures/equiRectangularCubeTexture.js +24 -4
  99. package/Materials/Textures/equiRectangularCubeTexture.js.map +1 -1
  100. package/Materials/standardMaterial.d.ts +1 -0
  101. package/Materials/standardMaterial.js +6 -0
  102. package/Materials/standardMaterial.js.map +1 -1
  103. package/Maths/math.vector.d.ts +1 -1
  104. package/Maths/math.vector.js +1 -1
  105. package/Maths/math.vector.js.map +1 -1
  106. package/Meshes/Compression/dracoCompression.d.ts +25 -8
  107. package/Meshes/Compression/dracoCompression.js +187 -119
  108. package/Meshes/Compression/dracoCompression.js.map +1 -1
  109. package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.d.ts +22 -2
  110. package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.js +62 -4
  111. package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.js.map +1 -1
  112. package/Meshes/Node/Blocks/debugBlock.d.ts +2 -1
  113. package/Meshes/Node/Blocks/debugBlock.js +8 -2
  114. package/Meshes/Node/Blocks/debugBlock.js.map +1 -1
  115. package/Meshes/Node/Blocks/randomBlock.d.ts +14 -3
  116. package/Meshes/Node/Blocks/randomBlock.js +40 -13
  117. package/Meshes/Node/Blocks/randomBlock.js.map +1 -1
  118. package/Meshes/Node/nodeGeometryBuildState.d.ts +2 -2
  119. package/Meshes/Node/nodeGeometryBuildState.js +5 -3
  120. package/Meshes/Node/nodeGeometryBuildState.js.map +1 -1
  121. package/Meshes/meshSimplification.d.ts +1 -1
  122. package/Meshes/meshSimplification.js.map +1 -1
  123. package/Meshes/subMesh.js +1 -1
  124. package/Meshes/subMesh.js.map +1 -1
  125. package/Physics/v2/IPhysicsEnginePlugin.d.ts +8 -0
  126. package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
  127. package/Shaders/ShadersInclude/bumpFragmentFunctions.js +14 -2
  128. package/Shaders/ShadersInclude/bumpFragmentFunctions.js.map +1 -1
  129. package/package.json +1 -1
  130. package/FlowGraph/Blocks/Data/flowGraphAddBlock.d.ts +0 -23
  131. package/FlowGraph/Blocks/Data/flowGraphAddBlock.js +0 -18
  132. package/FlowGraph/Blocks/Data/flowGraphAddBlock.js.map +0 -1
  133. package/FlowGraph/Blocks/Execution/flowGraphPlayAnimationBlock.js.map +0 -1
  134. package/FlowGraph/Blocks/Execution/flowGraphStopAnimationBlock.js.map +0 -1
@@ -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,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAS1D,SAAS,kBAAkB,CAAC,UAAwB;IAChD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,kBAAkB,CAAC,EAAE,UAAU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AC,CAAC;SACN;QAED,IAAI,IAAI,CAAC,qBAAqB,EAAE;YAC5B,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;gBAC/C,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC;gBACpC,UAAU,CACN,OAAO,CAAC,MAAM,EACd,QAAQ,EACR,UAAU,EACV,CAAC,OAAO,EAAE,EAAE;oBACR,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;gBACjC,CAAC,EACD,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;oBACX,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAC/B,CAAC,EACD,QAAQ,CACX,CAAC;gBACF,OAAO,UAAU,CAAC;YACtB,CAAC,CAAC,CAAC;SACN;QAED,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC7D,CAAC;;AA7ND;;;;;GAKG;AACW,8BAAa,GAAmC;IAC1D,OAAO,EAAE;QACL,OAAO,EAAE,0DAA0D;QACnE,aAAa,EAAE,uDAAuD;QACtE,WAAW,EAAE,qDAAqD;KACrE;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 } from \"../../scene\";\r\nimport { VertexData } from \"../../Meshes/mesh.vertexData\";\r\n\r\ndeclare let DracoDecoderModule: any;\r\ndeclare let WebAssembly: any;\r\n\r\n// WorkerGlobalScope\r\ndeclare function importScripts(...urls: string[]): void;\r\ndeclare function postMessage(message: any, transfer?: any[]): void;\r\n\r\nfunction createDecoderAsync(wasmBinary?: ArrayBuffer): Promise<any> {\r\n return new Promise((resolve) => {\r\n DracoDecoderModule({ wasmBinary: wasmBinary }).then((module: any) => {\r\n resolve({ module: module });\r\n });\r\n });\r\n}\r\n\r\nfunction decodeMesh(\r\n decoderModule: any,\r\n dataView: ArrayBufferView,\r\n attributes: { [kind: string]: number } | undefined,\r\n onIndicesData: (data: Uint32Array) => void,\r\n onAttributeData: (kind: string, data: Float32Array) => void,\r\n dividers?: { [kind: string]: number }\r\n): void {\r\n const buffer = new decoderModule.DecoderBuffer();\r\n buffer.Init(dataView, dataView.byteLength);\r\n\r\n const decoder = new decoderModule.Decoder();\r\n let geometry: any;\r\n let status: any;\r\n\r\n try {\r\n const type = decoder.GetEncodedGeometryType(buffer);\r\n switch (type) {\r\n case decoderModule.TRIANGULAR_MESH:\r\n geometry = new decoderModule.Mesh();\r\n status = decoder.DecodeBufferToMesh(buffer, geometry);\r\n break;\r\n case decoderModule.POINT_CLOUD:\r\n geometry = new decoderModule.PointCloud();\r\n status = decoder.DecodeBufferToPointCloud(buffer, geometry);\r\n break;\r\n default:\r\n throw new Error(`Invalid geometry type ${type}`);\r\n }\r\n\r\n if (!status.ok() || !geometry.ptr) {\r\n throw new Error(status.error_msg());\r\n }\r\n\r\n if (type === decoderModule.TRIANGULAR_MESH) {\r\n const numFaces = geometry.num_faces();\r\n const numIndices = numFaces * 3;\r\n const byteLength = numIndices * 4;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetTrianglesUInt32Array(geometry, byteLength, ptr);\r\n const indices = new Uint32Array(numIndices);\r\n indices.set(new Uint32Array(decoderModule.HEAPF32.buffer, ptr, numIndices));\r\n onIndicesData(indices);\r\n } finally {\r\n decoderModule._free(ptr);\r\n }\r\n }\r\n\r\n const processAttribute = (kind: string, attribute: any, divider = 1) => {\r\n const numComponents = attribute.num_components();\r\n const numPoints = geometry.num_points();\r\n const numValues = numPoints * numComponents;\r\n const byteLength = numValues * Float32Array.BYTES_PER_ELEMENT;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, decoderModule.DT_FLOAT32, byteLength, ptr);\r\n const values = new Float32Array(decoderModule.HEAPF32.buffer, ptr, numValues);\r\n if (kind === \"color\" && numComponents === 3) {\r\n const babylonData = new Float32Array(numPoints * 4);\r\n for (let i = 0, j = 0; i < babylonData.length; i += 4, j += numComponents) {\r\n babylonData[i + 0] = values[j + 0];\r\n babylonData[i + 1] = values[j + 1];\r\n babylonData[i + 2] = values[j + 2];\r\n babylonData[i + 3] = 1;\r\n }\r\n onAttributeData(kind, babylonData);\r\n } else {\r\n const babylonData = new Float32Array(numValues);\r\n babylonData.set(new Float32Array(decoderModule.HEAPF32.buffer, ptr, numValues));\r\n if (divider !== 1) {\r\n for (let i = 0; i < babylonData.length; i++) {\r\n babylonData[i] = babylonData[i] / divider;\r\n }\r\n }\r\n onAttributeData(kind, babylonData);\r\n }\r\n } finally {\r\n decoderModule._free(ptr);\r\n }\r\n };\r\n\r\n if (attributes) {\r\n for (const kind in attributes) {\r\n const id = attributes[kind];\r\n const attribute = decoder.GetAttributeByUniqueId(geometry, id);\r\n const divider = (dividers && dividers[kind]) || 1;\r\n processAttribute(kind, attribute, divider);\r\n }\r\n } else {\r\n const nativeAttributeTypes: { [kind: string]: string } = {\r\n position: \"POSITION\",\r\n normal: \"NORMAL\",\r\n color: \"COLOR\",\r\n uv: \"TEX_COORD\",\r\n };\r\n\r\n for (const kind in nativeAttributeTypes) {\r\n const id = decoder.GetAttributeId(geometry, decoderModule[nativeAttributeTypes[kind]]);\r\n if (id !== -1) {\r\n const attribute = decoder.GetAttribute(geometry, id);\r\n processAttribute(kind, attribute);\r\n }\r\n }\r\n }\r\n } finally {\r\n if (geometry) {\r\n decoderModule.destroy(geometry);\r\n }\r\n\r\n decoderModule.destroy(decoder);\r\n decoderModule.destroy(buffer);\r\n }\r\n}\r\n\r\n/**\r\n * The worker function that gets converted to a blob url to pass into a worker.\r\n */\r\nfunction worker(): void {\r\n let decoderPromise: PromiseLike<any> | undefined;\r\n\r\n onmessage = (event) => {\r\n const data = event.data;\r\n switch (data.id) {\r\n case \"init\": {\r\n const decoder = data.decoder;\r\n if (decoder.url) {\r\n importScripts(decoder.url);\r\n decoderPromise = DracoDecoderModule({ wasmBinary: decoder.wasmBinary });\r\n }\r\n postMessage(\"done\");\r\n break;\r\n }\r\n case \"decodeMesh\": {\r\n if (!decoderPromise) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n decoderPromise.then((decoder) => {\r\n decodeMesh(\r\n decoder,\r\n data.dataView,\r\n data.attributes,\r\n (indices) => {\r\n postMessage({ id: \"indices\", value: indices }, [indices.buffer]);\r\n },\r\n (kind, data) => {\r\n postMessage({ id: kind, value: data }, [data.buffer]);\r\n }\r\n );\r\n postMessage(\"done\");\r\n });\r\n break;\r\n }\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}\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 decodeMeshAsync:\r\n * ```javascript\r\n * var vertexData = await DracoCompression.Default.decodeMeshAsync(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<any>;\r\n\r\n /**\r\n * The configuration. Defaults to the following urls:\r\n * - wasmUrl: \"https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js\"\r\n * - wasmBinaryUrl: \"https://preview.babylonjs.com/draco_decoder_gltf.wasm\"\r\n * - fallbackUrl: \"https://preview.babylonjs.com/draco_decoder_gltf.js\"\r\n */\r\n public static Configuration: IDracoCompressionConfiguration = {\r\n decoder: {\r\n wasmUrl: \"https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js\",\r\n wasmBinaryUrl: \"https://preview.babylonjs.com/draco_decoder_gltf.wasm\",\r\n fallbackUrl: \"https://preview.babylonjs.com/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. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n constructor(numWorkers = DracoCompression.DefaultNumWorkers) {\r\n const decoder = DracoCompression.Configuration.decoder;\r\n\r\n const decoderInfo: { url: string | undefined; wasmBinaryPromise: Promise<ArrayBuffer | string | undefined> } =\r\n decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\"\r\n ? {\r\n url: Tools.GetAbsoluteUrl(decoder.wasmUrl),\r\n wasmBinaryPromise: Tools.LoadFileAsync(Tools.GetAbsoluteUrl(decoder.wasmBinaryUrl)),\r\n }\r\n : {\r\n url: Tools.GetAbsoluteUrl(decoder.fallbackUrl!),\r\n wasmBinaryPromise: Promise.resolve(undefined),\r\n };\r\n\r\n if (numWorkers && typeof Worker === \"function\" && typeof URL === \"function\") {\r\n this._workerPoolPromise = decoderInfo.wasmBinaryPromise.then((decoderWasmBinary) => {\r\n const workerContent = `${decodeMesh}(${worker})()`;\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n\r\n return new AutoReleaseWorkerPool(numWorkers, () => {\r\n return new Promise((resolve, reject) => {\r\n const worker = new Worker(workerBlobUrl);\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n };\r\n\r\n const onMessage = (message: MessageEvent) => {\r\n if (message.data === \"done\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(worker);\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n worker.postMessage({\r\n id: \"init\",\r\n decoder: {\r\n url: decoderInfo.url,\r\n wasmBinary: decoderWasmBinary,\r\n },\r\n });\r\n });\r\n });\r\n });\r\n } else {\r\n this._decoderModulePromise = decoderInfo.wasmBinaryPromise.then((decoderWasmBinary) => {\r\n if (!decoderInfo.url) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n\r\n return Tools.LoadScriptAsync(decoderInfo.url).then(() => {\r\n return createDecoderAsync(decoderWasmBinary as ArrayBuffer);\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 whenReadyAsync(): Promise<void> {\r\n if (this._workerPoolPromise) {\r\n return this._workerPoolPromise.then(() => {});\r\n }\r\n\r\n if (this._decoderModulePromise) {\r\n return this._decoderModulePromise.then(() => {});\r\n }\r\n\r\n return Promise.resolve();\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to 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 * @param dividers a list of optional dividers for normalization\r\n * @returns A promise that resolves with the decoded vertex data\r\n */\r\n public decodeMeshAsync(data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }, dividers?: { [kind: string]: number }): Promise<VertexData> {\r\n const dataView = data instanceof ArrayBuffer ? new Uint8Array(data) : data;\r\n\r\n if (this._workerPoolPromise) {\r\n return this._workerPoolPromise.then((workerPool) => {\r\n return new Promise<VertexData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n const vertexData = new VertexData();\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 = (message: MessageEvent) => {\r\n if (message.data === \"done\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(vertexData);\r\n onComplete();\r\n } else if (message.data.id === \"indices\") {\r\n vertexData.indices = message.data.value;\r\n } else {\r\n // check normalization\r\n const divider = dividers && dividers[message.data.id] ? dividers[message.data.id] : 1;\r\n if (divider !== 1) {\r\n // normalize\r\n for (let i = 0; i < message.data.value.length; i++) {\r\n message.data.value[i] = message.data.value[i] / divider;\r\n }\r\n }\r\n vertexData.set(message.data.value, message.data.id);\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n const dataViewCopy = new Uint8Array(dataView.byteLength);\r\n dataViewCopy.set(new Uint8Array(dataView.buffer, dataView.byteOffset, dataView.byteLength));\r\n\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 const vertexData = new VertexData();\r\n decodeMesh(\r\n decoder.module,\r\n dataView,\r\n attributes,\r\n (indices) => {\r\n vertexData.indices = indices;\r\n },\r\n (kind, data) => {\r\n vertexData.set(data, kind);\r\n },\r\n dividers\r\n );\r\n return vertexData;\r\n });\r\n }\r\n\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"dracoCompression.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/drac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CAAC,OAAO,EAAE;gBAClB,UAAU,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;aACzC;YAED,KAAK,MAAM,SAAS,IAAI,QAAQ,CAAC,UAAU,EAAE;gBACzC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,YAAY,CAAC,QAAQ,CAAC,aAAa,CAAE,EAAE,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;aACxF;YAED,OAAO,UAAU,CAAC;QACtB,CAAC,CAAC,CAAC;IACP,CAAC;;AA9UD;;;;;GAKG;AACW,8BAAa,GAAmC;IAC1D,OAAO,EAAE;QACL,OAAO,EAAE,0DAA0D;QACnE,aAAa,EAAE,uDAAuD;QACtE,WAAW,EAAE,qDAAqD;KACrE;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 { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport { DracoDecoderModule } from \"draco3dgltf\";\r\nimport type { DecoderModule, DecoderBuffer, Decoder, Mesh, PointCloud, Status } from \"draco3dgltf\";\r\nimport { Logger } from \"../../Misc/logger\";\r\n\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\ninterface MeshData {\r\n indices?: Uint16Array | Uint32Array;\r\n attributes: Array<VertexBuffer>;\r\n totalVertices: number;\r\n}\r\n\r\ninterface InitDoneMessage {\r\n id: \"initDone\";\r\n}\r\n\r\ninterface DecodeMeshDoneMessage {\r\n id: \"decodeMeshDone\";\r\n totalVertices: number;\r\n}\r\n\r\ninterface IndicesMessage {\r\n id: \"indices\";\r\n data: Uint16Array | Uint32Array;\r\n}\r\n\r\ninterface AttributeMessage {\r\n id: \"attribute\";\r\n kind: string;\r\n data: ArrayBufferView;\r\n offset: number;\r\n stride: number;\r\n normalized: boolean;\r\n}\r\n\r\ntype Message = InitDoneMessage | DecodeMeshDoneMessage | IndicesMessage | AttributeMessage;\r\n\r\n// WorkerGlobalScope\r\ndeclare function importScripts(...urls: string[]): void;\r\ndeclare function postMessage(message: Message, transfer?: any[]): void;\r\n\r\nfunction createDecoderAsync(wasmBinary?: ArrayBuffer): Promise<{ module: DecoderModule }> {\r\n return new Promise((resolve) => {\r\n DracoDecoderModule({ wasmBinary: wasmBinary }).then((module) => {\r\n resolve({ module: module });\r\n });\r\n });\r\n}\r\n\r\nfunction decodeMesh(\r\n decoderModule: DecoderModule,\r\n data: Int8Array,\r\n attributes: { [kind: string]: number } | undefined,\r\n onIndicesData: (indices: Uint16Array | Uint32Array) => void,\r\n onAttributeData: (kind: string, data: ArrayBufferView, offset: number, stride: number, normalized: boolean) => void\r\n): number {\r\n let decoder: Nullable<Decoder> = null;\r\n let buffer: Nullable<DecoderBuffer> = null;\r\n let geometry: Nullable<Mesh | PointCloud> = null;\r\n\r\n try {\r\n decoder = new decoderModule.Decoder();\r\n\r\n buffer = new decoderModule.DecoderBuffer();\r\n buffer.Init(data, data.byteLength);\r\n\r\n let status: Status;\r\n const type = decoder.GetEncodedGeometryType(buffer);\r\n switch (type) {\r\n case decoderModule.TRIANGULAR_MESH: {\r\n const mesh = new decoderModule.Mesh();\r\n status = decoder.DecodeBufferToMesh(buffer, mesh);\r\n if (!status.ok() || mesh.ptr === 0) {\r\n throw new Error(status.error_msg());\r\n }\r\n\r\n const numFaces = mesh.num_faces();\r\n const numIndices = numFaces * 3;\r\n const byteLength = numIndices * 4;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetTrianglesUInt32Array(mesh, byteLength, ptr);\r\n const indices = new Uint32Array(numIndices);\r\n indices.set(new Uint32Array(decoderModule.HEAPF32.buffer, ptr, numIndices));\r\n onIndicesData(indices);\r\n } finally {\r\n decoderModule._free(ptr);\r\n }\r\n\r\n geometry = mesh;\r\n break;\r\n }\r\n case decoderModule.POINT_CLOUD: {\r\n const pointCloud = new decoderModule.PointCloud();\r\n status = decoder.DecodeBufferToPointCloud(buffer, pointCloud);\r\n if (!status.ok() || !pointCloud.ptr) {\r\n throw new Error(status.error_msg());\r\n }\r\n\r\n geometry = pointCloud;\r\n break;\r\n }\r\n default: {\r\n throw new Error(`Invalid geometry type ${type}`);\r\n }\r\n }\r\n\r\n const numPoints = geometry.num_points();\r\n\r\n const processAttribute = (decoder: Decoder, geometry: Mesh | PointCloud, kind: string, attribute: any) => {\r\n const dataType = attribute.data_type();\r\n const numComponents = attribute.num_components();\r\n const normalized = attribute.normalized();\r\n const byteStride = attribute.byte_stride();\r\n const byteOffset = attribute.byte_offset();\r\n\r\n const dataTypeInfo = {\r\n [decoderModule.DT_FLOAT32]: { typedArrayConstructor: Float32Array, heap: decoderModule.HEAPF32 },\r\n [decoderModule.DT_INT8]: { typedArrayConstructor: Int8Array, heap: decoderModule.HEAP8 },\r\n [decoderModule.DT_INT16]: { typedArrayConstructor: Int16Array, heap: decoderModule.HEAP16 },\r\n [decoderModule.DT_INT32]: { typedArrayConstructor: Int32Array, heap: decoderModule.HEAP32 },\r\n [decoderModule.DT_UINT8]: { typedArrayConstructor: Uint8Array, heap: decoderModule.HEAPU8 },\r\n [decoderModule.DT_UINT16]: { typedArrayConstructor: Uint16Array, heap: decoderModule.HEAPU16 },\r\n [decoderModule.DT_UINT32]: { typedArrayConstructor: Uint32Array, heap: decoderModule.HEAPU32 },\r\n };\r\n\r\n const info = dataTypeInfo[dataType];\r\n if (!info) {\r\n throw new Error(`Invalid data type ${dataType}`);\r\n }\r\n\r\n const numValues = numPoints * numComponents;\r\n const byteLength = numValues * info.typedArrayConstructor.BYTES_PER_ELEMENT;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, dataType, byteLength, ptr);\r\n const data = new info.typedArrayConstructor(info.heap.buffer, ptr, numValues);\r\n onAttributeData(kind, data.slice(), byteOffset, byteStride, normalized);\r\n } finally {\r\n decoderModule._free(ptr);\r\n }\r\n };\r\n\r\n if (attributes) {\r\n for (const kind in attributes) {\r\n const id = attributes[kind];\r\n const attribute = decoder.GetAttributeByUniqueId(geometry, id);\r\n processAttribute(decoder, geometry, kind, attribute);\r\n }\r\n } else {\r\n const dracoAttributeTypes: { [kind: string]: number } = {\r\n position: decoderModule.POSITION,\r\n normal: decoderModule.NORMAL,\r\n color: decoderModule.COLOR,\r\n uv: decoderModule.TEX_COORD,\r\n };\r\n\r\n for (const kind in dracoAttributeTypes) {\r\n const id = decoder.GetAttributeId(geometry, dracoAttributeTypes[kind]);\r\n if (id !== -1) {\r\n const attribute = decoder.GetAttribute(geometry, id);\r\n processAttribute(decoder, geometry, kind, attribute);\r\n }\r\n }\r\n }\r\n\r\n return numPoints;\r\n } finally {\r\n if (geometry) {\r\n decoderModule.destroy(geometry);\r\n }\r\n\r\n if (buffer) {\r\n decoderModule.destroy(buffer);\r\n }\r\n\r\n if (decoder) {\r\n decoderModule.destroy(decoder);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * The worker function that gets converted to a blob url to pass into a worker.\r\n */\r\nfunction worker(): void {\r\n let decoderPromise: PromiseLike<any> | undefined;\r\n\r\n onmessage = (event) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"init\": {\r\n const decoder = message.decoder;\r\n if (decoder.url) {\r\n importScripts(decoder.url);\r\n decoderPromise = DracoDecoderModule({ wasmBinary: decoder.wasmBinary });\r\n }\r\n postMessage({ id: \"initDone\" });\r\n break;\r\n }\r\n case \"decodeMesh\": {\r\n if (!decoderPromise) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n decoderPromise.then((decoder) => {\r\n const numPoints = decodeMesh(\r\n decoder,\r\n message.dataView,\r\n message.attributes,\r\n (indices) => {\r\n postMessage({ id: \"indices\", data: indices }, [indices.buffer]);\r\n },\r\n (kind, data, offset, stride, normalized) => {\r\n postMessage({ id: \"attribute\", kind, data, offset, stride, normalized }, [data.buffer]);\r\n }\r\n );\r\n postMessage({ id: \"decodeMeshDone\", totalVertices: numPoints });\r\n });\r\n break;\r\n }\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}\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://preview.babylonjs.com/draco_wasm_wrapper_gltf.js\"\r\n * - wasmBinaryUrl: \"https://preview.babylonjs.com/draco_decoder_gltf.wasm\"\r\n * - fallbackUrl: \"https://preview.babylonjs.com/draco_decoder_gltf.js\"\r\n */\r\n public static Configuration: IDracoCompressionConfiguration = {\r\n decoder: {\r\n wasmUrl: \"https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js\",\r\n wasmBinaryUrl: \"https://preview.babylonjs.com/draco_decoder_gltf.wasm\",\r\n fallbackUrl: \"https://preview.babylonjs.com/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. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n constructor(numWorkers = DracoCompression.DefaultNumWorkers) {\r\n const decoder = DracoCompression.Configuration.decoder;\r\n\r\n const decoderInfo: { url: string | undefined; wasmBinaryPromise: Promise<ArrayBuffer | string | undefined> } =\r\n decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\"\r\n ? {\r\n url: Tools.GetAbsoluteUrl(decoder.wasmUrl),\r\n wasmBinaryPromise: Tools.LoadFileAsync(Tools.GetAbsoluteUrl(decoder.wasmBinaryUrl)),\r\n }\r\n : {\r\n url: Tools.GetAbsoluteUrl(decoder.fallbackUrl!),\r\n wasmBinaryPromise: Promise.resolve(undefined),\r\n };\r\n\r\n if (numWorkers && typeof Worker === \"function\" && typeof URL === \"function\") {\r\n this._workerPoolPromise = decoderInfo.wasmBinaryPromise.then((decoderWasmBinary) => {\r\n const workerContent = `${decodeMesh}(${worker})()`;\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n\r\n return new AutoReleaseWorkerPool(numWorkers, () => {\r\n return new Promise((resolve, reject) => {\r\n const worker = new Worker(workerBlobUrl);\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n };\r\n\r\n const onMessage = (event: MessageEvent<Message>) => {\r\n if (event.data.id === \"initDone\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(worker);\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n worker.postMessage({\r\n id: \"init\",\r\n decoder: {\r\n url: decoderInfo.url,\r\n wasmBinary: decoderWasmBinary,\r\n },\r\n });\r\n });\r\n });\r\n });\r\n } else {\r\n this._decoderModulePromise = decoderInfo.wasmBinaryPromise.then((decoderWasmBinary) => {\r\n if (!decoderInfo.url) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n\r\n return Tools.LoadScriptAsync(decoderInfo.url).then(() => {\r\n return createDecoderAsync(decoderWasmBinary as ArrayBuffer);\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 whenReadyAsync(): Promise<void> {\r\n if (this._workerPoolPromise) {\r\n return this._workerPoolPromise.then(() => {});\r\n }\r\n\r\n if (this._decoderModulePromise) {\r\n return this._decoderModulePromise.then(() => {});\r\n }\r\n\r\n return Promise.resolve();\r\n }\r\n\r\n private _decodeMeshAsync(\r\n engine: Nullable<ThinEngine>,\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<VertexBuffer> = [];\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 new VertexBuffer(\r\n engine,\r\n message.data,\r\n message.kind,\r\n false,\r\n undefined,\r\n message.stride,\r\n undefined,\r\n message.offset,\r\n undefined,\r\n undefined,\r\n applyGltfNormalizedOverride(message.kind, message.normalized),\r\n true\r\n )\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<VertexBuffer> = [];\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, offset, stride, normalized) => {\r\n resultAttributes.push(\r\n new VertexBuffer(\r\n null,\r\n data,\r\n kind,\r\n false,\r\n undefined,\r\n stride,\r\n undefined,\r\n offset,\r\n undefined,\r\n undefined,\r\n applyGltfNormalizedOverride(kind, normalized),\r\n true\r\n )\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 decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<Geometry> {\r\n return this._decodeMeshAsync(scene.getEngine(), data, attributes).then((meshData) => {\r\n const geometry = new Geometry(name, scene);\r\n\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(attribute);\r\n }\r\n\r\n return geometry;\r\n });\r\n }\r\n\r\n /** @internal */\r\n public _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 return this._decodeMeshAsync(scene.getEngine(), data, attributes, gltfNormalizedOverride).then((meshData) => {\r\n const geometry = new Geometry(name, scene);\r\n\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(attribute);\r\n }\r\n\r\n return geometry;\r\n });\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 decodeMeshAsync(data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<VertexData> {\r\n return this._decodeMeshAsync(null, data, attributes).then((meshData) => {\r\n const vertexData = new VertexData();\r\n\r\n if (meshData.indices) {\r\n vertexData.indices = meshData.indices;\r\n }\r\n\r\n for (const attribute of meshData.attributes) {\r\n vertexData.set(attribute.getFloatData(meshData.totalVertices)!, attribute.getKind());\r\n }\r\n\r\n return vertexData;\r\n });\r\n }\r\n}\r\n"]}
@@ -27,9 +27,29 @@ export declare class GeometryTextureFetchBlock extends NodeGeometryBlock {
27
27
  */
28
28
  get coordinates(): NodeGeometryConnectionPoint;
29
29
  /**
30
- * Gets the color component
30
+ * Gets the rgba component
31
31
  */
32
- get color(): NodeGeometryConnectionPoint;
32
+ get rgba(): NodeGeometryConnectionPoint;
33
+ /**
34
+ * Gets the rgb component
35
+ */
36
+ get rgb(): NodeGeometryConnectionPoint;
37
+ /**
38
+ * Gets the r component
39
+ */
40
+ get r(): NodeGeometryConnectionPoint;
41
+ /**
42
+ * Gets the g component
43
+ */
44
+ get g(): NodeGeometryConnectionPoint;
45
+ /**
46
+ * Gets the b component
47
+ */
48
+ get b(): NodeGeometryConnectionPoint;
49
+ /**
50
+ * Gets the a component
51
+ */
52
+ get a(): NodeGeometryConnectionPoint;
33
53
  private _repeatClamp;
34
54
  protected _buildBlock(): void;
35
55
  protected _dumpPropertiesCode(): string;
@@ -20,7 +20,12 @@ export class GeometryTextureFetchBlock extends NodeGeometryBlock {
20
20
  this.clampCoordinates = true;
21
21
  this.registerInput("texture", NodeGeometryBlockConnectionPointTypes.Texture);
22
22
  this.registerInput("coordinates", NodeGeometryBlockConnectionPointTypes.Vector2);
23
- this.registerOutput("color", NodeGeometryBlockConnectionPointTypes.Vector4);
23
+ this.registerOutput("rgba", NodeGeometryBlockConnectionPointTypes.Vector4);
24
+ this.registerOutput("rgb", NodeGeometryBlockConnectionPointTypes.Vector3);
25
+ this.registerOutput("r", NodeGeometryBlockConnectionPointTypes.Float);
26
+ this.registerOutput("g", NodeGeometryBlockConnectionPointTypes.Float);
27
+ this.registerOutput("b", NodeGeometryBlockConnectionPointTypes.Float);
28
+ this.registerOutput("a", NodeGeometryBlockConnectionPointTypes.Float);
24
29
  }
25
30
  /**
26
31
  * Gets the current class name
@@ -42,11 +47,41 @@ export class GeometryTextureFetchBlock extends NodeGeometryBlock {
42
47
  return this.inputs[1];
43
48
  }
44
49
  /**
45
- * Gets the color component
50
+ * Gets the rgba component
46
51
  */
47
- get color() {
52
+ get rgba() {
48
53
  return this._outputs[0];
49
54
  }
55
+ /**
56
+ * Gets the rgb component
57
+ */
58
+ get rgb() {
59
+ return this._outputs[1];
60
+ }
61
+ /**
62
+ * Gets the r component
63
+ */
64
+ get r() {
65
+ return this._outputs[2];
66
+ }
67
+ /**
68
+ * Gets the g component
69
+ */
70
+ get g() {
71
+ return this._outputs[3];
72
+ }
73
+ /**
74
+ * Gets the b component
75
+ */
76
+ get b() {
77
+ return this._outputs[4];
78
+ }
79
+ /**
80
+ * Gets the a component
81
+ */
82
+ get a() {
83
+ return this._outputs[5];
84
+ }
50
85
  _repeatClamp(num) {
51
86
  if (num >= 0) {
52
87
  return num % 1;
@@ -56,7 +91,7 @@ export class GeometryTextureFetchBlock extends NodeGeometryBlock {
56
91
  }
57
92
  }
58
93
  _buildBlock() {
59
- this.color._storedFunction = (state) => {
94
+ const func = (state) => {
60
95
  const textureData = this.texture.getConnectedValue(state);
61
96
  if (!textureData || !textureData.data) {
62
97
  return null;
@@ -72,6 +107,29 @@ export class GeometryTextureFetchBlock extends NodeGeometryBlock {
72
107
  const index = x + textureData.width * y;
73
108
  return Vector4.FromArray(textureData.data, index * 4);
74
109
  };
110
+ this.rgba._storedFunction = (state) => {
111
+ return func(state);
112
+ };
113
+ this.rgb._storedFunction = (state) => {
114
+ const color = func(state);
115
+ return color.toVector3();
116
+ };
117
+ this.r._storedFunction = (state) => {
118
+ const color = func(state);
119
+ return color.x;
120
+ };
121
+ this.g._storedFunction = (state) => {
122
+ const color = func(state);
123
+ return color.y;
124
+ };
125
+ this.b._storedFunction = (state) => {
126
+ const color = func(state);
127
+ return color.z;
128
+ };
129
+ this.a._storedFunction = (state) => {
130
+ const color = func(state);
131
+ return color.w;
132
+ };
75
133
  }
76
134
  _dumpPropertiesCode() {
77
135
  const codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.clampCoordinates = ${this.clampCoordinates};\n`;
@@ -1 +1 @@
1
- {"version":3,"file":"geometryTextureFetchBlock.js","sourceRoot":"","sources":["../../../../../../../dev/core/src/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAgB,yCAA+B;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,qCAAqC,EAAE,MAAM,8CAA8C,CAAC;AAErG,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,gDAAsC;AAE/F;;GAEG;AACH,MAAM,OAAO,yBAA0B,SAAQ,iBAAiB;IAO5D;;;OAGG;IACH,YAAmB,IAAY;QAC3B,KAAK,CAAC,IAAI,CAAC,CAAC;QAXhB;;WAEG;QAEI,qBAAgB,GAAG,IAAI,CAAC;QAS3B,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,qCAAqC,CAAC,OAAO,CAAC,CAAC;QAC7E,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE,qCAAqC,CAAC,OAAO,CAAC,CAAC;QACjF,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,qCAAqC,CAAC,OAAO,CAAC,CAAC;IAChF,CAAC;IAED;;;OAGG;IACI,YAAY;QACf,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AAE,CAAC;mEAC3F;AAmGnC,aAAa,CAAC,mCAAmC,EAAE,yBAAyB,CAAC,CAAC","sourcesContent":["import { Vector4, type Vector2 } from \"core/Maths/math.vector\";\r\nimport { RegisterClass } from \"../../../../Misc/typeStore\";\r\nimport { NodeGeometryBlockConnectionPointTypes } from \"../../Enums/nodeGeometryConnectionPointTypes\";\r\nimport type { INodeGeometryTextureData } from \"../../Interfaces/nodeGeometryTextureData\";\r\nimport { NodeGeometryBlock } from \"../../nodeGeometryBlock\";\r\nimport type { NodeGeometryConnectionPoint } from \"../../nodeGeometryBlockConnectionPoint\";\r\nimport { PropertyTypeForEdition, editableInPropertyPage } from \"core/Decorators/nodeDecorator\";\r\n\r\n/**\r\n * Block used to fetch a color from texture data\r\n */\r\nexport class GeometryTextureFetchBlock extends NodeGeometryBlock {\r\n /**\r\n * Gets or sets a boolean indicating if coordinates should be clamped between 0 and 1\r\n */\r\n @editableInPropertyPage(\"Clamp Coordinates\", PropertyTypeForEdition.Boolean, \"ADVANCED\", { notifiers: { rebuild: true } })\r\n public clampCoordinates = true;\r\n\r\n /**\r\n * Creates a new GeometryTextureFetchBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name);\r\n\r\n this.registerInput(\"texture\", NodeGeometryBlockConnectionPointTypes.Texture);\r\n this.registerInput(\"coordinates\", NodeGeometryBlockConnectionPointTypes.Vector2);\r\n this.registerOutput(\"color\", NodeGeometryBlockConnectionPointTypes.Vector4);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"GeometryTextureFetchBlock\";\r\n }\r\n\r\n /**\r\n * Gets the texture component\r\n */\r\n public get texture(): NodeGeometryConnectionPoint {\r\n return this.inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the coordinates component\r\n */\r\n public get coordinates(): NodeGeometryConnectionPoint {\r\n return this.inputs[1];\r\n }\r\n\r\n /**\r\n * Gets the color component\r\n */\r\n public get color(): NodeGeometryConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n private _repeatClamp(num: number) {\r\n if (num >= 0) {\r\n return num % 1;\r\n } else {\r\n return 1 - (Math.abs(num) % 1);\r\n }\r\n }\r\n\r\n protected _buildBlock() {\r\n this.color._storedFunction = (state) => {\r\n const textureData = this.texture.getConnectedValue(state) as INodeGeometryTextureData;\r\n if (!textureData || !textureData.data) {\r\n return null;\r\n }\r\n\r\n const uv = this.coordinates.getConnectedValue(state) as Vector2;\r\n\r\n if (!uv) {\r\n return null;\r\n }\r\n\r\n const u = this.clampCoordinates ? Math.max(0, Math.min(uv.x, 1.0)) : this._repeatClamp(uv.x);\r\n const v = this.clampCoordinates ? Math.max(0, Math.min(uv.y, 1.0)) : this._repeatClamp(uv.y);\r\n\r\n const x = Math.floor(u * (textureData.width - 1));\r\n const y = Math.floor(v * (textureData.height - 1));\r\n const index = x + textureData.width * y;\r\n\r\n return Vector4.FromArray(textureData.data, index * 4);\r\n };\r\n }\r\n\r\n protected _dumpPropertiesCode() {\r\n const codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.clampCoordinates = ${this.clampCoordinates};\\n`;\r\n return codeString;\r\n }\r\n\r\n /**\r\n * Serializes this block in a JSON representation\r\n * @returns the serialized block object\r\n */\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.clampCoordinates = this.clampCoordinates;\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any) {\r\n super._deserialize(serializationObject);\r\n\r\n this.clampCoordinates = serializationObject.clampCoordinates;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.GeometryTextureFetchBlock\", GeometryTextureFetchBlock);\r\n"]}
1
+ {"version":3,"file":"geometryTextureFetchBlock.js","sourceRoot":"","sources":["../../../../../../../dev/core/src/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAgB,yCAA+B;AAC/D,OAAO,EAAE,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AAO,EAAE,IAAI,EAAE,EAAE,CAAC;mEAC3F;AAwKnC,aAAa,CAAC,mCAAmC,EAAE,yBAAyB,CAAC,CAAC","sourcesContent":["import { Vector4, type Vector2 } from \"core/Maths/math.vector\";\r\nimport { RegisterClass } from \"../../../../Misc/typeStore\";\r\nimport { NodeGeometryBlockConnectionPointTypes } from \"../../Enums/nodeGeometryConnectionPointTypes\";\r\nimport type { INodeGeometryTextureData } from \"../../Interfaces/nodeGeometryTextureData\";\r\nimport { NodeGeometryBlock } from \"../../nodeGeometryBlock\";\r\nimport type { NodeGeometryConnectionPoint } from \"../../nodeGeometryBlockConnectionPoint\";\r\nimport { PropertyTypeForEdition, editableInPropertyPage } from \"core/Decorators/nodeDecorator\";\r\nimport type { NodeGeometryBuildState } from \"../../nodeGeometryBuildState\";\r\n\r\n/**\r\n * Block used to fetch a color from texture data\r\n */\r\nexport class GeometryTextureFetchBlock extends NodeGeometryBlock {\r\n /**\r\n * Gets or sets a boolean indicating if coordinates should be clamped between 0 and 1\r\n */\r\n @editableInPropertyPage(\"Clamp Coordinates\", PropertyTypeForEdition.Boolean, \"ADVANCED\", { notifiers: { rebuild: true } })\r\n public clampCoordinates = true;\r\n\r\n /**\r\n * Creates a new GeometryTextureFetchBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name);\r\n\r\n this.registerInput(\"texture\", NodeGeometryBlockConnectionPointTypes.Texture);\r\n this.registerInput(\"coordinates\", NodeGeometryBlockConnectionPointTypes.Vector2);\r\n this.registerOutput(\"rgba\", NodeGeometryBlockConnectionPointTypes.Vector4);\r\n this.registerOutput(\"rgb\", NodeGeometryBlockConnectionPointTypes.Vector3);\r\n this.registerOutput(\"r\", NodeGeometryBlockConnectionPointTypes.Float);\r\n this.registerOutput(\"g\", NodeGeometryBlockConnectionPointTypes.Float);\r\n this.registerOutput(\"b\", NodeGeometryBlockConnectionPointTypes.Float);\r\n this.registerOutput(\"a\", NodeGeometryBlockConnectionPointTypes.Float);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"GeometryTextureFetchBlock\";\r\n }\r\n\r\n /**\r\n * Gets the texture component\r\n */\r\n public get texture(): NodeGeometryConnectionPoint {\r\n return this.inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the coordinates component\r\n */\r\n public get coordinates(): NodeGeometryConnectionPoint {\r\n return this.inputs[1];\r\n }\r\n\r\n /**\r\n * Gets the rgba component\r\n */\r\n public get rgba(): NodeGeometryConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n /**\r\n * Gets the rgb component\r\n */\r\n public get rgb(): NodeGeometryConnectionPoint {\r\n return this._outputs[1];\r\n }\r\n\r\n /**\r\n * Gets the r component\r\n */\r\n public get r(): NodeGeometryConnectionPoint {\r\n return this._outputs[2];\r\n }\r\n\r\n /**\r\n * Gets the g component\r\n */\r\n public get g(): NodeGeometryConnectionPoint {\r\n return this._outputs[3];\r\n }\r\n\r\n /**\r\n * Gets the b component\r\n */\r\n public get b(): NodeGeometryConnectionPoint {\r\n return this._outputs[4];\r\n }\r\n\r\n /**\r\n * Gets the a component\r\n */\r\n public get a(): NodeGeometryConnectionPoint {\r\n return this._outputs[5];\r\n }\r\n\r\n private _repeatClamp(num: number) {\r\n if (num >= 0) {\r\n return num % 1;\r\n } else {\r\n return 1 - (Math.abs(num) % 1);\r\n }\r\n }\r\n\r\n protected _buildBlock() {\r\n const func = (state: NodeGeometryBuildState) => {\r\n const textureData = this.texture.getConnectedValue(state) as INodeGeometryTextureData;\r\n if (!textureData || !textureData.data) {\r\n return null;\r\n }\r\n\r\n const uv = this.coordinates.getConnectedValue(state) as Vector2;\r\n\r\n if (!uv) {\r\n return null;\r\n }\r\n\r\n const u = this.clampCoordinates ? Math.max(0, Math.min(uv.x, 1.0)) : this._repeatClamp(uv.x);\r\n const v = this.clampCoordinates ? Math.max(0, Math.min(uv.y, 1.0)) : this._repeatClamp(uv.y);\r\n\r\n const x = Math.floor(u * (textureData.width - 1));\r\n const y = Math.floor(v * (textureData.height - 1));\r\n const index = x + textureData.width * y;\r\n\r\n return Vector4.FromArray(textureData.data, index * 4);\r\n };\r\n\r\n this.rgba._storedFunction = (state) => {\r\n return func(state);\r\n };\r\n\r\n this.rgb._storedFunction = (state) => {\r\n const color = func(state) as Vector4;\r\n return color.toVector3();\r\n };\r\n\r\n this.r._storedFunction = (state) => {\r\n const color = func(state) as Vector4;\r\n return color.x;\r\n };\r\n\r\n this.g._storedFunction = (state) => {\r\n const color = func(state) as Vector4;\r\n return color.y;\r\n };\r\n\r\n this.b._storedFunction = (state) => {\r\n const color = func(state) as Vector4;\r\n return color.z;\r\n };\r\n\r\n this.a._storedFunction = (state) => {\r\n const color = func(state) as Vector4;\r\n return color.w;\r\n };\r\n }\r\n\r\n protected _dumpPropertiesCode() {\r\n const codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.clampCoordinates = ${this.clampCoordinates};\\n`;\r\n return codeString;\r\n }\r\n\r\n /**\r\n * Serializes this block in a JSON representation\r\n * @returns the serialized block object\r\n */\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.clampCoordinates = this.clampCoordinates;\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any) {\r\n super._deserialize(serializationObject);\r\n\r\n this.clampCoordinates = serializationObject.clampCoordinates;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.GeometryTextureFetchBlock\", GeometryTextureFetchBlock);\r\n"]}
@@ -1,5 +1,6 @@
1
1
  import { NodeGeometryBlock } from "../nodeGeometryBlock";
2
2
  import type { NodeGeometryConnectionPoint } from "../nodeGeometryBlockConnectionPoint";
3
+ import type { NodeGeometryBuildState } from "../nodeGeometryBuildState";
3
4
  /**
4
5
  * Defines a block used to debug values going through it
5
6
  */
@@ -30,5 +31,5 @@ export declare class DebugBlock extends NodeGeometryBlock {
30
31
  * Gets the output component
31
32
  */
32
33
  get output(): NodeGeometryConnectionPoint;
33
- protected _buildBlock(): void;
34
+ protected _buildBlock(state: NodeGeometryBuildState): void;
34
35
  }
@@ -47,14 +47,14 @@ export class DebugBlock extends NodeGeometryBlock {
47
47
  get output() {
48
48
  return this._outputs[0];
49
49
  }
50
- _buildBlock() {
50
+ _buildBlock(state) {
51
51
  if (!this.input.isConnected) {
52
52
  this.output._storedFunction = null;
53
53
  this.output._storedValue = null;
54
54
  return;
55
55
  }
56
56
  this.log = [];
57
- this.output._storedFunction = (state) => {
57
+ const func = (state) => {
58
58
  const input = this.input.getConnectedValue(state);
59
59
  if (input === null || input === undefined) {
60
60
  this.log.push("null");
@@ -63,6 +63,12 @@ export class DebugBlock extends NodeGeometryBlock {
63
63
  this.log.push(input.toString());
64
64
  return input;
65
65
  };
66
+ if (this.output.isConnected) {
67
+ this.output._storedFunction = func;
68
+ }
69
+ else {
70
+ this.output._storedValue = func(state);
71
+ }
66
72
  }
67
73
  }
68
74
  RegisterClass("BABYLON.DebugBlock", DebugBlock);
@@ -1 +1 @@
1
- {"version":3,"file":"debugBlock.js","sourceRoot":"","sources":["../../../../../../dev/core/src/Meshes/Node/Blocks/debugBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,qCAAqC,EAAE,MAAM,2CAA2C,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGzD;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,iBAAiB;IAM7C;;;OAGG;IACH,YAAmB,IAAY;QAC3B,KAAK,CAAC,IAAI,CAAC,CAAC;QAVhB;;WAEG;QACI,QAAG,GAAa,EAAE,CAAC;QAStB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QAErB,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,qCAAqC,CAAC,UAAU,CAAC,CAAC;QAC9E,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,qCAAqC,CAAC,Y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CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;YAEhC,OAAO,KAAK,CAAC;QACjB,CAAC,CAAC;IACN,CAAC;CACJ;AAED,aAAa,CAAC,oBAAoB,EAAE,UAAU,CAAC,CAAC","sourcesContent":["import { RegisterClass } from \"../../../Misc/typeStore\";\r\nimport { NodeGeometryBlockConnectionPointTypes } from \"../Enums/nodeGeometryConnectionPointTypes\";\r\nimport { NodeGeometryBlock } from \"../nodeGeometryBlock\";\r\nimport type { NodeGeometryConnectionPoint } from \"../nodeGeometryBlockConnectionPoint\";\r\n\r\n/**\r\n * Defines a block used to debug values going through it\r\n */\r\nexport class DebugBlock extends NodeGeometryBlock {\r\n /**\r\n * Gets the log entries\r\n */\r\n public log: string[] = [];\r\n\r\n /**\r\n * Create a new DebugBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name);\r\n\r\n this._isDebug = true;\r\n\r\n this.registerInput(\"input\", NodeGeometryBlockConnectionPointTypes.AutoDetect);\r\n this.registerOutput(\"output\", NodeGeometryBlockConnectionPointTypes.BasedOnInput);\r\n\r\n this._outputs[0]._typeConnectionSource = this._inputs[0];\r\n this._inputs[0].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Geometry);\r\n this._inputs[0].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Texture);\r\n }\r\n\r\n /**\r\n * Gets the time spent to build this block (in ms)\r\n */\r\n public get buildExecutionTime() {\r\n return 0;\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"DebugBlock\";\r\n }\r\n\r\n /**\r\n * Gets the input component\r\n */\r\n public get input(): NodeGeometryConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the output component\r\n */\r\n public get output(): NodeGeometryConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n protected _buildBlock() {\r\n if (!this.input.isConnected) {\r\n this.output._storedFunction = null;\r\n this.output._storedValue = null;\r\n return;\r\n }\r\n\r\n this.log = [];\r\n this.output._storedFunction = (state) => {\r\n const input = this.input.getConnectedValue(state);\r\n\r\n if (input === null || input === undefined) {\r\n this.log.push(\"null\");\r\n return input;\r\n }\r\n\r\n this.log.push(input.toString());\r\n\r\n return input;\r\n };\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.DebugBlock\", DebugBlock);\r\n"]}
1
+ {"version":3,"file":"debugBlock.js","sourceRoot":"","sources":["../../../../../../dev/core/src/Meshes/Node/Blocks/debugBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,qCAAqC,EAAE,MAAM,2CAA2C,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAIzD;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,iBAAiB;IAM7C;;;OAGG;IACH,YAAmB,IAAY;QAC3B,KAAK,CAAC,IAAI,CAAC,CAAC;QAVhB;;WAEG;QACI,QAAG,GAAa,EAAE,CAAC;QAStB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QAErB,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,qCAAqC,CAAC,UAAU,CAAC,CAAC;QAC9E,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,qCAAqC,CAAC,YAAY,CAAC,CAAC;QAElF,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,qBAAqB,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACzD,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,4BAA4B,CAAC,IAAI,CAAC,qCAAqC,CAAC,QAAQ,CAAC,CAAC;QAClG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,4BAA4B,CAAC,IAAI,CAAC,qCAAqC,CAAC,OAAO,CAAC,CAAC;IACrG,CAAC;IAED;;OAEG;IACH,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"../../../Misc/typeStore\";\r\nimport { NodeGeometryBlockConnectionPointTypes } from \"../Enums/nodeGeometryConnectionPointTypes\";\r\nimport { NodeGeometryBlock } from \"../nodeGeometryBlock\";\r\nimport type { NodeGeometryConnectionPoint } from \"../nodeGeometryBlockConnectionPoint\";\r\nimport type { NodeGeometryBuildState } from \"../nodeGeometryBuildState\";\r\n\r\n/**\r\n * Defines a block used to debug values going through it\r\n */\r\nexport class DebugBlock extends NodeGeometryBlock {\r\n /**\r\n * Gets the log entries\r\n */\r\n public log: string[] = [];\r\n\r\n /**\r\n * Create a new DebugBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name);\r\n\r\n this._isDebug = true;\r\n\r\n this.registerInput(\"input\", NodeGeometryBlockConnectionPointTypes.AutoDetect);\r\n this.registerOutput(\"output\", NodeGeometryBlockConnectionPointTypes.BasedOnInput);\r\n\r\n this._outputs[0]._typeConnectionSource = this._inputs[0];\r\n this._inputs[0].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Geometry);\r\n this._inputs[0].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Texture);\r\n }\r\n\r\n /**\r\n * Gets the time spent to build this block (in ms)\r\n */\r\n public get buildExecutionTime() {\r\n return 0;\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"DebugBlock\";\r\n }\r\n\r\n /**\r\n * Gets the input component\r\n */\r\n public get input(): NodeGeometryConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the output component\r\n */\r\n public get output(): NodeGeometryConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n protected _buildBlock(state: NodeGeometryBuildState) {\r\n if (!this.input.isConnected) {\r\n this.output._storedFunction = null;\r\n this.output._storedValue = null;\r\n return;\r\n }\r\n\r\n this.log = [];\r\n const func = (state: NodeGeometryBuildState) => {\r\n const input = this.input.getConnectedValue(state);\r\n\r\n if (input === null || input === undefined) {\r\n this.log.push(\"null\");\r\n return input;\r\n }\r\n\r\n this.log.push(input.toString());\r\n\r\n return input;\r\n };\r\n\r\n if (this.output.isConnected) {\r\n this.output._storedFunction = func;\r\n } else {\r\n this.output._storedValue = func(state);\r\n }\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.DebugBlock\", DebugBlock);\r\n"]}
@@ -1,14 +1,25 @@
1
1
  import { NodeGeometryBlock } from "../nodeGeometryBlock";
2
2
  import type { NodeGeometryConnectionPoint } from "../nodeGeometryBlockConnectionPoint";
3
+ /**
4
+ * Locks supported by the random block
5
+ */
6
+ export declare enum RandomBlockLocks {
7
+ /** None */
8
+ None = 0,
9
+ /** LoopID */
10
+ LoopID = 1,
11
+ /** InstanceID */
12
+ InstanceID = 2
13
+ }
3
14
  /**
4
15
  * Block used to get a random number
5
16
  */
6
17
  export declare class RandomBlock extends NodeGeometryBlock {
7
- private _currentLoopId;
18
+ private _currentLockId;
8
19
  /**
9
- * Gets or sets a boolean indicating that this block will generate a new value only once per loop
20
+ * Gets or sets a value indicating if that block will lock its value for a specific duration
10
21
  */
11
- lockPerLoop: boolean;
22
+ lockMode: RandomBlockLocks;
12
23
  /**
13
24
  * Create a new RandomBlock
14
25
  * @param name defines the block name
@@ -6,6 +6,18 @@ import { GeometryInputBlock } from "./geometryInputBlock.js";
6
6
  import { Vector2, Vector3, Vector4 } from "../../../Maths/math.vector.js";
7
7
  import { PropertyTypeForEdition, editableInPropertyPage } from "../../../Decorators/nodeDecorator.js";
8
8
  import { NodeGeometryContextualSources } from "../Enums/nodeGeometryContextualSources.js";
9
+ /**
10
+ * Locks supported by the random block
11
+ */
12
+ export var RandomBlockLocks;
13
+ (function (RandomBlockLocks) {
14
+ /** None */
15
+ RandomBlockLocks[RandomBlockLocks["None"] = 0] = "None";
16
+ /** LoopID */
17
+ RandomBlockLocks[RandomBlockLocks["LoopID"] = 1] = "LoopID";
18
+ /** InstanceID */
19
+ RandomBlockLocks[RandomBlockLocks["InstanceID"] = 2] = "InstanceID";
20
+ })(RandomBlockLocks || (RandomBlockLocks = {}));
9
21
  /**
10
22
  * Block used to get a random number
11
23
  */
@@ -16,11 +28,11 @@ export class RandomBlock extends NodeGeometryBlock {
16
28
  */
17
29
  constructor(name) {
18
30
  super(name);
19
- this._currentLoopId = -1;
31
+ this._currentLockId = -1;
20
32
  /**
21
- * Gets or sets a boolean indicating that this block will generate a new value only once per loop
33
+ * Gets or sets a value indicating if that block will lock its value for a specific duration
22
34
  */
23
- this.lockPerLoop = false;
35
+ this.lockMode = RandomBlockLocks.None;
24
36
  this.registerInput("min", NodeGeometryBlockConnectionPointTypes.AutoDetect);
25
37
  this.registerInput("max", NodeGeometryBlockConnectionPointTypes.AutoDetect);
26
38
  this.registerOutput("output", NodeGeometryBlockConnectionPointTypes.BasedOnInput);
@@ -72,7 +84,7 @@ export class RandomBlock extends NodeGeometryBlock {
72
84
  }
73
85
  _buildBlock() {
74
86
  let func = null;
75
- this._currentLoopId = -1;
87
+ this._currentLockId = -1;
76
88
  switch (this.min.type) {
77
89
  case NodeGeometryBlockConnectionPointTypes.Int:
78
90
  case NodeGeometryBlockConnectionPointTypes.Float: {
@@ -108,14 +120,22 @@ export class RandomBlock extends NodeGeometryBlock {
108
120
  break;
109
121
  }
110
122
  }
111
- if (!this.lockPerLoop || !func) {
123
+ if (this.lockMode === RandomBlockLocks.None || !func) {
112
124
  this.output._storedFunction = func;
113
125
  }
114
126
  else {
115
127
  this.output._storedFunction = (state) => {
116
- const loopId = state.getContextualValue(NodeGeometryContextualSources.LoopID);
117
- if (this._currentLoopId !== loopId) {
118
- this._currentLoopId = loopId;
128
+ let lockId = 0;
129
+ switch (this.lockMode) {
130
+ case RandomBlockLocks.InstanceID:
131
+ lockId = state.getContextualValue(NodeGeometryContextualSources.InstanceID, true) || 0;
132
+ break;
133
+ case RandomBlockLocks.LoopID:
134
+ lockId = state.getContextualValue(NodeGeometryContextualSources.LoopID, true) || 0;
135
+ break;
136
+ }
137
+ if (this._currentLockId !== lockId) {
138
+ this._currentLockId = lockId;
119
139
  this.output._storedValue = func(state);
120
140
  }
121
141
  return this.output._storedValue;
@@ -123,7 +143,7 @@ export class RandomBlock extends NodeGeometryBlock {
123
143
  }
124
144
  }
125
145
  _dumpPropertiesCode() {
126
- const codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.lockPerLoop = ${this.lockPerLoop ? "true" : "false"};\n`;
146
+ const codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.lockMode = BABYLON.RandomBlockLocks.${RandomBlockLocks[this.lockMode]};\n`;
127
147
  return codeString;
128
148
  }
129
149
  /**
@@ -132,16 +152,23 @@ export class RandomBlock extends NodeGeometryBlock {
132
152
  */
133
153
  serialize() {
134
154
  const serializationObject = super.serialize();
135
- serializationObject.lockPerLoop = this.lockPerLoop;
155
+ serializationObject.lockMode = this.lockMode;
136
156
  return serializationObject;
137
157
  }
138
158
  _deserialize(serializationObject) {
139
159
  super._deserialize(serializationObject);
140
- this.lockPerLoop = !!serializationObject.lockPerLoop;
160
+ this.lockMode = serializationObject.lockMode;
141
161
  }
142
162
  }
143
163
  __decorate([
144
- editableInPropertyPage("Lock per loop", PropertyTypeForEdition.Boolean, "ADVANCED", { notifiers: { rebuild: true } })
145
- ], RandomBlock.prototype, "lockPerLoop", void 0);
164
+ editableInPropertyPage("LockMode", PropertyTypeForEdition.List, "ADVANCED", {
165
+ notifiers: { rebuild: true },
166
+ options: [
167
+ { label: "None", value: RandomBlockLocks.None },
168
+ { label: "LoopID", value: RandomBlockLocks.LoopID },
169
+ { label: "InstanceID", value: RandomBlockLocks.InstanceID },
170
+ ],
171
+ })
172
+ ], RandomBlock.prototype, "lockMode", void 0);
146
173
  RegisterClass("BABYLON.RandomBlock", RandomBlock);
147
174
  //# sourceMappingURL=randomBlock.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"randomBlock.js","sourceRoot":"","sources":["../../../../../../dev/core/src/Meshes/Node/Blocks/randomBlock.ts"],"names":[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AAI,CAAC,WAAW,CAAC;QAEnD,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAEM,YAAY,CAAC,mBAAwB;QACxC,KAAK,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC;QAExC,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,mBAAmB,CAAC,WAAW,CAAC;IACzD,CAAC;CACJ;AArJU;IADN,sBAAsB,CAAC,eAAe,EAAE,sBAAsB,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;gDAC3F;AAuJ/B,aAAa,CAAC,qBAAqB,EAAE,WAAW,CAAC,CAAC","sourcesContent":["import { NodeGeometryBlock } from \"../nodeGeometryBlock\";\r\nimport type { NodeGeometryConnectionPoint } from \"../nodeGeometryBlockConnectionPoint\";\r\nimport { RegisterClass } from \"../../../Misc/typeStore\";\r\nimport { NodeGeometryBlockConnectionPointTypes } from \"../Enums/nodeGeometryConnectionPointTypes\";\r\nimport type { NodeGeometryBuildState } from \"../nodeGeometryBuildState\";\r\nimport { GeometryInputBlock } from \"./geometryInputBlock\";\r\nimport { Vector2, Vector3, Vector4 } from \"../../../Maths/math.vector\";\r\nimport type { Nullable } from \"../../../types\";\r\nimport { PropertyTypeForEdition, editableInPropertyPage } from \"core/Decorators/nodeDecorator\";\r\nimport { NodeGeometryContextualSources } from \"../Enums/nodeGeometryContextualSources\";\r\n\r\n/**\r\n * Block used to get a random number\r\n */\r\nexport class RandomBlock extends NodeGeometryBlock {\r\n private _currentLoopId = -1;\r\n /**\r\n * Gets or sets a boolean indicating that this block will generate a new value only once per loop\r\n */\r\n @editableInPropertyPage(\"Lock per loop\", PropertyTypeForEdition.Boolean, \"ADVANCED\", { notifiers: { rebuild: true } })\r\n public lockPerLoop = false;\r\n\r\n /**\r\n * Create a new RandomBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name);\r\n\r\n this.registerInput(\"min\", NodeGeometryBlockConnectionPointTypes.AutoDetect);\r\n this.registerInput(\"max\", NodeGeometryBlockConnectionPointTypes.AutoDetect);\r\n\r\n this.registerOutput(\"output\", NodeGeometryBlockConnectionPointTypes.BasedOnInput);\r\n\r\n this._inputs[0].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Matrix);\r\n this._inputs[0].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Geometry);\r\n this._inputs[0].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Texture);\r\n this._inputs[1].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Matrix);\r\n this._inputs[1].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Geometry);\r\n this._inputs[1].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Texture);\r\n\r\n this._outputs[0]._typeConnectionSource = this._inputs[0];\r\n this._linkConnectionTypes(0, 1);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"RandomBlock\";\r\n }\r\n\r\n /**\r\n * Gets the min input component\r\n */\r\n public get min(): NodeGeometryConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the max input component\r\n */\r\n public get max(): NodeGeometryConnectionPoint {\r\n return this._inputs[1];\r\n }\r\n\r\n /**\r\n * Gets the geometry output component\r\n */\r\n public get output(): NodeGeometryConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n public autoConfigure() {\r\n if (!this.min.isConnected) {\r\n const minInput = new GeometryInputBlock(\"Min\");\r\n minInput.value = 0;\r\n minInput.output.connectTo(this.min);\r\n }\r\n\r\n if (!this.max.isConnected) {\r\n const maxInput = new GeometryInputBlock(\"Max\");\r\n maxInput.value = 1;\r\n maxInput.output.connectTo(this.max);\r\n }\r\n }\r\n\r\n protected _buildBlock() {\r\n let func: Nullable<(state: NodeGeometryBuildState) => any> = null;\r\n this._currentLoopId = -1;\r\n\r\n switch (this.min.type) {\r\n case NodeGeometryBlockConnectionPointTypes.Int:\r\n case NodeGeometryBlockConnectionPointTypes.Float: {\r\n func = (state) => {\r\n const min = this.min.getConnectedValue(state) || 0;\r\n const max = this.max.getConnectedValue(state) || 0;\r\n return min + Math.random() * (max - min);\r\n };\r\n break;\r\n }\r\n case NodeGeometryBlockConnectionPointTypes.Vector2: {\r\n func = (state) => {\r\n const min = this.min.getConnectedValue(state) || Vector2.Zero();\r\n const max = this.max.getConnectedValue(state) || Vector2.Zero();\r\n return new Vector2(min.x + Math.random() * (max.x - min.x), min.y + Math.random() * (max.y - min.y));\r\n };\r\n break;\r\n }\r\n case NodeGeometryBlockConnectionPointTypes.Vector3: {\r\n func = (state) => {\r\n const min = this.min.getConnectedValue(state) || Vector3.Zero();\r\n const max = this.max.getConnectedValue(state) || Vector3.Zero();\r\n return new Vector3(min.x + Math.random() * (max.x - min.x), min.y + Math.random() * (max.y - min.y), min.z + Math.random() * (max.z - min.z));\r\n };\r\n break;\r\n }\r\n case NodeGeometryBlockConnectionPointTypes.Vector4: {\r\n func = (state) => {\r\n const min = this.min.getConnectedValue(state) || Vector4.Zero();\r\n const max = this.max.getConnectedValue(state) || Vector4.Zero();\r\n return new Vector4(\r\n min.x + Math.random() * (max.x - min.x),\r\n min.y + Math.random() * (max.y - min.y),\r\n min.z + Math.random() * (max.z - min.z),\r\n min.w + Math.random() * (max.w - min.w)\r\n );\r\n };\r\n break;\r\n }\r\n }\r\n\r\n if (!this.lockPerLoop || !func) {\r\n this.output._storedFunction = func;\r\n } else {\r\n this.output._storedFunction = (state) => {\r\n const loopId = state.getContextualValue(NodeGeometryContextualSources.LoopID);\r\n if (this._currentLoopId !== loopId) {\r\n this._currentLoopId = loopId;\r\n this.output._storedValue = func!(state);\r\n }\r\n return this.output._storedValue;\r\n };\r\n }\r\n }\r\n\r\n protected _dumpPropertiesCode() {\r\n const codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.lockPerLoop = ${this.lockPerLoop ? \"true\" : \"false\"};\\n`;\r\n return codeString;\r\n }\r\n\r\n /**\r\n * Serializes this block in a JSON representation\r\n * @returns the serialized block object\r\n */\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.lockPerLoop = this.lockPerLoop;\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any) {\r\n super._deserialize(serializationObject);\r\n\r\n this.lockPerLoop = !!serializationObject.lockPerLoop;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.RandomBlock\", RandomBlock);\r\n"]}
1
+ {"version":3,"file":"randomBlock.js","sourceRoot":"","sources":["../../../../../../dev/core/src/Meshes/Node/Blocks/randomBlock.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,qCAAqC,EAAE,MAAM,2CAA2C,CAAC;AAElG,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAEvE,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,6CAAsC;AAC/F,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AAEvF;;GAEG;AACH,MAAM,CAAN,IAAY,gBAOX;AAPD,WAAY,gBAAgB;IACxB,WAAW;IACX,uDAAI,CAAA;IACJ,aAAa;IACb,2DAAM,CAAA;IACN,iBAAiB;IACjB,mEAAU,CAAA;AACd,CAAC,EAPW,gBAAgB,KAAhB,gBAAgB,QAO3B;AAED;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,iBAAiB;IAe9C;;;OAGG;IACH,YAAmB,IAAY;QAC3B,KAAK,CAAC,IAAI,CAAC,CAAC;QAnBR,mBAAc,GAAG,CAAC,CAAC,CAAC;QAC5B;;WAEG;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EAAE,UAAU,EAAE;QACzE,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;QAC5B,OAAO,EAAE;YACL,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,CAAC,IAAI,EAAE;YAC/C,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,CAAC,MAAM,EAAE;YACnD,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,gBAAgB,CAAC,UAAU,EAAE;SAC9D;KACJ,CAAC;6CACsC;AAiK5C,aAAa,CAAC,qBAAqB,EAAE,WAAW,CAAC,CAAC","sourcesContent":["import { NodeGeometryBlock } from \"../nodeGeometryBlock\";\r\nimport type { NodeGeometryConnectionPoint } from \"../nodeGeometryBlockConnectionPoint\";\r\nimport { RegisterClass } from \"../../../Misc/typeStore\";\r\nimport { NodeGeometryBlockConnectionPointTypes } from \"../Enums/nodeGeometryConnectionPointTypes\";\r\nimport type { NodeGeometryBuildState } from \"../nodeGeometryBuildState\";\r\nimport { GeometryInputBlock } from \"./geometryInputBlock\";\r\nimport { Vector2, Vector3, Vector4 } from \"../../../Maths/math.vector\";\r\nimport type { Nullable } from \"../../../types\";\r\nimport { PropertyTypeForEdition, editableInPropertyPage } from \"core/Decorators/nodeDecorator\";\r\nimport { NodeGeometryContextualSources } from \"../Enums/nodeGeometryContextualSources\";\r\n\r\n/**\r\n * Locks supported by the random block\r\n */\r\nexport enum RandomBlockLocks {\r\n /** None */\r\n None,\r\n /** LoopID */\r\n LoopID,\r\n /** InstanceID */\r\n InstanceID,\r\n}\r\n\r\n/**\r\n * Block used to get a random number\r\n */\r\nexport class RandomBlock extends NodeGeometryBlock {\r\n private _currentLockId = -1;\r\n /**\r\n * Gets or sets a value indicating if that block will lock its value for a specific duration\r\n */\r\n @editableInPropertyPage(\"LockMode\", PropertyTypeForEdition.List, \"ADVANCED\", {\r\n notifiers: { rebuild: true },\r\n options: [\r\n { label: \"None\", value: RandomBlockLocks.None },\r\n { label: \"LoopID\", value: RandomBlockLocks.LoopID },\r\n { label: \"InstanceID\", value: RandomBlockLocks.InstanceID },\r\n ],\r\n })\r\n public lockMode = RandomBlockLocks.None;\r\n\r\n /**\r\n * Create a new RandomBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name);\r\n\r\n this.registerInput(\"min\", NodeGeometryBlockConnectionPointTypes.AutoDetect);\r\n this.registerInput(\"max\", NodeGeometryBlockConnectionPointTypes.AutoDetect);\r\n\r\n this.registerOutput(\"output\", NodeGeometryBlockConnectionPointTypes.BasedOnInput);\r\n\r\n this._inputs[0].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Matrix);\r\n this._inputs[0].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Geometry);\r\n this._inputs[0].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Texture);\r\n this._inputs[1].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Matrix);\r\n this._inputs[1].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Geometry);\r\n this._inputs[1].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Texture);\r\n\r\n this._outputs[0]._typeConnectionSource = this._inputs[0];\r\n this._linkConnectionTypes(0, 1);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"RandomBlock\";\r\n }\r\n\r\n /**\r\n * Gets the min input component\r\n */\r\n public get min(): NodeGeometryConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the max input component\r\n */\r\n public get max(): NodeGeometryConnectionPoint {\r\n return this._inputs[1];\r\n }\r\n\r\n /**\r\n * Gets the geometry output component\r\n */\r\n public get output(): NodeGeometryConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n public autoConfigure() {\r\n if (!this.min.isConnected) {\r\n const minInput = new GeometryInputBlock(\"Min\");\r\n minInput.value = 0;\r\n minInput.output.connectTo(this.min);\r\n }\r\n\r\n if (!this.max.isConnected) {\r\n const maxInput = new GeometryInputBlock(\"Max\");\r\n maxInput.value = 1;\r\n maxInput.output.connectTo(this.max);\r\n }\r\n }\r\n\r\n protected _buildBlock() {\r\n let func: Nullable<(state: NodeGeometryBuildState) => any> = null;\r\n this._currentLockId = -1;\r\n\r\n switch (this.min.type) {\r\n case NodeGeometryBlockConnectionPointTypes.Int:\r\n case NodeGeometryBlockConnectionPointTypes.Float: {\r\n func = (state) => {\r\n const min = this.min.getConnectedValue(state) || 0;\r\n const max = this.max.getConnectedValue(state) || 0;\r\n return min + Math.random() * (max - min);\r\n };\r\n break;\r\n }\r\n case NodeGeometryBlockConnectionPointTypes.Vector2: {\r\n func = (state) => {\r\n const min = this.min.getConnectedValue(state) || Vector2.Zero();\r\n const max = this.max.getConnectedValue(state) || Vector2.Zero();\r\n return new Vector2(min.x + Math.random() * (max.x - min.x), min.y + Math.random() * (max.y - min.y));\r\n };\r\n break;\r\n }\r\n case NodeGeometryBlockConnectionPointTypes.Vector3: {\r\n func = (state) => {\r\n const min = this.min.getConnectedValue(state) || Vector3.Zero();\r\n const max = this.max.getConnectedValue(state) || Vector3.Zero();\r\n return new Vector3(min.x + Math.random() * (max.x - min.x), min.y + Math.random() * (max.y - min.y), min.z + Math.random() * (max.z - min.z));\r\n };\r\n break;\r\n }\r\n case NodeGeometryBlockConnectionPointTypes.Vector4: {\r\n func = (state) => {\r\n const min = this.min.getConnectedValue(state) || Vector4.Zero();\r\n const max = this.max.getConnectedValue(state) || Vector4.Zero();\r\n return new Vector4(\r\n min.x + Math.random() * (max.x - min.x),\r\n min.y + Math.random() * (max.y - min.y),\r\n min.z + Math.random() * (max.z - min.z),\r\n min.w + Math.random() * (max.w - min.w)\r\n );\r\n };\r\n break;\r\n }\r\n }\r\n\r\n if (this.lockMode === RandomBlockLocks.None || !func) {\r\n this.output._storedFunction = func;\r\n } else {\r\n this.output._storedFunction = (state) => {\r\n let lockId = 0;\r\n\r\n switch (this.lockMode) {\r\n case RandomBlockLocks.InstanceID:\r\n lockId = state.getContextualValue(NodeGeometryContextualSources.InstanceID, true) || 0;\r\n break;\r\n case RandomBlockLocks.LoopID:\r\n lockId = state.getContextualValue(NodeGeometryContextualSources.LoopID, true) || 0;\r\n break;\r\n }\r\n\r\n if (this._currentLockId !== lockId) {\r\n this._currentLockId = lockId;\r\n this.output._storedValue = func!(state);\r\n }\r\n return this.output._storedValue;\r\n };\r\n }\r\n }\r\n\r\n protected _dumpPropertiesCode() {\r\n const codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.lockMode = BABYLON.RandomBlockLocks.${RandomBlockLocks[this.lockMode]};\\n`;\r\n return codeString;\r\n }\r\n\r\n /**\r\n * Serializes this block in a JSON representation\r\n * @returns the serialized block object\r\n */\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.lockMode = this.lockMode;\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any) {\r\n super._deserialize(serializationObject);\r\n\r\n this.lockMode = serializationObject.lockMode;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.RandomBlock\", RandomBlock);\r\n"]}