Skip to content

Commit 7cfdced

Browse files
committed
GLTFExporter: Rebased and fixed WebGLUtils use on the exporter
1 parent 49eb4d6 commit 7cfdced

File tree

6 files changed

+64
-61
lines changed

6 files changed

+64
-61
lines changed

examples/js/exporters/GLTFExporter.js

+21-21
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ THREE.GLTFExporter.prototype = {
114114
}
115115

116116
var offset = 0;
117-
var componentSize = componentType === THREE.WEBGL_CONSTANTS.UNSIGNED_SHORT ? 2 : 4;
117+
var componentSize = componentType === THREE.WebGLConstants.UNSIGNED_SHORT ? 2 : 4;
118118

119119
// Create a new dataview and dump the attribute's array into it
120120
var byteLength = count * attribute.itemSize * componentSize;
@@ -127,15 +127,15 @@ THREE.GLTFExporter.prototype = {
127127

128128
var value = attribute.array[ i * attribute.itemSize + a ];
129129

130-
if ( componentType === THREE.WEBGL_CONSTANTS.FLOAT ) {
130+
if ( componentType === THREE.WebGLConstants.FLOAT ) {
131131

132132
dataView.setFloat32( offset, value, true );
133133

134-
} else if ( componentType === THREE.WEBGL_CONSTANTS.UNSIGNED_INT ) {
134+
} else if ( componentType === THREE.WebGLConstants.UNSIGNED_INT ) {
135135

136136
dataView.setUint8( offset, value, true );
137137

138-
} else if ( componentType === THREE.WEBGL_CONSTANTS.UNSIGNED_SHORT ) {
138+
} else if ( componentType === THREE.WebGLConstants.UNSIGNED_SHORT ) {
139139

140140
dataView.setUint16( offset, value, true );
141141

@@ -161,15 +161,15 @@ THREE.GLTFExporter.prototype = {
161161
*/
162162
function processBufferView ( data, componentType, start, count ) {
163163

164-
var isVertexAttributes = componentType === THREE.WEBGL_CONSTANTS.FLOAT;
164+
var isVertexAttributes = componentType === THREE.WebGLConstants.FLOAT;
165165

166166
if ( !outputJSON.bufferViews ) {
167167

168168
outputJSON.bufferViews = [];
169169

170170
}
171171

172-
var componentSize = componentType === WEBGL_CONSTANTS.UNSIGNED_SHORT ? 2 : 4;
172+
var componentSize = componentType === THREE.WebGLConstants.UNSIGNED_SHORT ? 2 : 4;
173173

174174
// Create a new dataview and dump the attribute's array into it
175175
var byteLength = count * data.itemSize * componentSize;
@@ -180,7 +180,7 @@ THREE.GLTFExporter.prototype = {
180180
byteOffset: byteOffset,
181181
byteLength: byteLength,
182182
byteStride: data.itemSize * componentSize,
183-
target: isVertexAttributes ? THREE.WEBGL_CONSTANTS.ARRAY_BUFFER : THREE.WEBGL_CONSTANTS.ELEMENT_ARRAY_BUFFER
183+
target: isVertexAttributes ? THREE.WebGLConstants.ARRAY_BUFFER : THREE.WebGLConstants.ELEMENT_ARRAY_BUFFER
184184

185185
};
186186

@@ -227,15 +227,15 @@ THREE.GLTFExporter.prototype = {
227227
// Detect the component type of the attribute array (float, uint or ushort)
228228
if ( attribute.array.constructor === Float32Array ) {
229229

230-
componentType = THREE.WEBGL_CONSTANTS.FLOAT;
230+
componentType = THREE.WebGLConstants.FLOAT;
231231

232232
} else if ( attribute.array.constructor === Uint32Array ) {
233233

234-
componentType = THREE.WEBGL_CONSTANTS.UNSIGNED_INT;
234+
componentType = THREE.WebGLConstants.UNSIGNED_INT;
235235

236236
} else if ( attribute.array.constructor === Uint16Array ) {
237237

238-
componentType = THREE.WEBGL_CONSTANTS.UNSIGNED_SHORT;
238+
componentType = THREE.WebGLConstants.UNSIGNED_SHORT;
239239

240240
} else {
241241

@@ -321,10 +321,10 @@ THREE.GLTFExporter.prototype = {
321321

322322
var gltfSampler = {
323323

324-
magFilter: THREE.THREE_TO_WEBGL[ map.magFilter ],
325-
minFilter: THREE.THREE_TO_WEBGL[ map.minFilter ],
326-
wrapS: THREE.THREE_TO_WEBGL[ map.wrapS ],
327-
wrapT: THREE.THREE_TO_WEBGL[ map.wrapT ]
324+
magFilter: THREE.WebGLUtils.toGL[ map.magFilter ],
325+
minFilter: THREE.WebGLUtils.toGL[ map.minFilter ],
326+
wrapS: THREE.WebGLUtils.toGL[ map.wrapS ],
327+
wrapT: THREE.WebGLUtils.toGL[ map.wrapT ]
328328

329329
};
330330

@@ -524,19 +524,19 @@ THREE.GLTFExporter.prototype = {
524524
// Use the correct mode
525525
if ( mesh instanceof THREE.LineSegments ) {
526526

527-
mode = THREE.WEBGL_CONSTANTS.LINES;
527+
mode = THREE.WebGLConstants.LINES;
528528

529529
} else if ( mesh instanceof THREE.LineLoop ) {
530530

531-
mode = THREE.WEBGL_CONSTANTS.LINE_LOOP;
531+
mode = THREE.WebGLConstants.LINE_LOOP;
532532

533533
} else if ( mesh instanceof THREE.Line ) {
534534

535-
mode = THREE.WEBGL_CONSTANTS.LINE_STRIP;
535+
mode = THREE.WebGLConstants.LINE_STRIP;
536536

537537
} else if ( mesh instanceof THREE.Points ) {
538538

539-
mode = THREE.WEBGL_CONSTANTS.POINTS;
539+
mode = THREE.WebGLConstants.POINTS;
540540

541541
} else {
542542

@@ -551,15 +551,15 @@ THREE.GLTFExporter.prototype = {
551551
if ( mesh.drawMode === THREE.TriangleFanDrawMode ) {
552552

553553
console.warn( 'GLTFExporter: TriangleFanDrawMode and wireframe incompatible.' );
554-
mode = THREE.WEBGL_CONSTANTS.TRIANGLE_FAN;
554+
mode = THREE.WebGLConstants.TRIANGLE_FAN;
555555

556556
} else if ( mesh.drawMode === THREE.TriangleStripDrawMode ) {
557557

558-
mode = mesh.material.wireframe ? THREE.WEBGL_CONSTANTS.LINE_STRIP : THREE.WEBGL_CONSTANTS.TRIANGLE_STRIP;
558+
mode = mesh.material.wireframe ? THREE.WebGLConstants.LINE_STRIP : THREE.WebGLConstants.TRIANGLE_STRIP;
559559

560560
} else {
561561

562-
mode = mesh.material.wireframe ? THREE.WEBGL_CONSTANTS.LINES : THREE.WEBGL_CONSTANTS.TRIANGLES;
562+
mode = mesh.material.wireframe ? THREE.WebGLConstants.LINES : THREE.WebGLConstants.TRIANGLES;
563563

564564
}
565565

src/Three.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export { CurvePath } from './extras/core/CurvePath.js';
155155
export { Curve } from './extras/core/Curve.js';
156156
export { ShapeUtils } from './extras/ShapeUtils.js';
157157
export { SceneUtils } from './extras/SceneUtils.js';
158-
export * from './renderers/webgl/WebGLUtils.js';
158+
export { WebGLUtils } from './renderers/webgl/WebGLUtils.js';
159159
export { WebGLConstants } from './renderers/webgl/WebGLConstants.js';
160160
export * from './constants.js';
161161
export * from './Three.Legacy.js';

src/renderers/WebGLRenderer.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { Vector3 } from '../math/Vector3';
3131
import { WebGLClipping } from './webgl/WebGLClipping';
3232
import { Frustum } from '../math/Frustum';
3333
import { Vector4 } from '../math/Vector4';
34-
import { toGL } from './webgl/WebGLUtils';
34+
import { WebGLUtils } from './webgl/WebGLUtils';
3535

3636
/**
3737
* @author supereggbert / http://www.paulbrunt.co.uk/
@@ -2447,14 +2447,14 @@ function WebGLRenderer( parameters ) {
24472447
var textureFormat = texture.format;
24482448
var textureType = texture.type;
24492449

2450-
if ( textureFormat !== RGBAFormat && toGL( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
2450+
if ( textureFormat !== RGBAFormat && WebGLUtils.toGL( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
24512451

24522452
console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
24532453
return;
24542454

24552455
}
24562456

2457-
if ( textureType !== UnsignedByteType && toGL( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // IE11, Edge and Chrome Mac < 52 (#9513)
2457+
if ( textureType !== UnsignedByteType && WebGLUtils.toGL( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // IE11, Edge and Chrome Mac < 52 (#9513)
24582458
! ( textureType === FloatType && ( extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
24592459
! ( textureType === HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
24602460

@@ -2469,7 +2469,7 @@ function WebGLRenderer( parameters ) {
24692469

24702470
if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
24712471

2472-
_gl.readPixels( x, y, width, height, toGL( textureFormat ), toGL( textureType ), buffer );
2472+
_gl.readPixels( x, y, width, height, WebGLUtils.toGL( textureFormat ), WebGLUtils.toGL( textureType ), buffer );
24732473

24742474
}
24752475

src/renderers/webgl/WebGLState.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import { NotEqualDepth, GreaterDepth, GreaterEqualDepth, EqualDepth, LessEqualDepth, LessDepth, AlwaysDepth, NeverDepth, CullFaceFront, CullFaceBack, CullFaceNone, CustomBlending, MultiplyBlending, SubtractiveBlending, AdditiveBlending, NoBlending, NormalBlending, DoubleSide, BackSide } from '../../constants';
66
import { Vector4 } from '../../math/Vector4';
7-
import { toGL } from './WebGLUtils';
7+
import { WebGLUtils } from './WebGLUtils';
88

99
function WebGLState( gl, extensions ) {
1010

@@ -622,7 +622,7 @@ function WebGLState( gl, extensions ) {
622622

623623
if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
624624

625-
gl.blendEquationSeparate( toGL( blendEquation ), toGL( blendEquationAlpha ) );
625+
gl.blendEquationSeparate( WebGLUtils.toGL( blendEquation ), WebGLUtils.toGL( blendEquationAlpha ) );
626626

627627
currentBlendEquation = blendEquation;
628628
currentBlendEquationAlpha = blendEquationAlpha;
@@ -631,7 +631,7 @@ function WebGLState( gl, extensions ) {
631631

632632
if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
633633

634-
gl.blendFuncSeparate( toGL( blendSrc ), toGL( blendDst ), toGL( blendSrcAlpha ), toGL( blendDstAlpha ) );
634+
gl.blendFuncSeparate( WebGLUtils.toGL( blendSrc ), WebGLUtils.toGL( blendDst ), WebGLUtils.toGL( blendSrcAlpha ), WebGLUtils.toGL( blendDstAlpha ) );
635635

636636
currentBlendSrc = blendSrc;
637637
currentBlendDst = blendDst;

src/renderers/webgl/WebGLTextures.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import { LinearFilter, NearestFilter, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, ClampToEdgeWrapping, NearestMipMapLinearFilter, NearestMipMapNearestFilter } from '../../constants';
66
import { _Math } from '../../math/Math';
7-
import { toGL } from './WebGLUtils';
7+
import { WebGLUtils } from './WebGLUtils';
88

99
function WebGLTextures( _gl, extensions, state, properties, capabilities, infoMemory ) {
1010

@@ -265,8 +265,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, infoMe
265265

266266
var image = cubeImage[ 0 ],
267267
isPowerOfTwoImage = isPowerOfTwo( image ),
268-
glFormat = toGL( texture.format ),
269-
glType = toGL( texture.type );
268+
glFormat = WebGLUtils.toGL( texture.format ),
269+
glType = WebGLUtils.toGL( texture.type );
270270

271271
setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
272272

@@ -350,11 +350,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, infoMe
350350

351351
if ( isPowerOfTwoImage ) {
352352

353-
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, toGL( texture.wrapS ) );
354-
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, toGL( texture.wrapT ) );
353+
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, WebGLUtils.toGL( texture.wrapS ) );
354+
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, WebGLUtils.toGL( texture.wrapT ) );
355355

356-
_gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, toGL( texture.magFilter ) );
357-
_gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, toGL( texture.minFilter ) );
356+
_gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, WebGLUtils.toGL( texture.magFilter ) );
357+
_gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, WebGLUtils.toGL( texture.minFilter ) );
358358

359359
} else {
360360

@@ -426,8 +426,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, infoMe
426426
}
427427

428428
var isPowerOfTwoImage = isPowerOfTwo( image ),
429-
glFormat = toGL( texture.format ),
430-
glType = toGL( texture.type );
429+
glFormat = WebGLUtils.toGL( texture.format ),
430+
glType = WebGLUtils.toGL( texture.type );
431431

432432
setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
433433

@@ -461,7 +461,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, infoMe
461461
console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
462462

463463
texture.type = UnsignedShortType;
464-
glType = toGL( texture.type );
464+
glType = WebGLUtils.toGL( texture.type );
465465

466466
}
467467

@@ -481,7 +481,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, infoMe
481481
console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
482482

483483
texture.type = UnsignedInt248Type;
484-
glType = toGL( texture.type );
484+
glType = WebGLUtils.toGL( texture.type );
485485

486486
}
487487

@@ -578,8 +578,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, infoMe
578578
// Setup storage for target texture and bind it to correct framebuffer
579579
function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
580580

581-
var glFormat = toGL( renderTarget.texture.format );
582-
var glType = toGL( renderTarget.texture.type );
581+
var glFormat = WebGLUtils.toGL( renderTarget.texture.format );
582+
var glType = WebGLUtils.toGL( renderTarget.texture.type );
583583
state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
584584
_gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
585585
_gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );

src/renderers/webgl/WebGLUtils.js

+22-19
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,6 @@ var THREE_TO_WEBGL = {
9191

9292
};
9393

94-
/**
95-
* Convert a THREE.js constant to WEBGL
96-
* @param {Number} threeConstant Three.js constant
97-
* @return {Number} WebGL constant
98-
*/
99-
function toGL ( threeConstant ) {
100-
101-
return THREE_TO_WEBGL[ threeConstant ];
102-
103-
}
104-
10594
//------------------------------------------------------------------------------
10695
// WEBGL TO THREE
10796
//------------------------------------------------------------------------------
@@ -195,15 +184,29 @@ var WEBGL_TO_THREE = {
195184
};
196185

197186

198-
/**
199-
* Convert a WEBGL constant to THREE.js
200-
* @param {Number} webglConstant WebGL constant
201-
* @return {Number} Three.js constant
202-
*/
203-
function fromGL ( webglConstant ) {
187+
var WebGLUtils = {
188+
189+
/**
190+
* Convert a WEBGL constant to THREE.js
191+
* @param {Number} webglConstant WebGL constant
192+
* @return {Number} Three.js constant
193+
*/
194+
fromGL: function( webglConstant ) {
195+
196+
return WEBGL_TO_THREE[ webglConstant ];
197+
198+
},
199+
200+
/**
201+
* Convert a THREE.js constant to WEBGL
202+
* @param {Number} threeConstant Three.js constant
203+
* @return {Number} WebGL constant
204+
*/
205+
toGL: function( threeConstant ) {
204206

205-
return WEBGL_TO_THREE[ webglConstant ];
207+
return THREE_TO_WEBGL[ threeConstant ];
206208

209+
}
207210
}
208211

209-
export { toGL, fromGL };
212+
export { WebGLUtils };

0 commit comments

Comments
 (0)