@react-three/drei 11.0.0-alpha.1 → 11.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/core/index.d.mts +1858 -0
  2. package/core/index.d.ts +1858 -0
  3. package/core/index.mjs +8559 -0
  4. package/experimental/index.d.mts +222 -0
  5. package/experimental/index.d.ts +222 -0
  6. package/experimental/index.mjs +353 -0
  7. package/external/index.d.mts +464 -0
  8. package/external/index.d.ts +464 -0
  9. package/external/index.mjs +5079 -0
  10. package/index.d.mts +1746 -2147
  11. package/index.d.ts +2166 -0
  12. package/index.mjs +12940 -19766
  13. package/legacy/index.d.mts +2350 -0
  14. package/legacy/index.d.ts +2350 -0
  15. package/legacy/index.mjs +12326 -0
  16. package/native/index.d.mts +2515 -0
  17. package/native/index.d.ts +2515 -0
  18. package/native/index.mjs +12383 -0
  19. package/package.json +18 -15
  20. package/webgpu/index.d.mts +2514 -0
  21. package/webgpu/index.d.ts +2514 -0
  22. package/webgpu/index.mjs +12547 -0
  23. package/_chunks/hls.mjs +0 -3
  24. package/_chunks/libs/@mediapipe/tasks-vision.mjs +0 -4781
  25. package/_chunks/libs/@monogrid/gainmap-js.mjs +0 -1137
  26. package/_chunks/libs/@use-gesture/core.mjs +0 -1650
  27. package/_chunks/libs/@use-gesture/react.mjs +0 -207
  28. package/_chunks/libs/camera-controls.mjs +0 -2207
  29. package/_chunks/libs/detect-gpu.mjs +0 -515
  30. package/_chunks/libs/hls.js.mjs +0 -21925
  31. package/_chunks/libs/maath.mjs +0 -5200
  32. package/_chunks/libs/stats-gl.mjs +0 -301
  33. package/_chunks/libs/stats.js.mjs +0 -90
  34. package/_chunks/libs/suspend-react.mjs +0 -60
  35. package/_chunks/libs/three.mjs +0 -23169
  36. package/_chunks/libs/tunnel-rat.mjs +0 -458
  37. package/_chunks/libs/zustand.mjs +0 -104
  38. package/_chunks/rolldown-runtime.mjs +0 -47
  39. package/_chunks/vision_bundle.mjs +0 -3
  40. package/core/_chunks/hls.mjs +0 -3
  41. package/core/_chunks/libs/@monogrid/gainmap-js.mjs +0 -1137
  42. package/core/_chunks/libs/@use-gesture/core.mjs +0 -1650
  43. package/core/_chunks/libs/@use-gesture/react.mjs +0 -207
  44. package/core/_chunks/libs/detect-gpu.mjs +0 -515
  45. package/core/_chunks/libs/hls.js.mjs +0 -21925
  46. package/core/_chunks/libs/maath.mjs +0 -5200
  47. package/core/_chunks/libs/stats-gl.mjs +0 -301
  48. package/core/_chunks/libs/stats.js.mjs +0 -90
  49. package/core/_chunks/libs/suspend-react.mjs +0 -60
  50. package/core/_chunks/libs/three.mjs +0 -22457
  51. package/core/_chunks/libs/tunnel-rat.mjs +0 -458
  52. package/core/_chunks/libs/zustand.mjs +0 -104
  53. package/core/_chunks/rolldown-runtime.mjs +0 -47
  54. package/core/core/index.d.mts +0 -2232
  55. package/core/core/index.mjs +0 -11082
  56. package/experimental/_chunks/libs/three.mjs +0 -15386
  57. package/experimental/experimental/index.d.mts +0 -253
  58. package/experimental/experimental/index.mjs +0 -434
  59. package/external/_chunks/hls.mjs +0 -3
  60. package/external/_chunks/libs/@mediapipe/tasks-vision.mjs +0 -4781
  61. package/external/_chunks/libs/camera-controls.mjs +0 -2207
  62. package/external/_chunks/libs/hls.js.mjs +0 -21925
  63. package/external/_chunks/libs/maath.mjs +0 -5200
  64. package/external/_chunks/libs/suspend-react.mjs +0 -58
  65. package/external/_chunks/libs/three.mjs +0 -15387
  66. package/external/_chunks/rolldown-runtime.mjs +0 -32
  67. package/external/_chunks/vision_bundle.mjs +0 -3
  68. package/external/external/index.d.mts +0 -499
  69. package/external/external/index.mjs +0 -9422
  70. package/legacy/_chunks/hls.mjs +0 -3
  71. package/legacy/_chunks/libs/@monogrid/gainmap-js.mjs +0 -1137
  72. package/legacy/_chunks/libs/@use-gesture/core.mjs +0 -1650
  73. package/legacy/_chunks/libs/@use-gesture/react.mjs +0 -207
  74. package/legacy/_chunks/libs/bidi-js.mjs +0 -675
  75. package/legacy/_chunks/libs/detect-gpu.mjs +0 -515
  76. package/legacy/_chunks/libs/hls.js.mjs +0 -21925
  77. package/legacy/_chunks/libs/maath.mjs +0 -5200
  78. package/legacy/_chunks/libs/stats-gl.mjs +0 -301
  79. package/legacy/_chunks/libs/stats.js.mjs +0 -90
  80. package/legacy/_chunks/libs/suspend-react.mjs +0 -60
  81. package/legacy/_chunks/libs/three.mjs +0 -26062
  82. package/legacy/_chunks/libs/troika-three-text.mjs +0 -6494
  83. package/legacy/_chunks/libs/tunnel-rat.mjs +0 -458
  84. package/legacy/_chunks/libs/zustand.mjs +0 -104
  85. package/legacy/_chunks/rolldown-runtime.mjs +0 -47
  86. package/legacy/legacy/index.d.mts +0 -2788
  87. package/legacy/legacy/index.mjs +0 -14984
  88. package/native/_chunks/hls.mjs +0 -3
  89. package/native/_chunks/libs/@monogrid/gainmap-js.mjs +0 -1137
  90. package/native/_chunks/libs/@use-gesture/core.mjs +0 -1650
  91. package/native/_chunks/libs/@use-gesture/react.mjs +0 -207
  92. package/native/_chunks/libs/detect-gpu.mjs +0 -515
  93. package/native/_chunks/libs/hls.js.mjs +0 -21925
  94. package/native/_chunks/libs/maath.mjs +0 -5200
  95. package/native/_chunks/libs/stats-gl.mjs +0 -301
  96. package/native/_chunks/libs/stats.js.mjs +0 -90
  97. package/native/_chunks/libs/suspend-react.mjs +0 -60
  98. package/native/_chunks/libs/three.mjs +0 -22592
  99. package/native/_chunks/libs/tunnel-rat.mjs +0 -458
  100. package/native/_chunks/libs/zustand.mjs +0 -104
  101. package/native/_chunks/rolldown-runtime.mjs +0 -47
  102. package/native/native/index.d.mts +0 -3168
  103. package/native/native/index.mjs +0 -14863
  104. package/webgpu/_chunks/hls.mjs +0 -3
  105. package/webgpu/_chunks/libs/@monogrid/gainmap-js.mjs +0 -1137
  106. package/webgpu/_chunks/libs/@use-gesture/core.mjs +0 -1650
  107. package/webgpu/_chunks/libs/@use-gesture/react.mjs +0 -207
  108. package/webgpu/_chunks/libs/detect-gpu.mjs +0 -515
  109. package/webgpu/_chunks/libs/hls.js.mjs +0 -21925
  110. package/webgpu/_chunks/libs/maath.mjs +0 -5200
  111. package/webgpu/_chunks/libs/stats-gl.mjs +0 -301
  112. package/webgpu/_chunks/libs/stats.js.mjs +0 -90
  113. package/webgpu/_chunks/libs/suspend-react.mjs +0 -60
  114. package/webgpu/_chunks/libs/three.mjs +0 -22592
  115. package/webgpu/_chunks/libs/tunnel-rat.mjs +0 -458
  116. package/webgpu/_chunks/libs/zustand.mjs +0 -104
  117. package/webgpu/_chunks/rolldown-runtime.mjs +0 -47
  118. package/webgpu/webgpu/index.d.mts +0 -3166
  119. package/webgpu/webgpu/index.mjs +0 -15015
