Skip to content

Commit ab3400c

Browse files
committed
GLTFExporter: Rebased and fixed WebGLUtils use on the exporter
1 parent f7cd331 commit ab3400c

File tree

8 files changed

+790
-401
lines changed

8 files changed

+790
-401
lines changed

build/three.js

+363-162
Large diffs are not rendered by default.

build/three.module.js

+363-163
Large diffs are not rendered by default.

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.js';
3131
import { WebGLClipping } from './webgl/WebGLClipping.js';
3232
import { Frustum } from '../math/Frustum.js';
3333
import { Vector4 } from '../math/Vector4.js';
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-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22
* @author mrdoob / http://mrdoob.com/
33
*/
44

5-
<<<<<<< HEAD
65
import { NotEqualDepth, GreaterDepth, GreaterEqualDepth, EqualDepth, LessEqualDepth, LessDepth, AlwaysDepth, NeverDepth, CullFaceFront, CullFaceBack, CullFaceNone, CustomBlending, MultiplyBlending, SubtractiveBlending, AdditiveBlending, NoBlending, NormalBlending, DoubleSide, BackSide } from '../../constants.js';
76
import { Vector4 } from '../../math/Vector4.js';
8-
=======
9-
import { NotEqualDepth, GreaterDepth, GreaterEqualDepth, EqualDepth, LessEqualDepth, LessDepth, AlwaysDepth, NeverDepth, CullFaceFront, CullFaceBack, CullFaceNone, CustomBlending, MultiplyBlending, SubtractiveBlending, AdditiveBlending, NoBlending, NormalBlending, DoubleSide, BackSide } from '../../constants';
10-
import { Vector4 } from '../../math/Vector4';
11-
import { toGL } from './WebGLUtils';
12-
>>>>>>> Replaced WebGLUtils.convert with toGL
7+
import { WebGLUtils } from './WebGLUtils';
138

149
function WebGLState( gl, extensions ) {
1510

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

628623
if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
629624

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

632627
currentBlendEquation = blendEquation;
633628
currentBlendEquationAlpha = blendEquationAlpha;
@@ -636,7 +631,7 @@ function WebGLState( gl, extensions ) {
636631

637632
if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
638633

639-
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 ) );
640635

641636
currentBlendSrc = blendSrc;
642637
currentBlendDst = blendDst;

src/renderers/webgl/WebGLTextures.js

+13-18
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22
* @author mrdoob / http://mrdoob.com/
33
*/
44

5-
<<<<<<< HEAD
65
import { LinearFilter, NearestFilter, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, ClampToEdgeWrapping, NearestMipMapLinearFilter, NearestMipMapNearestFilter } from '../../constants.js';
76
import { _Math } from '../../math/Math.js';
8-
=======
9-
import { LinearFilter, NearestFilter, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, ClampToEdgeWrapping, NearestMipMapLinearFilter, NearestMipMapNearestFilter } from '../../constants';
10-
import { _Math } from '../../math/Math';
11-
import { toGL } from './WebGLUtils';
12-
>>>>>>> Replaced WebGLUtils.convert with toGL
7+
import { WebGLUtils } from './WebGLUtils';
138

149
function WebGLTextures( _gl, extensions, state, properties, capabilities, infoMemory ) {
1510

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

271266
var image = cubeImage[ 0 ],
272267
isPowerOfTwoImage = isPowerOfTwo( image ),
273-
glFormat = toGL( texture.format ),
274-
glType = toGL( texture.type );
268+
glFormat = WebGLUtils.toGL( texture.format ),
269+
glType = WebGLUtils.toGL( texture.type );
275270

276271
setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
277272

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

356351
if ( isPowerOfTwoImage ) {
357352

358-
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, toGL( texture.wrapS ) );
359-
_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 ) );
360355

361-
_gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, toGL( texture.magFilter ) );
362-
_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 ) );
363358

364359
} else {
365360

@@ -431,8 +426,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, infoMe
431426
}
432427

433428
var isPowerOfTwoImage = isPowerOfTwo( image ),
434-
glFormat = toGL( texture.format ),
435-
glType = toGL( texture.type );
429+
glFormat = WebGLUtils.toGL( texture.format ),
430+
glType = WebGLUtils.toGL( texture.type );
436431

437432
setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
438433

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

468463
texture.type = UnsignedShortType;
469-
glType = toGL( texture.type );
464+
glType = WebGLUtils.toGL( texture.type );
470465

471466
}
472467

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

488483
texture.type = UnsignedInt248Type;
489-
glType = toGL( texture.type );
484+
glType = WebGLUtils.toGL( texture.type );
490485

491486
}
492487

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

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

src/renderers/webgl/WebGLUtils.js

+22-24
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44
*/
55
/* jshint esversion: 6 */
66

7-
<<<<<<< HEAD
8-
import { MaxEquation, MinEquation, RGB_ETC1_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT5_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT1_Format, RGB_S3TC_DXT1_Format, SrcAlphaSaturateFactor, OneMinusDstColorFactor, DstColorFactor, OneMinusDstAlphaFactor, DstAlphaFactor, OneMinusSrcAlphaFactor, SrcAlphaFactor, OneMinusSrcColorFactor, SrcColorFactor, OneFactor, ZeroFactor, ReverseSubtractEquation, SubtractEquation, AddEquation, DepthFormat, DepthStencilFormat, LuminanceAlphaFormat, LuminanceFormat, RGBAFormat, RGBFormat, AlphaFormat, HalfFloatType, FloatType, UnsignedIntType, IntType, UnsignedShortType, ShortType, ByteType, UnsignedInt248Type, UnsignedShort565Type, UnsignedShort5551Type, UnsignedShort4444Type, UnsignedByteType, LinearMipMapLinearFilter, LinearMipMapNearestFilter, LinearFilter, NearestMipMapLinearFilter, NearestMipMapNearestFilter, NearestFilter, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping } from '../../constants.js';
9-
export { WebGLConstants } from './renderers/webgl/WebGLConstants.js';
10-
=======
117
import * as Constants from '../../constants';
128
import { WebGLConstants } from './WebGLConstants';
13-
>>>>>>> Replaced WebGLUtils.convert with toGL
149

1510
//------------------------------------------------------------------------------
1611
// THREE TO WEBGL
@@ -96,17 +91,6 @@ var THREE_TO_WEBGL = {
9691

9792
};
9893

99-
/**
100-
* Convert a THREE.js constant to WEBGL
101-
* @param {Number} threeConstant Three.js constant
102-
* @return {Number} WebGL constant
103-
*/
104-
function toGL ( threeConstant ) {
105-
106-
return THREE_TO_WEBGL[ threeConstant ];
107-
108-
}
109-
11094
//------------------------------------------------------------------------------
11195
// WEBGL TO THREE
11296
//------------------------------------------------------------------------------
@@ -200,15 +184,29 @@ var WEBGL_TO_THREE = {
200184
};
201185

202186

203-
/**
204-
* Convert a WEBGL constant to THREE.js
205-
* @param {Number} webglConstant WebGL constant
206-
* @return {Number} Three.js constant
207-
*/
208-
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 ) {
209206

210-
return WEBGL_TO_THREE[ webglConstant ];
207+
return THREE_TO_WEBGL[ threeConstant ];
211208

209+
}
212210
}
213211

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

0 commit comments

Comments
 (0)