@@ -21,61 +21,107 @@ const ZIP_COMPRESSION = 3;
21
21
22
22
class EXRExporter {
23
23
24
- parse ( renderer , renderTarget , options ) {
24
+ parse ( arg1 , arg2 , arg3 ) {
25
25
26
- if ( ! supported ( renderer , renderTarget ) ) return undefined ;
26
+ if ( ! arg1 || ! ( arg1 . isWebGLRenderer || arg1 . isDataTexture ) ) {
27
27
28
- const info = buildInfo ( renderTarget , options ) ,
29
- dataBuffer = getPixelData ( renderer , renderTarget , info ) ,
30
- rawContentBuffer = reorganizeDataBuffer ( dataBuffer , info ) ,
31
- chunks = compressData ( rawContentBuffer , info ) ;
28
+ throw Error ( 'EXRExporter.parse: Unsupported first parameter, expected instance of WebGLRenderer or DataTexture.' ) ;
32
29
33
- return fillData ( chunks , info ) ;
30
+ } else if ( arg1 . isWebGLRenderer ) {
34
31
35
- }
32
+ const renderer = arg1 , renderTarget = arg2 , options = arg3 ;
36
33
37
- }
34
+ supportedRTT ( renderTarget ) ;
35
+
36
+ const info = buildInfoRTT ( renderTarget , options ) ,
37
+ dataBuffer = getPixelData ( renderer , renderTarget , info ) ,
38
+ rawContentBuffer = reorganizeDataBuffer ( dataBuffer , info ) ,
39
+ chunks = compressData ( rawContentBuffer , info ) ;
40
+
41
+ return fillData ( chunks , info ) ;
38
42
39
- function supported ( renderer , renderTarget ) {
43
+ } else if ( arg1 . isDataTexture ) {
40
44
41
- if ( ! renderer || ! renderer . isWebGLRenderer ) {
45
+ const texture = arg1 , options = arg2 ;
42
46
43
- console . error ( 'EXRExporter.parse: Unsupported first parameter, expected instance of WebGLRenderer.' ) ;
47
+ supportedDT ( texture ) ;
44
48
45
- return false ;
49
+ const info = buildInfoDT ( texture , options ) ,
50
+ dataBuffer = texture . image . data ,
51
+ rawContentBuffer = reorganizeDataBuffer ( dataBuffer , info ) ,
52
+ chunks = compressData ( rawContentBuffer , info ) ;
53
+
54
+ return fillData ( chunks , info ) ;
55
+
56
+ }
46
57
47
58
}
48
59
60
+ }
61
+
62
+ function supportedRTT ( renderTarget ) {
63
+
49
64
if ( ! renderTarget || ! renderTarget . isWebGLRenderTarget ) {
50
65
51
- console . error ( 'EXRExporter.parse: Unsupported second parameter, expected instance of WebGLRenderTarget.' ) ;
66
+ throw Error ( 'EXRExporter.parse: Unsupported second parameter, expected instance of WebGLRenderTarget.' ) ;
67
+
68
+ }
69
+
70
+ if ( renderTarget . isWebGLCubeRenderTarget || renderTarget . isWebGL3DRenderTarget || renderTarget . isWebGLArrayRenderTarget ) {
52
71
53
- return false ;
72
+ throw Error ( 'EXRExporter.parse: Unsupported render target type, expected instance of WebGLRenderTarget.' ) ;
54
73
55
74
}
56
75
57
76
if ( renderTarget . texture . type !== FloatType && renderTarget . texture . type !== HalfFloatType ) {
58
77
59
- console . error ( 'EXRExporter.parse: Unsupported WebGLRenderTarget texture type.' ) ;
60
-
61
- return false ;
78
+ throw Error ( 'EXRExporter.parse: Unsupported WebGLRenderTarget texture type.' ) ;
62
79
63
80
}
64
81
65
82
if ( renderTarget . texture . format !== RGBAFormat ) {
66
83
67
- console . error ( 'EXRExporter.parse: Unsupported WebGLRenderTarget texture format, expected RGBAFormat.' ) ;
84
+ throw Error ( 'EXRExporter.parse: Unsupported WebGLRenderTarget texture format, expected RGBAFormat.' ) ;
85
+
86
+ }
87
+
88
+ }
89
+
90
+ function supportedDT ( texture ) {
91
+
92
+ if ( texture . type !== FloatType && texture . type !== HalfFloatType ) {
93
+
94
+ throw Error ( 'EXRExporter.parse: Unsupported DataTexture texture type.' ) ;
95
+
96
+ }
97
+
98
+ if ( texture . format !== RGBAFormat ) {
99
+
100
+ throw Error ( 'EXRExporter.parse: Unsupported DataTexture texture format, expected RGBAFormat.' ) ;
101
+
102
+ }
103
+
104
+ if ( ! texture . image . data ) {
105
+
106
+ throw Error ( 'EXRExporter.parse: Invalid DataTexture image data.' ) ;
107
+
108
+ }
109
+
110
+ if ( texture . type === FloatType && texture . image . data . constructor . name !== 'Float32Array' ) {
68
111
69
- return false ;
112
+ throw Error ( 'EXRExporter.parse: DataTexture image data doesn\'t match type, expected \'Float32Array\'.' ) ;
70
113
71
114
}
72
115
116
+ if ( texture . type === HalfFloatType && texture . image . data . constructor . name !== 'Uint16Array' ) {
73
117
74
- return true ;
118
+ throw Error ( 'EXRExporter.parse: DataTexture image data doesn\'t match type, expected \'Uint16Array\'.' ) ;
119
+
120
+ }
75
121
76
122
}
77
123
78
- function buildInfo ( renderTarget , options = { } ) {
124
+ function buildInfoRTT ( renderTarget , options = { } ) {
79
125
80
126
const compressionSizes = {
81
127
0 : 1 ,
@@ -87,7 +133,6 @@ function buildInfo( renderTarget, options = {} ) {
87
133
HEIGHT = renderTarget . height ,
88
134
TYPE = renderTarget . texture . type ,
89
135
FORMAT = renderTarget . texture . format ,
90
- COLOR_SPACE = renderTarget . texture . colorSpace ,
91
136
COMPRESSION = ( options . compression !== undefined ) ? options . compression : ZIP_COMPRESSION ,
92
137
EXPORTER_TYPE = ( options . type !== undefined ) ? options . type : HalfFloatType ,
93
138
OUT_TYPE = ( EXPORTER_TYPE === FloatType ) ? 2 : 1 ,
@@ -99,7 +144,40 @@ function buildInfo( renderTarget, options = {} ) {
99
144
height : HEIGHT ,
100
145
type : TYPE ,
101
146
format : FORMAT ,
102
- colorSpace : COLOR_SPACE ,
147
+ compression : COMPRESSION ,
148
+ blockLines : COMPRESSION_SIZE ,
149
+ dataType : OUT_TYPE ,
150
+ dataSize : 2 * OUT_TYPE ,
151
+ numBlocks : Math . ceil ( HEIGHT / COMPRESSION_SIZE ) ,
152
+ numInputChannels : 4 ,
153
+ numOutputChannels : NUM_CHANNELS ,
154
+ } ;
155
+
156
+ }
157
+
158
+ function buildInfoDT ( texture , options = { } ) {
159
+
160
+ const compressionSizes = {
161
+ 0 : 1 ,
162
+ 2 : 1 ,
163
+ 3 : 16
164
+ } ;
165
+
166
+ const WIDTH = texture . image . width ,
167
+ HEIGHT = texture . image . height ,
168
+ TYPE = texture . type ,
169
+ FORMAT = texture . format ,
170
+ COMPRESSION = ( options . compression !== undefined ) ? options . compression : ZIP_COMPRESSION ,
171
+ EXPORTER_TYPE = ( options . type !== undefined ) ? options . type : HalfFloatType ,
172
+ OUT_TYPE = ( EXPORTER_TYPE === FloatType ) ? 2 : 1 ,
173
+ COMPRESSION_SIZE = compressionSizes [ COMPRESSION ] ,
174
+ NUM_CHANNELS = 4 ;
175
+
176
+ return {
177
+ width : WIDTH ,
178
+ height : HEIGHT ,
179
+ type : TYPE ,
180
+ format : FORMAT ,
103
181
compression : COMPRESSION ,
104
182
blockLines : COMPRESSION_SIZE ,
105
183
dataType : OUT_TYPE ,
0 commit comments