elation-engine 0.9.113 → 0.9.115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/css/systems/render.css +5 -1
- package/package.json +1 -1
- package/scripts/assets.js +103 -20
- package/scripts/assetworker.js +18 -1
- package/scripts/external/holoplay.js +1494 -0
- package/scripts/external/octree.js +0 -0
- package/scripts/external/three/CSS3DRenderer.js +46 -43
- package/scripts/external/three/CubemapToEquirectangular.js +1 -1
- package/scripts/external/three/three-extras.js +1553 -392
- package/scripts/external/three/three-icosa.js +2575 -0
- package/scripts/external/three/three-loaders.js +925 -133
- package/scripts/external/three/three-postprocessing.js +3 -3
- package/scripts/external/three/three-r116dev.js +50930 -0
- package/scripts/external/three/three-spotlighttextures.js +50953 -0
- package/scripts/external/three/three-vrm.js +2 -2
- package/scripts/external/three/three-working.js +35968 -0
- package/scripts/external/three/three.js +38532 -24087
- package/scripts/external/three-mesh-bvh.js +5370 -0
- package/scripts/external/three-old/BVHLoader.js +406 -0
- package/scripts/external/three-old/ColladaLoader.js +5519 -0
- package/scripts/external/three-old/ColladaLoader2.js +1694 -0
- package/scripts/external/three-old/CubemapToEquirectangular.js +188 -0
- package/scripts/external/three-old/DDSLoader.js +269 -0
- package/scripts/external/three-old/FBXLoader-mine.js +5063 -0
- package/scripts/external/three-old/FBXLoader.js +5112 -0
- package/scripts/external/three-old/FlyControls.js +295 -0
- package/scripts/external/three-old/GLTF2Loader.js +2950 -0
- package/scripts/external/three-old/GLTFLoader.js +2213 -0
- package/scripts/external/three-old/JSONLoader.js +435 -0
- package/scripts/external/three-old/MTLLoader.js +533 -0
- package/scripts/external/three-old/OBJLoader-experimental.js +874 -0
- package/scripts/external/three-old/OBJLoader-working.js +727 -0
- package/scripts/external/three-old/OBJLoader.js +723 -0
- package/scripts/external/three-old/OBJMTLLoader.js +440 -0
- package/scripts/external/three-old/OrbitControls.js +592 -0
- package/scripts/external/three-old/PLYLoader.js +517 -0
- package/scripts/external/three-old/TransformControls.js +1100 -0
- package/scripts/external/three-old/VRMLLoader.js +1021 -0
- package/scripts/external/three-old/glTFLoader-combined.js +2513 -0
- package/scripts/external/three-old/nodethree.js +44018 -0
- package/scripts/external/three-old/render/BleachBypassShader.js +64 -0
- package/scripts/external/three-old/render/BloomPass.js +116 -0
- package/scripts/external/three-old/render/CSS3DRenderer.js +310 -0
- package/scripts/external/three-old/render/ClearPass.js +44 -0
- package/scripts/external/three-old/render/ConvolutionShader.js +101 -0
- package/scripts/external/three-old/render/CopyShader.js +46 -0
- package/scripts/external/three-old/render/EffectComposer.js +211 -0
- package/scripts/external/three-old/render/FXAAShader.js +88 -0
- package/scripts/external/three-old/render/FilmPass.js +60 -0
- package/scripts/external/three-old/render/FilmShader.js +104 -0
- package/scripts/external/three-old/render/ManualMSAARenderPass.js +168 -0
- package/scripts/external/three-old/render/MaskPass.js +97 -0
- package/scripts/external/three-old/render/OculusRenderPass.js +84 -0
- package/scripts/external/three-old/render/OculusRiftEffect.js +240 -0
- package/scripts/external/three-old/render/PortalRenderPass.js +166 -0
- package/scripts/external/three-old/render/RecordingPass.js +208 -0
- package/scripts/external/three-old/render/RenderPass.js +57 -0
- package/scripts/external/three-old/render/SSAOShader.js +259 -0
- package/scripts/external/three-old/render/SepiaShader.js +54 -0
- package/scripts/external/three-old/render/ShaderPass.js +66 -0
- package/scripts/external/three-old/render/VREffect.js +482 -0
- package/scripts/external/three-old/shimthree.js +23 -0
- package/scripts/external/three-old/stats.js +6 -0
- package/scripts/external/three-old/three-88dev.js +45004 -0
- package/scripts/external/three-old/three-backgroundoptimization.js +44432 -0
- package/scripts/external/three-old/three-updates.js +44735 -0
- package/scripts/external/three-old/three-working.js +44719 -0
- package/scripts/external/three-old/three.js +44431 -0
- package/scripts/external/three-old/threex.rendererstats.js +66 -0
- package/scripts/external/three-old/tween.js +13 -0
- package/scripts/external/webvr-polyfill-new.js +3497 -0
- package/scripts/external/webvr-polyfill-newest.js +3491 -0
- package/scripts/external/webvr-polyfill-old.js +6337 -0
- package/scripts/geometries.js +2 -2
- package/scripts/math.js +6 -6
- package/scripts/systems/admin.js +1 -1
- package/scripts/systems/controls.js +6 -4
- package/scripts/systems/physics.js +10 -10
- package/scripts/systems/render.js +58 -20
- package/scripts/systems/render2.js +38 -0
- package/scripts/things/camera.js +6 -1
- package/scripts/things/generic-trackedvectors.js +1875 -0
- package/scripts/things/generic.js +3 -4
- package/scripts/things/label2d.js +1 -1
- package/scripts/things/leapmotion.js +6 -6
- package/scripts/things/menu.js +1 -1
- package/scripts/things/player-bak.js +638 -0
- package/scripts/things/player.js +28 -10
- package/scripts/things/skysphere.js +1 -1
- package/scripts/things/terrain.js +1 -1
- package/scripts/things/text.js +1 -1
|
@@ -7649,6 +7649,11 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
7649
7649
|
|
|
7650
7650
|
return new GLTFTextureWebPExtension( parser );
|
|
7651
7651
|
|
|
7652
|
+
} );
|
|
7653
|
+
this.register( function ( parser ) {
|
|
7654
|
+
|
|
7655
|
+
return new GLTFMaterialsSheenExtension( parser );
|
|
7656
|
+
|
|
7652
7657
|
} );
|
|
7653
7658
|
this.register( function ( parser ) {
|
|
7654
7659
|
|
|
@@ -7664,6 +7669,11 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
7664
7669
|
|
|
7665
7670
|
return new GLTFMaterialsIorExtension( parser );
|
|
7666
7671
|
|
|
7672
|
+
} );
|
|
7673
|
+
this.register( function ( parser ) {
|
|
7674
|
+
|
|
7675
|
+
return new GLTFMaterialsEmissiveStrengthExtension( parser );
|
|
7676
|
+
|
|
7667
7677
|
} );
|
|
7668
7678
|
this.register( function ( parser ) {
|
|
7669
7679
|
|
|
@@ -7917,6 +7927,17 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
7917
7927
|
|
|
7918
7928
|
}
|
|
7919
7929
|
|
|
7930
|
+
parseAsync( data, path ) {
|
|
7931
|
+
|
|
7932
|
+
const scope = this;
|
|
7933
|
+
return new Promise( function ( resolve, reject ) {
|
|
7934
|
+
|
|
7935
|
+
scope.parse( data, path, resolve, reject );
|
|
7936
|
+
|
|
7937
|
+
} );
|
|
7938
|
+
|
|
7939
|
+
}
|
|
7940
|
+
|
|
7920
7941
|
}
|
|
7921
7942
|
/* GLTFREGISTRY */
|
|
7922
7943
|
|
|
@@ -7962,6 +7983,7 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
7962
7983
|
KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',
|
|
7963
7984
|
KHR_MATERIALS_IOR: 'KHR_materials_ior',
|
|
7964
7985
|
KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: 'KHR_materials_pbrSpecularGlossiness',
|
|
7986
|
+
KHR_MATERIALS_SHEEN: 'KHR_materials_sheen',
|
|
7965
7987
|
KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',
|
|
7966
7988
|
KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission',
|
|
7967
7989
|
KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
|
|
@@ -7969,6 +7991,7 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
7969
7991
|
KHR_TEXTURE_BASISU: 'KHR_texture_basisu',
|
|
7970
7992
|
KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform',
|
|
7971
7993
|
KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization',
|
|
7994
|
+
KHR_MATERIALS_EMISSIVE_STRENGTH: 'KHR_materials_emissive_strength',
|
|
7972
7995
|
EXT_TEXTURE_WEBP: 'EXT_texture_webp',
|
|
7973
7996
|
EXT_MESHOPT_COMPRESSION: 'EXT_meshopt_compression'
|
|
7974
7997
|
};
|
|
@@ -8127,7 +8150,7 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
8127
8150
|
|
|
8128
8151
|
if ( metallicRoughness.baseColorTexture !== undefined ) {
|
|
8129
8152
|
|
|
8130
|
-
pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture ) );
|
|
8153
|
+
pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture, THREE.sRGBEncoding ) );
|
|
8131
8154
|
|
|
8132
8155
|
}
|
|
8133
8156
|
|
|
@@ -8137,6 +8160,46 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
8137
8160
|
|
|
8138
8161
|
}
|
|
8139
8162
|
|
|
8163
|
+
}
|
|
8164
|
+
/**
|
|
8165
|
+
* Materials Emissive Strength Extension
|
|
8166
|
+
*
|
|
8167
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/5768b3ce0ef32bc39cdf1bef10b948586635ead3/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md
|
|
8168
|
+
*/
|
|
8169
|
+
|
|
8170
|
+
|
|
8171
|
+
class GLTFMaterialsEmissiveStrengthExtension {
|
|
8172
|
+
|
|
8173
|
+
constructor( parser ) {
|
|
8174
|
+
|
|
8175
|
+
this.parser = parser;
|
|
8176
|
+
this.name = EXTENSIONS.KHR_MATERIALS_EMISSIVE_STRENGTH;
|
|
8177
|
+
|
|
8178
|
+
}
|
|
8179
|
+
|
|
8180
|
+
extendMaterialParams( materialIndex, materialParams ) {
|
|
8181
|
+
|
|
8182
|
+
const parser = this.parser;
|
|
8183
|
+
const materialDef = parser.json.materials[ materialIndex ];
|
|
8184
|
+
|
|
8185
|
+
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
8186
|
+
|
|
8187
|
+
return Promise.resolve();
|
|
8188
|
+
|
|
8189
|
+
}
|
|
8190
|
+
|
|
8191
|
+
const emissiveStrength = materialDef.extensions[ this.name ].emissiveStrength;
|
|
8192
|
+
|
|
8193
|
+
if ( emissiveStrength !== undefined ) {
|
|
8194
|
+
|
|
8195
|
+
materialParams.emissiveIntensity = emissiveStrength;
|
|
8196
|
+
|
|
8197
|
+
}
|
|
8198
|
+
|
|
8199
|
+
return Promise.resolve();
|
|
8200
|
+
|
|
8201
|
+
}
|
|
8202
|
+
|
|
8140
8203
|
}
|
|
8141
8204
|
/**
|
|
8142
8205
|
* Clearcoat Materials Extension
|
|
@@ -8207,9 +8270,8 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
8207
8270
|
|
|
8208
8271
|
if ( extension.clearcoatNormalTexture.scale !== undefined ) {
|
|
8209
8272
|
|
|
8210
|
-
const scale = extension.clearcoatNormalTexture.scale;
|
|
8211
|
-
|
|
8212
|
-
materialParams.clearcoatNormalScale = new THREE.Vector2( scale, - scale );
|
|
8273
|
+
const scale = extension.clearcoatNormalTexture.scale;
|
|
8274
|
+
materialParams.clearcoatNormalScale = new THREE.Vector2( scale, scale );
|
|
8213
8275
|
|
|
8214
8276
|
}
|
|
8215
8277
|
|
|
@@ -8219,6 +8281,77 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
8219
8281
|
|
|
8220
8282
|
}
|
|
8221
8283
|
|
|
8284
|
+
}
|
|
8285
|
+
/**
|
|
8286
|
+
* Sheen Materials Extension
|
|
8287
|
+
*
|
|
8288
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen
|
|
8289
|
+
*/
|
|
8290
|
+
|
|
8291
|
+
|
|
8292
|
+
class GLTFMaterialsSheenExtension {
|
|
8293
|
+
|
|
8294
|
+
constructor( parser ) {
|
|
8295
|
+
|
|
8296
|
+
this.parser = parser;
|
|
8297
|
+
this.name = EXTENSIONS.KHR_MATERIALS_SHEEN;
|
|
8298
|
+
|
|
8299
|
+
}
|
|
8300
|
+
|
|
8301
|
+
getMaterialType( materialIndex ) {
|
|
8302
|
+
|
|
8303
|
+
const parser = this.parser;
|
|
8304
|
+
const materialDef = parser.json.materials[ materialIndex ];
|
|
8305
|
+
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
8306
|
+
return THREE.MeshPhysicalMaterial;
|
|
8307
|
+
|
|
8308
|
+
}
|
|
8309
|
+
|
|
8310
|
+
extendMaterialParams( materialIndex, materialParams ) {
|
|
8311
|
+
|
|
8312
|
+
const parser = this.parser;
|
|
8313
|
+
const materialDef = parser.json.materials[ materialIndex ];
|
|
8314
|
+
|
|
8315
|
+
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
8316
|
+
|
|
8317
|
+
return Promise.resolve();
|
|
8318
|
+
|
|
8319
|
+
}
|
|
8320
|
+
|
|
8321
|
+
const pending = [];
|
|
8322
|
+
materialParams.sheenColor = new THREE.Color( 0, 0, 0 );
|
|
8323
|
+
materialParams.sheenRoughness = 0;
|
|
8324
|
+
materialParams.sheen = 1;
|
|
8325
|
+
const extension = materialDef.extensions[ this.name ];
|
|
8326
|
+
|
|
8327
|
+
if ( extension.sheenColorFactor !== undefined ) {
|
|
8328
|
+
|
|
8329
|
+
materialParams.sheenColor.fromArray( extension.sheenColorFactor );
|
|
8330
|
+
|
|
8331
|
+
}
|
|
8332
|
+
|
|
8333
|
+
if ( extension.sheenRoughnessFactor !== undefined ) {
|
|
8334
|
+
|
|
8335
|
+
materialParams.sheenRoughness = extension.sheenRoughnessFactor;
|
|
8336
|
+
|
|
8337
|
+
}
|
|
8338
|
+
|
|
8339
|
+
if ( extension.sheenColorTexture !== undefined ) {
|
|
8340
|
+
|
|
8341
|
+
pending.push( parser.assignTexture( materialParams, 'sheenColorMap', extension.sheenColorTexture, THREE.sRGBEncoding ) );
|
|
8342
|
+
|
|
8343
|
+
}
|
|
8344
|
+
|
|
8345
|
+
if ( extension.sheenRoughnessTexture !== undefined ) {
|
|
8346
|
+
|
|
8347
|
+
pending.push( parser.assignTexture( materialParams, 'sheenRoughnessMap', extension.sheenRoughnessTexture ) );
|
|
8348
|
+
|
|
8349
|
+
}
|
|
8350
|
+
|
|
8351
|
+
return Promise.all( pending );
|
|
8352
|
+
|
|
8353
|
+
}
|
|
8354
|
+
|
|
8222
8355
|
}
|
|
8223
8356
|
/**
|
|
8224
8357
|
* Transmission Materials Extension
|
|
@@ -8325,7 +8458,7 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
8325
8458
|
|
|
8326
8459
|
materialParams.attenuationDistance = extension.attenuationDistance || 0;
|
|
8327
8460
|
const colorArray = extension.attenuationColor || [ 1, 1, 1 ];
|
|
8328
|
-
materialParams.
|
|
8461
|
+
materialParams.attenuationColor = new THREE.Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );
|
|
8329
8462
|
return Promise.all( pending );
|
|
8330
8463
|
|
|
8331
8464
|
}
|
|
@@ -8421,15 +8554,11 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
8421
8554
|
}
|
|
8422
8555
|
|
|
8423
8556
|
const colorArray = extension.specularColorFactor || [ 1, 1, 1 ];
|
|
8424
|
-
materialParams.
|
|
8557
|
+
materialParams.specularColor = new THREE.Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );
|
|
8425
8558
|
|
|
8426
8559
|
if ( extension.specularColorTexture !== undefined ) {
|
|
8427
8560
|
|
|
8428
|
-
pending.push( parser.assignTexture( materialParams, '
|
|
8429
|
-
|
|
8430
|
-
texture.encoding = THREE.sRGBEncoding;
|
|
8431
|
-
|
|
8432
|
-
} ) );
|
|
8561
|
+
pending.push( parser.assignTexture( materialParams, 'specularColorMap', extension.specularColorTexture, THREE.sRGBEncoding ) );
|
|
8433
8562
|
|
|
8434
8563
|
}
|
|
8435
8564
|
|
|
@@ -8467,7 +8596,6 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
8467
8596
|
}
|
|
8468
8597
|
|
|
8469
8598
|
const extension = textureDef.extensions[ this.name ];
|
|
8470
|
-
const source = json.images[ extension.source ];
|
|
8471
8599
|
const loader = parser.options.ktx2Loader;
|
|
8472
8600
|
|
|
8473
8601
|
if ( ! loader ) {
|
|
@@ -8485,7 +8613,7 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
8485
8613
|
|
|
8486
8614
|
}
|
|
8487
8615
|
|
|
8488
|
-
return parser.loadTextureImage( textureIndex, source, loader );
|
|
8616
|
+
return parser.loadTextureImage( textureIndex, extension.source, loader );
|
|
8489
8617
|
|
|
8490
8618
|
}
|
|
8491
8619
|
|
|
@@ -8533,7 +8661,7 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
8533
8661
|
|
|
8534
8662
|
return this.detectSupport().then( function ( isSupported ) {
|
|
8535
8663
|
|
|
8536
|
-
if ( isSupported ) return parser.loadTextureImage( textureIndex, source, loader );
|
|
8664
|
+
if ( isSupported ) return parser.loadTextureImage( textureIndex, extension.source, loader );
|
|
8537
8665
|
|
|
8538
8666
|
if ( json.extensionsRequired && json.extensionsRequired.indexOf( name ) >= 0 ) {
|
|
8539
8667
|
|
|
@@ -8849,7 +8977,7 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
8849
8977
|
/**
|
|
8850
8978
|
* Specular-Glossiness Extension
|
|
8851
8979
|
*
|
|
8852
|
-
* Specification: https://github.com/KhronosGroup/glTF/tree/
|
|
8980
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness
|
|
8853
8981
|
*/
|
|
8854
8982
|
|
|
8855
8983
|
/**
|
|
@@ -8868,9 +8996,9 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
8868
8996
|
|
|
8869
8997
|
const specularMapParsFragmentChunk = [ '#ifdef USE_SPECULARMAP', ' uniform sampler2D specularMap;', '#endif' ].join( '\n' );
|
|
8870
8998
|
const glossinessMapParsFragmentChunk = [ '#ifdef USE_GLOSSINESSMAP', ' uniform sampler2D glossinessMap;', '#endif' ].join( '\n' );
|
|
8871
|
-
const specularMapFragmentChunk = [ 'vec3 specularFactor = specular;', '#ifdef USE_SPECULARMAP', ' vec4 texelSpecular = texture2D( specularMap, vUv );', '
|
|
8999
|
+
const specularMapFragmentChunk = [ 'vec3 specularFactor = specular;', '#ifdef USE_SPECULARMAP', ' vec4 texelSpecular = texture2D( specularMap, vUv );', ' // reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture', ' specularFactor *= texelSpecular.rgb;', '#endif' ].join( '\n' );
|
|
8872
9000
|
const glossinessMapFragmentChunk = [ 'float glossinessFactor = glossiness;', '#ifdef USE_GLOSSINESSMAP', ' vec4 texelGlossiness = texture2D( glossinessMap, vUv );', ' // reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture', ' glossinessFactor *= texelGlossiness.a;', '#endif' ].join( '\n' );
|
|
8873
|
-
const lightPhysicalFragmentChunk = [ 'PhysicalMaterial material;', 'material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );', 'vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );', 'float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );', 'material.
|
|
9001
|
+
const lightPhysicalFragmentChunk = [ 'PhysicalMaterial material;', 'material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );', 'vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );', 'float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );', 'material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.', 'material.roughness += geometryRoughness;', 'material.roughness = min( material.roughness, 1.0 );', 'material.specularColor = specularFactor;' ].join( '\n' );
|
|
8874
9002
|
const uniforms = {
|
|
8875
9003
|
specular: {
|
|
8876
9004
|
value: new THREE.Color().setHex( 0xffffff )
|
|
@@ -9001,7 +9129,7 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
9001
9129
|
constructor() {
|
|
9002
9130
|
|
|
9003
9131
|
this.name = EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS;
|
|
9004
|
-
this.specularGlossinessParams = [ 'color', 'map', 'lightMap', 'lightMapIntensity', 'aoMap', 'aoMapIntensity', 'emissive', 'emissiveIntensity', 'emissiveMap', 'bumpMap', 'bumpScale', 'normalMap', 'normalMapType', 'displacementMap', 'displacementScale', 'displacementBias', 'specularMap', 'specular', 'glossinessMap', 'glossiness', 'alphaMap', 'envMap', 'envMapIntensity'
|
|
9132
|
+
this.specularGlossinessParams = [ 'color', 'map', 'lightMap', 'lightMapIntensity', 'aoMap', 'aoMapIntensity', 'emissive', 'emissiveIntensity', 'emissiveMap', 'bumpMap', 'bumpScale', 'normalMap', 'normalMapType', 'displacementMap', 'displacementScale', 'displacementBias', 'specularMap', 'specular', 'glossinessMap', 'glossiness', 'alphaMap', 'envMap', 'envMapIntensity' ];
|
|
9005
9133
|
|
|
9006
9134
|
}
|
|
9007
9135
|
|
|
@@ -9028,7 +9156,7 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
9028
9156
|
|
|
9029
9157
|
if ( pbrSpecularGlossiness.diffuseTexture !== undefined ) {
|
|
9030
9158
|
|
|
9031
|
-
pending.push( parser.assignTexture( materialParams, 'map', pbrSpecularGlossiness.diffuseTexture ) );
|
|
9159
|
+
pending.push( parser.assignTexture( materialParams, 'map', pbrSpecularGlossiness.diffuseTexture, THREE.sRGBEncoding ) );
|
|
9032
9160
|
|
|
9033
9161
|
}
|
|
9034
9162
|
|
|
@@ -9046,7 +9174,7 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
9046
9174
|
|
|
9047
9175
|
const specGlossMapDef = pbrSpecularGlossiness.specularGlossinessTexture;
|
|
9048
9176
|
pending.push( parser.assignTexture( materialParams, 'glossinessMap', specGlossMapDef ) );
|
|
9049
|
-
pending.push( parser.assignTexture( materialParams, 'specularMap', specGlossMapDef ) );
|
|
9177
|
+
pending.push( parser.assignTexture( materialParams, 'specularMap', specGlossMapDef, THREE.sRGBEncoding ) );
|
|
9050
9178
|
|
|
9051
9179
|
}
|
|
9052
9180
|
|
|
@@ -9065,7 +9193,7 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
9065
9193
|
material.aoMap = materialParams.aoMap === undefined ? null : materialParams.aoMap;
|
|
9066
9194
|
material.aoMapIntensity = 1.0;
|
|
9067
9195
|
material.emissive = materialParams.emissive;
|
|
9068
|
-
material.emissiveIntensity = 1.0;
|
|
9196
|
+
material.emissiveIntensity = materialParams.emissiveIntensity === undefined ? 1.0 : materialParams.emissiveIntensity;
|
|
9069
9197
|
material.emissiveMap = materialParams.emissiveMap === undefined ? null : materialParams.emissiveMap;
|
|
9070
9198
|
material.bumpMap = materialParams.bumpMap === undefined ? null : materialParams.bumpMap;
|
|
9071
9199
|
material.bumpScale = 1;
|
|
@@ -9082,7 +9210,6 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
9082
9210
|
material.alphaMap = null;
|
|
9083
9211
|
material.envMap = materialParams.envMap === undefined ? null : materialParams.envMap;
|
|
9084
9212
|
material.envMapIntensity = 1.0;
|
|
9085
|
-
material.refractionRatio = 0.98;
|
|
9086
9213
|
return material;
|
|
9087
9214
|
|
|
9088
9215
|
}
|
|
@@ -9181,6 +9308,22 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
9181
9308
|
return result;
|
|
9182
9309
|
|
|
9183
9310
|
};
|
|
9311
|
+
|
|
9312
|
+
const _q = new THREE.Quaternion();
|
|
9313
|
+
|
|
9314
|
+
class GLTFCubicSplineQuaternionInterpolant extends GLTFCubicSplineInterpolant {
|
|
9315
|
+
|
|
9316
|
+
interpolate_( i1, t0, t, t1 ) {
|
|
9317
|
+
|
|
9318
|
+
const result = super.interpolate_( i1, t0, t, t1 );
|
|
9319
|
+
|
|
9320
|
+
_q.fromArray( result ).normalize().toArray( result );
|
|
9321
|
+
|
|
9322
|
+
return result;
|
|
9323
|
+
|
|
9324
|
+
}
|
|
9325
|
+
|
|
9326
|
+
}
|
|
9184
9327
|
/*********************************/
|
|
9185
9328
|
|
|
9186
9329
|
/********** INTERNALS ************/
|
|
@@ -9269,34 +9412,10 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
9269
9412
|
MASK: 'MASK',
|
|
9270
9413
|
BLEND: 'BLEND'
|
|
9271
9414
|
};
|
|
9272
|
-
/* UTILITY FUNCTIONS */
|
|
9273
|
-
|
|
9274
|
-
function resolveURL( url, path ) {
|
|
9275
|
-
|
|
9276
|
-
// Invalid URL
|
|
9277
|
-
if ( typeof url !== 'string' || url === '' ) return ''; // Host Relative URL
|
|
9278
|
-
|
|
9279
|
-
if ( /^https?:\/\//i.test( path ) && /^\//.test( url ) ) {
|
|
9280
|
-
|
|
9281
|
-
path = path.replace( /(^https?:\/\/[^\/]+).*/i, '$1' );
|
|
9282
|
-
|
|
9283
|
-
} // Absolute URL http://,https://,//
|
|
9284
|
-
|
|
9285
|
-
|
|
9286
|
-
if ( /^(https?:)?\/\//i.test( url ) ) return url; // Data URI
|
|
9287
|
-
|
|
9288
|
-
if ( /^data:.*,.*$/i.test( url ) ) return url; // Blob URL
|
|
9289
|
-
|
|
9290
|
-
if ( /^blob:.*$/i.test( url ) ) return url; // Relative URL
|
|
9291
|
-
|
|
9292
|
-
return path + url;
|
|
9293
|
-
|
|
9294
|
-
}
|
|
9295
9415
|
/**
|
|
9296
9416
|
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#default-material
|
|
9297
9417
|
*/
|
|
9298
9418
|
|
|
9299
|
-
|
|
9300
9419
|
function createDefaultMaterial( cache ) {
|
|
9301
9420
|
|
|
9302
9421
|
if ( cache[ 'DefaultMaterial' ] === undefined ) {
|
|
@@ -9369,19 +9488,22 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
9369
9488
|
|
|
9370
9489
|
let hasMorphPosition = false;
|
|
9371
9490
|
let hasMorphNormal = false;
|
|
9491
|
+
let hasMorphColor = false;
|
|
9372
9492
|
|
|
9373
9493
|
for ( let i = 0, il = targets.length; i < il; i ++ ) {
|
|
9374
9494
|
|
|
9375
9495
|
const target = targets[ i ];
|
|
9376
9496
|
if ( target.POSITION !== undefined ) hasMorphPosition = true;
|
|
9377
9497
|
if ( target.NORMAL !== undefined ) hasMorphNormal = true;
|
|
9378
|
-
if (
|
|
9498
|
+
if ( target.COLOR_0 !== undefined ) hasMorphColor = true;
|
|
9499
|
+
if ( hasMorphPosition && hasMorphNormal && hasMorphColor ) break;
|
|
9379
9500
|
|
|
9380
9501
|
}
|
|
9381
9502
|
|
|
9382
|
-
if ( ! hasMorphPosition && ! hasMorphNormal ) return Promise.resolve( geometry );
|
|
9503
|
+
if ( ! hasMorphPosition && ! hasMorphNormal && ! hasMorphColor ) return Promise.resolve( geometry );
|
|
9383
9504
|
const pendingPositionAccessors = [];
|
|
9384
9505
|
const pendingNormalAccessors = [];
|
|
9506
|
+
const pendingColorAccessors = [];
|
|
9385
9507
|
|
|
9386
9508
|
for ( let i = 0, il = targets.length; i < il; i ++ ) {
|
|
9387
9509
|
|
|
@@ -9401,14 +9523,23 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
9401
9523
|
|
|
9402
9524
|
}
|
|
9403
9525
|
|
|
9526
|
+
if ( hasMorphColor ) {
|
|
9527
|
+
|
|
9528
|
+
const pendingAccessor = target.COLOR_0 !== undefined ? parser.getDependency( 'accessor', target.COLOR_0 ) : geometry.attributes.color;
|
|
9529
|
+
pendingColorAccessors.push( pendingAccessor );
|
|
9530
|
+
|
|
9531
|
+
}
|
|
9532
|
+
|
|
9404
9533
|
}
|
|
9405
9534
|
|
|
9406
|
-
return Promise.all( [ Promise.all( pendingPositionAccessors ), Promise.all( pendingNormalAccessors ) ] ).then( function ( accessors ) {
|
|
9535
|
+
return Promise.all( [ Promise.all( pendingPositionAccessors ), Promise.all( pendingNormalAccessors ), Promise.all( pendingColorAccessors ) ] ).then( function ( accessors ) {
|
|
9407
9536
|
|
|
9408
9537
|
const morphPositions = accessors[ 0 ];
|
|
9409
9538
|
const morphNormals = accessors[ 1 ];
|
|
9539
|
+
const morphColors = accessors[ 2 ];
|
|
9410
9540
|
if ( hasMorphPosition ) geometry.morphAttributes.position = morphPositions;
|
|
9411
9541
|
if ( hasMorphNormal ) geometry.morphAttributes.normal = morphNormals;
|
|
9542
|
+
if ( hasMorphColor ) geometry.morphAttributes.color = morphColors;
|
|
9412
9543
|
geometry.morphTargetsRelative = true;
|
|
9413
9544
|
return geometry;
|
|
9414
9545
|
|
|
@@ -9517,6 +9648,14 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
9517
9648
|
|
|
9518
9649
|
}
|
|
9519
9650
|
|
|
9651
|
+
}
|
|
9652
|
+
|
|
9653
|
+
function getImageURIMimeType( uri ) {
|
|
9654
|
+
|
|
9655
|
+
if ( uri.search( /\.jpe?g($|\?)/i ) > 0 || uri.search( /^data\:image\/jpeg/ ) === 0 ) return 'image/jpeg';
|
|
9656
|
+
if ( uri.search( /\.webp($|\?)/i ) > 0 || uri.search( /^data\:image\/webp/ ) === 0 ) return 'image/webp';
|
|
9657
|
+
return 'image/png';
|
|
9658
|
+
|
|
9520
9659
|
}
|
|
9521
9660
|
/* GLTF PARSER */
|
|
9522
9661
|
|
|
@@ -9548,18 +9687,23 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
9548
9687
|
refs: {},
|
|
9549
9688
|
uses: {}
|
|
9550
9689
|
};
|
|
9690
|
+
this.sourceCache = {};
|
|
9551
9691
|
this.textureCache = {}; // Track node names, to ensure no duplicates
|
|
9552
9692
|
|
|
9553
9693
|
this.nodeNamesUsed = {}; // Use an THREE.ImageBitmapLoader if imageBitmaps are supported. Moves much of the
|
|
9554
9694
|
// expensive work of uploading a texture to the GPU off the main thread.
|
|
9555
9695
|
|
|
9556
|
-
|
|
9696
|
+
const isSafari = /^((?!chrome|android).)*safari/i.test( navigator.userAgent ) === true;
|
|
9697
|
+
const isFirefox = navigator.userAgent.indexOf( 'Firefox' ) > - 1;
|
|
9698
|
+
const firefoxVersion = isFirefox ? navigator.userAgent.match( /Firefox\/([0-9]+)\./ )[ 1 ] : - 1;
|
|
9557
9699
|
|
|
9558
|
-
|
|
9700
|
+
if ( typeof createImageBitmap === 'undefined' || isSafari || isFirefox && firefoxVersion < 98 ) {
|
|
9701
|
+
|
|
9702
|
+
this.textureLoader = new THREE.TextureLoader( this.options.manager );
|
|
9559
9703
|
|
|
9560
9704
|
} else {
|
|
9561
9705
|
|
|
9562
|
-
this.textureLoader = new THREE.
|
|
9706
|
+
this.textureLoader = new THREE.ImageBitmapLoader( this.options.manager );
|
|
9563
9707
|
|
|
9564
9708
|
}
|
|
9565
9709
|
|
|
@@ -9720,7 +9864,28 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
9720
9864
|
_getNodeRef( cache, index, object ) {
|
|
9721
9865
|
|
|
9722
9866
|
if ( cache.refs[ index ] <= 1 ) return object;
|
|
9723
|
-
const ref = object.clone();
|
|
9867
|
+
const ref = object.clone(); // Propagates mappings to the cloned object, prevents mappings on the
|
|
9868
|
+
// original object from being lost.
|
|
9869
|
+
|
|
9870
|
+
const updateMappings = ( original, clone ) => {
|
|
9871
|
+
|
|
9872
|
+
const mappings = this.associations.get( original );
|
|
9873
|
+
|
|
9874
|
+
if ( mappings != null ) {
|
|
9875
|
+
|
|
9876
|
+
this.associations.set( clone, mappings );
|
|
9877
|
+
|
|
9878
|
+
}
|
|
9879
|
+
|
|
9880
|
+
for ( const [ i, child ] of original.children.entries() ) {
|
|
9881
|
+
|
|
9882
|
+
updateMappings( child, clone.children[ i ] );
|
|
9883
|
+
|
|
9884
|
+
}
|
|
9885
|
+
|
|
9886
|
+
};
|
|
9887
|
+
|
|
9888
|
+
updateMappings( object, ref );
|
|
9724
9889
|
ref.name += '_instance_' + cache.uses[ index ] ++;
|
|
9725
9890
|
return ref;
|
|
9726
9891
|
|
|
@@ -9828,7 +9993,11 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
9828
9993
|
break;
|
|
9829
9994
|
|
|
9830
9995
|
case 'animation':
|
|
9831
|
-
dependency = this.
|
|
9996
|
+
dependency = this._invokeOne( function ( ext ) {
|
|
9997
|
+
|
|
9998
|
+
return ext.loadAnimation && ext.loadAnimation( index );
|
|
9999
|
+
|
|
10000
|
+
} );
|
|
9832
10001
|
break;
|
|
9833
10002
|
|
|
9834
10003
|
case 'camera':
|
|
@@ -9902,7 +10071,7 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
9902
10071
|
const options = this.options;
|
|
9903
10072
|
return new Promise( function ( resolve, reject ) {
|
|
9904
10073
|
|
|
9905
|
-
loader.load( resolveURL( bufferDef.uri, options.path ), resolve, undefined, function () {
|
|
10074
|
+
loader.load( THREE.LoaderUtils.resolveURL( bufferDef.uri, options.path ), resolve, undefined, function () {
|
|
9906
10075
|
|
|
9907
10076
|
reject( new Error( 'THREE.GLTFLoader: Failed to load buffer "' + bufferDef.uri + '".' ) );
|
|
9908
10077
|
|
|
@@ -10066,27 +10235,28 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
10066
10235
|
const json = this.json;
|
|
10067
10236
|
const options = this.options;
|
|
10068
10237
|
const textureDef = json.textures[ textureIndex ];
|
|
10069
|
-
const
|
|
10238
|
+
const sourceIndex = textureDef.source;
|
|
10239
|
+
const sourceDef = json.images[ sourceIndex ];
|
|
10070
10240
|
let loader = this.textureLoader;
|
|
10071
10241
|
|
|
10072
|
-
if (
|
|
10242
|
+
if ( sourceDef.uri ) {
|
|
10073
10243
|
|
|
10074
|
-
const handler = options.manager.getHandler(
|
|
10244
|
+
const handler = options.manager.getHandler( sourceDef.uri );
|
|
10075
10245
|
if ( handler !== null ) loader = handler;
|
|
10076
10246
|
|
|
10077
10247
|
}
|
|
10078
10248
|
|
|
10079
|
-
return this.loadTextureImage( textureIndex,
|
|
10249
|
+
return this.loadTextureImage( textureIndex, sourceIndex, loader );
|
|
10080
10250
|
|
|
10081
10251
|
}
|
|
10082
10252
|
|
|
10083
|
-
loadTextureImage( textureIndex,
|
|
10253
|
+
loadTextureImage( textureIndex, sourceIndex, loader ) {
|
|
10084
10254
|
|
|
10085
10255
|
const parser = this;
|
|
10086
10256
|
const json = this.json;
|
|
10087
|
-
const options = this.options;
|
|
10088
10257
|
const textureDef = json.textures[ textureIndex ];
|
|
10089
|
-
const
|
|
10258
|
+
const sourceDef = json.images[ sourceIndex ];
|
|
10259
|
+
const cacheKey = ( sourceDef.uri || sourceDef.bufferView ) + ':' + textureDef.sampler;
|
|
10090
10260
|
|
|
10091
10261
|
if ( this.textureCache[ cacheKey ] ) {
|
|
10092
10262
|
|
|
@@ -10095,43 +10265,65 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
10095
10265
|
|
|
10096
10266
|
}
|
|
10097
10267
|
|
|
10098
|
-
const
|
|
10099
|
-
let sourceURI = source.uri || '';
|
|
10100
|
-
let isObjectURL = false;
|
|
10101
|
-
let hasAlpha = true;
|
|
10102
|
-
const isJPEG = sourceURI.search( /\.jpe?g($|\?)/i ) > 0 || sourceURI.search( /^data\:image\/jpeg/ ) === 0;
|
|
10103
|
-
if ( source.mimeType === 'image/jpeg' || isJPEG ) hasAlpha = false;
|
|
10268
|
+
const promise = this.loadImageSource( sourceIndex, loader ).then( function ( texture ) {
|
|
10104
10269
|
|
|
10105
|
-
|
|
10270
|
+
texture.flipY = false;
|
|
10271
|
+
if ( textureDef.name ) texture.name = textureDef.name;
|
|
10272
|
+
const samplers = json.samplers || {};
|
|
10273
|
+
const sampler = samplers[ textureDef.sampler ] || {};
|
|
10274
|
+
texture.magFilter = WEBGL_FILTERS[ sampler.magFilter ] || THREE.LinearFilter;
|
|
10275
|
+
texture.minFilter = WEBGL_FILTERS[ sampler.minFilter ] || THREE.LinearMipmapLinearFilter;
|
|
10276
|
+
texture.wrapS = WEBGL_WRAPPINGS[ sampler.wrapS ] || THREE.RepeatWrapping;
|
|
10277
|
+
texture.wrapT = WEBGL_WRAPPINGS[ sampler.wrapT ] || THREE.RepeatWrapping;
|
|
10278
|
+
parser.associations.set( texture, {
|
|
10279
|
+
textures: textureIndex
|
|
10280
|
+
} );
|
|
10281
|
+
return texture;
|
|
10106
10282
|
|
|
10107
|
-
|
|
10108
|
-
sourceURI = parser.getDependency( 'bufferView', source.bufferView ).then( function ( bufferView ) {
|
|
10283
|
+
} ).catch( function () {
|
|
10109
10284
|
|
|
10110
|
-
|
|
10285
|
+
return null;
|
|
10111
10286
|
|
|
10112
|
-
|
|
10113
|
-
|
|
10114
|
-
|
|
10115
|
-
// sometimes contains alpha.
|
|
10116
|
-
//
|
|
10117
|
-
// https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header
|
|
10118
|
-
const colorType = new DataView( bufferView, 25, 1 ).getUint8( 0, false );
|
|
10119
|
-
hasAlpha = colorType === 6 || colorType === 4 || colorType === 3;
|
|
10287
|
+
} );
|
|
10288
|
+
this.textureCache[ cacheKey ] = promise;
|
|
10289
|
+
return promise;
|
|
10120
10290
|
|
|
10121
|
-
|
|
10291
|
+
}
|
|
10292
|
+
|
|
10293
|
+
loadImageSource( sourceIndex, loader ) {
|
|
10294
|
+
|
|
10295
|
+
const parser = this;
|
|
10296
|
+
const json = this.json;
|
|
10297
|
+
const options = this.options;
|
|
10298
|
+
|
|
10299
|
+
if ( this.sourceCache[ sourceIndex ] !== undefined ) {
|
|
10300
|
+
|
|
10301
|
+
return this.sourceCache[ sourceIndex ].then( texture => texture.clone() );
|
|
10302
|
+
|
|
10303
|
+
}
|
|
10304
|
+
|
|
10305
|
+
const sourceDef = json.images[ sourceIndex ];
|
|
10306
|
+
const URL = self.URL || self.webkitURL;
|
|
10307
|
+
let sourceURI = sourceDef.uri || '';
|
|
10308
|
+
let isObjectURL = false;
|
|
10309
|
+
|
|
10310
|
+
if ( sourceDef.bufferView !== undefined ) {
|
|
10311
|
+
|
|
10312
|
+
// Load binary image data from bufferView, if provided.
|
|
10313
|
+
sourceURI = parser.getDependency( 'bufferView', sourceDef.bufferView ).then( function ( bufferView ) {
|
|
10122
10314
|
|
|
10123
10315
|
isObjectURL = true;
|
|
10124
10316
|
const blob = new Blob( [ bufferView ], {
|
|
10125
|
-
type:
|
|
10317
|
+
type: sourceDef.mimeType
|
|
10126
10318
|
} );
|
|
10127
10319
|
sourceURI = URL.createObjectURL( blob );
|
|
10128
10320
|
return sourceURI;
|
|
10129
10321
|
|
|
10130
10322
|
} );
|
|
10131
10323
|
|
|
10132
|
-
} else if (
|
|
10324
|
+
} else if ( sourceDef.uri === undefined ) {
|
|
10133
10325
|
|
|
10134
|
-
throw new Error( 'THREE.GLTFLoader: Image ' +
|
|
10326
|
+
throw new Error( 'THREE.GLTFLoader: Image ' + sourceIndex + ' is missing URI and bufferView' );
|
|
10135
10327
|
|
|
10136
10328
|
}
|
|
10137
10329
|
|
|
@@ -10145,8 +10337,6 @@ if (typeof THREE == 'undefined') var THREE = {};
|
|
|
10145
10337
|
|
|
10146
10338
|
onLoad = function ( imageBitmap ) {
|
|
10147
10339
|
|
|
10148
|
-
imageBitmap.originalSrc = sourceURI;
|
|
10149
|
-
|
|
10150
10340
|
const texture = new THREE.Texture( imageBitmap );
|
|
10151
10341
|
texture.needsUpdate = true;
|
|
10152
10342
|
resolve( texture );
|
|
@@ -10155,7 +10345,7 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
10155
10345
|
|
|
10156
10346
|
}
|
|
10157
10347
|
|
|
10158
|
-
loader.load( resolveURL( sourceURI, options.path ), onLoad, undefined, reject );
|
|
10348
|
+
loader.load( THREE.LoaderUtils.resolveURL( sourceURI, options.path ), onLoad, undefined, reject );
|
|
10159
10349
|
|
|
10160
10350
|
} );
|
|
10161
10351
|
|
|
@@ -10164,33 +10354,20 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
10164
10354
|
// Clean up resources and configure THREE.Texture.
|
|
10165
10355
|
if ( isObjectURL === true ) {
|
|
10166
10356
|
|
|
10167
|
-
|
|
10357
|
+
URL.revokeObjectURL( sourceURI );
|
|
10168
10358
|
|
|
10169
10359
|
}
|
|
10170
10360
|
|
|
10171
|
-
texture.
|
|
10172
|
-
if ( textureDef.name ) texture.name = textureDef.name; // When there is definitely no alpha channel in the texture, set THREE.RGBFormat to save space.
|
|
10173
|
-
|
|
10174
|
-
if ( ! hasAlpha ) texture.format = THREE.RGBFormat;
|
|
10175
|
-
const samplers = json.samplers || {};
|
|
10176
|
-
const sampler = samplers[ textureDef.sampler ] || {};
|
|
10177
|
-
texture.magFilter = WEBGL_FILTERS[ sampler.magFilter ] || THREE.LinearFilter;
|
|
10178
|
-
texture.minFilter = WEBGL_FILTERS[ sampler.minFilter ] || THREE.LinearMipmapLinearFilter;
|
|
10179
|
-
texture.wrapS = WEBGL_WRAPPINGS[ sampler.wrapS ] || THREE.RepeatWrapping;
|
|
10180
|
-
texture.wrapT = WEBGL_WRAPPINGS[ sampler.wrapT ] || THREE.RepeatWrapping;
|
|
10181
|
-
parser.associations.set( texture, {
|
|
10182
|
-
type: 'textures',
|
|
10183
|
-
index: textureIndex
|
|
10184
|
-
} );
|
|
10361
|
+
texture.userData.mimeType = sourceDef.mimeType || getImageURIMimeType( sourceDef.uri );
|
|
10185
10362
|
return texture;
|
|
10186
10363
|
|
|
10187
|
-
} ).catch( function () {
|
|
10364
|
+
} ).catch( function ( error ) {
|
|
10188
10365
|
|
|
10189
10366
|
console.error( 'THREE.GLTFLoader: Couldn\'t load texture', sourceURI );
|
|
10190
|
-
|
|
10367
|
+
throw error;
|
|
10191
10368
|
|
|
10192
10369
|
} );
|
|
10193
|
-
this.
|
|
10370
|
+
this.sourceCache[ sourceIndex ] = promise;
|
|
10194
10371
|
return promise;
|
|
10195
10372
|
|
|
10196
10373
|
}
|
|
@@ -10203,7 +10380,7 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
10203
10380
|
*/
|
|
10204
10381
|
|
|
10205
10382
|
|
|
10206
|
-
assignTexture( materialParams, mapName, mapDef ) {
|
|
10383
|
+
assignTexture( materialParams, mapName, mapDef, encoding ) {
|
|
10207
10384
|
|
|
10208
10385
|
const parser = this;
|
|
10209
10386
|
return this.getDependency( 'texture', mapDef.index ).then( function ( texture ) {
|
|
@@ -10230,6 +10407,12 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
10230
10407
|
|
|
10231
10408
|
}
|
|
10232
10409
|
|
|
10410
|
+
if ( texture && encoding !== undefined ) {
|
|
10411
|
+
|
|
10412
|
+
texture.encoding = encoding;
|
|
10413
|
+
|
|
10414
|
+
}
|
|
10415
|
+
|
|
10233
10416
|
materialParams[ mapName ] = texture;
|
|
10234
10417
|
return texture;
|
|
10235
10418
|
|
|
@@ -10250,7 +10433,7 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
10250
10433
|
|
|
10251
10434
|
const geometry = mesh.geometry;
|
|
10252
10435
|
let material = mesh.material;
|
|
10253
|
-
const
|
|
10436
|
+
const useDerivativeTangents = geometry.attributes.tangent === undefined;
|
|
10254
10437
|
const useVertexColors = geometry.attributes.color !== undefined;
|
|
10255
10438
|
const useFlatShading = geometry.attributes.normal === undefined;
|
|
10256
10439
|
|
|
@@ -10292,11 +10475,11 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
10292
10475
|
} // Clone the material if it will be modified
|
|
10293
10476
|
|
|
10294
10477
|
|
|
10295
|
-
if (
|
|
10478
|
+
if ( useDerivativeTangents || useVertexColors || useFlatShading ) {
|
|
10296
10479
|
|
|
10297
10480
|
let cacheKey = 'ClonedMaterial:' + material.uuid + ':';
|
|
10298
10481
|
if ( material.isGLTFSpecularGlossinessMaterial ) cacheKey += 'specular-glossiness:';
|
|
10299
|
-
if (
|
|
10482
|
+
if ( useDerivativeTangents ) cacheKey += 'derivative-tangents:';
|
|
10300
10483
|
if ( useVertexColors ) cacheKey += 'vertex-colors:';
|
|
10301
10484
|
if ( useFlatShading ) cacheKey += 'flat-shading:';
|
|
10302
10485
|
let cachedMaterial = this.cache.get( cacheKey );
|
|
@@ -10307,7 +10490,7 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
10307
10490
|
if ( useVertexColors ) cachedMaterial.vertexColors = true;
|
|
10308
10491
|
if ( useFlatShading ) cachedMaterial.flatShading = true;
|
|
10309
10492
|
|
|
10310
|
-
if (
|
|
10493
|
+
if ( useDerivativeTangents ) {
|
|
10311
10494
|
|
|
10312
10495
|
// https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
|
|
10313
10496
|
if ( cachedMaterial.normalScale ) cachedMaterial.normalScale.y *= - 1;
|
|
@@ -10335,7 +10518,7 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
10335
10518
|
|
|
10336
10519
|
}
|
|
10337
10520
|
|
|
10338
|
-
getMaterialType(
|
|
10521
|
+
getMaterialType() {
|
|
10339
10522
|
|
|
10340
10523
|
return THREE.MeshStandardMaterial;
|
|
10341
10524
|
|
|
@@ -10388,7 +10571,7 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
10388
10571
|
|
|
10389
10572
|
if ( metallicRoughness.baseColorTexture !== undefined ) {
|
|
10390
10573
|
|
|
10391
|
-
pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture ) );
|
|
10574
|
+
pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture, THREE.sRGBEncoding ) );
|
|
10392
10575
|
|
|
10393
10576
|
}
|
|
10394
10577
|
|
|
@@ -10443,13 +10626,13 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
10443
10626
|
|
|
10444
10627
|
if ( materialDef.normalTexture !== undefined && materialType !== THREE.MeshBasicMaterial ) {
|
|
10445
10628
|
|
|
10446
|
-
pending.push( parser.assignTexture( materialParams, 'normalMap', materialDef.normalTexture ) );
|
|
10447
|
-
|
|
10448
|
-
materialParams.normalScale = new THREE.Vector2( 1, - 1 );
|
|
10629
|
+
pending.push( parser.assignTexture( materialParams, 'normalMap', materialDef.normalTexture ) );
|
|
10630
|
+
materialParams.normalScale = new THREE.Vector2( 1, 1 );
|
|
10449
10631
|
|
|
10450
10632
|
if ( materialDef.normalTexture.scale !== undefined ) {
|
|
10451
10633
|
|
|
10452
|
-
|
|
10634
|
+
const scale = materialDef.normalTexture.scale;
|
|
10635
|
+
materialParams.normalScale.set( scale, scale );
|
|
10453
10636
|
|
|
10454
10637
|
}
|
|
10455
10638
|
|
|
@@ -10475,7 +10658,7 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
10475
10658
|
|
|
10476
10659
|
if ( materialDef.emissiveTexture !== undefined && materialType !== THREE.MeshBasicMaterial ) {
|
|
10477
10660
|
|
|
10478
|
-
pending.push( parser.assignTexture( materialParams, 'emissiveMap', materialDef.emissiveTexture ) );
|
|
10661
|
+
pending.push( parser.assignTexture( materialParams, 'emissiveMap', materialDef.emissiveTexture, THREE.sRGBEncoding ) );
|
|
10479
10662
|
|
|
10480
10663
|
}
|
|
10481
10664
|
|
|
@@ -10493,14 +10676,10 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
10493
10676
|
|
|
10494
10677
|
}
|
|
10495
10678
|
|
|
10496
|
-
if ( materialDef.name ) material.name = materialDef.name;
|
|
10497
|
-
|
|
10498
|
-
if ( material.map ) material.map.encoding = THREE.sRGBEncoding;
|
|
10499
|
-
if ( material.emissiveMap ) material.emissiveMap.encoding = THREE.sRGBEncoding;
|
|
10679
|
+
if ( materialDef.name ) material.name = materialDef.name;
|
|
10500
10680
|
assignExtrasToUserData( material, materialDef );
|
|
10501
10681
|
parser.associations.set( material, {
|
|
10502
|
-
|
|
10503
|
-
index: materialIndex
|
|
10682
|
+
materials: materialIndex
|
|
10504
10683
|
} );
|
|
10505
10684
|
if ( materialDef.extensions ) addUnknownExtensionsToUserData( extensions, material, materialDef );
|
|
10506
10685
|
return material;
|
|
@@ -10693,6 +10872,15 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
10693
10872
|
|
|
10694
10873
|
}
|
|
10695
10874
|
|
|
10875
|
+
for ( let i = 0, il = meshes.length; i < il; i ++ ) {
|
|
10876
|
+
|
|
10877
|
+
parser.associations.set( meshes[ i ], {
|
|
10878
|
+
meshes: meshIndex,
|
|
10879
|
+
primitives: i
|
|
10880
|
+
} );
|
|
10881
|
+
|
|
10882
|
+
}
|
|
10883
|
+
|
|
10696
10884
|
if ( meshes.length === 1 ) {
|
|
10697
10885
|
|
|
10698
10886
|
return meshes[ 0 ];
|
|
@@ -10700,6 +10888,9 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
10700
10888
|
}
|
|
10701
10889
|
|
|
10702
10890
|
const group = new THREE.Group();
|
|
10891
|
+
parser.associations.set( group, {
|
|
10892
|
+
meshes: meshIndex
|
|
10893
|
+
} );
|
|
10703
10894
|
|
|
10704
10895
|
for ( let i = 0, il = meshes.length; i < il; i ++ ) {
|
|
10705
10896
|
|
|
@@ -10854,10 +11045,9 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
10854
11045
|
|
|
10855
11046
|
if ( PATH_PROPERTIES[ target.path ] === PATH_PROPERTIES.weights ) {
|
|
10856
11047
|
|
|
10857
|
-
// Node may be a THREE.Group (glTF mesh with several primitives) or a THREE.Mesh.
|
|
10858
11048
|
node.traverse( function ( object ) {
|
|
10859
11049
|
|
|
10860
|
-
if ( object.
|
|
11050
|
+
if ( object.morphTargetInfluences ) {
|
|
10861
11051
|
|
|
10862
11052
|
targetNames.push( object.name ? object.name : object.uuid );
|
|
10863
11053
|
|
|
@@ -10899,7 +11089,8 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
10899
11089
|
// A CUBICSPLINE keyframe in glTF has three output values for each input value,
|
|
10900
11090
|
// representing inTangent, splineVertex, and outTangent. As a result, track.getValueSize()
|
|
10901
11091
|
// must be divided by three to get the interpolant's sampleSize argument.
|
|
10902
|
-
|
|
11092
|
+
const interpolantType = this instanceof THREE.QuaternionKeyframeTrack ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
|
|
11093
|
+
return new interpolantType( this.times, this.values, this.getValueSize() / 3, result );
|
|
10903
11094
|
|
|
10904
11095
|
}; // Mark as CUBICSPLINE. `track.getInterpolation()` doesn't support custom interpolants.
|
|
10905
11096
|
|
|
@@ -11076,10 +11267,13 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
11076
11267
|
|
|
11077
11268
|
}
|
|
11078
11269
|
|
|
11079
|
-
parser.associations.
|
|
11080
|
-
|
|
11081
|
-
|
|
11082
|
-
|
|
11270
|
+
if ( ! parser.associations.has( node ) ) {
|
|
11271
|
+
|
|
11272
|
+
parser.associations.set( node, {} );
|
|
11273
|
+
|
|
11274
|
+
}
|
|
11275
|
+
|
|
11276
|
+
parser.associations.get( node ).nodes = nodeIndex;
|
|
11083
11277
|
return node;
|
|
11084
11278
|
|
|
11085
11279
|
} );
|
|
@@ -11109,12 +11303,44 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
11109
11303
|
|
|
11110
11304
|
for ( let i = 0, il = nodeIds.length; i < il; i ++ ) {
|
|
11111
11305
|
|
|
11112
|
-
pending.push(
|
|
11306
|
+
pending.push( buildNodeHierarchy( nodeIds[ i ], scene, json, parser ) );
|
|
11113
11307
|
|
|
11114
11308
|
}
|
|
11115
11309
|
|
|
11116
11310
|
return Promise.all( pending ).then( function () {
|
|
11117
11311
|
|
|
11312
|
+
// Removes dangling associations, associations that reference a node that
|
|
11313
|
+
// didn't make it into the scene.
|
|
11314
|
+
const reduceAssociations = node => {
|
|
11315
|
+
|
|
11316
|
+
const reducedAssociations = new Map();
|
|
11317
|
+
|
|
11318
|
+
for ( const [ key, value ] of parser.associations ) {
|
|
11319
|
+
|
|
11320
|
+
if ( key instanceof THREE.Material || key instanceof THREE.Texture ) {
|
|
11321
|
+
|
|
11322
|
+
reducedAssociations.set( key, value );
|
|
11323
|
+
|
|
11324
|
+
}
|
|
11325
|
+
|
|
11326
|
+
}
|
|
11327
|
+
|
|
11328
|
+
node.traverse( node => {
|
|
11329
|
+
|
|
11330
|
+
const mappings = parser.associations.get( node );
|
|
11331
|
+
|
|
11332
|
+
if ( mappings != null ) {
|
|
11333
|
+
|
|
11334
|
+
reducedAssociations.set( node, mappings );
|
|
11335
|
+
|
|
11336
|
+
}
|
|
11337
|
+
|
|
11338
|
+
} );
|
|
11339
|
+
return reducedAssociations;
|
|
11340
|
+
|
|
11341
|
+
};
|
|
11342
|
+
|
|
11343
|
+
parser.associations = reduceAssociations( scene );
|
|
11118
11344
|
return scene;
|
|
11119
11345
|
|
|
11120
11346
|
} );
|
|
@@ -11123,7 +11349,7 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
11123
11349
|
|
|
11124
11350
|
}
|
|
11125
11351
|
|
|
11126
|
-
function
|
|
11352
|
+
function buildNodeHierarchy( nodeId, parentObject, json, parser ) {
|
|
11127
11353
|
|
|
11128
11354
|
const nodeDef = json.nodes[ nodeId ];
|
|
11129
11355
|
return parser.getDependency( 'node', nodeId ).then( function ( node ) {
|
|
@@ -11197,7 +11423,7 @@ imageBitmap.originalSrc = sourceURI;
|
|
|
11197
11423
|
for ( let i = 0, il = children.length; i < il; i ++ ) {
|
|
11198
11424
|
|
|
11199
11425
|
const child = children[ i ];
|
|
11200
|
-
pending.push(
|
|
11426
|
+
pending.push( buildNodeHierarchy( child, node, json, parser ) );
|
|
11201
11427
|
|
|
11202
11428
|
}
|
|
11203
11429
|
|
|
@@ -16128,3 +16354,569 @@ THREE.MMDLoader = ( function () {
|
|
|
16128
16354
|
THREE.DRACOLoader = DRACOLoader;
|
|
16129
16355
|
|
|
16130
16356
|
} )();
|
|
16357
|
+
( function () {
|
|
16358
|
+
|
|
16359
|
+
/**
|
|
16360
|
+
* THREE.Loader for KTX 2.0 GPU Texture containers.
|
|
16361
|
+
*
|
|
16362
|
+
* KTX 2.0 is a container format for various GPU texture formats. The loader
|
|
16363
|
+
* supports Basis Universal GPU textures, which can be quickly transcoded to
|
|
16364
|
+
* a wide variety of GPU texture compression formats. While KTX 2.0 also allows
|
|
16365
|
+
* other hardware-specific formats, this loader does not yet parse them.
|
|
16366
|
+
*
|
|
16367
|
+
* References:
|
|
16368
|
+
* - KTX: http://github.khronos.org/KTX-Specification/
|
|
16369
|
+
* - DFD: https://www.khronos.org/registry/DataFormat/specs/1.3/dataformat.1.3.html#basicdescriptor
|
|
16370
|
+
*/
|
|
16371
|
+
const KTX2TransferSRGB = 2;
|
|
16372
|
+
const KTX2_ALPHA_PREMULTIPLIED = 1;
|
|
16373
|
+
|
|
16374
|
+
const _taskCache = new WeakMap();
|
|
16375
|
+
|
|
16376
|
+
let _activeLoaders = 0;
|
|
16377
|
+
|
|
16378
|
+
class KTX2Loader extends THREE.Loader {
|
|
16379
|
+
|
|
16380
|
+
constructor( manager ) {
|
|
16381
|
+
|
|
16382
|
+
super( manager );
|
|
16383
|
+
this.transcoderPath = '';
|
|
16384
|
+
this.transcoderBinary = null;
|
|
16385
|
+
this.transcoderPending = null;
|
|
16386
|
+
this.workerPool = new THREE.WorkerPool();
|
|
16387
|
+
this.workerSourceURL = '';
|
|
16388
|
+
this.workerConfig = null;
|
|
16389
|
+
|
|
16390
|
+
if ( typeof MSC_TRANSCODER !== 'undefined' ) {
|
|
16391
|
+
|
|
16392
|
+
console.warn( 'THREE.KTX2Loader: Please update to latest "basis_transcoder".' + ' "msc_basis_transcoder" is no longer supported in three.js r125+.' );
|
|
16393
|
+
|
|
16394
|
+
}
|
|
16395
|
+
|
|
16396
|
+
}
|
|
16397
|
+
|
|
16398
|
+
setTranscoderPath( path ) {
|
|
16399
|
+
|
|
16400
|
+
this.transcoderPath = path;
|
|
16401
|
+
return this;
|
|
16402
|
+
|
|
16403
|
+
}
|
|
16404
|
+
|
|
16405
|
+
setWorkerLimit( num ) {
|
|
16406
|
+
|
|
16407
|
+
this.workerPool.setWorkerLimit( num );
|
|
16408
|
+
return this;
|
|
16409
|
+
|
|
16410
|
+
}
|
|
16411
|
+
|
|
16412
|
+
detectSupport( renderer ) {
|
|
16413
|
+
|
|
16414
|
+
this.workerConfig = {
|
|
16415
|
+
astcSupported: renderer.extensions.has( 'WEBGL_compressed_texture_astc' ),
|
|
16416
|
+
etc1Supported: renderer.extensions.has( 'WEBGL_compressed_texture_etc1' ),
|
|
16417
|
+
etc2Supported: renderer.extensions.has( 'WEBGL_compressed_texture_etc' ),
|
|
16418
|
+
dxtSupported: renderer.extensions.has( 'WEBGL_compressed_texture_s3tc' ),
|
|
16419
|
+
bptcSupported: renderer.extensions.has( 'EXT_texture_compression_bptc' ),
|
|
16420
|
+
pvrtcSupported: renderer.extensions.has( 'WEBGL_compressed_texture_pvrtc' ) || renderer.extensions.has( 'WEBKIT_WEBGL_compressed_texture_pvrtc' )
|
|
16421
|
+
};
|
|
16422
|
+
|
|
16423
|
+
if ( renderer.capabilities.isWebGL2 ) {
|
|
16424
|
+
|
|
16425
|
+
// https://github.com/mrdoob/three.js/pull/22928
|
|
16426
|
+
this.workerConfig.etc1Supported = false;
|
|
16427
|
+
|
|
16428
|
+
}
|
|
16429
|
+
|
|
16430
|
+
return this;
|
|
16431
|
+
|
|
16432
|
+
}
|
|
16433
|
+
|
|
16434
|
+
dispose() {
|
|
16435
|
+
|
|
16436
|
+
this.workerPool.dispose();
|
|
16437
|
+
if ( this.workerSourceURL ) URL.revokeObjectURL( this.workerSourceURL );
|
|
16438
|
+
return this;
|
|
16439
|
+
|
|
16440
|
+
}
|
|
16441
|
+
|
|
16442
|
+
init() {
|
|
16443
|
+
|
|
16444
|
+
if ( ! this.transcoderPending ) {
|
|
16445
|
+
|
|
16446
|
+
// Load transcoder wrapper.
|
|
16447
|
+
const jsLoader = new THREE.FileLoader( this.manager );
|
|
16448
|
+
jsLoader.setPath( this.transcoderPath );
|
|
16449
|
+
jsLoader.setWithCredentials( this.withCredentials );
|
|
16450
|
+
const jsContent = jsLoader.loadAsync( 'basis_transcoder.js' ); // Load transcoder WASM binary.
|
|
16451
|
+
|
|
16452
|
+
const binaryLoader = new THREE.FileLoader( this.manager );
|
|
16453
|
+
binaryLoader.setPath( this.transcoderPath );
|
|
16454
|
+
binaryLoader.setResponseType( 'arraybuffer' );
|
|
16455
|
+
binaryLoader.setWithCredentials( this.withCredentials );
|
|
16456
|
+
const binaryContent = binaryLoader.loadAsync( 'basis_transcoder.wasm' );
|
|
16457
|
+
this.transcoderPending = Promise.all( [ jsContent, binaryContent ] ).then( ( [ jsContent, binaryContent ] ) => {
|
|
16458
|
+
|
|
16459
|
+
const fn = KTX2Loader.BasisWorker.toString();
|
|
16460
|
+
const body = [ '/* constants */', 'let _EngineFormat = ' + JSON.stringify( KTX2Loader.EngineFormat ), 'let _TranscoderFormat = ' + JSON.stringify( KTX2Loader.TranscoderFormat ), 'let _BasisFormat = ' + JSON.stringify( KTX2Loader.BasisFormat ), '/* basis_transcoder.js */', jsContent, '/* worker */', fn.substring( fn.indexOf( '{' ) + 1, fn.lastIndexOf( '}' ) ) ].join( '\n' );
|
|
16461
|
+
this.workerSourceURL = URL.createObjectURL( new Blob( [ body ] ) );
|
|
16462
|
+
this.transcoderBinary = binaryContent;
|
|
16463
|
+
this.workerPool.setWorkerCreator( () => {
|
|
16464
|
+
|
|
16465
|
+
const worker = new Worker( this.workerSourceURL );
|
|
16466
|
+
const transcoderBinary = this.transcoderBinary.slice( 0 );
|
|
16467
|
+
worker.postMessage( {
|
|
16468
|
+
type: 'init',
|
|
16469
|
+
config: this.workerConfig,
|
|
16470
|
+
transcoderBinary
|
|
16471
|
+
}, [ transcoderBinary ] );
|
|
16472
|
+
return worker;
|
|
16473
|
+
|
|
16474
|
+
} );
|
|
16475
|
+
|
|
16476
|
+
} );
|
|
16477
|
+
|
|
16478
|
+
if ( _activeLoaders > 0 ) {
|
|
16479
|
+
|
|
16480
|
+
// Each instance loads a transcoder and allocates workers, increasing network and memory cost.
|
|
16481
|
+
console.warn( 'THREE.KTX2Loader: Multiple active KTX2 loaders may cause performance issues.' + ' Use a single KTX2Loader instance, or call .dispose() on old instances.' );
|
|
16482
|
+
|
|
16483
|
+
}
|
|
16484
|
+
|
|
16485
|
+
_activeLoaders ++;
|
|
16486
|
+
|
|
16487
|
+
}
|
|
16488
|
+
|
|
16489
|
+
return this.transcoderPending;
|
|
16490
|
+
|
|
16491
|
+
}
|
|
16492
|
+
|
|
16493
|
+
load( url, onLoad, onProgress, onError ) {
|
|
16494
|
+
|
|
16495
|
+
if ( this.workerConfig === null ) {
|
|
16496
|
+
|
|
16497
|
+
throw new Error( 'THREE.KTX2Loader: Missing initialization with `.detectSupport( renderer )`.' );
|
|
16498
|
+
|
|
16499
|
+
}
|
|
16500
|
+
|
|
16501
|
+
const loader = new THREE.FileLoader( this.manager );
|
|
16502
|
+
loader.setResponseType( 'arraybuffer' );
|
|
16503
|
+
loader.setWithCredentials( this.withCredentials );
|
|
16504
|
+
const texture = new THREE.CompressedTexture();
|
|
16505
|
+
loader.load( url, buffer => {
|
|
16506
|
+
|
|
16507
|
+
// Check for an existing task using this buffer. A transferred buffer cannot be transferred
|
|
16508
|
+
// again from this thread.
|
|
16509
|
+
if ( _taskCache.has( buffer ) ) {
|
|
16510
|
+
|
|
16511
|
+
const cachedTask = _taskCache.get( buffer );
|
|
16512
|
+
|
|
16513
|
+
return cachedTask.promise.then( onLoad ).catch( onError );
|
|
16514
|
+
|
|
16515
|
+
}
|
|
16516
|
+
|
|
16517
|
+
this._createTexture( [ buffer ] ).then( function ( _texture ) {
|
|
16518
|
+
|
|
16519
|
+
texture.copy( _texture );
|
|
16520
|
+
texture.needsUpdate = true;
|
|
16521
|
+
if ( onLoad ) onLoad( texture );
|
|
16522
|
+
|
|
16523
|
+
} ).catch( onError );
|
|
16524
|
+
|
|
16525
|
+
}, onProgress, onError );
|
|
16526
|
+
return texture;
|
|
16527
|
+
|
|
16528
|
+
}
|
|
16529
|
+
|
|
16530
|
+
_createTextureFrom( transcodeResult ) {
|
|
16531
|
+
|
|
16532
|
+
const {
|
|
16533
|
+
mipmaps,
|
|
16534
|
+
width,
|
|
16535
|
+
height,
|
|
16536
|
+
format,
|
|
16537
|
+
type,
|
|
16538
|
+
error,
|
|
16539
|
+
dfdTransferFn,
|
|
16540
|
+
dfdFlags
|
|
16541
|
+
} = transcodeResult;
|
|
16542
|
+
if ( type === 'error' ) return Promise.reject( error );
|
|
16543
|
+
const texture = new THREE.CompressedTexture( mipmaps, width, height, format, THREE.UnsignedByteType );
|
|
16544
|
+
texture.minFilter = mipmaps.length === 1 ? THREE.LinearFilter : THREE.LinearMipmapLinearFilter;
|
|
16545
|
+
texture.magFilter = THREE.LinearFilter;
|
|
16546
|
+
texture.generateMipmaps = false;
|
|
16547
|
+
texture.needsUpdate = true;
|
|
16548
|
+
texture.encoding = dfdTransferFn === KTX2TransferSRGB ? THREE.sRGBEncoding : THREE.LinearEncoding;
|
|
16549
|
+
texture.premultiplyAlpha = !! ( dfdFlags & KTX2_ALPHA_PREMULTIPLIED );
|
|
16550
|
+
return texture;
|
|
16551
|
+
|
|
16552
|
+
}
|
|
16553
|
+
/**
|
|
16554
|
+
* @param {ArrayBuffer[]} buffers
|
|
16555
|
+
* @param {object?} config
|
|
16556
|
+
* @return {Promise<CompressedTexture>}
|
|
16557
|
+
*/
|
|
16558
|
+
|
|
16559
|
+
|
|
16560
|
+
_createTexture( buffers, config = {} ) {
|
|
16561
|
+
|
|
16562
|
+
const taskConfig = config;
|
|
16563
|
+
const texturePending = this.init().then( () => {
|
|
16564
|
+
|
|
16565
|
+
return this.workerPool.postMessage( {
|
|
16566
|
+
type: 'transcode',
|
|
16567
|
+
buffers,
|
|
16568
|
+
taskConfig: taskConfig
|
|
16569
|
+
}, buffers );
|
|
16570
|
+
|
|
16571
|
+
} ).then( e => this._createTextureFrom( e.data ) ); // Cache the task result.
|
|
16572
|
+
|
|
16573
|
+
_taskCache.set( buffers[ 0 ], {
|
|
16574
|
+
promise: texturePending
|
|
16575
|
+
} );
|
|
16576
|
+
|
|
16577
|
+
return texturePending;
|
|
16578
|
+
|
|
16579
|
+
}
|
|
16580
|
+
|
|
16581
|
+
dispose() {
|
|
16582
|
+
|
|
16583
|
+
URL.revokeObjectURL( this.workerSourceURL );
|
|
16584
|
+
this.workerPool.dispose();
|
|
16585
|
+
_activeLoaders --;
|
|
16586
|
+
return this;
|
|
16587
|
+
|
|
16588
|
+
}
|
|
16589
|
+
|
|
16590
|
+
}
|
|
16591
|
+
/* CONSTANTS */
|
|
16592
|
+
|
|
16593
|
+
|
|
16594
|
+
KTX2Loader.BasisFormat = {
|
|
16595
|
+
ETC1S: 0,
|
|
16596
|
+
UASTC_4x4: 1
|
|
16597
|
+
};
|
|
16598
|
+
KTX2Loader.TranscoderFormat = {
|
|
16599
|
+
ETC1: 0,
|
|
16600
|
+
ETC2: 1,
|
|
16601
|
+
BC1: 2,
|
|
16602
|
+
BC3: 3,
|
|
16603
|
+
BC4: 4,
|
|
16604
|
+
BC5: 5,
|
|
16605
|
+
BC7_M6_OPAQUE_ONLY: 6,
|
|
16606
|
+
BC7_M5: 7,
|
|
16607
|
+
PVRTC1_4_RGB: 8,
|
|
16608
|
+
PVRTC1_4_RGBA: 9,
|
|
16609
|
+
ASTC_4x4: 10,
|
|
16610
|
+
ATC_RGB: 11,
|
|
16611
|
+
ATC_RGBA_INTERPOLATED_ALPHA: 12,
|
|
16612
|
+
RGBA32: 13,
|
|
16613
|
+
RGB565: 14,
|
|
16614
|
+
BGR565: 15,
|
|
16615
|
+
RGBA4444: 16
|
|
16616
|
+
};
|
|
16617
|
+
KTX2Loader.EngineFormat = {
|
|
16618
|
+
RGBAFormat: THREE.RGBAFormat,
|
|
16619
|
+
RGBA_ASTC_4x4_Format: THREE.RGBA_ASTC_4x4_Format,
|
|
16620
|
+
RGBA_BPTC_Format: THREE.RGBA_BPTC_Format,
|
|
16621
|
+
RGBA_ETC2_EAC_Format: THREE.RGBA_ETC2_EAC_Format,
|
|
16622
|
+
RGBA_PVRTC_4BPPV1_Format: THREE.RGBA_PVRTC_4BPPV1_Format,
|
|
16623
|
+
RGBA_S3TC_DXT5_Format: THREE.RGBA_S3TC_DXT5_Format,
|
|
16624
|
+
RGB_ETC1_Format: THREE.RGB_ETC1_Format,
|
|
16625
|
+
RGB_ETC2_Format: THREE.RGB_ETC2_Format,
|
|
16626
|
+
RGB_PVRTC_4BPPV1_Format: THREE.RGB_PVRTC_4BPPV1_Format,
|
|
16627
|
+
RGB_S3TC_DXT1_Format: THREE.RGB_S3TC_DXT1_Format
|
|
16628
|
+
};
|
|
16629
|
+
/* WEB WORKER */
|
|
16630
|
+
|
|
16631
|
+
KTX2Loader.BasisWorker = function () {
|
|
16632
|
+
|
|
16633
|
+
let config;
|
|
16634
|
+
let transcoderPending;
|
|
16635
|
+
let BasisModule;
|
|
16636
|
+
const EngineFormat = _EngineFormat; // eslint-disable-line no-undef
|
|
16637
|
+
|
|
16638
|
+
const TranscoderFormat = _TranscoderFormat; // eslint-disable-line no-undef
|
|
16639
|
+
|
|
16640
|
+
const BasisFormat = _BasisFormat; // eslint-disable-line no-undef
|
|
16641
|
+
|
|
16642
|
+
self.addEventListener( 'message', function ( e ) {
|
|
16643
|
+
|
|
16644
|
+
const message = e.data;
|
|
16645
|
+
|
|
16646
|
+
switch ( message.type ) {
|
|
16647
|
+
|
|
16648
|
+
case 'init':
|
|
16649
|
+
config = message.config;
|
|
16650
|
+
init( message.transcoderBinary );
|
|
16651
|
+
break;
|
|
16652
|
+
|
|
16653
|
+
case 'transcode':
|
|
16654
|
+
transcoderPending.then( () => {
|
|
16655
|
+
|
|
16656
|
+
try {
|
|
16657
|
+
|
|
16658
|
+
const {
|
|
16659
|
+
width,
|
|
16660
|
+
height,
|
|
16661
|
+
hasAlpha,
|
|
16662
|
+
mipmaps,
|
|
16663
|
+
format,
|
|
16664
|
+
dfdTransferFn,
|
|
16665
|
+
dfdFlags
|
|
16666
|
+
} = transcode( message.buffers[ 0 ] );
|
|
16667
|
+
const buffers = [];
|
|
16668
|
+
|
|
16669
|
+
for ( let i = 0; i < mipmaps.length; ++ i ) {
|
|
16670
|
+
|
|
16671
|
+
buffers.push( mipmaps[ i ].data.buffer );
|
|
16672
|
+
|
|
16673
|
+
}
|
|
16674
|
+
|
|
16675
|
+
self.postMessage( {
|
|
16676
|
+
type: 'transcode',
|
|
16677
|
+
id: message.id,
|
|
16678
|
+
width,
|
|
16679
|
+
height,
|
|
16680
|
+
hasAlpha,
|
|
16681
|
+
mipmaps,
|
|
16682
|
+
format,
|
|
16683
|
+
dfdTransferFn,
|
|
16684
|
+
dfdFlags
|
|
16685
|
+
}, buffers );
|
|
16686
|
+
|
|
16687
|
+
} catch ( error ) {
|
|
16688
|
+
|
|
16689
|
+
console.error( error );
|
|
16690
|
+
self.postMessage( {
|
|
16691
|
+
type: 'error',
|
|
16692
|
+
id: message.id,
|
|
16693
|
+
error: error.message
|
|
16694
|
+
} );
|
|
16695
|
+
|
|
16696
|
+
}
|
|
16697
|
+
|
|
16698
|
+
} );
|
|
16699
|
+
break;
|
|
16700
|
+
|
|
16701
|
+
}
|
|
16702
|
+
|
|
16703
|
+
} );
|
|
16704
|
+
|
|
16705
|
+
function init( wasmBinary ) {
|
|
16706
|
+
|
|
16707
|
+
transcoderPending = new Promise( resolve => {
|
|
16708
|
+
|
|
16709
|
+
BasisModule = {
|
|
16710
|
+
wasmBinary,
|
|
16711
|
+
onRuntimeInitialized: resolve
|
|
16712
|
+
};
|
|
16713
|
+
BASIS( BasisModule ); // eslint-disable-line no-undef
|
|
16714
|
+
|
|
16715
|
+
} ).then( () => {
|
|
16716
|
+
|
|
16717
|
+
BasisModule.initializeBasis();
|
|
16718
|
+
|
|
16719
|
+
if ( BasisModule.KTX2File === undefined ) {
|
|
16720
|
+
|
|
16721
|
+
console.warn( 'THREE.KTX2Loader: Please update Basis Universal transcoder.' );
|
|
16722
|
+
|
|
16723
|
+
}
|
|
16724
|
+
|
|
16725
|
+
} );
|
|
16726
|
+
|
|
16727
|
+
}
|
|
16728
|
+
|
|
16729
|
+
function transcode( buffer ) {
|
|
16730
|
+
|
|
16731
|
+
const ktx2File = new BasisModule.KTX2File( new Uint8Array( buffer ) );
|
|
16732
|
+
|
|
16733
|
+
function cleanup() {
|
|
16734
|
+
|
|
16735
|
+
ktx2File.close();
|
|
16736
|
+
ktx2File.delete();
|
|
16737
|
+
|
|
16738
|
+
}
|
|
16739
|
+
|
|
16740
|
+
if ( ! ktx2File.isValid() ) {
|
|
16741
|
+
|
|
16742
|
+
cleanup();
|
|
16743
|
+
throw new Error( 'THREE.KTX2Loader: Invalid or unsupported .ktx2 file' );
|
|
16744
|
+
|
|
16745
|
+
}
|
|
16746
|
+
|
|
16747
|
+
const basisFormat = ktx2File.isUASTC() ? BasisFormat.UASTC_4x4 : BasisFormat.ETC1S;
|
|
16748
|
+
const width = ktx2File.getWidth();
|
|
16749
|
+
const height = ktx2File.getHeight();
|
|
16750
|
+
const levels = ktx2File.getLevels();
|
|
16751
|
+
const hasAlpha = ktx2File.getHasAlpha();
|
|
16752
|
+
const dfdTransferFn = ktx2File.getDFDTransferFunc();
|
|
16753
|
+
const dfdFlags = ktx2File.getDFDFlags();
|
|
16754
|
+
const {
|
|
16755
|
+
transcoderFormat,
|
|
16756
|
+
engineFormat
|
|
16757
|
+
} = getTranscoderFormat( basisFormat, width, height, hasAlpha );
|
|
16758
|
+
|
|
16759
|
+
if ( ! width || ! height || ! levels ) {
|
|
16760
|
+
|
|
16761
|
+
cleanup();
|
|
16762
|
+
throw new Error( 'THREE.KTX2Loader: Invalid texture' );
|
|
16763
|
+
|
|
16764
|
+
}
|
|
16765
|
+
|
|
16766
|
+
if ( ! ktx2File.startTranscoding() ) {
|
|
16767
|
+
|
|
16768
|
+
cleanup();
|
|
16769
|
+
throw new Error( 'THREE.KTX2Loader: .startTranscoding failed' );
|
|
16770
|
+
|
|
16771
|
+
}
|
|
16772
|
+
|
|
16773
|
+
const mipmaps = [];
|
|
16774
|
+
|
|
16775
|
+
for ( let mip = 0; mip < levels; mip ++ ) {
|
|
16776
|
+
|
|
16777
|
+
const levelInfo = ktx2File.getImageLevelInfo( mip, 0, 0 );
|
|
16778
|
+
const mipWidth = levelInfo.origWidth;
|
|
16779
|
+
const mipHeight = levelInfo.origHeight;
|
|
16780
|
+
const dst = new Uint8Array( ktx2File.getImageTranscodedSizeInBytes( mip, 0, 0, transcoderFormat ) );
|
|
16781
|
+
const status = ktx2File.transcodeImage( dst, mip, 0, 0, transcoderFormat, 0, - 1, - 1 );
|
|
16782
|
+
|
|
16783
|
+
if ( ! status ) {
|
|
16784
|
+
|
|
16785
|
+
cleanup();
|
|
16786
|
+
throw new Error( 'THREE.KTX2Loader: .transcodeImage failed.' );
|
|
16787
|
+
|
|
16788
|
+
}
|
|
16789
|
+
|
|
16790
|
+
mipmaps.push( {
|
|
16791
|
+
data: dst,
|
|
16792
|
+
width: mipWidth,
|
|
16793
|
+
height: mipHeight
|
|
16794
|
+
} );
|
|
16795
|
+
|
|
16796
|
+
}
|
|
16797
|
+
|
|
16798
|
+
cleanup();
|
|
16799
|
+
return {
|
|
16800
|
+
width,
|
|
16801
|
+
height,
|
|
16802
|
+
hasAlpha,
|
|
16803
|
+
mipmaps,
|
|
16804
|
+
format: engineFormat,
|
|
16805
|
+
dfdTransferFn,
|
|
16806
|
+
dfdFlags
|
|
16807
|
+
};
|
|
16808
|
+
|
|
16809
|
+
} //
|
|
16810
|
+
// Optimal choice of a transcoder target format depends on the Basis format (ETC1S or UASTC),
|
|
16811
|
+
// device capabilities, and texture dimensions. The list below ranks the formats separately
|
|
16812
|
+
// for ETC1S and UASTC.
|
|
16813
|
+
//
|
|
16814
|
+
// In some cases, transcoding UASTC to RGBA32 might be preferred for higher quality (at
|
|
16815
|
+
// significant memory cost) compared to ETC1/2, BC1/3, and PVRTC. The transcoder currently
|
|
16816
|
+
// chooses RGBA32 only as a last resort and does not expose that option to the caller.
|
|
16817
|
+
|
|
16818
|
+
|
|
16819
|
+
const FORMAT_OPTIONS = [ {
|
|
16820
|
+
if: 'astcSupported',
|
|
16821
|
+
basisFormat: [ BasisFormat.UASTC_4x4 ],
|
|
16822
|
+
transcoderFormat: [ TranscoderFormat.ASTC_4x4, TranscoderFormat.ASTC_4x4 ],
|
|
16823
|
+
engineFormat: [ EngineFormat.RGBA_ASTC_4x4_Format, EngineFormat.RGBA_ASTC_4x4_Format ],
|
|
16824
|
+
priorityETC1S: Infinity,
|
|
16825
|
+
priorityUASTC: 1,
|
|
16826
|
+
needsPowerOfTwo: false
|
|
16827
|
+
}, {
|
|
16828
|
+
if: 'bptcSupported',
|
|
16829
|
+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
|
|
16830
|
+
transcoderFormat: [ TranscoderFormat.BC7_M5, TranscoderFormat.BC7_M5 ],
|
|
16831
|
+
engineFormat: [ EngineFormat.RGBA_BPTC_Format, EngineFormat.RGBA_BPTC_Format ],
|
|
16832
|
+
priorityETC1S: 3,
|
|
16833
|
+
priorityUASTC: 2,
|
|
16834
|
+
needsPowerOfTwo: false
|
|
16835
|
+
}, {
|
|
16836
|
+
if: 'dxtSupported',
|
|
16837
|
+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
|
|
16838
|
+
transcoderFormat: [ TranscoderFormat.BC1, TranscoderFormat.BC3 ],
|
|
16839
|
+
engineFormat: [ EngineFormat.RGB_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format ],
|
|
16840
|
+
priorityETC1S: 4,
|
|
16841
|
+
priorityUASTC: 5,
|
|
16842
|
+
needsPowerOfTwo: false
|
|
16843
|
+
}, {
|
|
16844
|
+
if: 'etc2Supported',
|
|
16845
|
+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
|
|
16846
|
+
transcoderFormat: [ TranscoderFormat.ETC1, TranscoderFormat.ETC2 ],
|
|
16847
|
+
engineFormat: [ EngineFormat.RGB_ETC2_Format, EngineFormat.RGBA_ETC2_EAC_Format ],
|
|
16848
|
+
priorityETC1S: 1,
|
|
16849
|
+
priorityUASTC: 3,
|
|
16850
|
+
needsPowerOfTwo: false
|
|
16851
|
+
}, {
|
|
16852
|
+
if: 'etc1Supported',
|
|
16853
|
+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
|
|
16854
|
+
transcoderFormat: [ TranscoderFormat.ETC1 ],
|
|
16855
|
+
engineFormat: [ EngineFormat.RGB_ETC1_Format ],
|
|
16856
|
+
priorityETC1S: 2,
|
|
16857
|
+
priorityUASTC: 4,
|
|
16858
|
+
needsPowerOfTwo: false
|
|
16859
|
+
}, {
|
|
16860
|
+
if: 'pvrtcSupported',
|
|
16861
|
+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
|
|
16862
|
+
transcoderFormat: [ TranscoderFormat.PVRTC1_4_RGB, TranscoderFormat.PVRTC1_4_RGBA ],
|
|
16863
|
+
engineFormat: [ EngineFormat.RGB_PVRTC_4BPPV1_Format, EngineFormat.RGBA_PVRTC_4BPPV1_Format ],
|
|
16864
|
+
priorityETC1S: 5,
|
|
16865
|
+
priorityUASTC: 6,
|
|
16866
|
+
needsPowerOfTwo: true
|
|
16867
|
+
} ];
|
|
16868
|
+
const ETC1S_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) {
|
|
16869
|
+
|
|
16870
|
+
return a.priorityETC1S - b.priorityETC1S;
|
|
16871
|
+
|
|
16872
|
+
} );
|
|
16873
|
+
const UASTC_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) {
|
|
16874
|
+
|
|
16875
|
+
return a.priorityUASTC - b.priorityUASTC;
|
|
16876
|
+
|
|
16877
|
+
} );
|
|
16878
|
+
|
|
16879
|
+
function getTranscoderFormat( basisFormat, width, height, hasAlpha ) {
|
|
16880
|
+
|
|
16881
|
+
let transcoderFormat;
|
|
16882
|
+
let engineFormat;
|
|
16883
|
+
const options = basisFormat === BasisFormat.ETC1S ? ETC1S_OPTIONS : UASTC_OPTIONS;
|
|
16884
|
+
|
|
16885
|
+
for ( let i = 0; i < options.length; i ++ ) {
|
|
16886
|
+
|
|
16887
|
+
const opt = options[ i ];
|
|
16888
|
+
if ( ! config[ opt.if ] ) continue;
|
|
16889
|
+
if ( ! opt.basisFormat.includes( basisFormat ) ) continue;
|
|
16890
|
+
if ( hasAlpha && opt.transcoderFormat.length < 2 ) continue;
|
|
16891
|
+
if ( opt.needsPowerOfTwo && ! ( isPowerOfTwo( width ) && isPowerOfTwo( height ) ) ) continue;
|
|
16892
|
+
transcoderFormat = opt.transcoderFormat[ hasAlpha ? 1 : 0 ];
|
|
16893
|
+
engineFormat = opt.engineFormat[ hasAlpha ? 1 : 0 ];
|
|
16894
|
+
return {
|
|
16895
|
+
transcoderFormat,
|
|
16896
|
+
engineFormat
|
|
16897
|
+
};
|
|
16898
|
+
|
|
16899
|
+
}
|
|
16900
|
+
|
|
16901
|
+
console.warn( 'THREE.KTX2Loader: No suitable compressed texture format found. Decoding to RGBA32.' );
|
|
16902
|
+
transcoderFormat = TranscoderFormat.RGBA32;
|
|
16903
|
+
engineFormat = EngineFormat.RGBAFormat;
|
|
16904
|
+
return {
|
|
16905
|
+
transcoderFormat,
|
|
16906
|
+
engineFormat
|
|
16907
|
+
};
|
|
16908
|
+
|
|
16909
|
+
}
|
|
16910
|
+
|
|
16911
|
+
function isPowerOfTwo( value ) {
|
|
16912
|
+
|
|
16913
|
+
if ( value <= 2 ) return true;
|
|
16914
|
+
return ( value & value - 1 ) === 0 && value !== 0;
|
|
16915
|
+
|
|
16916
|
+
}
|
|
16917
|
+
|
|
16918
|
+
};
|
|
16919
|
+
|
|
16920
|
+
THREE.KTX2Loader = KTX2Loader;
|
|
16921
|
+
|
|
16922
|
+
} )();
|