sceneview-web 1.4.0 → 3.5.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,450 +0,0 @@
1
- import {
2
- DataTextureLoader,
3
- DataUtils,
4
- FloatType,
5
- HalfFloatType,
6
- LinearFilter,
7
- LinearSRGBColorSpace
8
- } from 'three';
9
-
10
- // https://github.com/mrdoob/three.js/issues/5552
11
- // http://en.wikipedia.org/wiki/RGBE_image_format
12
-
13
- class RGBELoader extends DataTextureLoader {
14
-
15
- constructor( manager ) {
16
-
17
- super( manager );
18
-
19
- this.type = HalfFloatType;
20
-
21
- }
22
-
23
- // adapted from http://www.graphics.cornell.edu/~bjw/rgbe.html
24
-
25
- parse( buffer ) {
26
-
27
- const
28
- /* default error routine. change this to change error handling */
29
- rgbe_read_error = 1,
30
- rgbe_write_error = 2,
31
- rgbe_format_error = 3,
32
- rgbe_memory_error = 4,
33
- rgbe_error = function ( rgbe_error_code, msg ) {
34
-
35
- switch ( rgbe_error_code ) {
36
-
37
- case rgbe_read_error: throw new Error( 'THREE.RGBELoader: Read Error: ' + ( msg || '' ) );
38
- case rgbe_write_error: throw new Error( 'THREE.RGBELoader: Write Error: ' + ( msg || '' ) );
39
- case rgbe_format_error: throw new Error( 'THREE.RGBELoader: Bad File Format: ' + ( msg || '' ) );
40
- default:
41
- case rgbe_memory_error: throw new Error( 'THREE.RGBELoader: Memory Error: ' + ( msg || '' ) );
42
-
43
- }
44
-
45
- },
46
-
47
- /* offsets to red, green, and blue components in a data (float) pixel */
48
- //RGBE_DATA_RED = 0,
49
- //RGBE_DATA_GREEN = 1,
50
- //RGBE_DATA_BLUE = 2,
51
-
52
- /* number of floats per pixel, use 4 since stored in rgba image format */
53
- //RGBE_DATA_SIZE = 4,
54
-
55
- /* flags indicating which fields in an rgbe_header_info are valid */
56
- RGBE_VALID_PROGRAMTYPE = 1,
57
- RGBE_VALID_FORMAT = 2,
58
- RGBE_VALID_DIMENSIONS = 4,
59
-
60
- NEWLINE = '\n',
61
-
62
- fgets = function ( buffer, lineLimit, consume ) {
63
-
64
- const chunkSize = 128;
65
-
66
- lineLimit = ! lineLimit ? 1024 : lineLimit;
67
- let p = buffer.pos,
68
- i = - 1, len = 0, s = '',
69
- chunk = String.fromCharCode.apply( null, new Uint16Array( buffer.subarray( p, p + chunkSize ) ) );
70
-
71
- while ( ( 0 > ( i = chunk.indexOf( NEWLINE ) ) ) && ( len < lineLimit ) && ( p < buffer.byteLength ) ) {
72
-
73
- s += chunk; len += chunk.length;
74
- p += chunkSize;
75
- chunk += String.fromCharCode.apply( null, new Uint16Array( buffer.subarray( p, p + chunkSize ) ) );
76
-
77
- }
78
-
79
- if ( - 1 < i ) {
80
-
81
- /*for (i=l-1; i>=0; i--) {
82
- byteCode = m.charCodeAt(i);
83
- if (byteCode > 0x7f && byteCode <= 0x7ff) byteLen++;
84
- else if (byteCode > 0x7ff && byteCode <= 0xffff) byteLen += 2;
85
- if (byteCode >= 0xDC00 && byteCode <= 0xDFFF) i--; //trail surrogate
86
- }*/
87
- if ( false !== consume ) buffer.pos += len + i + 1;
88
- return s + chunk.slice( 0, i );
89
-
90
- }
91
-
92
- return false;
93
-
94
- },
95
-
96
- /* minimal header reading. modify if you want to parse more information */
97
- RGBE_ReadHeader = function ( buffer ) {
98
-
99
-
100
- // regexes to parse header info fields
101
- const magic_token_re = /^#\?(\S+)/,
102
- gamma_re = /^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,
103
- exposure_re = /^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,
104
- format_re = /^\s*FORMAT=(\S+)\s*$/,
105
- dimensions_re = /^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,
106
-
107
- // RGBE format header struct
108
- header = {
109
-
110
- valid: 0, /* indicate which fields are valid */
111
-
112
- string: '', /* the actual header string */
113
-
114
- comments: '', /* comments found in header */
115
-
116
- programtype: 'RGBE', /* listed at beginning of file to identify it after "#?". defaults to "RGBE" */
117
-
118
- format: '', /* RGBE format, default 32-bit_rle_rgbe */
119
-
120
- gamma: 1.0, /* image has already been gamma corrected with given gamma. defaults to 1.0 (no correction) */
121
-
122
- exposure: 1.0, /* a value of 1.0 in an image corresponds to <exposure> watts/steradian/m^2. defaults to 1.0 */
123
-
124
- width: 0, height: 0 /* image dimensions, width/height */
125
-
126
- };
127
-
128
- let line, match;
129
-
130
- if ( buffer.pos >= buffer.byteLength || ! ( line = fgets( buffer ) ) ) {
131
-
132
- rgbe_error( rgbe_read_error, 'no header found' );
133
-
134
- }
135
-
136
- /* if you want to require the magic token then uncomment the next line */
137
- if ( ! ( match = line.match( magic_token_re ) ) ) {
138
-
139
- rgbe_error( rgbe_format_error, 'bad initial token' );
140
-
141
- }
142
-
143
- header.valid |= RGBE_VALID_PROGRAMTYPE;
144
- header.programtype = match[ 1 ];
145
- header.string += line + '\n';
146
-
147
- while ( true ) {
148
-
149
- line = fgets( buffer );
150
- if ( false === line ) break;
151
- header.string += line + '\n';
152
-
153
- if ( '#' === line.charAt( 0 ) ) {
154
-
155
- header.comments += line + '\n';
156
- continue; // comment line
157
-
158
- }
159
-
160
- if ( match = line.match( gamma_re ) ) {
161
-
162
- header.gamma = parseFloat( match[ 1 ] );
163
-
164
- }
165
-
166
- if ( match = line.match( exposure_re ) ) {
167
-
168
- header.exposure = parseFloat( match[ 1 ] );
169
-
170
- }
171
-
172
- if ( match = line.match( format_re ) ) {
173
-
174
- header.valid |= RGBE_VALID_FORMAT;
175
- header.format = match[ 1 ];//'32-bit_rle_rgbe';
176
-
177
- }
178
-
179
- if ( match = line.match( dimensions_re ) ) {
180
-
181
- header.valid |= RGBE_VALID_DIMENSIONS;
182
- header.height = parseInt( match[ 1 ], 10 );
183
- header.width = parseInt( match[ 2 ], 10 );
184
-
185
- }
186
-
187
- if ( ( header.valid & RGBE_VALID_FORMAT ) && ( header.valid & RGBE_VALID_DIMENSIONS ) ) break;
188
-
189
- }
190
-
191
- if ( ! ( header.valid & RGBE_VALID_FORMAT ) ) {
192
-
193
- rgbe_error( rgbe_format_error, 'missing format specifier' );
194
-
195
- }
196
-
197
- if ( ! ( header.valid & RGBE_VALID_DIMENSIONS ) ) {
198
-
199
- rgbe_error( rgbe_format_error, 'missing image size specifier' );
200
-
201
- }
202
-
203
- return header;
204
-
205
- },
206
-
207
- RGBE_ReadPixels_RLE = function ( buffer, w, h ) {
208
-
209
- const scanline_width = w;
210
-
211
- if (
212
- // run length encoding is not allowed so read flat
213
- ( ( scanline_width < 8 ) || ( scanline_width > 0x7fff ) ) ||
214
- // this file is not run length encoded
215
- ( ( 2 !== buffer[ 0 ] ) || ( 2 !== buffer[ 1 ] ) || ( buffer[ 2 ] & 0x80 ) )
216
- ) {
217
-
218
- // return the flat buffer
219
- return new Uint8Array( buffer );
220
-
221
- }
222
-
223
- if ( scanline_width !== ( ( buffer[ 2 ] << 8 ) | buffer[ 3 ] ) ) {
224
-
225
- rgbe_error( rgbe_format_error, 'wrong scanline width' );
226
-
227
- }
228
-
229
- const data_rgba = new Uint8Array( 4 * w * h );
230
-
231
- if ( ! data_rgba.length ) {
232
-
233
- rgbe_error( rgbe_memory_error, 'unable to allocate buffer space' );
234
-
235
- }
236
-
237
- let offset = 0, pos = 0;
238
-
239
- const ptr_end = 4 * scanline_width;
240
- const rgbeStart = new Uint8Array( 4 );
241
- const scanline_buffer = new Uint8Array( ptr_end );
242
- let num_scanlines = h;
243
-
244
- // read in each successive scanline
245
- while ( ( num_scanlines > 0 ) && ( pos < buffer.byteLength ) ) {
246
-
247
- if ( pos + 4 > buffer.byteLength ) {
248
-
249
- rgbe_error( rgbe_read_error );
250
-
251
- }
252
-
253
- rgbeStart[ 0 ] = buffer[ pos ++ ];
254
- rgbeStart[ 1 ] = buffer[ pos ++ ];
255
- rgbeStart[ 2 ] = buffer[ pos ++ ];
256
- rgbeStart[ 3 ] = buffer[ pos ++ ];
257
-
258
- if ( ( 2 != rgbeStart[ 0 ] ) || ( 2 != rgbeStart[ 1 ] ) || ( ( ( rgbeStart[ 2 ] << 8 ) | rgbeStart[ 3 ] ) != scanline_width ) ) {
259
-
260
- rgbe_error( rgbe_format_error, 'bad rgbe scanline format' );
261
-
262
- }
263
-
264
- // read each of the four channels for the scanline into the buffer
265
- // first red, then green, then blue, then exponent
266
- let ptr = 0, count;
267
-
268
- while ( ( ptr < ptr_end ) && ( pos < buffer.byteLength ) ) {
269
-
270
- count = buffer[ pos ++ ];
271
- const isEncodedRun = count > 128;
272
- if ( isEncodedRun ) count -= 128;
273
-
274
- if ( ( 0 === count ) || ( ptr + count > ptr_end ) ) {
275
-
276
- rgbe_error( rgbe_format_error, 'bad scanline data' );
277
-
278
- }
279
-
280
- if ( isEncodedRun ) {
281
-
282
- // a (encoded) run of the same value
283
- const byteValue = buffer[ pos ++ ];
284
- for ( let i = 0; i < count; i ++ ) {
285
-
286
- scanline_buffer[ ptr ++ ] = byteValue;
287
-
288
- }
289
- //ptr += count;
290
-
291
- } else {
292
-
293
- // a literal-run
294
- scanline_buffer.set( buffer.subarray( pos, pos + count ), ptr );
295
- ptr += count; pos += count;
296
-
297
- }
298
-
299
- }
300
-
301
-
302
- // now convert data from buffer into rgba
303
- // first red, then green, then blue, then exponent (alpha)
304
- const l = scanline_width; //scanline_buffer.byteLength;
305
- for ( let i = 0; i < l; i ++ ) {
306
-
307
- let off = 0;
308
- data_rgba[ offset ] = scanline_buffer[ i + off ];
309
- off += scanline_width; //1;
310
- data_rgba[ offset + 1 ] = scanline_buffer[ i + off ];
311
- off += scanline_width; //1;
312
- data_rgba[ offset + 2 ] = scanline_buffer[ i + off ];
313
- off += scanline_width; //1;
314
- data_rgba[ offset + 3 ] = scanline_buffer[ i + off ];
315
- offset += 4;
316
-
317
- }
318
-
319
- num_scanlines --;
320
-
321
- }
322
-
323
- return data_rgba;
324
-
325
- };
326
-
327
- const RGBEByteToRGBFloat = function ( sourceArray, sourceOffset, destArray, destOffset ) {
328
-
329
- const e = sourceArray[ sourceOffset + 3 ];
330
- const scale = Math.pow( 2.0, e - 128.0 ) / 255.0;
331
-
332
- destArray[ destOffset + 0 ] = sourceArray[ sourceOffset + 0 ] * scale;
333
- destArray[ destOffset + 1 ] = sourceArray[ sourceOffset + 1 ] * scale;
334
- destArray[ destOffset + 2 ] = sourceArray[ sourceOffset + 2 ] * scale;
335
- destArray[ destOffset + 3 ] = 1;
336
-
337
- };
338
-
339
- const RGBEByteToRGBHalf = function ( sourceArray, sourceOffset, destArray, destOffset ) {
340
-
341
- const e = sourceArray[ sourceOffset + 3 ];
342
- const scale = Math.pow( 2.0, e - 128.0 ) / 255.0;
343
-
344
- // clamping to 65504, the maximum representable value in float16
345
- destArray[ destOffset + 0 ] = DataUtils.toHalfFloat( Math.min( sourceArray[ sourceOffset + 0 ] * scale, 65504 ) );
346
- destArray[ destOffset + 1 ] = DataUtils.toHalfFloat( Math.min( sourceArray[ sourceOffset + 1 ] * scale, 65504 ) );
347
- destArray[ destOffset + 2 ] = DataUtils.toHalfFloat( Math.min( sourceArray[ sourceOffset + 2 ] * scale, 65504 ) );
348
- destArray[ destOffset + 3 ] = DataUtils.toHalfFloat( 1 );
349
-
350
- };
351
-
352
- const byteArray = new Uint8Array( buffer );
353
- byteArray.pos = 0;
354
- const rgbe_header_info = RGBE_ReadHeader( byteArray );
355
-
356
- const w = rgbe_header_info.width,
357
- h = rgbe_header_info.height,
358
- image_rgba_data = RGBE_ReadPixels_RLE( byteArray.subarray( byteArray.pos ), w, h );
359
-
360
-
361
- let data, type;
362
- let numElements;
363
-
364
- switch ( this.type ) {
365
-
366
- case FloatType:
367
-
368
- numElements = image_rgba_data.length / 4;
369
- const floatArray = new Float32Array( numElements * 4 );
370
-
371
- for ( let j = 0; j < numElements; j ++ ) {
372
-
373
- RGBEByteToRGBFloat( image_rgba_data, j * 4, floatArray, j * 4 );
374
-
375
- }
376
-
377
- data = floatArray;
378
- type = FloatType;
379
- break;
380
-
381
- case HalfFloatType:
382
-
383
- numElements = image_rgba_data.length / 4;
384
- const halfArray = new Uint16Array( numElements * 4 );
385
-
386
- for ( let j = 0; j < numElements; j ++ ) {
387
-
388
- RGBEByteToRGBHalf( image_rgba_data, j * 4, halfArray, j * 4 );
389
-
390
- }
391
-
392
- data = halfArray;
393
- type = HalfFloatType;
394
- break;
395
-
396
- default:
397
-
398
- throw new Error( 'THREE.RGBELoader: Unsupported type: ' + this.type );
399
- break;
400
-
401
- }
402
-
403
- return {
404
- width: w, height: h,
405
- data: data,
406
- header: rgbe_header_info.string,
407
- gamma: rgbe_header_info.gamma,
408
- exposure: rgbe_header_info.exposure,
409
- type: type
410
- };
411
-
412
- }
413
-
414
- setDataType( value ) {
415
-
416
- this.type = value;
417
- return this;
418
-
419
- }
420
-
421
- load( url, onLoad, onProgress, onError ) {
422
-
423
- function onLoadCallback( texture, texData ) {
424
-
425
- switch ( texture.type ) {
426
-
427
- case FloatType:
428
- case HalfFloatType:
429
-
430
- texture.colorSpace = LinearSRGBColorSpace;
431
- texture.minFilter = LinearFilter;
432
- texture.magFilter = LinearFilter;
433
- texture.generateMipmaps = false;
434
- texture.flipY = true;
435
-
436
- break;
437
-
438
- }
439
-
440
- if ( onLoad ) onLoad( texture, texData );
441
-
442
- }
443
-
444
- return super.load( url, onLoadCallback, onProgress, onError );
445
-
446
- }
447
-
448
- }
449
-
450
- export { RGBELoader };
@@ -1,148 +0,0 @@
1
- /**
2
- * https://github.com/google/model-viewer/blob/master/packages/model-viewer/src/three-components/EnvironmentScene.ts
3
- */
4
-
5
- import {
6
- BackSide,
7
- BoxGeometry,
8
- Mesh,
9
- MeshBasicMaterial,
10
- MeshStandardMaterial,
11
- PointLight,
12
- Scene,
13
- } from 'three';
14
-
15
- class RoomEnvironment extends Scene {
16
-
17
- constructor( renderer = null ) {
18
-
19
- super();
20
-
21
- const geometry = new BoxGeometry();
22
- geometry.deleteAttribute( 'uv' );
23
-
24
- const roomMaterial = new MeshStandardMaterial( { side: BackSide } );
25
- const boxMaterial = new MeshStandardMaterial();
26
-
27
- let intensity = 5;
28
-
29
- if ( renderer !== null && renderer._useLegacyLights === false ) intensity = 900;
30
-
31
- const mainLight = new PointLight( 0xffffff, intensity, 28, 2 );
32
- mainLight.position.set( 0.418, 16.199, 0.300 );
33
- this.add( mainLight );
34
-
35
- const room = new Mesh( geometry, roomMaterial );
36
- room.position.set( - 0.757, 13.219, 0.717 );
37
- room.scale.set( 31.713, 28.305, 28.591 );
38
- this.add( room );
39
-
40
- const box1 = new Mesh( geometry, boxMaterial );
41
- box1.position.set( - 10.906, 2.009, 1.846 );
42
- box1.rotation.set( 0, - 0.195, 0 );
43
- box1.scale.set( 2.328, 7.905, 4.651 );
44
- this.add( box1 );
45
-
46
- const box2 = new Mesh( geometry, boxMaterial );
47
- box2.position.set( - 5.607, - 0.754, - 0.758 );
48
- box2.rotation.set( 0, 0.994, 0 );
49
- box2.scale.set( 1.970, 1.534, 3.955 );
50
- this.add( box2 );
51
-
52
- const box3 = new Mesh( geometry, boxMaterial );
53
- box3.position.set( 6.167, 0.857, 7.803 );
54
- box3.rotation.set( 0, 0.561, 0 );
55
- box3.scale.set( 3.927, 6.285, 3.687 );
56
- this.add( box3 );
57
-
58
- const box4 = new Mesh( geometry, boxMaterial );
59
- box4.position.set( - 2.017, 0.018, 6.124 );
60
- box4.rotation.set( 0, 0.333, 0 );
61
- box4.scale.set( 2.002, 4.566, 2.064 );
62
- this.add( box4 );
63
-
64
- const box5 = new Mesh( geometry, boxMaterial );
65
- box5.position.set( 2.291, - 0.756, - 2.621 );
66
- box5.rotation.set( 0, - 0.286, 0 );
67
- box5.scale.set( 1.546, 1.552, 1.496 );
68
- this.add( box5 );
69
-
70
- const box6 = new Mesh( geometry, boxMaterial );
71
- box6.position.set( - 2.193, - 0.369, - 5.547 );
72
- box6.rotation.set( 0, 0.516, 0 );
73
- box6.scale.set( 3.875, 3.487, 2.986 );
74
- this.add( box6 );
75
-
76
-
77
- // -x right
78
- const light1 = new Mesh( geometry, createAreaLightMaterial( 50 ) );
79
- light1.position.set( - 16.116, 14.37, 8.208 );
80
- light1.scale.set( 0.1, 2.428, 2.739 );
81
- this.add( light1 );
82
-
83
- // -x left
84
- const light2 = new Mesh( geometry, createAreaLightMaterial( 50 ) );
85
- light2.position.set( - 16.109, 18.021, - 8.207 );
86
- light2.scale.set( 0.1, 2.425, 2.751 );
87
- this.add( light2 );
88
-
89
- // +x
90
- const light3 = new Mesh( geometry, createAreaLightMaterial( 17 ) );
91
- light3.position.set( 14.904, 12.198, - 1.832 );
92
- light3.scale.set( 0.15, 4.265, 6.331 );
93
- this.add( light3 );
94
-
95
- // +z
96
- const light4 = new Mesh( geometry, createAreaLightMaterial( 43 ) );
97
- light4.position.set( - 0.462, 8.89, 14.520 );
98
- light4.scale.set( 4.38, 5.441, 0.088 );
99
- this.add( light4 );
100
-
101
- // -z
102
- const light5 = new Mesh( geometry, createAreaLightMaterial( 20 ) );
103
- light5.position.set( 3.235, 11.486, - 12.541 );
104
- light5.scale.set( 2.5, 2.0, 0.1 );
105
- this.add( light5 );
106
-
107
- // +y
108
- const light6 = new Mesh( geometry, createAreaLightMaterial( 100 ) );
109
- light6.position.set( 0.0, 20.0, 0.0 );
110
- light6.scale.set( 1.0, 0.1, 1.0 );
111
- this.add( light6 );
112
-
113
- }
114
-
115
- dispose() {
116
-
117
- const resources = new Set();
118
-
119
- this.traverse( ( object ) => {
120
-
121
- if ( object.isMesh ) {
122
-
123
- resources.add( object.geometry );
124
- resources.add( object.material );
125
-
126
- }
127
-
128
- } );
129
-
130
- for ( const resource of resources ) {
131
-
132
- resource.dispose();
133
-
134
- }
135
-
136
- }
137
-
138
- }
139
-
140
- function createAreaLightMaterial( intensity ) {
141
-
142
- const material = new MeshBasicMaterial();
143
- material.color.setScalar( intensity );
144
- return material;
145
-
146
- }
147
-
148
- export { RoomEnvironment };