@shapediver/viewer.rendering-engine.rendering-engine-threejs 3.3.4 → 3.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +19 -20
- package/src/RenderingEngine.ts +0 -1336
- package/src/index.ts +0 -81
- package/src/injectors/Tag3dGeometryCreationInjector.ts +0 -154
- package/src/injectors/TextureUnifierInjector.ts +0 -214
- package/src/interfaces/ILoader.ts +0 -3
- package/src/interfaces/IPostProcessingEffectDefinitions.ts +0 -402
- package/src/interfaces/IRenderingEngine.ts +0 -48
- package/src/loaders/EnvironmentMapLoader.ts +0 -357
- package/src/loaders/GeometryLoader.ts +0 -585
- package/src/loaders/HTMLElementAnchorLoader.ts +0 -107
- package/src/loaders/LightLoader.ts +0 -171
- package/src/loaders/MaterialLoader.ts +0 -1413
- package/src/managers/CameraManager.ts +0 -178
- package/src/managers/EnvironmentGeometryManager.ts +0 -224
- package/src/managers/PostProcessingManager.ts +0 -1181
- package/src/managers/RenderingManager.ts +0 -657
- package/src/managers/SceneTracingManager.ts +0 -127
- package/src/managers/SceneTreeManager.ts +0 -576
- package/src/managers/postprocessing/GodRaysManager.ts +0 -52
- package/src/managers/postprocessing/OutlineManager.ts +0 -58
- package/src/managers/postprocessing/SSAARenderPass.ts +0 -339
- package/src/managers/postprocessing/SelectiveBloomManager.ts +0 -58
- package/src/managers/postprocessing/ao/ao/AOEffect.ts +0 -180
- package/src/managers/postprocessing/ao/ao/AOPass.ts +0 -128
- package/src/managers/postprocessing/ao/ao/shader/ao_compose.glsl +0 -17
- package/src/managers/postprocessing/ao/ao/shader/ao_compose.ts +0 -19
- package/src/managers/postprocessing/ao/hbao/HBAOEffect.ts +0 -41
- package/src/managers/postprocessing/ao/hbao/shader/hbao.glsl +0 -96
- package/src/managers/postprocessing/ao/hbao/shader/hbao.ts +0 -98
- package/src/managers/postprocessing/ao/hbao/shader/hbao_utils.glsl +0 -92
- package/src/managers/postprocessing/ao/hbao/shader/hbao_utils.ts +0 -95
- package/src/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.ts +0 -259
- package/src/managers/postprocessing/ao/poissionDenoise/shader/poissionDenoise.glsl +0 -125
- package/src/managers/postprocessing/ao/poissionDenoise/shader/poissionDenoise.ts +0 -127
- package/src/managers/postprocessing/ao/ssao/SSAOEffect.ts +0 -106
- package/src/managers/postprocessing/ao/ssao/shader/ssao.glsl +0 -128
- package/src/managers/postprocessing/ao/ssao/shader/ssao.ts +0 -130
- package/src/managers/postprocessing/ao/utils/shader/basic.glsl +0 -6
- package/src/managers/postprocessing/ao/utils/shader/basic.ts +0 -8
- package/src/managers/postprocessing/ao/utils/shader/sampleBlueNoise.glsl +0 -36
- package/src/managers/postprocessing/ao/utils/shader/sampleBlueNoise.ts +0 -38
- package/src/managers/postprocessing/utils/CopyMaterial.ts +0 -130
- package/src/managers/postprocessing/utils/CopyShader.ts +0 -39
- package/src/managers/postprocessing/utils/FullScreenQuad.ts +0 -47
- package/src/managers/postprocessing/utils/NormalPass.ts +0 -222
- package/src/managers/postprocessing/utils/RenderPass.ts +0 -366
- package/src/materials/GemMaterial.ts +0 -268
- package/src/materials/MeshUnlitMaterialParameters.ts +0 -4
- package/src/materials/MultiPointsMaterial.ts +0 -646
- package/src/materials/SpecularGlossinessMaterial.ts +0 -182
- package/src/objects/SDBone.ts +0 -51
- package/src/objects/SDColor.ts +0 -54
- package/src/objects/SDData.ts +0 -44
- package/src/objects/SDObject.ts +0 -58
- package/src/shaders/PCSS.ts +0 -124
- package/src/shaders/gem.ts +0 -579
- package/src/shaders/gem_frag.glsl +0 -522
- package/src/shaders/gem_vert.glsl +0 -53
- package/src/shaders/multi_points.ts +0 -291
- package/src/shaders/multi_points_frag.glsl +0 -166
- package/src/shaders/multi_points_vert.glsl +0 -120
- package/src/styling/viewport-css.ts +0 -113
- package/src/styling/viewport.css +0 -111
- package/src/three/font.ts +0 -2
- package/src/three/geometries/TextGeometry.ts +0 -58
- package/src/three/loaders/FontLoader.ts +0 -205
- package/src/three/loaders/RGBELoader.ts +0 -496
- package/src/types/IThreejsData.ts +0 -16
- package/src/types/ThreejsData.ts +0 -43
- package/tsconfig.json +0 -20
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import {
|
|
3
|
-
FileLoader,
|
|
4
|
-
Loader,
|
|
5
|
-
LoadingManager,
|
|
6
|
-
ShapePath
|
|
7
|
-
} from 'three';
|
|
8
|
-
|
|
9
|
-
class FontLoader extends Loader {
|
|
10
|
-
|
|
11
|
-
constructor( manager: LoadingManager | undefined ) {
|
|
12
|
-
|
|
13
|
-
super( manager );
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
load( url: string,
|
|
18
|
-
onLoad?: (responseFont: Font) => void,
|
|
19
|
-
onProgress?: (event: ProgressEvent) => void,
|
|
20
|
-
onError?: (event: unknown) => void, ) {
|
|
21
|
-
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
23
|
-
const scope = this;
|
|
24
|
-
|
|
25
|
-
const loader = new FileLoader( this.manager );
|
|
26
|
-
loader.setPath( this.path );
|
|
27
|
-
loader.setRequestHeader( this.requestHeader );
|
|
28
|
-
loader.setWithCredentials( scope.withCredentials );
|
|
29
|
-
loader.load( url, function ( text ) {
|
|
30
|
-
|
|
31
|
-
let json;
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
|
|
35
|
-
json = JSON.parse( (text as string) );
|
|
36
|
-
|
|
37
|
-
} catch ( e ) {
|
|
38
|
-
|
|
39
|
-
console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
|
|
40
|
-
json = JSON.parse( (text as string).substring( 65, (text as string).length - 2 ) );
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const font = scope.parse( json );
|
|
45
|
-
|
|
46
|
-
if ( onLoad ) onLoad( font );
|
|
47
|
-
|
|
48
|
-
}, onProgress, onError );
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
parse( json: any ) {
|
|
53
|
-
|
|
54
|
-
return new Font( json );
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
class Font {
|
|
63
|
-
data: any;
|
|
64
|
-
type: string;
|
|
65
|
-
isFont: boolean = true;
|
|
66
|
-
|
|
67
|
-
constructor( data: any ) {
|
|
68
|
-
|
|
69
|
-
this.type = 'Font';
|
|
70
|
-
|
|
71
|
-
this.data = data;
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
generateShapes( text: any, size = 100 ) {
|
|
76
|
-
|
|
77
|
-
const shapes: any[] = [];
|
|
78
|
-
const paths = createPaths( text, size, this.data );
|
|
79
|
-
|
|
80
|
-
for ( let p = 0, pl = paths.length; p < pl; p ++ ) {
|
|
81
|
-
|
|
82
|
-
Array.prototype.push.apply( shapes, (paths[ p ] as any).toShapes() );
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return shapes;
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function createPaths( text: Iterable<unknown> | ArrayLike<unknown>, size: number, data: { resolution: number; boundingBox: { yMax: number; yMin: number; }; underlineThickness: number; } ) {
|
|
93
|
-
|
|
94
|
-
const chars = Array.from( text );
|
|
95
|
-
const scale = size / data.resolution;
|
|
96
|
-
const line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
|
|
97
|
-
|
|
98
|
-
const paths = [];
|
|
99
|
-
|
|
100
|
-
let offsetX = 0, offsetY = 0;
|
|
101
|
-
|
|
102
|
-
for ( let i = 0; i < chars.length; i ++ ) {
|
|
103
|
-
|
|
104
|
-
const char = chars[ i ];
|
|
105
|
-
|
|
106
|
-
if ( char === '\n' ) {
|
|
107
|
-
|
|
108
|
-
offsetX = 0;
|
|
109
|
-
offsetY -= line_height;
|
|
110
|
-
|
|
111
|
-
} else {
|
|
112
|
-
|
|
113
|
-
const ret = createPath( char, scale, offsetX, offsetY, data )!;
|
|
114
|
-
offsetX += ret.offsetX;
|
|
115
|
-
paths.push( ret.path );
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return paths;
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function createPath( char: any, scale: number, offsetX: number, offsetY: number, data: { resolution?: number; boundingBox?: { yMax: number; yMin: number; }; underlineThickness?: number; glyphs?: any; familyName?: any; } ) {
|
|
126
|
-
|
|
127
|
-
const glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
|
|
128
|
-
|
|
129
|
-
if ( ! glyph ) {
|
|
130
|
-
|
|
131
|
-
console.error( 'THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.' );
|
|
132
|
-
|
|
133
|
-
return;
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const path = new ShapePath();
|
|
138
|
-
|
|
139
|
-
let x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
|
|
140
|
-
|
|
141
|
-
if ( glyph.o ) {
|
|
142
|
-
|
|
143
|
-
const outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
|
|
144
|
-
|
|
145
|
-
for ( let i = 0, l = outline.length; i < l; ) {
|
|
146
|
-
|
|
147
|
-
const action = outline[ i ++ ];
|
|
148
|
-
|
|
149
|
-
switch ( action ) {
|
|
150
|
-
|
|
151
|
-
case 'm': // moveTo
|
|
152
|
-
|
|
153
|
-
x = outline[ i ++ ] * scale + offsetX;
|
|
154
|
-
y = outline[ i ++ ] * scale + offsetY;
|
|
155
|
-
|
|
156
|
-
path.moveTo( x, y );
|
|
157
|
-
|
|
158
|
-
break;
|
|
159
|
-
|
|
160
|
-
case 'l': // lineTo
|
|
161
|
-
|
|
162
|
-
x = outline[ i ++ ] * scale + offsetX;
|
|
163
|
-
y = outline[ i ++ ] * scale + offsetY;
|
|
164
|
-
|
|
165
|
-
path.lineTo( x, y );
|
|
166
|
-
|
|
167
|
-
break;
|
|
168
|
-
|
|
169
|
-
case 'q': // quadraticCurveTo
|
|
170
|
-
|
|
171
|
-
cpx = outline[ i ++ ] * scale + offsetX;
|
|
172
|
-
cpy = outline[ i ++ ] * scale + offsetY;
|
|
173
|
-
cpx1 = outline[ i ++ ] * scale + offsetX;
|
|
174
|
-
cpy1 = outline[ i ++ ] * scale + offsetY;
|
|
175
|
-
|
|
176
|
-
path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
|
|
177
|
-
|
|
178
|
-
break;
|
|
179
|
-
|
|
180
|
-
case 'b': // bezierCurveTo
|
|
181
|
-
|
|
182
|
-
cpx = outline[ i ++ ] * scale + offsetX;
|
|
183
|
-
cpy = outline[ i ++ ] * scale + offsetY;
|
|
184
|
-
cpx1 = outline[ i ++ ] * scale + offsetX;
|
|
185
|
-
cpy1 = outline[ i ++ ] * scale + offsetY;
|
|
186
|
-
cpx2 = outline[ i ++ ] * scale + offsetX;
|
|
187
|
-
cpy2 = outline[ i ++ ] * scale + offsetY;
|
|
188
|
-
|
|
189
|
-
path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
|
|
190
|
-
|
|
191
|
-
break;
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return { offsetX: glyph.ha * scale, path: path };
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
Font.prototype.isFont = true;
|
|
204
|
-
|
|
205
|
-
export { FontLoader, Font };
|
|
@@ -1,496 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-case-declarations */
|
|
2
|
-
/* eslint-disable no-cond-assign */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
-
import {
|
|
5
|
-
DataTextureLoader,
|
|
6
|
-
DataUtils,
|
|
7
|
-
FloatType,
|
|
8
|
-
HalfFloatType,
|
|
9
|
-
LinearFilter,
|
|
10
|
-
LinearSRGBColorSpace,
|
|
11
|
-
LoadingManager,
|
|
12
|
-
PixelFormat,
|
|
13
|
-
TextureDataType
|
|
14
|
-
} from 'three';
|
|
15
|
-
|
|
16
|
-
export interface RGBE {
|
|
17
|
-
width: number;
|
|
18
|
-
height: number;
|
|
19
|
-
data: Float32Array | Uint8Array;
|
|
20
|
-
header: string;
|
|
21
|
-
gamma: number;
|
|
22
|
-
exposure: number;
|
|
23
|
-
format: PixelFormat;
|
|
24
|
-
type: TextureDataType;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// https://github.com/mrdoob/three.js/issues/5552
|
|
28
|
-
// http://en.wikipedia.org/wiki/RGBE_image_format
|
|
29
|
-
|
|
30
|
-
class RGBELoader extends DataTextureLoader {
|
|
31
|
-
type: number;
|
|
32
|
-
|
|
33
|
-
constructor( manager?: LoadingManager ) {
|
|
34
|
-
|
|
35
|
-
super( manager );
|
|
36
|
-
|
|
37
|
-
this.type = HalfFloatType;
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// adapted from http://www.graphics.cornell.edu/~bjw/rgbe.html
|
|
42
|
-
|
|
43
|
-
parse(buffer: ArrayBuffer): RGBE{
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
/* return codes for rgbe routines */
|
|
47
|
-
//RGBE_RETURN_SUCCESS = 0,
|
|
48
|
-
RGBE_RETURN_FAILURE = - 1,
|
|
49
|
-
|
|
50
|
-
/* default error routine. change this to change error handling */
|
|
51
|
-
rgbe_read_error = 1,
|
|
52
|
-
rgbe_write_error = 2,
|
|
53
|
-
rgbe_format_error = 3,
|
|
54
|
-
rgbe_memory_error = 4,
|
|
55
|
-
rgbe_error = function ( rgbe_error_code: number, msg: string | undefined ) {
|
|
56
|
-
|
|
57
|
-
switch ( rgbe_error_code ) {
|
|
58
|
-
|
|
59
|
-
case rgbe_read_error: console.error( 'THREE.RGBELoader Read Error: ' + ( msg || '' ) );
|
|
60
|
-
break;
|
|
61
|
-
case rgbe_write_error: console.error( 'THREE.RGBELoader Write Error: ' + ( msg || '' ) );
|
|
62
|
-
break;
|
|
63
|
-
case rgbe_format_error: console.error( 'THREE.RGBELoader Bad File Format: ' + ( msg || '' ) );
|
|
64
|
-
break;
|
|
65
|
-
default:
|
|
66
|
-
case rgbe_memory_error: console.error( 'THREE.RGBELoader: Error: ' + ( msg || '' ) );
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return RGBE_RETURN_FAILURE;
|
|
71
|
-
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
/* offsets to red, green, and blue components in a data (float) pixel */
|
|
75
|
-
//RGBE_DATA_RED = 0,
|
|
76
|
-
//RGBE_DATA_GREEN = 1,
|
|
77
|
-
//RGBE_DATA_BLUE = 2,
|
|
78
|
-
|
|
79
|
-
/* number of floats per pixel, use 4 since stored in rgba image format */
|
|
80
|
-
//RGBE_DATA_SIZE = 4,
|
|
81
|
-
|
|
82
|
-
/* flags indicating which fields in an rgbe_header_info are valid */
|
|
83
|
-
RGBE_VALID_PROGRAMTYPE = 1,
|
|
84
|
-
RGBE_VALID_FORMAT = 2,
|
|
85
|
-
RGBE_VALID_DIMENSIONS = 4,
|
|
86
|
-
|
|
87
|
-
NEWLINE = '\n',
|
|
88
|
-
|
|
89
|
-
fgets = function ( buffer: { pos: number; subarray: (arg0: any, arg1: any) => Iterable<number>; byteLength: number; }, lineLimit: number | undefined, consume: boolean | undefined ) {
|
|
90
|
-
|
|
91
|
-
const chunkSize = 128;
|
|
92
|
-
|
|
93
|
-
lineLimit = ! lineLimit ? 1024 : lineLimit;
|
|
94
|
-
let p = buffer.pos,
|
|
95
|
-
i = - 1, len = 0, s = '',
|
|
96
|
-
chunk = String.fromCharCode.apply( null, new Uint16Array( buffer.subarray( p, p + chunkSize ) ) as any );
|
|
97
|
-
|
|
98
|
-
while ( ( 0 > ( i = chunk.indexOf( NEWLINE ) ) ) && ( len < lineLimit ) && ( p < buffer.byteLength ) ) {
|
|
99
|
-
|
|
100
|
-
s += chunk; len += chunk.length;
|
|
101
|
-
p += chunkSize;
|
|
102
|
-
chunk += String.fromCharCode.apply( null, new Uint16Array( buffer.subarray( p, p + chunkSize ) ) as any );
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if ( - 1 < i ) {
|
|
107
|
-
|
|
108
|
-
/*for (i=l-1; i>=0; i--) {
|
|
109
|
-
byteCode = m.charCodeAt(i);
|
|
110
|
-
if (byteCode > 0x7f && byteCode <= 0x7ff) byteLen++;
|
|
111
|
-
else if (byteCode > 0x7ff && byteCode <= 0xffff) byteLen += 2;
|
|
112
|
-
if (byteCode >= 0xDC00 && byteCode <= 0xDFFF) i--; //trail surrogate
|
|
113
|
-
}*/
|
|
114
|
-
if ( false !== consume ) buffer.pos += len + i + 1;
|
|
115
|
-
return s + chunk.slice( 0, i );
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return false;
|
|
120
|
-
|
|
121
|
-
},
|
|
122
|
-
|
|
123
|
-
/* minimal header reading. modify if you want to parse more information */
|
|
124
|
-
RGBE_ReadHeader = function ( buffer: Uint8Array ) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
// regexes to parse header info fields
|
|
128
|
-
const magic_token_re = /^#\?(\S+)/,
|
|
129
|
-
gamma_re = /^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,
|
|
130
|
-
exposure_re = /^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,
|
|
131
|
-
format_re = /^\s*FORMAT=(\S+)\s*$/,
|
|
132
|
-
// eslint-disable-next-line no-useless-escape
|
|
133
|
-
dimensions_re = /^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,
|
|
134
|
-
|
|
135
|
-
// RGBE format header struct
|
|
136
|
-
header = {
|
|
137
|
-
|
|
138
|
-
valid: 0, /* indicate which fields are valid */
|
|
139
|
-
|
|
140
|
-
string: '', /* the actual header string */
|
|
141
|
-
|
|
142
|
-
comments: '', /* comments found in header */
|
|
143
|
-
|
|
144
|
-
programtype: 'RGBE', /* listed at beginning of file to identify it after "#?". defaults to "RGBE" */
|
|
145
|
-
|
|
146
|
-
format: '', /* RGBE format, default 32-bit_rle_rgbe */
|
|
147
|
-
|
|
148
|
-
gamma: 1.0, /* image has already been gamma corrected with given gamma. defaults to 1.0 (no correction) */
|
|
149
|
-
|
|
150
|
-
exposure: 1.0, /* a value of 1.0 in an image corresponds to <exposure> watts/steradian/m^2. defaults to 1.0 */
|
|
151
|
-
|
|
152
|
-
width: 0, height: 0 /* image dimensions, width/height */
|
|
153
|
-
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
let line, match;
|
|
157
|
-
|
|
158
|
-
if ( (buffer as any).pos >= buffer.byteLength || ! ( line = fgets( buffer as any, undefined, undefined ) ) ) {
|
|
159
|
-
|
|
160
|
-
return rgbe_error( rgbe_read_error, 'no header found' );
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/* if you want to require the magic token then uncomment the next line */
|
|
165
|
-
if ( ! ( match = (line as string).match( magic_token_re ) ) ) {
|
|
166
|
-
|
|
167
|
-
return rgbe_error( rgbe_format_error, 'bad initial token' );
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
header.valid |= RGBE_VALID_PROGRAMTYPE;
|
|
172
|
-
header.programtype = match[ 1 ];
|
|
173
|
-
header.string += line + '\n';
|
|
174
|
-
|
|
175
|
-
// eslint-disable-next-line no-constant-condition
|
|
176
|
-
while ( true ) {
|
|
177
|
-
|
|
178
|
-
line = fgets( buffer as any, undefined, undefined );
|
|
179
|
-
if ( false === line ) break;
|
|
180
|
-
header.string += line + '\n';
|
|
181
|
-
|
|
182
|
-
if ( '#' === (line as string).charAt( 0 ) ) {
|
|
183
|
-
|
|
184
|
-
header.comments += line + '\n';
|
|
185
|
-
continue; // comment line
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if ( match = (line as string).match( gamma_re ) ) {
|
|
190
|
-
|
|
191
|
-
header.gamma = parseFloat( match[ 1 ] );
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if ( match = (line as string).match( exposure_re ) ) {
|
|
196
|
-
|
|
197
|
-
header.exposure = parseFloat( match[ 1 ] );
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if ( match = (line as string).match( format_re ) ) {
|
|
202
|
-
|
|
203
|
-
header.valid |= RGBE_VALID_FORMAT;
|
|
204
|
-
header.format = match[ 1 ];//'32-bit_rle_rgbe';
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if ( match = (line as string).match( dimensions_re ) ) {
|
|
209
|
-
|
|
210
|
-
header.valid |= RGBE_VALID_DIMENSIONS;
|
|
211
|
-
header.height = parseInt( match[ 1 ], 10 );
|
|
212
|
-
header.width = parseInt( match[ 2 ], 10 );
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if ( ( header.valid & RGBE_VALID_FORMAT ) && ( header.valid & RGBE_VALID_DIMENSIONS ) ) break;
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if ( ! ( header.valid & RGBE_VALID_FORMAT ) ) {
|
|
221
|
-
|
|
222
|
-
return rgbe_error( rgbe_format_error, 'missing format specifier' );
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if ( ! ( header.valid & RGBE_VALID_DIMENSIONS ) ) {
|
|
227
|
-
|
|
228
|
-
return rgbe_error( rgbe_format_error, 'missing image size specifier' );
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return header;
|
|
233
|
-
|
|
234
|
-
},
|
|
235
|
-
|
|
236
|
-
RGBE_ReadPixels_RLE = function ( buffer: any, w: number, h: number ) {
|
|
237
|
-
|
|
238
|
-
const scanline_width = w;
|
|
239
|
-
|
|
240
|
-
if (
|
|
241
|
-
// run length encoding is not allowed so read flat
|
|
242
|
-
( ( scanline_width < 8 ) || ( scanline_width > 0x7fff ) ) ||
|
|
243
|
-
// this file is not run length encoded
|
|
244
|
-
( ( 2 !== buffer[ 0 ] ) || ( 2 !== buffer[ 1 ] ) || ( buffer[ 2 ] & 0x80 ) )
|
|
245
|
-
) {
|
|
246
|
-
|
|
247
|
-
// return the flat buffer
|
|
248
|
-
return new Uint8Array( buffer );
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if ( scanline_width !== ( ( buffer[ 2 ] << 8 ) | buffer[ 3 ] ) ) {
|
|
253
|
-
|
|
254
|
-
return rgbe_error( rgbe_format_error, 'wrong scanline width' );
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const data_rgba = new Uint8Array( 4 * w * h );
|
|
259
|
-
|
|
260
|
-
if ( ! data_rgba.length ) {
|
|
261
|
-
|
|
262
|
-
return rgbe_error( rgbe_memory_error, 'unable to allocate buffer space' );
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
let offset = 0, pos = 0;
|
|
267
|
-
|
|
268
|
-
const ptr_end = 4 * scanline_width;
|
|
269
|
-
const rgbeStart = new Uint8Array( 4 );
|
|
270
|
-
const scanline_buffer = new Uint8Array( ptr_end );
|
|
271
|
-
let num_scanlines = h;
|
|
272
|
-
|
|
273
|
-
// read in each successive scanline
|
|
274
|
-
while ( ( num_scanlines > 0 ) && ( pos < buffer.byteLength ) ) {
|
|
275
|
-
|
|
276
|
-
if ( pos + 4 > buffer.byteLength ) {
|
|
277
|
-
|
|
278
|
-
return rgbe_error( rgbe_read_error, undefined );
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
rgbeStart[ 0 ] = buffer[ pos ++ ];
|
|
283
|
-
rgbeStart[ 1 ] = buffer[ pos ++ ];
|
|
284
|
-
rgbeStart[ 2 ] = buffer[ pos ++ ];
|
|
285
|
-
rgbeStart[ 3 ] = buffer[ pos ++ ];
|
|
286
|
-
|
|
287
|
-
if ( ( 2 != rgbeStart[ 0 ] ) || ( 2 != rgbeStart[ 1 ] ) || ( ( ( rgbeStart[ 2 ] << 8 ) | rgbeStart[ 3 ] ) != scanline_width ) ) {
|
|
288
|
-
|
|
289
|
-
return rgbe_error( rgbe_format_error, 'bad rgbe scanline format' );
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
// read each of the four channels for the scanline into the buffer
|
|
294
|
-
// first red, then green, then blue, then exponent
|
|
295
|
-
let ptr = 0, count;
|
|
296
|
-
|
|
297
|
-
while ( ( ptr < ptr_end ) && ( pos < buffer.byteLength ) ) {
|
|
298
|
-
|
|
299
|
-
count = buffer[ pos ++ ];
|
|
300
|
-
const isEncodedRun = count > 128;
|
|
301
|
-
if ( isEncodedRun ) count -= 128;
|
|
302
|
-
|
|
303
|
-
if ( ( 0 === count ) || ( ptr + count > ptr_end ) ) {
|
|
304
|
-
|
|
305
|
-
return rgbe_error( rgbe_format_error, 'bad scanline data' );
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
if ( isEncodedRun ) {
|
|
310
|
-
|
|
311
|
-
// a (encoded) run of the same value
|
|
312
|
-
const byteValue = buffer[ pos ++ ];
|
|
313
|
-
for ( let i = 0; i < count; i ++ ) {
|
|
314
|
-
|
|
315
|
-
scanline_buffer[ ptr ++ ] = byteValue;
|
|
316
|
-
|
|
317
|
-
}
|
|
318
|
-
//ptr += count;
|
|
319
|
-
|
|
320
|
-
} else {
|
|
321
|
-
|
|
322
|
-
// a literal-run
|
|
323
|
-
scanline_buffer.set( buffer.subarray( pos, pos + count ), ptr );
|
|
324
|
-
ptr += count; pos += count;
|
|
325
|
-
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
// now convert data from buffer into rgba
|
|
332
|
-
// first red, then green, then blue, then exponent (alpha)
|
|
333
|
-
const l = scanline_width; //scanline_buffer.byteLength;
|
|
334
|
-
for ( let i = 0; i < l; i ++ ) {
|
|
335
|
-
|
|
336
|
-
let off = 0;
|
|
337
|
-
data_rgba[ offset ] = scanline_buffer[ i + off ];
|
|
338
|
-
off += scanline_width; //1;
|
|
339
|
-
data_rgba[ offset + 1 ] = scanline_buffer[ i + off ];
|
|
340
|
-
off += scanline_width; //1;
|
|
341
|
-
data_rgba[ offset + 2 ] = scanline_buffer[ i + off ];
|
|
342
|
-
off += scanline_width; //1;
|
|
343
|
-
data_rgba[ offset + 3 ] = scanline_buffer[ i + off ];
|
|
344
|
-
offset += 4;
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
num_scanlines --;
|
|
349
|
-
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
return data_rgba;
|
|
353
|
-
|
|
354
|
-
};
|
|
355
|
-
|
|
356
|
-
const RGBEByteToRGBFloat = function ( sourceArray: any, sourceOffset: number, destArray: Float32Array, destOffset: number ) {
|
|
357
|
-
|
|
358
|
-
const e = sourceArray[ sourceOffset + 3 ];
|
|
359
|
-
const scale = Math.pow( 2.0, e - 128.0 ) / 255.0;
|
|
360
|
-
|
|
361
|
-
destArray[ destOffset + 0 ] = sourceArray[ sourceOffset + 0 ] * scale;
|
|
362
|
-
destArray[ destOffset + 1 ] = sourceArray[ sourceOffset + 1 ] * scale;
|
|
363
|
-
destArray[ destOffset + 2 ] = sourceArray[ sourceOffset + 2 ] * scale;
|
|
364
|
-
destArray[ destOffset + 3 ] = 1;
|
|
365
|
-
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
const RGBEByteToRGBHalf = function ( sourceArray: any, sourceOffset: number, destArray: Uint16Array, destOffset: number ) {
|
|
369
|
-
|
|
370
|
-
const e = sourceArray[ sourceOffset + 3 ];
|
|
371
|
-
const scale = Math.pow( 2.0, e - 128.0 ) / 255.0;
|
|
372
|
-
|
|
373
|
-
// clamping to 65504, the maximum representable value in float16
|
|
374
|
-
destArray[ destOffset + 0 ] = DataUtils.toHalfFloat( Math.min( sourceArray[ sourceOffset + 0 ] * scale, 65504 ) );
|
|
375
|
-
destArray[ destOffset + 1 ] = DataUtils.toHalfFloat( Math.min( sourceArray[ sourceOffset + 1 ] * scale, 65504 ) );
|
|
376
|
-
destArray[ destOffset + 2 ] = DataUtils.toHalfFloat( Math.min( sourceArray[ sourceOffset + 2 ] * scale, 65504 ) );
|
|
377
|
-
destArray[ destOffset + 3 ] = DataUtils.toHalfFloat( 1 );
|
|
378
|
-
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
const byteArray = new Uint8Array( buffer ) as any;
|
|
382
|
-
byteArray.pos = 0;
|
|
383
|
-
const rgbe_header_info = RGBE_ReadHeader( byteArray ) as any;
|
|
384
|
-
|
|
385
|
-
if ( RGBE_RETURN_FAILURE !== rgbe_header_info ) {
|
|
386
|
-
|
|
387
|
-
const w = rgbe_header_info.width,
|
|
388
|
-
h = rgbe_header_info.height,
|
|
389
|
-
image_rgba_data = RGBE_ReadPixels_RLE( byteArray.subarray( byteArray.pos ), w, h );
|
|
390
|
-
|
|
391
|
-
if ( RGBE_RETURN_FAILURE !== image_rgba_data ) {
|
|
392
|
-
|
|
393
|
-
let data, format, type;
|
|
394
|
-
let numElements;
|
|
395
|
-
|
|
396
|
-
switch ( this.type ) {
|
|
397
|
-
|
|
398
|
-
case FloatType:
|
|
399
|
-
|
|
400
|
-
numElements = (image_rgba_data as Uint8Array).length / 4;
|
|
401
|
-
const floatArray = new Float32Array( numElements * 4 );
|
|
402
|
-
|
|
403
|
-
for ( let j = 0; j < numElements; j ++ ) {
|
|
404
|
-
|
|
405
|
-
RGBEByteToRGBFloat( image_rgba_data, j * 4, floatArray, j * 4 );
|
|
406
|
-
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
data = floatArray;
|
|
410
|
-
type = FloatType;
|
|
411
|
-
break;
|
|
412
|
-
|
|
413
|
-
case HalfFloatType:
|
|
414
|
-
|
|
415
|
-
numElements = (image_rgba_data as Uint8Array).length / 4;
|
|
416
|
-
const halfArray = new Uint16Array( numElements * 4 );
|
|
417
|
-
|
|
418
|
-
for ( let j = 0; j < numElements; j ++ ) {
|
|
419
|
-
|
|
420
|
-
RGBEByteToRGBHalf( image_rgba_data, j * 4, halfArray, j * 4 );
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
data = halfArray;
|
|
425
|
-
type = HalfFloatType;
|
|
426
|
-
break;
|
|
427
|
-
|
|
428
|
-
default:
|
|
429
|
-
|
|
430
|
-
console.error( 'THREE.RGBELoader: unsupported type: ', this.type );
|
|
431
|
-
break;
|
|
432
|
-
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
return {
|
|
436
|
-
width: w, height: h,
|
|
437
|
-
data: data as any,
|
|
438
|
-
header: rgbe_header_info.string,
|
|
439
|
-
gamma: rgbe_header_info.gamma,
|
|
440
|
-
exposure: rgbe_header_info.exposure,
|
|
441
|
-
format: format as any,
|
|
442
|
-
type: type as any
|
|
443
|
-
};
|
|
444
|
-
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
return null as any;
|
|
450
|
-
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
setDataType( value: number ) {
|
|
454
|
-
|
|
455
|
-
this.type = value;
|
|
456
|
-
return this;
|
|
457
|
-
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
load( url: string, onLoad: { (texture: any, texData: any): void; (texture: any): void; (arg0: any, arg1: any): void; }, onProgress: ((event: ProgressEvent<EventTarget>) => void) | undefined, onError: ((event: unknown) => void) | undefined ) {
|
|
461
|
-
|
|
462
|
-
function onLoadCallback( texture: { type: any; colorSpace: string; minFilter: number; magFilter: number; generateMipmaps: boolean; flipY: boolean; }, texData: any ) {
|
|
463
|
-
|
|
464
|
-
switch ( texture.type ) {
|
|
465
|
-
|
|
466
|
-
case FloatType:
|
|
467
|
-
|
|
468
|
-
texture.colorSpace = LinearSRGBColorSpace;
|
|
469
|
-
texture.minFilter = LinearFilter;
|
|
470
|
-
texture.magFilter = LinearFilter;
|
|
471
|
-
texture.generateMipmaps = false;
|
|
472
|
-
texture.flipY = true;
|
|
473
|
-
break;
|
|
474
|
-
|
|
475
|
-
case HalfFloatType:
|
|
476
|
-
|
|
477
|
-
texture.colorSpace = LinearSRGBColorSpace;
|
|
478
|
-
texture.minFilter = LinearFilter;
|
|
479
|
-
texture.magFilter = LinearFilter;
|
|
480
|
-
texture.generateMipmaps = false;
|
|
481
|
-
texture.flipY = true;
|
|
482
|
-
break;
|
|
483
|
-
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
if ( onLoad ) onLoad( texture, texData );
|
|
487
|
-
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
return super.load( url, onLoadCallback, onProgress, onError );
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
export { RGBELoader };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three'
|
|
2
|
-
import { ITreeNodeData } from '@shapediver/viewer.shared.node-tree'
|
|
3
|
-
|
|
4
|
-
export interface IThreejsData extends ITreeNodeData {
|
|
5
|
-
// #region Properties (1)
|
|
6
|
-
|
|
7
|
-
obj: THREE.Object3D;
|
|
8
|
-
|
|
9
|
-
// #endregion Properties (1)
|
|
10
|
-
|
|
11
|
-
// #region Public Methods (1)
|
|
12
|
-
|
|
13
|
-
clone(): IThreejsData;
|
|
14
|
-
|
|
15
|
-
// #endregion Public Methods (1)
|
|
16
|
-
}
|