Skip to content

Commit 2ff2690

Browse files
committed
GLTFExporter: Rebased and fixed WebGLUtils use on the exporter
1 parent aa69847 commit 2ff2690

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
@@ -120,7 +120,7 @@ THREE.GLTFExporter.prototype = {
120120
}
121121

122122
var offset = 0;
123-
var componentSize = componentType === THREE.WEBGL_CONSTANTS.UNSIGNED_SHORT ? 2 : 4;
123+
var componentSize = componentType === THREE.WebGLConstants.UNSIGNED_SHORT ? 2 : 4;
124124

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

134134
var value = attribute.array[ i * attribute.itemSize + a ];
135135

136-
if ( componentType === THREE.WEBGL_CONSTANTS.FLOAT ) {
136+
if ( componentType === THREE.WebGLConstants.FLOAT ) {
137137

138138
dataView.setFloat32( offset, value, true );
139139

140-
} else if ( componentType === THREE.WEBGL_CONSTANTS.UNSIGNED_INT ) {
140+
} else if ( componentType === THREE.WebGLConstants.UNSIGNED_INT ) {
141141

142142
dataView.setUint8( offset, value, true );
143143

144-
} else if ( componentType === THREE.WEBGL_CONSTANTS.UNSIGNED_SHORT ) {
144+
} else if ( componentType === THREE.WebGLConstants.UNSIGNED_SHORT ) {
145145

146146
dataView.setUint16( offset, value, true );
147147

@@ -167,15 +167,15 @@ THREE.GLTFExporter.prototype = {
167167
*/
168168
function processBufferView( data, componentType, start, count ) {
169169

170-
var isVertexAttributes = componentType === THREE.WEBGL_CONSTANTS.FLOAT;
170+
var isVertexAttributes = componentType === THREE.WebGLConstants.FLOAT;
171171

172172
if ( !outputJSON.bufferViews ) {
173173

174174
outputJSON.bufferViews = [];
175175

176176
}
177177

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

180180
// Create a new dataview and dump the attribute's array into it
181181
var byteLength = count * data.itemSize * componentSize;
@@ -186,7 +186,7 @@ THREE.GLTFExporter.prototype = {
186186
byteOffset: byteOffset,
187187
byteLength: byteLength,
188188
byteStride: data.itemSize * componentSize,
189-
target: isVertexAttributes ? THREE.WEBGL_CONSTANTS.ARRAY_BUFFER : THREE.WEBGL_CONSTANTS.ELEMENT_ARRAY_BUFFER
189+
target: isVertexAttributes ? THREE.WebGLConstants.ARRAY_BUFFER : THREE.WebGLConstants.ELEMENT_ARRAY_BUFFER
190190

191191
};
192192

@@ -233,15 +233,15 @@ THREE.GLTFExporter.prototype = {
233233
// Detect the component type of the attribute array (float, uint or ushort)
234234
if ( attribute.array.constructor === Float32Array ) {
235235

236-
componentType = THREE.WEBGL_CONSTANTS.FLOAT;
236+
componentType = THREE.WebGLConstants.FLOAT;
237237

238238
} else if ( attribute.array.constructor === Uint32Array ) {
239239

240-
componentType = THREE.WEBGL_CONSTANTS.UNSIGNED_INT;
240+
componentType = THREE.WebGLConstants.UNSIGNED_INT;
241241

242242
} else if ( attribute.array.constructor === Uint16Array ) {
243243

244-
componentType = THREE.WEBGL_CONSTANTS.UNSIGNED_SHORT;
244+
componentType = THREE.WebGLConstants.UNSIGNED_SHORT;
245245

246246
} else {
247247

@@ -336,10 +336,10 @@ THREE.GLTFExporter.prototype = {
336336

337337
var gltfSampler = {
338338

339-
magFilter: THREE.THREE_TO_WEBGL[ map.magFilter ],
340-
minFilter: THREE.THREE_TO_WEBGL[ map.minFilter ],
341-
wrapS: THREE.THREE_TO_WEBGL[ map.wrapS ],
342-
wrapT: THREE.THREE_TO_WEBGL[ map.wrapT ]
339+
magFilter: THREE.WebGLUtils.toGL[ map.magFilter ],
340+
minFilter: THREE.WebGLUtils.toGL[ map.minFilter ],
341+
wrapS: THREE.WebGLUtils.toGL[ map.wrapS ],
342+
wrapT: THREE.WebGLUtils.toGL[ map.wrapT ]
343343

344344
};
345345

@@ -570,19 +570,19 @@ THREE.GLTFExporter.prototype = {
570570
// Use the correct mode
571571
if ( mesh instanceof THREE.LineSegments ) {
572572

573-
mode = THREE.WEBGL_CONSTANTS.LINES;
573+
mode = THREE.WebGLConstants.LINES;
574574

575575
} else if ( mesh instanceof THREE.LineLoop ) {
576576

577-
mode = THREE.WEBGL_CONSTANTS.LINE_LOOP;
577+
mode = THREE.WebGLConstants.LINE_LOOP;
578578

579579
} else if ( mesh instanceof THREE.Line ) {
580580

581-
mode = THREE.WEBGL_CONSTANTS.LINE_STRIP;
581+
mode = THREE.WebGLConstants.LINE_STRIP;
582582

583583
} else if ( mesh instanceof THREE.Points ) {
584584

585-
mode = THREE.WEBGL_CONSTANTS.POINTS;
585+
mode = THREE.WebGLConstants.POINTS;
586586

587587
} else {
588588

@@ -597,15 +597,15 @@ THREE.GLTFExporter.prototype = {
597597
if ( mesh.drawMode === THREE.TriangleFanDrawMode ) {
598598

599599
console.warn( 'GLTFExporter: TriangleFanDrawMode and wireframe incompatible.' );
600-
mode = THREE.WEBGL_CONSTANTS.TRIANGLE_FAN;
600+
mode = THREE.WebGLConstants.TRIANGLE_FAN;
601601

602602
} else if ( mesh.drawMode === THREE.TriangleStripDrawMode ) {
603603

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

606606
} else {
607607

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

610610
}
611611

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/
@@ -2459,14 +2459,14 @@ function WebGLRenderer( parameters ) {
24592459
var textureFormat = texture.format;
24602460
var textureType = texture.type;
24612461

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

24642464
console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
24652465
return;
24662466

24672467
}
24682468

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

@@ -2481,7 +2481,7 @@ function WebGLRenderer( parameters ) {
24812481

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

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

24862486
}
24872487

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)