Skip to content

Commit 6910a7a

Browse files
committed
GLTFExporter: Clean up.
1 parent 66e4d92 commit 6910a7a

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

examples/js/exporters/GLTFExporter.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -785,21 +785,32 @@ THREE.GLTFExporter.prototype = {
785785

786786
} else {
787787

788-
if ( format !== THREE.RGBAFormat && format !== THREE.RGBFormat )
789-
throw "Only RGB and RGBA formats are supported";
788+
if ( format !== THREE.RGBAFormat && format !== THREE.RGBFormat ) {
790789

791-
if ( image.width !== canvas.width || image.height !== canvas.height )
792-
console.warn( "Image size and imposed canvas sized do not match" );
790+
console.error( 'GLTFExporter: Only RGB and RGBA formats are supported.' );
791+
792+
}
793+
794+
if ( image.width > options.maxTextureSize || image.height > options.maxTextureSize ) {
795+
796+
console.warn( 'GLTFExporter: Image size is bigger than maxTextureSize', image );
797+
798+
}
793799

794800
let data = image.data;
801+
795802
if ( format === THREE.RGBFormat ) {
796803

797804
data = new Uint8ClampedArray( image.height * image.width * 4 );
798-
data.forEach( function ( _, i ) {
799805

800-
data[ i ] = i % 4 === 3 ? 255 : image.data[ 3 * Math.floor( i / 4 ) + i % 4 ];
806+
for ( var i = 0; i < data.length; i += 4 ) {
801807

802-
} );
808+
data[ i + 0 ] = image.data[ i + 0 ];
809+
data[ i + 1 ] = image.data[ i + 1 ];
810+
data[ i + 2 ] = image.data[ i + 2 ];
811+
data[ i + 3 ] = 255;
812+
813+
}
803814

804815
}
805816

examples/jsm/exporters/GLTFExporter.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ import {
1414
NearestMipmapLinearFilter,
1515
NearestMipmapNearestFilter,
1616
PropertyBinding,
17-
RepeatWrapping,
1817
RGBAFormat,
1918
RGBFormat,
19+
RepeatWrapping,
2020
Scene,
2121
Vector3
2222
} from "../../../build/three.module.js";
2323

2424
//------------------------------------------------------------------------------
2525
// Constants
2626
//------------------------------------------------------------------------------
27+
2728
var WEBGL_CONSTANTS = {
2829
POINTS: 0x0000,
2930
LINES: 0x0001,
@@ -753,7 +754,7 @@ GLTFExporter.prototype = {
753754
/**
754755
* Process image
755756
* @param {Image} image to process
756-
* @param {Integer} format of the image (e.g. THREE.RGBFormat, RGBAFormat etc)
757+
* @param {Integer} format of the image (e.g. RGBFormat, RGBAFormat etc)
757758
* @param {Boolean} flipY before writing out the image
758759
* @return {Integer} Index of the processed texture in the "images" array
759760
*/
@@ -807,21 +808,32 @@ GLTFExporter.prototype = {
807808

808809
} else {
809810

810-
if ( format !== RGBAFormat && format !== RGBFormat )
811-
throw "Only RGB and RGBA formats are supported";
811+
if ( format !== RGBAFormat && format !== RGBFormat ) {
812+
813+
console.error( 'GLTFExporter: Only RGB and RGBA formats are supported.' );
814+
815+
}
816+
817+
if ( image.width > options.maxTextureSize || image.height > options.maxTextureSize ) {
818+
819+
console.warn( 'GLTFExporter: Image size is bigger than maxTextureSize', image );
812820

813-
if ( image.width !== canvas.width || image.height !== canvas.height )
814-
console.warn( "Image size and imposed canvas sized do not match" );
821+
}
815822

816823
let data = image.data;
824+
817825
if ( format === RGBFormat ) {
818826

819827
data = new Uint8ClampedArray( image.height * image.width * 4 );
820-
data.forEach( function ( _, i ) {
821828

822-
data[ i ] = i % 4 === 3 ? 255 : image.data[ 3 * Math.floor( i / 4 ) + i % 4 ];
829+
for ( var i = 0; i < data.length; i += 4 ) {
830+
831+
data[ i + 0 ] = image.data[ i + 0 ];
832+
data[ i + 1 ] = image.data[ i + 1 ];
833+
data[ i + 2 ] = image.data[ i + 2 ];
834+
data[ i + 3 ] = 255;
823835

824-
} );
836+
}
825837

826838
}
827839

utils/modularize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var files = [
3535

3636
{ path: 'exporters/ColladaExporter.js', dependencies: [], ignoreList: [] },
3737
{ path: 'exporters/DRACOExporter.js', dependencies: [], ignoreList: [ 'Geometry' ] },
38-
{ path: 'exporters/GLTFExporter.js', dependencies: [], ignoreList: [ 'AnimationClip', 'Camera', 'Geometry', 'Material', 'Mesh', 'Object3D', 'RGBFormat', 'Scenes', 'ShaderMaterial', 'Matrix4' ] },
38+
{ path: 'exporters/GLTFExporter.js', dependencies: [], ignoreList: [ 'AnimationClip', 'Camera', 'Geometry', 'Material', 'Mesh', 'Object3D', 'Scenes', 'ShaderMaterial', 'Matrix4' ] },
3939
{ path: 'exporters/MMDExporter.js', dependencies: [ { name: 'MMDParser', path: 'libs/mmdparser.module.js' } ], ignoreList: [] },
4040
{ path: 'exporters/OBJExporter.js', dependencies: [], ignoreList: [] },
4141
{ path: 'exporters/PLYExporter.js', dependencies: [], ignoreList: [] },

0 commit comments

Comments
 (0)