Skip to content

Commit

Permalink
GLTFExporter: Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Nov 22, 2020
1 parent 66e4d92 commit 6910a7a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
25 changes: 18 additions & 7 deletions examples/js/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}

}

Expand Down
30 changes: 21 additions & 9 deletions examples/jsm/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ import {
NearestMipmapLinearFilter,
NearestMipmapNearestFilter,
PropertyBinding,
RepeatWrapping,
RGBAFormat,
RGBFormat,
RepeatWrapping,
Scene,
Vector3
} from "../../../build/three.module.js";

//------------------------------------------------------------------------------
// Constants
//------------------------------------------------------------------------------

var WEBGL_CONSTANTS = {
POINTS: 0x0000,
LINES: 0x0001,
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;

} );
}

}

Expand Down
2 changes: 1 addition & 1 deletion utils/modularize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] },
Expand Down

0 comments on commit 6910a7a

Please sign in to comment.