Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable tree-shaking both for the main and examples files #16301

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/jsm/controls/MapControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Spherical,
Vector2,
Vector3
} from "../../../build/three.module.js";
} from "../../../src/Three.js";

// This set of controls performs orbiting, dollying (zooming), and panning.
// Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/controls/OrbitControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
Spherical,
Vector2,
Vector3
} from "../../../build/three.module.js";
} from "../../../src/Three.js";

// This set of controls performs orbiting, dollying (zooming), and panning.
// Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/controls/TrackballControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Quaternion,
Vector2,
Vector3
} from "../../../build/three.module.js";
} from "../../../src/Three.js";

var TrackballControls = function ( object, domElement ) {

Expand Down
44 changes: 33 additions & 11 deletions examples/jsm/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
TriangleFanDrawMode,
TriangleStripDrawMode,
Vector3
} from "../../../build/three.module.js";
} from "../../../src/Three.js";

//------------------------------------------------------------------------------
// Constants
Expand Down Expand Up @@ -147,9 +147,23 @@ GLTFExporter.prototype = {

var cachedCanvas;

var uids = new Map();
var uid = 0;

/**
* Compare two arrays
* Assign and return a temporal unique id for an object
* especially which doesn't have .uuid
* @param {Object} object
* @return {Integer}
*/
function getUID( object ) {

if ( ! uids.has( object ) ) uids.set( object, uid ++ );

return uids.get( object );

}

/**
* Compare two arrays
* @param {Array} array1 Array 1 to compare
Expand Down Expand Up @@ -1202,9 +1216,9 @@ GLTFExporter.prototype = {

}

if ( cachedData.attributes.has( attribute ) ) {
if ( cachedData.attributes.has( getUID( attribute ) ) ) {

attributes[ attributeName ] = cachedData.attributes.get( attribute );
attributes[ attributeName ] = cachedData.attributes.get( getUID( attribute ) );
continue;

}
Expand All @@ -1225,7 +1239,7 @@ GLTFExporter.prototype = {
if ( accessor !== null ) {

attributes[ attributeName ] = accessor;
cachedData.attributes.set( attribute, accessor );
cachedData.attributes.set( getUID( attribute ), accessor );

}

Expand Down Expand Up @@ -1291,9 +1305,9 @@ GLTFExporter.prototype = {

var baseAttribute = geometry.attributes[ attributeName ];

if ( cachedData.attributes.has( attribute ) ) {
if ( cachedData.attributes.has( getUID( attribute ) ) ) {

target[ gltfAttributeName ] = cachedData.attributes.get( attribute );
target[ gltfAttributeName ] = cachedData.attributes.get( getUID( attribute ) );
continue;

}
Expand All @@ -1313,7 +1327,7 @@ GLTFExporter.prototype = {
}

target[ gltfAttributeName ] = processAccessor( relativeAttribute, geometry );
cachedData.attributes.set( baseAttribute, target[ gltfAttributeName ] );
cachedData.attributes.set( getUID( baseAttribute ), target[ gltfAttributeName ] );

}

Expand Down Expand Up @@ -1382,14 +1396,22 @@ GLTFExporter.prototype = {

if ( geometry.index !== null ) {

if ( cachedData.attributes.has( geometry.index ) ) {
var cacheKey = getUID( geometry.index );

if ( groups[ i ].start !== undefined || groups[ i ].count !== undefined ) {

cacheKey += ':' + groups[ i ].start + ':' + groups[ i ].count;

}

if ( cachedData.attributes.has( cacheKey ) ) {

primitive.indices = cachedData.attributes.get( geometry.index );
primitive.indices = cachedData.attributes.get( cacheKey );

} else {

primitive.indices = processAccessor( geometry.index, geometry, groups[ i ].start, groups[ i ].count );
cachedData.attributes.set( geometry.index, primitive.indices );
cachedData.attributes.set( cacheKey, primitive.indices );

}

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/exporters/MMDExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Matrix4,
Quaternion,
Vector3
} from "../../../build/three.module.js";
} from "../../../src/Three.js";

var MMDExporter = function () {

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/exporters/OBJExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Mesh,
Vector2,
Vector3
} from "../../../build/three.module.js";
} from "../../../src/Three.js";

var OBJExporter = function () {};

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/exporters/PLYExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
BufferGeometry,
Matrix3,
Vector3
} from "../../../build/three.module.js";
} from "../../../src/Three.js";

var PLYExporter = function () {};

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/exporters/STLExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
Geometry,
Matrix3,
Vector3
} from "../../../build/three.module.js";
} from "../../../src/Three.js";

var STLExporter = function () {};

Expand Down
71 changes: 38 additions & 33 deletions examples/jsm/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ import {
VertexColors,
ZeroFactor,
sRGBEncoding
} from "../../../build/three.module.js";
} from "../../../src/Three.js";

var GLTFLoader = ( function () {

Expand Down Expand Up @@ -460,26 +460,26 @@ var GLTFLoader = ( function () {
*
* PR: https://github.com/KhronosGroup/glTF/pull/1163
*/
function GLTFMaterialsUnlitExtension( json ) {
function GLTFMaterialsUnlitExtension() {

this.name = EXTENSIONS.KHR_MATERIALS_UNLIT;

}

GLTFMaterialsUnlitExtension.prototype.getMaterialType = function ( material ) {
GLTFMaterialsUnlitExtension.prototype.getMaterialType = function () {

return MeshBasicMaterial;

};

GLTFMaterialsUnlitExtension.prototype.extendParams = function ( materialParams, material, parser ) {
GLTFMaterialsUnlitExtension.prototype.extendParams = function ( materialParams, materialDef, parser ) {

var pending = [];

materialParams.color = new Color( 1.0, 1.0, 1.0 );
materialParams.opacity = 1.0;

var metallicRoughness = material.pbrMetallicRoughness;
var metallicRoughness = materialDef.pbrMetallicRoughness;

if ( metallicRoughness ) {

Expand Down Expand Up @@ -655,7 +655,7 @@ var GLTFLoader = ( function () {
*
* Specification:
*/
function GLTFTextureTransformExtension( json ) {
function GLTFTextureTransformExtension() {

this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM;

Expand Down Expand Up @@ -738,9 +738,9 @@ var GLTFLoader = ( function () {

},

extendParams: function ( params, material, parser ) {
extendParams: function ( materialParams, materialDef, parser ) {

var pbrSpecularGlossiness = material.extensions[ this.name ];
var pbrSpecularGlossiness = materialDef.extensions[ this.name ];

var shader = ShaderLib[ 'standard' ];

Expand Down Expand Up @@ -803,46 +803,46 @@ var GLTFLoader = ( function () {
uniforms.specularMap = { value: null };
uniforms.glossinessMap = { value: null };

params.vertexShader = shader.vertexShader;
params.fragmentShader = fragmentShader;
params.uniforms = uniforms;
params.defines = { 'STANDARD': '' };
materialParams.vertexShader = shader.vertexShader;
materialParams.fragmentShader = fragmentShader;
materialParams.uniforms = uniforms;
materialParams.defines = { 'STANDARD': '' };

params.color = new Color( 1.0, 1.0, 1.0 );
params.opacity = 1.0;
materialParams.color = new Color( 1.0, 1.0, 1.0 );
materialParams.opacity = 1.0;

var pending = [];

if ( Array.isArray( pbrSpecularGlossiness.diffuseFactor ) ) {

var array = pbrSpecularGlossiness.diffuseFactor;

params.color.fromArray( array );
params.opacity = array[ 3 ];
materialParams.color.fromArray( array );
materialParams.opacity = array[ 3 ];

}

if ( pbrSpecularGlossiness.diffuseTexture !== undefined ) {

pending.push( parser.assignTexture( params, 'map', pbrSpecularGlossiness.diffuseTexture ) );
pending.push( parser.assignTexture( materialParams, 'map', pbrSpecularGlossiness.diffuseTexture ) );

}

params.emissive = new Color( 0.0, 0.0, 0.0 );
params.glossiness = pbrSpecularGlossiness.glossinessFactor !== undefined ? pbrSpecularGlossiness.glossinessFactor : 1.0;
params.specular = new Color( 1.0, 1.0, 1.0 );
materialParams.emissive = new Color( 0.0, 0.0, 0.0 );
materialParams.glossiness = pbrSpecularGlossiness.glossinessFactor !== undefined ? pbrSpecularGlossiness.glossinessFactor : 1.0;
materialParams.specular = new Color( 1.0, 1.0, 1.0 );

if ( Array.isArray( pbrSpecularGlossiness.specularFactor ) ) {

params.specular.fromArray( pbrSpecularGlossiness.specularFactor );
materialParams.specular.fromArray( pbrSpecularGlossiness.specularFactor );

}

if ( pbrSpecularGlossiness.specularGlossinessTexture !== undefined ) {

var specGlossMapDef = pbrSpecularGlossiness.specularGlossinessTexture;
pending.push( parser.assignTexture( params, 'glossinessMap', specGlossMapDef ) );
pending.push( parser.assignTexture( params, 'specularMap', specGlossMapDef ) );
pending.push( parser.assignTexture( materialParams, 'glossinessMap', specGlossMapDef ) );
pending.push( parser.assignTexture( materialParams, 'specularMap', specGlossMapDef ) );

}

Expand Down Expand Up @@ -885,6 +885,7 @@ var GLTFLoader = ( function () {
material.bumpScale = 1;

material.normalMap = params.normalMap === undefined ? null : params.normalMap;

if ( params.normalScale ) material.normalScale = params.normalScale;

material.displacementMap = null;
Expand Down Expand Up @@ -2208,15 +2209,19 @@ var GLTFLoader = ( function () {

return this.getDependency( 'texture', mapDef.index ).then( function ( texture ) {

switch ( mapName ) {
if ( ! texture.isCompressedTexture ) {

case 'aoMap':
case 'emissiveMap':
case 'metalnessMap':
case 'normalMap':
case 'roughnessMap':
texture.format = RGBFormat;
break;
switch ( mapName ) {

case 'aoMap':
case 'emissiveMap':
case 'metalnessMap':
case 'normalMap':
case 'roughnessMap':
texture.format = RGBFormat;
break;

}

}

Expand Down Expand Up @@ -2377,13 +2382,13 @@ var GLTFLoader = ( function () {
if ( materialExtensions[ EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS ] ) {

var sgExtension = extensions[ EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS ];
materialType = sgExtension.getMaterialType( materialDef );
materialType = sgExtension.getMaterialType();
pending.push( sgExtension.extendParams( materialParams, materialDef, parser ) );

} else if ( materialExtensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ] ) {

var kmuExtension = extensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ];
materialType = kmuExtension.getMaterialType( materialDef );
materialType = kmuExtension.getMaterialType();
pending.push( kmuExtension.extendParams( materialParams, materialDef, parser ) );

} else {
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/loaders/MTLLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
RepeatWrapping,
TextureLoader,
Vector2
} from "../../../build/three.module.js";
} from "../../../src/Three.js";

var MTLLoader = function ( manager ) {

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/loaders/OBJLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
Points,
PointsMaterial,
VertexColors
} from "../../../build/three.module.js";
} from "../../../src/Three.js";

var OBJLoader = ( function () {

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/pmrem/PMREMCubeUVPacker.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
Vector2,
Vector3,
WebGLRenderTarget
} from "../../../build/three.module.js";
} from "../../../src/Three.js";

var PMREMCubeUVPacker = ( function () {

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/pmrem/PMREMGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
ShaderMaterial,
WebGLRenderTargetCube,
sRGBEncoding
} from "../../../build/three.module.js";
} from "../../../src/Three.js";

var PMREMGenerator = ( function () {

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/utils/BufferGeometryUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
InterleavedBufferAttribute,
Vector2,
Vector3
} from "../../../build/three.module.js";
} from "../../../src/Three.js";

var BufferGeometryUtils = {

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/utils/GeometryUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import {
Mesh,
Vector3
} from "../../../build/three.module.js";
} from "../../../src/Three.js";

var GeometryUtils = {

Expand Down
Loading