@monogrid/gainmap-js 2.0.6 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.5
2
+ * @monogrid/gainmap-js v2.0.7
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -153,23 +153,13 @@
153
153
  * @param type
154
154
  * @param renderer
155
155
  * @param camera
156
+ * @param renderTargetOptions
156
157
  * @returns
157
158
  */
158
- const canReadPixels = (type, renderer, camera) => {
159
+ const canReadPixels = (type, renderer, camera, renderTargetOptions) => {
159
160
  if (_canReadPixelsResult !== undefined)
160
161
  return _canReadPixelsResult;
161
- const testRT = new three.WebGLRenderTarget(1, 1, {
162
- type,
163
- colorSpace: three.LinearSRGBColorSpace,
164
- format: three.RGBAFormat,
165
- magFilter: three.LinearFilter,
166
- minFilter: three.LinearFilter,
167
- wrapS: three.RepeatWrapping,
168
- wrapT: three.RepeatWrapping,
169
- depthBuffer: false,
170
- stencilBuffer: false,
171
- generateMipmaps: true
172
- });
162
+ const testRT = new three.WebGLRenderTarget(1, 1, renderTargetOptions);
173
163
  renderer.setRenderTarget(testRT);
174
164
  const mesh = new three.Mesh(new three.PlaneGeometry(), new three.MeshBasicMaterial({ color: 0xffffff }));
175
165
  renderer.render(mesh, camera);
@@ -194,7 +184,8 @@
194
184
  * @param sourceTexture
195
185
  * @param renderer
196
186
  */
197
- constructor(width, height, type, colorSpace, material, renderer) {
187
+ constructor(options) {
188
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
198
189
  this._rendererIsDisposable = false;
199
190
  this._supportsReadPixels = true;
200
191
  /**
@@ -211,13 +202,29 @@
211
202
  }
212
203
  this._renderer.setRenderTarget(null);
213
204
  };
214
- this._width = width;
215
- this._height = height;
216
- this._type = type;
217
- this._colorSpace = colorSpace;
218
- this._material = material;
219
- if (renderer) {
220
- this._renderer = renderer;
205
+ this._width = options.width;
206
+ this._height = options.height;
207
+ this._type = options.type;
208
+ this._colorSpace = options.colorSpace;
209
+ const rtOptions = {
210
+ // fixed options
211
+ format: three.RGBAFormat,
212
+ depthBuffer: false,
213
+ stencilBuffer: false,
214
+ // user options
215
+ type: this._type,
216
+ colorSpace: this._colorSpace,
217
+ anisotropy: ((_a = options.renderTargetOptions) === null || _a === void 0 ? void 0 : _a.anisotropy) !== undefined ? (_b = options.renderTargetOptions) === null || _b === void 0 ? void 0 : _b.anisotropy : 1,
218
+ generateMipmaps: ((_c = options.renderTargetOptions) === null || _c === void 0 ? void 0 : _c.generateMipmaps) !== undefined ? (_d = options.renderTargetOptions) === null || _d === void 0 ? void 0 : _d.generateMipmaps : false,
219
+ magFilter: ((_e = options.renderTargetOptions) === null || _e === void 0 ? void 0 : _e.magFilter) !== undefined ? (_f = options.renderTargetOptions) === null || _f === void 0 ? void 0 : _f.magFilter : three.LinearFilter,
220
+ minFilter: ((_g = options.renderTargetOptions) === null || _g === void 0 ? void 0 : _g.minFilter) !== undefined ? (_h = options.renderTargetOptions) === null || _h === void 0 ? void 0 : _h.minFilter : three.LinearFilter,
221
+ samples: ((_j = options.renderTargetOptions) === null || _j === void 0 ? void 0 : _j.samples) !== undefined ? (_k = options.renderTargetOptions) === null || _k === void 0 ? void 0 : _k.samples : undefined,
222
+ wrapS: ((_l = options.renderTargetOptions) === null || _l === void 0 ? void 0 : _l.wrapS) !== undefined ? (_m = options.renderTargetOptions) === null || _m === void 0 ? void 0 : _m.wrapS : three.ClampToEdgeWrapping,
223
+ wrapT: ((_o = options.renderTargetOptions) === null || _o === void 0 ? void 0 : _o.wrapT) !== undefined ? (_p = options.renderTargetOptions) === null || _p === void 0 ? void 0 : _p.wrapT : three.ClampToEdgeWrapping
224
+ };
225
+ this._material = options.material;
226
+ if (options.renderer) {
227
+ this._renderer = options.renderer;
221
228
  }
222
229
  else {
223
230
  this._renderer = QuadRenderer.instantiateRenderer();
@@ -231,7 +238,7 @@
231
238
  this._camera.top = 0.5;
232
239
  this._camera.bottom = -0.5;
233
240
  this._camera.updateProjectionMatrix();
234
- if (!canReadPixels(this._type, this._renderer, this._camera)) {
241
+ if (!canReadPixels(this._type, this._renderer, this._camera, rtOptions)) {
235
242
  let alternativeType;
236
243
  switch (this._type) {
237
244
  case three.HalfFloatType:
@@ -250,18 +257,8 @@
250
257
  this._quad = new three.Mesh(new three.PlaneGeometry(), this._material);
251
258
  this._quad.geometry.computeBoundingBox();
252
259
  this._scene.add(this._quad);
253
- this._renderTarget = new three.WebGLRenderTarget(width, height, {
254
- type: this._type,
255
- colorSpace,
256
- format: three.RGBAFormat,
257
- magFilter: three.LinearFilter,
258
- minFilter: three.LinearMipMapLinearFilter,
259
- wrapS: three.RepeatWrapping,
260
- wrapT: three.RepeatWrapping,
261
- depthBuffer: false,
262
- stencilBuffer: false,
263
- generateMipmaps: true
264
- });
260
+ this._renderTarget = new three.WebGLRenderTarget(this.width, this.height, rtOptions);
261
+ this._renderTarget.texture.mapping = ((_q = options.renderTargetOptions) === null || _q === void 0 ? void 0 : _q.mapping) !== undefined ? (_r = options.renderTargetOptions) === null || _r === void 0 ? void 0 : _r.mapping : three.UVMapping;
265
262
  }
266
263
  /**
267
264
  * Instantiates a temporary renderer
@@ -290,19 +287,85 @@
290
287
  this._renderer.readRenderTargetPixels(this._renderTarget, 0, 0, this._width, this._height, out);
291
288
  return out;
292
289
  }
293
- toDataTexture() {
294
- return new three.DataTexture(this.toArray(), this.width, this.height, three.RGBAFormat, this._type, three.UVMapping, three.RepeatWrapping, three.RepeatWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, 1, three.LinearSRGBColorSpace);
290
+ /**
291
+ * Performs a readPixel operation in the renderTarget
292
+ * and returns a DataTexture containing the read data
293
+ *
294
+ * @params options
295
+ * @returns
296
+ */
297
+ toDataTexture(options) {
298
+ const returnValue = new three.DataTexture(
299
+ // fixed values
300
+ this.toArray(), this.width, this.height, three.RGBAFormat, this._type,
301
+ // user values
302
+ (options === null || options === void 0 ? void 0 : options.mapping) || three.UVMapping, (options === null || options === void 0 ? void 0 : options.wrapS) || three.ClampToEdgeWrapping, (options === null || options === void 0 ? void 0 : options.wrapT) || three.ClampToEdgeWrapping, (options === null || options === void 0 ? void 0 : options.magFilter) || three.LinearFilter, (options === null || options === void 0 ? void 0 : options.minFilter) || three.LinearFilter, (options === null || options === void 0 ? void 0 : options.anisotropy) || 1,
303
+ // fixed value
304
+ three.LinearSRGBColorSpace);
305
+ // set this afterwards, we can't set it in constructor
306
+ returnValue.generateMipmaps = (options === null || options === void 0 ? void 0 : options.generateMipmaps) !== undefined ? options === null || options === void 0 ? void 0 : options.generateMipmaps : false;
307
+ return returnValue;
295
308
  }
296
309
  /**
297
310
  * If using a disposable renderer, it will dispose it.
298
311
  */
299
- dispose() {
312
+ disposeOnDemandRenderer() {
300
313
  this._renderer.setRenderTarget(null);
301
314
  if (this._rendererIsDisposable) {
302
315
  this._renderer.dispose();
303
316
  this._renderer.forceContextLoss();
304
317
  }
305
318
  }
319
+ /**
320
+ * Will dispose of **all** assets used by this renderer.
321
+ *
322
+ *
323
+ * @param disposeRenderTarget will dispose of the renderTarget which will not be usable later
324
+ * set this to true if you passed the `renderTarget.texture` to a `PMREMGenerator`
325
+ * or are otherwise done with it.
326
+ *
327
+ * @example
328
+ * ```js
329
+ * const loader = new HDRJPGLoader(renderer)
330
+ * const result = await loader.loadAsync('gainmap.jpeg')
331
+ * const mesh = new Mesh(geometry, new MeshBasicMaterial({ map: result.renderTarget.texture }) )
332
+ * // DO NOT dispose the renderTarget here,
333
+ * // it is used directly in the material
334
+ * result.dispose()
335
+ * ```
336
+ *
337
+ * @example
338
+ * ```js
339
+ * const loader = new HDRJPGLoader(renderer)
340
+ * const pmremGenerator = new PMREMGenerator( renderer );
341
+ * const result = await loader.loadAsync('gainmap.jpeg')
342
+ * const envMap = pmremGenerator.fromEquirectangular(result.renderTarget.texture)
343
+ * const mesh = new Mesh(geometry, new MeshStandardMaterial({ envMap }) )
344
+ * // renderTarget can be disposed here
345
+ * // because it was used to generate a PMREM texture
346
+ * result.dispose(true)
347
+ * ```
348
+ */
349
+ dispose(disposeRenderTarget) {
350
+ this.disposeOnDemandRenderer();
351
+ if (disposeRenderTarget) {
352
+ this.renderTarget.dispose();
353
+ }
354
+ // dispose shader material texture uniforms
355
+ if (this.material instanceof three.ShaderMaterial) {
356
+ Object.values(this.material.uniforms).forEach(v => {
357
+ if (v.value instanceof three.Texture)
358
+ v.value.dispose();
359
+ });
360
+ }
361
+ // dispose other material properties
362
+ Object.values(this.material).forEach(value => {
363
+ if (value instanceof three.Texture)
364
+ value.dispose();
365
+ });
366
+ this.material.dispose();
367
+ this._quad.geometry.dispose();
368
+ }
306
369
  /**
307
370
  * Width of the texture
308
371
  */
@@ -503,12 +566,20 @@ void main() {
503
566
  sdr: sdr.renderTarget.texture,
504
567
  hdr: dataTexture
505
568
  });
506
- const quadRenderer = new QuadRenderer(dataTexture.image.width, dataTexture.image.height, three.UnsignedByteType, three.LinearSRGBColorSpace, material, renderer);
569
+ const quadRenderer = new QuadRenderer({
570
+ width: dataTexture.image.width,
571
+ height: dataTexture.image.height,
572
+ type: three.UnsignedByteType,
573
+ colorSpace: three.LinearSRGBColorSpace,
574
+ material,
575
+ renderer,
576
+ renderTargetOptions: params.renderTargetOptions
577
+ });
507
578
  try {
508
579
  quadRenderer.render();
509
580
  }
510
581
  catch (e) {
511
- quadRenderer.dispose();
582
+ quadRenderer.disposeOnDemandRenderer();
512
583
  throw e;
513
584
  }
514
585
  return quadRenderer;
@@ -726,16 +797,25 @@ void main() {
726
797
  * @param hdrTexture The HDR image to be rendered
727
798
  * @param renderer (optional) WebGLRenderer to use during the rendering, a disposable renderer will be create and destroyed if this is not provided.
728
799
  * @param toneMapping (optional) Tone mapping to be applied to the SDR Rendition
800
+ * @param renderTargetOptions (optional) Options to use when creating the output renderTarget
729
801
  * @throws {Error} if the WebGLRenderer fails to render the SDR image
730
802
  */
731
- const getSDRRendition = (hdrTexture, renderer, toneMapping) => {
803
+ const getSDRRendition = (hdrTexture, renderer, toneMapping, renderTargetOptions) => {
732
804
  hdrTexture.needsUpdate = true;
733
- const quadRenderer = new QuadRenderer(hdrTexture.image.width, hdrTexture.image.height, three.UnsignedByteType, three.SRGBColorSpace, new SDRMaterial({ map: hdrTexture, toneMapping }), renderer);
805
+ const quadRenderer = new QuadRenderer({
806
+ width: hdrTexture.image.width,
807
+ height: hdrTexture.image.height,
808
+ type: three.UnsignedByteType,
809
+ colorSpace: three.SRGBColorSpace,
810
+ material: new SDRMaterial({ map: hdrTexture, toneMapping }),
811
+ renderer,
812
+ renderTargetOptions
813
+ });
734
814
  try {
735
815
  quadRenderer.render();
736
816
  }
737
817
  catch (e) {
738
- quadRenderer.dispose();
818
+ quadRenderer.disposeOnDemandRenderer();
739
819
  throw e;
740
820
  }
741
821
  return quadRenderer;
@@ -784,7 +864,10 @@ void main() {
784
864
  * encodingResult.gainMap.material.gamma = [1.1, 1.1, 1.1]
785
865
  * encodingResult.gainMap.render()
786
866
  *
787
- * // must be manually disposed
867
+ * // do something with encodingResult.gainMap.toArray()
868
+ * // and encodingResult.sdr.toArray()
869
+ *
870
+ * // renderers must be manually disposed
788
871
  * encodingResult.sdr.dispose()
789
872
  * encodingResult.gainMap.dispose()
790
873
  *
@@ -794,7 +877,7 @@ void main() {
794
877
  const encode = (params) => {
795
878
  const { image, renderer } = params;
796
879
  const dataTexture = getDataTexture(image);
797
- const sdr = getSDRRendition(dataTexture, renderer, params.toneMapping);
880
+ const sdr = getSDRRendition(dataTexture, renderer, params.toneMapping, params.renderTargetOptions);
798
881
  const gainMapRenderer = getGainMap({
799
882
  ...params,
800
883
  image: dataTexture,
@@ -994,7 +1077,14 @@ void main() {
994
1077
  mat.needsUpdate = true;
995
1078
  let w = srcTex.image.width;
996
1079
  let h = srcTex.image.height;
997
- const quadRenderer = new QuadRenderer(w, h, srcTex.type, srcTex.colorSpace, mat, renderer);
1080
+ const quadRenderer = new QuadRenderer({
1081
+ width: w,
1082
+ height: h,
1083
+ type: srcTex.type,
1084
+ colorSpace: srcTex.colorSpace,
1085
+ material: mat,
1086
+ renderer
1087
+ });
998
1088
  const frameBuffers = [];
999
1089
  while (w > 1 || h > 1) {
1000
1090
  w = Math.max(1, (w + cellSize - 1) / cellSize | 0);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.5
2
+ * @monogrid/gainmap-js v2.0.7
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.5
2
+ * @monogrid/gainmap-js v2.0.7
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.5
2
+ * @monogrid/gainmap-js v2.0.7
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-iRbo2TdN.js';
6
+ import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-7LfDr0XA.js';
7
7
 
8
8
  var lib$1;
9
9
  var hasRequiredLib$1;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.5
2
+ * @monogrid/gainmap-js v2.0.7
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
package/dist/worker.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.5
2
+ * @monogrid/gainmap-js v2.0.7
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { g as getDefaultExportFromCjs } from './_commonjsHelpers-iRbo2TdN.js';
7
- import { c as compress } from './compress-_4jEQonS.js';
6
+ import { g as getDefaultExportFromCjs } from './_commonjsHelpers-7LfDr0XA.js';
7
+ import { c as compress } from './compress-AzvRyeg9.js';
8
8
 
9
9
  var isPromise$2 = {exports: {}};
10
10
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.5
2
+ * @monogrid/gainmap-js v2.0.7
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monogrid/gainmap-js",
3
- "version": "2.0.6",
3
+ "version": "3.0.0",
4
4
  "description": "A Javascript (TypeScript) Port of Adobe Gainmap Technology for storing HDR Images using an SDR Image + a gain map",
5
5
  "homepage": "https://github.com/MONOGRID/gainmap-js#readme",
6
6
  "repository": {