@@ -1,1137 +0,0 @@
1
- import { ByteType, ClampToEdgeWrapping, DataTexture, FileLoader, FloatType, HalfFloatType, IntType, LinearFilter, LinearMipMapLinearFilter, LinearSRGBColorSpace, Loader, LoadingManager, Mesh, MeshBasicMaterial, NoBlending, OrthographicCamera, PlaneGeometry, RGBAFormat, SRGBColorSpace, Scene, ShaderMaterial, ShortType, Texture, UVMapping, UnsignedByteType, UnsignedIntType, Vector3, WebGLRenderTarget, WebGLRenderer } from "three";
2
-
3
- //#region node_modules/@monogrid/gainmap-js/dist/QuadRenderer-B3h-sJtp.js
4
- /**
5
- * @monogrid/gainmap-js v3.0.6
6
- * With ❤️, by MONOGRID <rnd@monogrid.com>
7
- */
8
- const getBufferForType = (type, width, height) => {
9
- let out;
10
- switch (type) {
11
- case UnsignedByteType:
12
- out = new Uint8ClampedArray(width * height * 4);
13
- break;
14
- case HalfFloatType:
15
- out = new Uint16Array(width * height * 4);
16
- break;
17
- case UnsignedIntType:
18
- out = new Uint32Array(width * height * 4);
19
- break;
20
- case ByteType:
21
- out = new Int8Array(width * height * 4);
22
- break;
23
- case ShortType:
24
- out = new Int16Array(width * height * 4);
25
- break;
26
- case IntType:
27
- out = new Int32Array(width * height * 4);
28
- break;
29
- case FloatType:
30
- out = new Float32Array(width * height * 4);
31
- break;
32
- default: throw new Error("Unsupported data type");
33
- }
34
- return out;
35
- };
36
- let _canReadPixelsResult;
37
- /**
38
- * Test if this browser implementation can correctly read pixels from the specified
39
- * Render target type.
40
- *
41
- * Runs only once
42
- *
43
- * @param type
44
- * @param renderer
45
- * @param camera
46
- * @param renderTargetOptions
47
- * @returns
48
- */
49
- const canReadPixels = (type, renderer, camera, renderTargetOptions) => {
50
- if (_canReadPixelsResult !== void 0) return _canReadPixelsResult;
51
- const testRT = new WebGLRenderTarget(1, 1, renderTargetOptions);
52
- renderer.setRenderTarget(testRT);
53
- const mesh = new Mesh(new PlaneGeometry(), new MeshBasicMaterial({ color: 16777215 }));
54
- renderer.render(mesh, camera);
55
- renderer.setRenderTarget(null);
56
- const out = getBufferForType(type, testRT.width, testRT.height);
57
- renderer.readRenderTargetPixels(testRT, 0, 0, testRT.width, testRT.height, out);
58
- testRT.dispose();
59
- mesh.geometry.dispose();
60
- mesh.material.dispose();
61
- _canReadPixelsResult = out[0] !== 0;
62
- return _canReadPixelsResult;
63
- };
64
- /**
65
- * Utility class used for rendering a texture with a material
66
- *
67
- * @category Core
68
- * @group Core
69
- */
70
- var QuadRenderer = class QuadRenderer {
71
- /**
72
- * Constructs a new QuadRenderer
73
- *
74
- * @param options Parameters for this QuadRenderer
75
- */
76
- constructor(options) {
77
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
78
- this._rendererIsDisposable = false;
79
- this._supportsReadPixels = true;
80
- /**
81
- * Renders the input texture using the specified material
82
- */
83
- this.render = () => {
84
- this._renderer.setRenderTarget(this._renderTarget);
85
- try {
86
- this._renderer.render(this._scene, this._camera);
87
- } catch (e) {
88
- this._renderer.setRenderTarget(null);
89
- throw e;
90
- }
91
- this._renderer.setRenderTarget(null);
92
- };
93
- this._width = options.width;
94
- this._height = options.height;
95
- this._type = options.type;
96
- this._colorSpace = options.colorSpace;
97
- const rtOptions = {
98
- format: RGBAFormat,
99
- depthBuffer: false,
100
- stencilBuffer: false,
101
- type: this._type,
102
- colorSpace: this._colorSpace,
103
- anisotropy: ((_a = options.renderTargetOptions) === null || _a === void 0 ? void 0 : _a.anisotropy) !== void 0 ? (_b = options.renderTargetOptions) === null || _b === void 0 ? void 0 : _b.anisotropy : 1,
104
- generateMipmaps: ((_c = options.renderTargetOptions) === null || _c === void 0 ? void 0 : _c.generateMipmaps) !== void 0 ? (_d = options.renderTargetOptions) === null || _d === void 0 ? void 0 : _d.generateMipmaps : false,
105
- magFilter: ((_e = options.renderTargetOptions) === null || _e === void 0 ? void 0 : _e.magFilter) !== void 0 ? (_f = options.renderTargetOptions) === null || _f === void 0 ? void 0 : _f.magFilter : LinearFilter,
106
- minFilter: ((_g = options.renderTargetOptions) === null || _g === void 0 ? void 0 : _g.minFilter) !== void 0 ? (_h = options.renderTargetOptions) === null || _h === void 0 ? void 0 : _h.minFilter : LinearFilter,
107
- samples: ((_j = options.renderTargetOptions) === null || _j === void 0 ? void 0 : _j.samples) !== void 0 ? (_k = options.renderTargetOptions) === null || _k === void 0 ? void 0 : _k.samples : void 0,
108
- wrapS: ((_l = options.renderTargetOptions) === null || _l === void 0 ? void 0 : _l.wrapS) !== void 0 ? (_m = options.renderTargetOptions) === null || _m === void 0 ? void 0 : _m.wrapS : ClampToEdgeWrapping,
109
- wrapT: ((_o = options.renderTargetOptions) === null || _o === void 0 ? void 0 : _o.wrapT) !== void 0 ? (_p = options.renderTargetOptions) === null || _p === void 0 ? void 0 : _p.wrapT : ClampToEdgeWrapping
110
- };
111
- this._material = options.material;
112
- if (options.renderer) this._renderer = options.renderer;
113
- else {
114
- this._renderer = QuadRenderer.instantiateRenderer();
115
- this._rendererIsDisposable = true;
116
- }
117
- this._scene = new Scene();
118
- this._camera = new OrthographicCamera();
119
- this._camera.position.set(0, 0, 10);
120
- this._camera.left = -.5;
121
- this._camera.right = .5;
122
- this._camera.top = .5;
123
- this._camera.bottom = -.5;
124
- this._camera.updateProjectionMatrix();
125
- if (!canReadPixels(this._type, this._renderer, this._camera, rtOptions)) {
126
- let alternativeType;
127
- switch (this._type) {
128
- case HalfFloatType:
129
- alternativeType = this._renderer.extensions.has("EXT_color_buffer_float") ? FloatType : void 0;
130
- break;
131
- }
132
- if (alternativeType !== void 0) {
133
- console.warn(`This browser does not support reading pixels from ${this._type} RenderTargets, switching to ${FloatType}`);
134
- this._type = alternativeType;
135
- } else {
136
- this._supportsReadPixels = false;
137
- console.warn("This browser dos not support toArray or toDataTexture, calls to those methods will result in an error thrown");
138
- }
139
- }
140
- this._quad = new Mesh(new PlaneGeometry(), this._material);
141
- this._quad.geometry.computeBoundingBox();
142
- this._scene.add(this._quad);
143
- this._renderTarget = new WebGLRenderTarget(this.width, this.height, rtOptions);
144
- this._renderTarget.texture.mapping = ((_q = options.renderTargetOptions) === null || _q === void 0 ? void 0 : _q.mapping) !== void 0 ? (_r = options.renderTargetOptions) === null || _r === void 0 ? void 0 : _r.mapping : UVMapping;
145
- }
146
- /**
147
- * Instantiates a temporary renderer
148
- *
149
- * @returns
150
- */
151
- static instantiateRenderer() {
152
- const renderer = new WebGLRenderer();
153
- renderer.setSize(128, 128);
154
- return renderer;
155
- }
156
- /**
157
- * Obtains a Buffer containing the rendered texture.
158
- *
159
- * @throws Error if the browser cannot read pixels from this RenderTarget type.
160
- * @returns a TypedArray containing RGBA values from this renderer
161
- */
162
- toArray() {
163
- if (!this._supportsReadPixels) throw new Error("Can't read pixels in this browser");
164
- const out = getBufferForType(this._type, this._width, this._height);
165
- this._renderer.readRenderTargetPixels(this._renderTarget, 0, 0, this._width, this._height, out);
166
- return out;
167
- }
168
- /**
169
- * Performs a readPixel operation in the renderTarget
170
- * and returns a DataTexture containing the read data
171
- *
172
- * @param options options
173
- * @returns
174
- */
175
- toDataTexture(options) {
176
- const returnValue = new DataTexture(this.toArray(), this.width, this.height, RGBAFormat, this._type, (options === null || options === void 0 ? void 0 : options.mapping) || UVMapping, (options === null || options === void 0 ? void 0 : options.wrapS) || ClampToEdgeWrapping, (options === null || options === void 0 ? void 0 : options.wrapT) || ClampToEdgeWrapping, (options === null || options === void 0 ? void 0 : options.magFilter) || LinearFilter, (options === null || options === void 0 ? void 0 : options.minFilter) || LinearFilter, (options === null || options === void 0 ? void 0 : options.anisotropy) || 1, LinearSRGBColorSpace);
177
- returnValue.generateMipmaps = (options === null || options === void 0 ? void 0 : options.generateMipmaps) !== void 0 ? options === null || options === void 0 ? void 0 : options.generateMipmaps : false;
178
- return returnValue;
179
- }
180
- /**
181
- * If using a disposable renderer, it will dispose it.
182
- */
183
- disposeOnDemandRenderer() {
184
- this._renderer.setRenderTarget(null);
185
- if (this._rendererIsDisposable) {
186
- this._renderer.dispose();
187
- this._renderer.forceContextLoss();
188
- }
189
- }
190
- /**
191
- * Will dispose of **all** assets used by this renderer.
192
- *
193
- *
194
- * @param disposeRenderTarget will dispose of the renderTarget which will not be usable later
195
- * set this to true if you passed the `renderTarget.texture` to a `PMREMGenerator`
196
- * or are otherwise done with it.
197
- *
198
- * @example
199
- * ```js
200
- * const loader = new HDRJPGLoader(renderer)
201
- * const result = await loader.loadAsync('gainmap.jpeg')
202
- * const mesh = new Mesh(geometry, new MeshBasicMaterial({ map: result.renderTarget.texture }) )
203
- * // DO NOT dispose the renderTarget here,
204
- * // it is used directly in the material
205
- * result.dispose()
206
- * ```
207
- *
208
- * @example
209
- * ```js
210
- * const loader = new HDRJPGLoader(renderer)
211
- * const pmremGenerator = new PMREMGenerator( renderer );
212
- * const result = await loader.loadAsync('gainmap.jpeg')
213
- * const envMap = pmremGenerator.fromEquirectangular(result.renderTarget.texture)
214
- * const mesh = new Mesh(geometry, new MeshStandardMaterial({ envMap }) )
215
- * // renderTarget can be disposed here
216
- * // because it was used to generate a PMREM texture
217
- * result.dispose(true)
218
- * ```
219
- */
220
- dispose(disposeRenderTarget) {
221
- this.disposeOnDemandRenderer();
222
- if (disposeRenderTarget) this.renderTarget.dispose();
223
- if (this.material instanceof ShaderMaterial) Object.values(this.material.uniforms).forEach((v) => {
224
- if (v.value instanceof Texture) v.value.dispose();
225
- });
226
- Object.values(this.material).forEach((value) => {
227
- if (value instanceof Texture) value.dispose();
228
- });
229
- this.material.dispose();
230
- this._quad.geometry.dispose();
231
- }
232
- /**
233
- * Width of the texture
234
- */
235
- get width() {
236
- return this._width;
237
- }
238
- set width(value) {
239
- this._width = value;
240
- this._renderTarget.setSize(this._width, this._height);
241
- }
242
- /**
243
- * Height of the texture
244
- */
245
- get height() {
246
- return this._height;
247
- }
248
- set height(value) {
249
- this._height = value;
250
- this._renderTarget.setSize(this._width, this._height);
251
- }
252
- /**
253
- * The renderer used
254
- */
255
- get renderer() {
256
- return this._renderer;
257
- }
258
- /**
259
- * The `WebGLRenderTarget` used.
260
- */
261
- get renderTarget() {
262
- return this._renderTarget;
263
- }
264
- set renderTarget(value) {
265
- this._renderTarget = value;
266
- this._width = value.width;
267
- this._height = value.height;
268
- }
269
- /**
270
- * The `Material` used.
271
- */
272
- get material() {
273
- return this._material;
274
- }
275
- /**
276
- *
277
- */
278
- get type() {
279
- return this._type;
280
- }
281
- get colorSpace() {
282
- return this._colorSpace;
283
- }
284
- };
285
-
286
- //#endregion
287
- //#region node_modules/@monogrid/gainmap-js/dist/decode.js
288
- /**
289
- * @monogrid/gainmap-js v3.0.6
290
- * With ❤️, by MONOGRID <rnd@monogrid.com>
291
- */
292
- const vertexShader = `
293
- varying vec2 vUv;
294
-
295
- void main() {
296
- vUv = uv;
297
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
298
- }
299
- `;
300
- const fragmentShader = `
301
- // min half float value
302
- #define HALF_FLOAT_MIN vec3( -65504, -65504, -65504 )
303
- // max half float value
304
- #define HALF_FLOAT_MAX vec3( 65504, 65504, 65504 )
305
-
306
- uniform sampler2D sdr;
307
- uniform sampler2D gainMap;
308
- uniform vec3 gamma;
309
- uniform vec3 offsetHdr;
310
- uniform vec3 offsetSdr;
311
- uniform vec3 gainMapMin;
312
- uniform vec3 gainMapMax;
313
- uniform float weightFactor;
314
-
315
- varying vec2 vUv;
316
-
317
- void main() {
318
- vec3 rgb = texture2D( sdr, vUv ).rgb;
319
- vec3 recovery = texture2D( gainMap, vUv ).rgb;
320
- vec3 logRecovery = pow( recovery, gamma );
321
- vec3 logBoost = gainMapMin * ( 1.0 - logRecovery ) + gainMapMax * logRecovery;
322
- vec3 hdrColor = (rgb + offsetSdr) * exp2( logBoost * weightFactor ) - offsetHdr;
323
- vec3 clampedHdrColor = max( HALF_FLOAT_MIN, min( HALF_FLOAT_MAX, hdrColor ));
324
- gl_FragColor = vec4( clampedHdrColor , 1.0 );
325
- }
326
- `;
327
- /**
328
- * A Material which is able to decode the Gainmap into a full HDR Representation
329
- *
330
- * @category Materials
331
- * @group Materials
332
- */
333
- var GainMapDecoderMaterial = class extends ShaderMaterial {
334
- /**
335
- *
336
- * @param params
337
- */
338
- constructor({ gamma, offsetHdr, offsetSdr, gainMapMin, gainMapMax, maxDisplayBoost, hdrCapacityMin, hdrCapacityMax, sdr, gainMap }) {
339
- super({
340
- name: "GainMapDecoderMaterial",
341
- vertexShader,
342
- fragmentShader,
343
- uniforms: {
344
- sdr: { value: sdr },
345
- gainMap: { value: gainMap },
346
- gamma: { value: new Vector3(1 / gamma[0], 1 / gamma[1], 1 / gamma[2]) },
347
- offsetHdr: { value: new Vector3().fromArray(offsetHdr) },
348
- offsetSdr: { value: new Vector3().fromArray(offsetSdr) },
349
- gainMapMin: { value: new Vector3().fromArray(gainMapMin) },
350
- gainMapMax: { value: new Vector3().fromArray(gainMapMax) },
351
- weightFactor: { value: (Math.log2(maxDisplayBoost) - hdrCapacityMin) / (hdrCapacityMax - hdrCapacityMin) }
352
- },
353
- blending: NoBlending,
354
- depthTest: false,
355
- depthWrite: false
356
- });
357
- this._maxDisplayBoost = maxDisplayBoost;
358
- this._hdrCapacityMin = hdrCapacityMin;
359
- this._hdrCapacityMax = hdrCapacityMax;
360
- this.needsUpdate = true;
361
- this.uniformsNeedUpdate = true;
362
- }
363
- get sdr() {
364
- return this.uniforms.sdr.value;
365
- }
366
- set sdr(value) {
367
- this.uniforms.sdr.value = value;
368
- }
369
- get gainMap() {
370
- return this.uniforms.gainMap.value;
371
- }
372
- set gainMap(value) {
373
- this.uniforms.gainMap.value = value;
374
- }
375
- /**
376
- * @see {@link GainMapMetadata.offsetHdr}
377
- */
378
- get offsetHdr() {
379
- return this.uniforms.offsetHdr.value.toArray();
380
- }
381
- set offsetHdr(value) {
382
- this.uniforms.offsetHdr.value.fromArray(value);
383
- }
384
- /**
385
- * @see {@link GainMapMetadata.offsetSdr}
386
- */
387
- get offsetSdr() {
388
- return this.uniforms.offsetSdr.value.toArray();
389
- }
390
- set offsetSdr(value) {
391
- this.uniforms.offsetSdr.value.fromArray(value);
392
- }
393
- /**
394
- * @see {@link GainMapMetadata.gainMapMin}
395
- */
396
- get gainMapMin() {
397
- return this.uniforms.gainMapMin.value.toArray();
398
- }
399
- set gainMapMin(value) {
400
- this.uniforms.gainMapMin.value.fromArray(value);
401
- }
402
- /**
403
- * @see {@link GainMapMetadata.gainMapMax}
404
- */
405
- get gainMapMax() {
406
- return this.uniforms.gainMapMax.value.toArray();
407
- }
408
- set gainMapMax(value) {
409
- this.uniforms.gainMapMax.value.fromArray(value);
410
- }
411
- /**
412
- * @see {@link GainMapMetadata.gamma}
413
- */
414
- get gamma() {
415
- const g = this.uniforms.gamma.value;
416
- return [
417
- 1 / g.x,
418
- 1 / g.y,
419
- 1 / g.z
420
- ];
421
- }
422
- set gamma(value) {
423
- const g = this.uniforms.gamma.value;
424
- g.x = 1 / value[0];
425
- g.y = 1 / value[1];
426
- g.z = 1 / value[2];
427
- }
428
- /**
429
- * @see {@link GainMapMetadata.hdrCapacityMin}
430
- * @remarks Logarithmic space
431
- */
432
- get hdrCapacityMin() {
433
- return this._hdrCapacityMin;
434
- }
435
- set hdrCapacityMin(value) {
436
- this._hdrCapacityMin = value;
437
- this.calculateWeight();
438
- }
439
- /**
440
- * @see {@link GainMapMetadata.hdrCapacityMin}
441
- * @remarks Logarithmic space
442
- */
443
- get hdrCapacityMax() {
444
- return this._hdrCapacityMax;
445
- }
446
- set hdrCapacityMax(value) {
447
- this._hdrCapacityMax = value;
448
- this.calculateWeight();
449
- }
450
- /**
451
- * @see {@link GainmapDecodingParameters.maxDisplayBoost}
452
- * @remarks Non Logarithmic space
453
- */
454
- get maxDisplayBoost() {
455
- return this._maxDisplayBoost;
456
- }
457
- set maxDisplayBoost(value) {
458
- this._maxDisplayBoost = Math.max(1, Math.min(65504, value));
459
- this.calculateWeight();
460
- }
461
- calculateWeight() {
462
- const val = (Math.log2(this._maxDisplayBoost) - this._hdrCapacityMin) / (this._hdrCapacityMax - this._hdrCapacityMin);
463
- this.uniforms.weightFactor.value = Math.max(0, Math.min(1, val));
464
- }
465
- };
466
- var GainMapNotFoundError = class extends Error {};
467
- var XMPMetadataNotFoundError = class extends Error {};
468
- const getAttribute = (description, name, defaultValue) => {
469
- var _a;
470
- let returnValue;
471
- const parsedValue = (_a = description.attributes.getNamedItem(name)) === null || _a === void 0 ? void 0 : _a.nodeValue;
472
- if (!parsedValue) {
473
- const node = description.getElementsByTagName(name)[0];
474
- if (node) {
475
- const values = node.getElementsByTagName("rdf:li");
476
- if (values.length === 3) returnValue = Array.from(values).map((v) => v.innerHTML);
477
- else throw new Error(`Gainmap metadata contains an array of items for ${name} but its length is not 3`);
478
- } else if (defaultValue) return defaultValue;
479
- else throw new Error(`Can't find ${name} in gainmap metadata`);
480
- } else returnValue = parsedValue;
481
- return returnValue;
482
- };
483
- /**
484
- *
485
- * @param input
486
- * @returns
487
- */
488
- const extractXMP = (input) => {
489
- var _a, _b;
490
- let str;
491
- if (typeof TextDecoder !== "undefined") str = new TextDecoder().decode(input);
492
- else str = input.toString();
493
- let start = str.indexOf("<x:xmpmeta");
494
- const parser = new DOMParser();
495
- while (start !== -1) {
496
- const end = str.indexOf("x:xmpmeta>", start);
497
- str.slice(start, end + 10);
498
- const xmpBlock = str.slice(start, end + 10);
499
- try {
500
- const description = parser.parseFromString(xmpBlock, "text/xml").getElementsByTagName("rdf:Description")[0];
501
- const gainMapMin = getAttribute(description, "hdrgm:GainMapMin", "0");
502
- const gainMapMax = getAttribute(description, "hdrgm:GainMapMax");
503
- const gamma = getAttribute(description, "hdrgm:Gamma", "1");
504
- const offsetSDR = getAttribute(description, "hdrgm:OffsetSDR", "0.015625");
505
- const offsetHDR = getAttribute(description, "hdrgm:OffsetHDR", "0.015625");
506
- let hdrCapacityMin = (_a = description.attributes.getNamedItem("hdrgm:HDRCapacityMin")) === null || _a === void 0 ? void 0 : _a.nodeValue;
507
- if (!hdrCapacityMin) hdrCapacityMin = "0";
508
- const hdrCapacityMax = (_b = description.attributes.getNamedItem("hdrgm:HDRCapacityMax")) === null || _b === void 0 ? void 0 : _b.nodeValue;
509
- if (!hdrCapacityMax) throw new Error("Incomplete gainmap metadata");
510
- return {
511
- gainMapMin: Array.isArray(gainMapMin) ? gainMapMin.map((v) => parseFloat(v)) : [
512
- parseFloat(gainMapMin),
513
- parseFloat(gainMapMin),
514
- parseFloat(gainMapMin)
515
- ],
516
- gainMapMax: Array.isArray(gainMapMax) ? gainMapMax.map((v) => parseFloat(v)) : [
517
- parseFloat(gainMapMax),
518
- parseFloat(gainMapMax),
519
- parseFloat(gainMapMax)
520
- ],
521
- gamma: Array.isArray(gamma) ? gamma.map((v) => parseFloat(v)) : [
522
- parseFloat(gamma),
523
- parseFloat(gamma),
524
- parseFloat(gamma)
525
- ],
526
- offsetSdr: Array.isArray(offsetSDR) ? offsetSDR.map((v) => parseFloat(v)) : [
527
- parseFloat(offsetSDR),
528
- parseFloat(offsetSDR),
529
- parseFloat(offsetSDR)
530
- ],
531
- offsetHdr: Array.isArray(offsetHDR) ? offsetHDR.map((v) => parseFloat(v)) : [
532
- parseFloat(offsetHDR),
533
- parseFloat(offsetHDR),
534
- parseFloat(offsetHDR)
535
- ],
536
- hdrCapacityMin: parseFloat(hdrCapacityMin),
537
- hdrCapacityMax: parseFloat(hdrCapacityMax)
538
- };
539
- } catch (e) {}
540
- start = str.indexOf("<x:xmpmeta", end);
541
- }
542
- };
543
- /**
544
- * MPF Extractor (Multi Picture Format Extractor)
545
- * By Henrik S Nilsson 2019
546
- *
547
- * Extracts images stored in images based on the MPF format (found here: https://www.cipa.jp/e/std/std-sec.html
548
- * under "CIPA DC-007-Translation-2021 Multi-Picture Format"
549
- *
550
- * Overly commented, and without intention of being complete or production ready.
551
- * Created to extract depth maps from iPhone images, and to learn about image metadata.
552
- * Kudos to: Phil Harvey (exiftool), Jaume Sanchez (android-lens-blur-depth-extractor)
553
- */
554
- var MPFExtractor = class {
555
- constructor(options) {
556
- this.options = {
557
- debug: options && options.debug !== void 0 ? options.debug : false,
558
- extractFII: options && options.extractFII !== void 0 ? options.extractFII : true,
559
- extractNonFII: options && options.extractNonFII !== void 0 ? options.extractNonFII : true
560
- };
561
- }
562
- extract(imageArrayBuffer) {
563
- return new Promise((resolve, reject) => {
564
- const debug = this.options.debug;
565
- const dataView = new DataView(imageArrayBuffer.buffer);
566
- if (dataView.getUint16(0) !== 65496) {
567
- reject(/* @__PURE__ */ new Error("Not a valid jpeg"));
568
- return;
569
- }
570
- const length = dataView.byteLength;
571
- let offset = 2;
572
- let loops = 0;
573
- let marker;
574
- while (offset < length) {
575
- if (++loops > 250) {
576
- reject(/* @__PURE__ */ new Error(`Found no marker after ${loops} loops 😵`));
577
- return;
578
- }
579
- if (dataView.getUint8(offset) !== 255) {
580
- reject(/* @__PURE__ */ new Error(`Not a valid marker at offset 0x${offset.toString(16)}, found: 0x${dataView.getUint8(offset).toString(16)}`));
581
- return;
582
- }
583
- marker = dataView.getUint8(offset + 1);
584
- if (debug) console.log(`Marker: ${marker.toString(16)}`);
585
- if (marker === 226) {
586
- if (debug) console.log("Found APP2 marker (0xffe2)");
587
- const formatPt = offset + 4;
588
- if (dataView.getUint32(formatPt) === 1297106432) {
589
- const tiffOffset = formatPt + 4;
590
- let bigEnd;
591
- if (dataView.getUint16(tiffOffset) === 18761) bigEnd = false;
592
- else if (dataView.getUint16(tiffOffset) === 19789) bigEnd = true;
593
- else {
594
- reject(/* @__PURE__ */ new Error("No valid endianness marker found in TIFF header"));
595
- return;
596
- }
597
- if (dataView.getUint16(tiffOffset + 2, !bigEnd) !== 42) {
598
- reject(/* @__PURE__ */ new Error("Not valid TIFF data! (no 0x002A marker)"));
599
- return;
600
- }
601
- const firstIFDOffset = dataView.getUint32(tiffOffset + 4, !bigEnd);
602
- if (firstIFDOffset < 8) {
603
- reject(/* @__PURE__ */ new Error("Not valid TIFF data! (First offset less than 8)"));
604
- return;
605
- }
606
- const dirStart = tiffOffset + firstIFDOffset;
607
- const count = dataView.getUint16(dirStart, !bigEnd);
608
- const entriesStart = dirStart + 2;
609
- let numberOfImages = 0;
610
- for (let i = entriesStart; i < entriesStart + 12 * count; i += 12) if (dataView.getUint16(i, !bigEnd) === 45057) numberOfImages = dataView.getUint32(i + 8, !bigEnd);
611
- const MPImageListValPt = dirStart + 2 + count * 12 + 4;
612
- const images = [];
613
- for (let i = MPImageListValPt; i < MPImageListValPt + numberOfImages * 16; i += 16) {
614
- const image = {
615
- MPType: dataView.getUint32(i, !bigEnd),
616
- size: dataView.getUint32(i + 4, !bigEnd),
617
- dataOffset: dataView.getUint32(i + 8, !bigEnd),
618
- dependantImages: dataView.getUint32(i + 12, !bigEnd),
619
- start: -1,
620
- end: -1,
621
- isFII: false
622
- };
623
- if (!image.dataOffset) {
624
- image.start = 0;
625
- image.isFII = true;
626
- } else {
627
- image.start = tiffOffset + image.dataOffset;
628
- image.isFII = false;
629
- }
630
- image.end = image.start + image.size;
631
- images.push(image);
632
- }
633
- if (this.options.extractNonFII && images.length) {
634
- const bufferBlob = new Blob([dataView]);
635
- const imgs = [];
636
- for (const image of images) {
637
- if (image.isFII && !this.options.extractFII) continue;
638
- const imageBlob = bufferBlob.slice(image.start, image.end + 1, "image/jpeg");
639
- imgs.push(imageBlob);
640
- }
641
- resolve(imgs);
642
- }
643
- }
644
- }
645
- offset += 2 + dataView.getUint16(offset + 2);
646
- }
647
- });
648
- }
649
- };
650
- /**
651
- * Extracts XMP Metadata and the gain map recovery image
652
- * from a single JPEG file.
653
- *
654
- * @category Decoding Functions
655
- * @group Decoding Functions
656
- * @param jpegFile an `Uint8Array` containing and encoded JPEG file
657
- * @returns an sdr `Uint8Array` compressed in JPEG, a gainMap `Uint8Array` compressed in JPEG and the XMP parsed XMP metadata
658
- * @throws Error if XMP Metadata is not found
659
- * @throws Error if Gain map image is not found
660
- * @example
661
- * import { FileLoader } from 'three'
662
- * import { extractGainmapFromJPEG } from '@monogrid/gainmap-js'
663
- *
664
- * const jpegFile = await new FileLoader()
665
- * .setResponseType('arraybuffer')
666
- * .loadAsync('image.jpg')
667
- *
668
- * const { sdr, gainMap, metadata } = extractGainmapFromJPEG(jpegFile)
669
- */
670
- const extractGainmapFromJPEG = async (jpegFile) => {
671
- const metadata = extractXMP(jpegFile);
672
- if (!metadata) throw new XMPMetadataNotFoundError("Gain map XMP metadata not found");
673
- const images = await new MPFExtractor({
674
- extractFII: true,
675
- extractNonFII: true
676
- }).extract(jpegFile);
677
- if (images.length !== 2) throw new GainMapNotFoundError("Gain map recovery image not found");
678
- return {
679
- sdr: new Uint8Array(await images[0].arrayBuffer()),
680
- gainMap: new Uint8Array(await images[1].arrayBuffer()),
681
- metadata
682
- };
683
- };
684
- /**
685
- * private function, async get image from blob
686
- *
687
- * @param blob
688
- * @returns
689
- */
690
- const getHTMLImageFromBlob = (blob) => {
691
- return new Promise((resolve, reject) => {
692
- const img = document.createElement("img");
693
- img.onload = () => {
694
- resolve(img);
695
- };
696
- img.onerror = (e) => {
697
- reject(e);
698
- };
699
- img.src = URL.createObjectURL(blob);
700
- });
701
- };
702
- var LoaderBase = class extends Loader {
703
- /**
704
- *
705
- * @param renderer
706
- * @param manager
707
- */
708
- constructor(renderer, manager) {
709
- super(manager);
710
- if (renderer) this._renderer = renderer;
711
- this._internalLoadingManager = new LoadingManager();
712
- }
713
- /**
714
- * Specify the renderer to use when rendering the gain map
715
- *
716
- * @param renderer
717
- * @returns
718
- */
719
- setRenderer(renderer) {
720
- this._renderer = renderer;
721
- return this;
722
- }
723
- /**
724
- * Specify the renderTarget options to use when rendering the gain map
725
- *
726
- * @param options
727
- * @returns
728
- */
729
- setRenderTargetOptions(options) {
730
- this._renderTargetOptions = options;
731
- return this;
732
- }
733
- /**
734
- * @private
735
- * @returns
736
- */
737
- prepareQuadRenderer() {
738
- if (!this._renderer) console.warn("WARNING: An existing WebGL Renderer was not passed to this Loader constructor or in setRenderer, the result of this Loader will need to be converted to a Data Texture with toDataTexture() before you can use it in your renderer.");
739
- return new QuadRenderer({
740
- width: 16,
741
- height: 16,
742
- type: HalfFloatType,
743
- colorSpace: LinearSRGBColorSpace,
744
- material: new GainMapDecoderMaterial({
745
- gainMapMax: [
746
- 1,
747
- 1,
748
- 1
749
- ],
750
- gainMapMin: [
751
- 0,
752
- 0,
753
- 0
754
- ],
755
- gamma: [
756
- 1,
757
- 1,
758
- 1
759
- ],
760
- offsetHdr: [
761
- 1,
762
- 1,
763
- 1
764
- ],
765
- offsetSdr: [
766
- 1,
767
- 1,
768
- 1
769
- ],
770
- hdrCapacityMax: 1,
771
- hdrCapacityMin: 0,
772
- maxDisplayBoost: 1,
773
- gainMap: new Texture(),
774
- sdr: new Texture()
775
- }),
776
- renderer: this._renderer,
777
- renderTargetOptions: this._renderTargetOptions
778
- });
779
- }
780
- /**
781
- * @private
782
- * @param quadRenderer
783
- * @param metadata
784
- * @param sdrBuffer
785
- * @param gainMapBuffer
786
- */
787
- async render(quadRenderer, metadata, sdrBuffer, gainMapBuffer) {
788
- const gainMapBlob = gainMapBuffer ? new Blob([gainMapBuffer], { type: "image/jpeg" }) : void 0;
789
- const sdrBlob = new Blob([sdrBuffer], { type: "image/jpeg" });
790
- let sdrImage;
791
- let gainMapImage;
792
- let needsFlip = false;
793
- if (typeof createImageBitmap === "undefined") {
794
- const res = await Promise.all([gainMapBlob ? getHTMLImageFromBlob(gainMapBlob) : Promise.resolve(void 0), getHTMLImageFromBlob(sdrBlob)]);
795
- gainMapImage = res[0];
796
- sdrImage = res[1];
797
- needsFlip = true;
798
- } else {
799
- const res = await Promise.all([gainMapBlob ? createImageBitmap(gainMapBlob, { imageOrientation: "flipY" }) : Promise.resolve(void 0), createImageBitmap(sdrBlob, { imageOrientation: "flipY" })]);
800
- gainMapImage = res[0];
801
- sdrImage = res[1];
802
- }
803
- const gainMap = new Texture(gainMapImage || new ImageData(2, 2), UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, LinearSRGBColorSpace);
804
- gainMap.flipY = needsFlip;
805
- gainMap.needsUpdate = true;
806
- const sdr = new Texture(sdrImage, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, SRGBColorSpace);
807
- sdr.flipY = needsFlip;
808
- sdr.needsUpdate = true;
809
- quadRenderer.width = sdrImage.width;
810
- quadRenderer.height = sdrImage.height;
811
- quadRenderer.material.gainMap = gainMap;
812
- quadRenderer.material.sdr = sdr;
813
- quadRenderer.material.gainMapMin = metadata.gainMapMin;
814
- quadRenderer.material.gainMapMax = metadata.gainMapMax;
815
- quadRenderer.material.offsetHdr = metadata.offsetHdr;
816
- quadRenderer.material.offsetSdr = metadata.offsetSdr;
817
- quadRenderer.material.gamma = metadata.gamma;
818
- quadRenderer.material.hdrCapacityMin = metadata.hdrCapacityMin;
819
- quadRenderer.material.hdrCapacityMax = metadata.hdrCapacityMax;
820
- quadRenderer.material.maxDisplayBoost = Math.pow(2, metadata.hdrCapacityMax);
821
- quadRenderer.material.needsUpdate = true;
822
- quadRenderer.render();
823
- }
824
- };
825
- /**
826
- * A Three.js Loader for the gain map format.
827
- *
828
- * @category Loaders
829
- * @group Loaders
830
- *
831
- * @example
832
- * import { GainMapLoader } from '@monogrid/gainmap-js'
833
- * import {
834
- * EquirectangularReflectionMapping,
835
- * LinearFilter,
836
- * Mesh,
837
- * MeshBasicMaterial,
838
- * PerspectiveCamera,
839
- * PlaneGeometry,
840
- * Scene,
841
- * WebGLRenderer
842
- * } from 'three'
843
- *
844
- * const renderer = new WebGLRenderer()
845
- *
846
- * const loader = new GainMapLoader(renderer)
847
- *
848
- * const result = await loader.loadAsync(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json'])
849
- * // `result` can be used to populate a Texture
850
- *
851
- * const scene = new Scene()
852
- * const mesh = new Mesh(
853
- * new PlaneGeometry(),
854
- * new MeshBasicMaterial({ map: result.renderTarget.texture })
855
- * )
856
- * scene.add(mesh)
857
- * renderer.render(scene, new PerspectiveCamera())
858
- *
859
- * // Starting from three.js r159
860
- * // `result.renderTarget.texture` can
861
- * // also be used as Equirectangular scene background
862
- * //
863
- * // it was previously needed to convert it
864
- * // to a DataTexture with `result.toDataTexture()`
865
- * scene.background = result.renderTarget.texture
866
- * scene.background.mapping = EquirectangularReflectionMapping
867
- *
868
- * // result must be manually disposed
869
- * // when you are done using it
870
- * result.dispose()
871
- *
872
- */
873
- var GainMapLoader = class extends LoaderBase {
874
- /**
875
- * Loads a gainmap using separate data
876
- * * sdr image
877
- * * gain map image
878
- * * metadata json
879
- *
880
- * useful for webp gain maps
881
- *
882
- * @param urls An array in the form of [sdr.jpg, gainmap.jpg, metadata.json]
883
- * @param onLoad Load complete callback, will receive the result
884
- * @param onProgress Progress callback, will receive a {@link ProgressEvent}
885
- * @param onError Error callback
886
- * @returns
887
- */
888
- load([sdrUrl, gainMapUrl, metadataUrl], onLoad, onProgress, onError) {
889
- const quadRenderer = this.prepareQuadRenderer();
890
- let sdr;
891
- let gainMap;
892
- let metadata;
893
- const loadCheck = async () => {
894
- if (sdr && gainMap && metadata) {
895
- try {
896
- await this.render(quadRenderer, metadata, sdr, gainMap);
897
- } catch (error) {
898
- this.manager.itemError(sdrUrl);
899
- this.manager.itemError(gainMapUrl);
900
- this.manager.itemError(metadataUrl);
901
- if (typeof onError === "function") onError(error);
902
- quadRenderer.disposeOnDemandRenderer();
903
- return;
904
- }
905
- if (typeof onLoad === "function") onLoad(quadRenderer);
906
- this.manager.itemEnd(sdrUrl);
907
- this.manager.itemEnd(gainMapUrl);
908
- this.manager.itemEnd(metadataUrl);
909
- quadRenderer.disposeOnDemandRenderer();
910
- }
911
- };
912
- let sdrLengthComputable = true;
913
- let sdrTotal = 0;
914
- let sdrLoaded = 0;
915
- let gainMapLengthComputable = true;
916
- let gainMapTotal = 0;
917
- let gainMapLoaded = 0;
918
- let metadataLengthComputable = true;
919
- let metadataTotal = 0;
920
- let metadataLoaded = 0;
921
- const progressHandler = () => {
922
- if (typeof onProgress === "function") {
923
- const total = sdrTotal + gainMapTotal + metadataTotal;
924
- const loaded = sdrLoaded + gainMapLoaded + metadataLoaded;
925
- const lengthComputable = sdrLengthComputable && gainMapLengthComputable && metadataLengthComputable;
926
- onProgress(new ProgressEvent("progress", {
927
- lengthComputable,
928
- loaded,
929
- total
930
- }));
931
- }
932
- };
933
- this.manager.itemStart(sdrUrl);
934
- this.manager.itemStart(gainMapUrl);
935
- this.manager.itemStart(metadataUrl);
936
- const sdrLoader = new FileLoader(this._internalLoadingManager);
937
- sdrLoader.setResponseType("arraybuffer");
938
- sdrLoader.setRequestHeader(this.requestHeader);
939
- sdrLoader.setPath(this.path);
940
- sdrLoader.setWithCredentials(this.withCredentials);
941
- sdrLoader.load(sdrUrl, async (buffer) => {
942
- /* istanbul ignore if
943
- this condition exists only because of three.js types + strict mode
944
- */
945
- if (typeof buffer === "string") throw new Error("Invalid sdr buffer");
946
- sdr = buffer;
947
- await loadCheck();
948
- }, (e) => {
949
- sdrLengthComputable = e.lengthComputable;
950
- sdrLoaded = e.loaded;
951
- sdrTotal = e.total;
952
- progressHandler();
953
- }, (error) => {
954
- this.manager.itemError(sdrUrl);
955
- if (typeof onError === "function") onError(error);
956
- });
957
- const gainMapLoader = new FileLoader(this._internalLoadingManager);
958
- gainMapLoader.setResponseType("arraybuffer");
959
- gainMapLoader.setRequestHeader(this.requestHeader);
960
- gainMapLoader.setPath(this.path);
961
- gainMapLoader.setWithCredentials(this.withCredentials);
962
- gainMapLoader.load(gainMapUrl, async (buffer) => {
963
- /* istanbul ignore if
964
- this condition exists only because of three.js types + strict mode
965
- */
966
- if (typeof buffer === "string") throw new Error("Invalid gainmap buffer");
967
- gainMap = buffer;
968
- await loadCheck();
969
- }, (e) => {
970
- gainMapLengthComputable = e.lengthComputable;
971
- gainMapLoaded = e.loaded;
972
- gainMapTotal = e.total;
973
- progressHandler();
974
- }, (error) => {
975
- this.manager.itemError(gainMapUrl);
976
- if (typeof onError === "function") onError(error);
977
- });
978
- const metadataLoader = new FileLoader(this._internalLoadingManager);
979
- metadataLoader.setRequestHeader(this.requestHeader);
980
- metadataLoader.setPath(this.path);
981
- metadataLoader.setWithCredentials(this.withCredentials);
982
- metadataLoader.load(metadataUrl, async (json) => {
983
- /* istanbul ignore if
984
- this condition exists only because of three.js types + strict mode
985
- */
986
- if (typeof json !== "string") throw new Error("Invalid metadata string");
987
- metadata = JSON.parse(json);
988
- await loadCheck();
989
- }, (e) => {
990
- metadataLengthComputable = e.lengthComputable;
991
- metadataLoaded = e.loaded;
992
- metadataTotal = e.total;
993
- progressHandler();
994
- }, (error) => {
995
- this.manager.itemError(metadataUrl);
996
- if (typeof onError === "function") onError(error);
997
- });
998
- return quadRenderer;
999
- }
1000
- };
1001
- /**
1002
- * A Three.js Loader for a JPEG with embedded gainmap metadata.
1003
- *
1004
- * @category Loaders
1005
- * @group Loaders
1006
- *
1007
- * @example
1008
- * import { HDRJPGLoader } from '@monogrid/gainmap-js'
1009
- * import {
1010
- * EquirectangularReflectionMapping,
1011
- * LinearFilter,
1012
- * Mesh,
1013
- * MeshBasicMaterial,
1014
- * PerspectiveCamera,
1015
- * PlaneGeometry,
1016
- * Scene,
1017
- * WebGLRenderer
1018
- * } from 'three'
1019
- *
1020
- * const renderer = new WebGLRenderer()
1021
- *
1022
- * const loader = new HDRJPGLoader(renderer)
1023
- *
1024
- * const result = await loader.loadAsync('gainmap.jpeg')
1025
- * // `result` can be used to populate a Texture
1026
- *
1027
- * const scene = new Scene()
1028
- * const mesh = new Mesh(
1029
- * new PlaneGeometry(),
1030
- * new MeshBasicMaterial({ map: result.renderTarget.texture })
1031
- * )
1032
- * scene.add(mesh)
1033
- * renderer.render(scene, new PerspectiveCamera())
1034
- *
1035
- * // Starting from three.js r159
1036
- * // `result.renderTarget.texture` can
1037
- * // also be used as Equirectangular scene background
1038
- * //
1039
- * // it was previously needed to convert it
1040
- * // to a DataTexture with `result.toDataTexture()`
1041
- * scene.background = result.renderTarget.texture
1042
- * scene.background.mapping = EquirectangularReflectionMapping
1043
- *
1044
- * // result must be manually disposed
1045
- * // when you are done using it
1046
- * result.dispose()
1047
- *
1048
- */
1049
- var HDRJPGLoader = class extends LoaderBase {
1050
- /**
1051
- * Loads a JPEG containing gain map metadata
1052
- * Renders a normal SDR image if gainmap data is not found
1053
- *
1054
- * @param url An array in the form of [sdr.jpg, gainmap.jpg, metadata.json]
1055
- * @param onLoad Load complete callback, will receive the result
1056
- * @param onProgress Progress callback, will receive a {@link ProgressEvent}
1057
- * @param onError Error callback
1058
- * @returns
1059
- */
1060
- load(url, onLoad, onProgress, onError) {
1061
- const quadRenderer = this.prepareQuadRenderer();
1062
- const loader = new FileLoader(this._internalLoadingManager);
1063
- loader.setResponseType("arraybuffer");
1064
- loader.setRequestHeader(this.requestHeader);
1065
- loader.setPath(this.path);
1066
- loader.setWithCredentials(this.withCredentials);
1067
- this.manager.itemStart(url);
1068
- loader.load(url, async (jpeg) => {
1069
- /* istanbul ignore if
1070
- this condition exists only because of three.js types + strict mode
1071
- */
1072
- if (typeof jpeg === "string") throw new Error("Invalid buffer, received [string], was expecting [ArrayBuffer]");
1073
- const jpegBuffer = new Uint8Array(jpeg);
1074
- let sdrJPEG;
1075
- let gainMapJPEG;
1076
- let metadata;
1077
- try {
1078
- const extractionResult = await extractGainmapFromJPEG(jpegBuffer);
1079
- sdrJPEG = extractionResult.sdr;
1080
- gainMapJPEG = extractionResult.gainMap;
1081
- metadata = extractionResult.metadata;
1082
- } catch (e) {
1083
- if (e instanceof XMPMetadataNotFoundError || e instanceof GainMapNotFoundError) {
1084
- console.warn(`Failure to reconstruct an HDR image from ${url}: Gain map metadata not found in the file, HDRJPGLoader will render the SDR jpeg`);
1085
- metadata = {
1086
- gainMapMin: [
1087
- 0,
1088
- 0,
1089
- 0
1090
- ],
1091
- gainMapMax: [
1092
- 1,
1093
- 1,
1094
- 1
1095
- ],
1096
- gamma: [
1097
- 1,
1098
- 1,
1099
- 1
1100
- ],
1101
- hdrCapacityMin: 0,
1102
- hdrCapacityMax: 1,
1103
- offsetHdr: [
1104
- 0,
1105
- 0,
1106
- 0
1107
- ],
1108
- offsetSdr: [
1109
- 0,
1110
- 0,
1111
- 0
1112
- ]
1113
- };
1114
- sdrJPEG = jpegBuffer;
1115
- } else throw e;
1116
- }
1117
- try {
1118
- await this.render(quadRenderer, metadata, sdrJPEG, gainMapJPEG);
1119
- } catch (error) {
1120
- this.manager.itemError(url);
1121
- if (typeof onError === "function") onError(error);
1122
- quadRenderer.disposeOnDemandRenderer();
1123
- return;
1124
- }
1125
- if (typeof onLoad === "function") onLoad(quadRenderer);
1126
- this.manager.itemEnd(url);
1127
- quadRenderer.disposeOnDemandRenderer();
1128
- }, onProgress, (error) => {
1129
- this.manager.itemError(url);
1130
- if (typeof onError === "function") onError(error);
1131
- });
1132
- return quadRenderer;
1133
- }
1134
- };
1135
-
1136
- //#endregion
1137
- export { HDRJPGLoader as n, GainMapLoader as t };