From 6910a7a207e34982b108c029a4056c5110f0e098 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Sun, 22 Nov 2020 12:09:41 +0000 Subject: [PATCH] GLTFExporter: Clean up. --- examples/js/exporters/GLTFExporter.js | 25 +++++++++++++++------ examples/jsm/exporters/GLTFExporter.js | 30 ++++++++++++++++++-------- utils/modularize.js | 2 +- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/examples/js/exporters/GLTFExporter.js b/examples/js/exporters/GLTFExporter.js index c89b3d5122..a2e486e761 100644 --- a/examples/js/exporters/GLTFExporter.js +++ b/examples/js/exporters/GLTFExporter.js @@ -785,21 +785,32 @@ THREE.GLTFExporter.prototype = { } else { - if ( format !== THREE.RGBAFormat && format !== THREE.RGBFormat ) - throw "Only RGB and RGBA formats are supported"; + if ( format !== THREE.RGBAFormat && format !== THREE.RGBFormat ) { - if ( image.width !== canvas.width || image.height !== canvas.height ) - console.warn( "Image size and imposed canvas sized do not match" ); + console.error( 'GLTFExporter: Only RGB and RGBA formats are supported.' ); + + } + + if ( image.width > options.maxTextureSize || image.height > options.maxTextureSize ) { + + console.warn( 'GLTFExporter: Image size is bigger than maxTextureSize', image ); + + } let data = image.data; + if ( format === THREE.RGBFormat ) { data = new Uint8ClampedArray( image.height * image.width * 4 ); - data.forEach( function ( _, i ) { - data[ i ] = i % 4 === 3 ? 255 : image.data[ 3 * Math.floor( i / 4 ) + i % 4 ]; + for ( var i = 0; i < data.length; i += 4 ) { - } ); + data[ i + 0 ] = image.data[ i + 0 ]; + data[ i + 1 ] = image.data[ i + 1 ]; + data[ i + 2 ] = image.data[ i + 2 ]; + data[ i + 3 ] = 255; + + } } diff --git a/examples/jsm/exporters/GLTFExporter.js b/examples/jsm/exporters/GLTFExporter.js index 20dfaf0f61..3dace3767e 100644 --- a/examples/jsm/exporters/GLTFExporter.js +++ b/examples/jsm/exporters/GLTFExporter.js @@ -14,9 +14,9 @@ import { NearestMipmapLinearFilter, NearestMipmapNearestFilter, PropertyBinding, - RepeatWrapping, RGBAFormat, RGBFormat, + RepeatWrapping, Scene, Vector3 } from "../../../build/three.module.js"; @@ -24,6 +24,7 @@ import { //------------------------------------------------------------------------------ // Constants //------------------------------------------------------------------------------ + var WEBGL_CONSTANTS = { POINTS: 0x0000, LINES: 0x0001, @@ -753,7 +754,7 @@ GLTFExporter.prototype = { /** * Process image * @param {Image} image to process - * @param {Integer} format of the image (e.g. THREE.RGBFormat, RGBAFormat etc) + * @param {Integer} format of the image (e.g. RGBFormat, RGBAFormat etc) * @param {Boolean} flipY before writing out the image * @return {Integer} Index of the processed texture in the "images" array */ @@ -807,21 +808,32 @@ GLTFExporter.prototype = { } else { - if ( format !== RGBAFormat && format !== RGBFormat ) - throw "Only RGB and RGBA formats are supported"; + if ( format !== RGBAFormat && format !== RGBFormat ) { + + console.error( 'GLTFExporter: Only RGB and RGBA formats are supported.' ); + + } + + if ( image.width > options.maxTextureSize || image.height > options.maxTextureSize ) { + + console.warn( 'GLTFExporter: Image size is bigger than maxTextureSize', image ); - if ( image.width !== canvas.width || image.height !== canvas.height ) - console.warn( "Image size and imposed canvas sized do not match" ); + } let data = image.data; + if ( format === RGBFormat ) { data = new Uint8ClampedArray( image.height * image.width * 4 ); - data.forEach( function ( _, i ) { - data[ i ] = i % 4 === 3 ? 255 : image.data[ 3 * Math.floor( i / 4 ) + i % 4 ]; + for ( var i = 0; i < data.length; i += 4 ) { + + data[ i + 0 ] = image.data[ i + 0 ]; + data[ i + 1 ] = image.data[ i + 1 ]; + data[ i + 2 ] = image.data[ i + 2 ]; + data[ i + 3 ] = 255; - } ); + } } diff --git a/utils/modularize.js b/utils/modularize.js index 30787506f9..1a5935f03c 100644 --- a/utils/modularize.js +++ b/utils/modularize.js @@ -35,7 +35,7 @@ var files = [ { path: 'exporters/ColladaExporter.js', dependencies: [], ignoreList: [] }, { path: 'exporters/DRACOExporter.js', dependencies: [], ignoreList: [ 'Geometry' ] }, - { path: 'exporters/GLTFExporter.js', dependencies: [], ignoreList: [ 'AnimationClip', 'Camera', 'Geometry', 'Material', 'Mesh', 'Object3D', 'RGBFormat', 'Scenes', 'ShaderMaterial', 'Matrix4' ] }, + { path: 'exporters/GLTFExporter.js', dependencies: [], ignoreList: [ 'AnimationClip', 'Camera', 'Geometry', 'Material', 'Mesh', 'Object3D', 'Scenes', 'ShaderMaterial', 'Matrix4' ] }, { path: 'exporters/MMDExporter.js', dependencies: [ { name: 'MMDParser', path: 'libs/mmdparser.module.js' } ], ignoreList: [] }, { path: 'exporters/OBJExporter.js', dependencies: [], ignoreList: [] }, { path: 'exporters/PLYExporter.js', dependencies: [], ignoreList: [] }, -- GitLab