summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/3rdparty/meshoptimizer/demo/GLTFLoader.js
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/3rdparty/meshoptimizer/demo/GLTFLoader.js')
-rw-r--r--3rdparty/bgfx/3rdparty/meshoptimizer/demo/GLTFLoader.js288
1 files changed, 119 insertions, 169 deletions
diff --git a/3rdparty/bgfx/3rdparty/meshoptimizer/demo/GLTFLoader.js b/3rdparty/bgfx/3rdparty/meshoptimizer/demo/GLTFLoader.js
index 6a54452a82b..c98ea3af338 100644
--- a/3rdparty/bgfx/3rdparty/meshoptimizer/demo/GLTFLoader.js
+++ b/3rdparty/bgfx/3rdparty/meshoptimizer/demo/GLTFLoader.js
@@ -10,29 +10,29 @@ THREE.GLTFLoader = ( function () {
function GLTFLoader( manager ) {
- this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
+ THREE.Loader.call( this, manager );
+
this.dracoLoader = null;
+ this.ddsLoader = null;
this.meshoptDecoder = null;
}
- GLTFLoader.prototype = {
+ GLTFLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype ), {
constructor: GLTFLoader,
- crossOrigin: 'anonymous',
-
load: function ( url, onLoad, onProgress, onError ) {
var scope = this;
var resourcePath;
- if ( this.resourcePath !== undefined ) {
+ if ( this.resourcePath !== '' ) {
resourcePath = this.resourcePath;
- } else if ( this.path !== undefined ) {
+ } else if ( this.path !== '' ) {
resourcePath = this.path;
@@ -69,6 +69,12 @@ THREE.GLTFLoader = ( function () {
loader.setPath( this.path );
loader.setResponseType( 'arraybuffer' );
+ if ( scope.crossOrigin === 'use-credentials' ) {
+
+ loader.setWithCredentials( true );
+
+ }
+
loader.load( url, function ( data ) {
try {
@@ -91,30 +97,16 @@ THREE.GLTFLoader = ( function () {
},
- setCrossOrigin: function ( value ) {
-
- this.crossOrigin = value;
- return this;
-
- },
-
- setPath: function ( value ) {
-
- this.path = value;
- return this;
-
- },
-
- setResourcePath: function ( value ) {
+ setDRACOLoader: function ( dracoLoader ) {
- this.resourcePath = value;
+ this.dracoLoader = dracoLoader;
return this;
},
- setDRACOLoader: function ( dracoLoader ) {
+ setDDSLoader: function ( ddsLoader ) {
- this.dracoLoader = dracoLoader;
+ this.ddsLoader = ddsLoader;
return this;
},
@@ -185,11 +177,11 @@ THREE.GLTFLoader = ( function () {
break;
case EXTENSIONS.KHR_MATERIALS_UNLIT:
- extensions[ extensionName ] = new GLTFMaterialsUnlitExtension( json );
+ extensions[ extensionName ] = new GLTFMaterialsUnlitExtension();
break;
case EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:
- extensions[ extensionName ] = new GLTFMaterialsPbrSpecularGlossinessExtension( json );
+ extensions[ extensionName ] = new GLTFMaterialsPbrSpecularGlossinessExtension();
break;
case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
@@ -197,15 +189,15 @@ THREE.GLTFLoader = ( function () {
break;
case EXTENSIONS.MSFT_TEXTURE_DDS:
- extensions[ EXTENSIONS.MSFT_TEXTURE_DDS ] = new GLTFTextureDDSExtension();
+ extensions[ EXTENSIONS.MSFT_TEXTURE_DDS ] = new GLTFTextureDDSExtension( this.ddsLoader );
break;
case EXTENSIONS.KHR_TEXTURE_TRANSFORM:
- extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] = new GLTFTextureTransformExtension( json );
+ extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] = new GLTFTextureTransformExtension();
break;
case EXTENSIONS.MESHOPT_COMPRESSION:
- extensions[ extensionName ] = new GLTFMeshoptCompressionExtension( json, this.meshoptDecoder );
+ extensions[ extensionName ] = new GLTFMeshoptCompressionExtension( this.meshoptDecoder );
break;
default:
@@ -234,7 +226,7 @@ THREE.GLTFLoader = ( function () {
}
- };
+ } );
/* GLTFREGISTRY */
@@ -290,27 +282,26 @@ THREE.GLTFLoader = ( function () {
/**
* DDS Texture Extension
*
- * Specification:
- * https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_texture_dds
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_texture_dds
*
*/
- function GLTFTextureDDSExtension() {
+ function GLTFTextureDDSExtension( ddsLoader ) {
- if ( ! THREE.DDSLoader ) {
+ if ( ! ddsLoader ) {
throw new Error( 'THREE.GLTFLoader: Attempting to load .dds texture without importing THREE.DDSLoader' );
}
this.name = EXTENSIONS.MSFT_TEXTURE_DDS;
- this.ddsLoader = new THREE.DDSLoader();
+ this.ddsLoader = ddsLoader;
}
/**
- * Lights Extension
+ * Punctual Lights Extension
*
- * Specification: PENDING
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
*/
function GLTFLightsExtension( json ) {
@@ -377,9 +368,9 @@ THREE.GLTFLoader = ( function () {
};
/**
- * Unlit Materials Extension (pending)
+ * Unlit Materials Extension
*
- * PR: https://github.com/KhronosGroup/glTF/pull/1163
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
*/
function GLTFMaterialsUnlitExtension() {
@@ -426,8 +417,6 @@ THREE.GLTFLoader = ( function () {
};
/* BINARY EXTENSION */
-
- var BINARY_EXTENSION_BUFFER_NAME = 'binary_glTF';
var BINARY_EXTENSION_HEADER_MAGIC = 'glTF';
var BINARY_EXTENSION_HEADER_LENGTH = 12;
var BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4E4F534A, BIN: 0x004E4942 };
@@ -496,7 +485,7 @@ THREE.GLTFLoader = ( function () {
/**
* DRACO Mesh Compression Extension
*
- * Specification: https://github.com/KhronosGroup/glTF/pull/874
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
*/
function GLTFDracoMeshCompressionExtension( json, dracoLoader ) {
@@ -574,7 +563,7 @@ THREE.GLTFLoader = ( function () {
/**
* Texture Transform Extension
*
- * Specification:
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_transform
*/
function GLTFTextureTransformExtension() {
@@ -864,7 +853,7 @@ THREE.GLTFLoader = ( function () {
},
// Here's based on refreshUniformsCommon() and refreshUniformsStandard() in WebGLRenderer.
- refreshUniforms: function ( renderer, scene, camera, geometry, material, group ) {
+ refreshUniforms: function ( renderer, scene, camera, geometry, material ) {
if ( material.isGLTFSpecularGlossinessMaterial !== true ) {
@@ -1008,7 +997,7 @@ THREE.GLTFLoader = ( function () {
/**
* meshoptimizer Compression Extension
*/
- function GLTFMeshoptCompressionExtension( json, meshoptDecoder ) {
+ function GLTFMeshoptCompressionExtension( meshoptDecoder ) {
if ( ! meshoptDecoder ) {
@@ -1017,21 +1006,18 @@ THREE.GLTFLoader = ( function () {
}
this.name = EXTENSIONS.MESHOPT_COMPRESSION;
- this.json = json;
this.meshoptDecoder = meshoptDecoder;
}
- GLTFMeshoptCompressionExtension.prototype.decodeBufferView = function ( bufferViewDef, buffer ) {
+ GLTFMeshoptCompressionExtension.prototype.decodeBufferView = function ( extensionDef, buffer ) {
var decoder = this.meshoptDecoder;
return decoder.ready.then( function () {
- var extensionDef = bufferViewDef.extensions[ EXTENSIONS.MESHOPT_COMPRESSION ];
-
- var byteOffset = bufferViewDef.byteOffset || 0;
- var byteLength = bufferViewDef.byteLength || 0;
+ var byteOffset = extensionDef.byteOffset || 0;
+ var byteLength = extensionDef.byteLength || 0;
var count = extensionDef.count;
var stride = extensionDef.byteStride;
@@ -1058,7 +1044,7 @@ THREE.GLTFLoader = ( function () {
} );
- }
+ };
/*********************************/
/********** INTERPOLATION ********/
@@ -1167,17 +1153,6 @@ THREE.GLTFLoader = ( function () {
UNSIGNED_SHORT: 5123
};
- var WEBGL_TYPE = {
- 5126: Number,
- //35674: THREE.Matrix2,
- 35675: THREE.Matrix3,
- 35676: THREE.Matrix4,
- 35664: THREE.Vector2,
- 35665: THREE.Vector3,
- 35666: THREE.Vector4,
- 35678: THREE.Texture
- };
-
var WEBGL_COMPONENT_TYPES = {
5120: Int8Array,
5121: Uint8Array,
@@ -1190,10 +1165,10 @@ THREE.GLTFLoader = ( function () {
var WEBGL_FILTERS = {
9728: THREE.NearestFilter,
9729: THREE.LinearFilter,
- 9984: THREE.NearestMipMapNearestFilter,
- 9985: THREE.LinearMipMapNearestFilter,
- 9986: THREE.NearestMipMapLinearFilter,
- 9987: THREE.LinearMipMapLinearFilter
+ 9984: THREE.NearestMipmapNearestFilter,
+ 9985: THREE.LinearMipmapNearestFilter,
+ 9986: THREE.NearestMipmapLinearFilter,
+ 9987: THREE.LinearMipmapLinearFilter
};
var WEBGL_WRAPPINGS = {
@@ -1202,48 +1177,6 @@ THREE.GLTFLoader = ( function () {
10497: THREE.RepeatWrapping
};
- var WEBGL_SIDES = {
- 1028: THREE.BackSide, // Culling front
- 1029: THREE.FrontSide // Culling back
- //1032: THREE.NoSide // Culling front and back, what to do?
- };
-
- var WEBGL_DEPTH_FUNCS = {
- 512: THREE.NeverDepth,
- 513: THREE.LessDepth,
- 514: THREE.EqualDepth,
- 515: THREE.LessEqualDepth,
- 516: THREE.GreaterEqualDepth,
- 517: THREE.NotEqualDepth,
- 518: THREE.GreaterEqualDepth,
- 519: THREE.AlwaysDepth
- };
-
- var WEBGL_BLEND_EQUATIONS = {
- 32774: THREE.AddEquation,
- 32778: THREE.SubtractEquation,
- 32779: THREE.ReverseSubtractEquation
- };
-
- var WEBGL_BLEND_FUNCS = {
- 0: THREE.ZeroFactor,
- 1: THREE.OneFactor,
- 768: THREE.SrcColorFactor,
- 769: THREE.OneMinusSrcColorFactor,
- 770: THREE.SrcAlphaFactor,
- 771: THREE.OneMinusSrcAlphaFactor,
- 772: THREE.DstAlphaFactor,
- 773: THREE.OneMinusDstAlphaFactor,
- 774: THREE.DstColorFactor,
- 775: THREE.OneMinusDstColorFactor,
- 776: THREE.SrcAlphaSaturateFactor
- // The followings are not supported by Three.js yet
- //32769: CONSTANT_COLOR,
- //32770: ONE_MINUS_CONSTANT_COLOR,
- //32771: CONSTANT_ALPHA,
- //32772: ONE_MINUS_CONSTANT_COLOR
- };
-
var WEBGL_TYPE_SIZES = {
'SCALAR': 1,
'VEC2': 2,
@@ -1279,15 +1212,6 @@ THREE.GLTFLoader = ( function () {
STEP: THREE.InterpolateDiscrete
};
- var STATES_ENABLES = {
- 2884: 'CULL_FACE',
- 2929: 'DEPTH_TEST',
- 3042: 'BLEND',
- 3089: 'SCISSOR_TEST',
- 32823: 'POLYGON_OFFSET_FILL',
- 32926: 'SAMPLE_ALPHA_TO_COVERAGE'
- };
-
var ALPHA_MODES = {
OPAQUE: 'OPAQUE',
MASK: 'MASK',
@@ -1306,6 +1230,13 @@ THREE.GLTFLoader = ( function () {
// Invalid URL
if ( typeof url !== 'string' || url === '' ) return '';
+ // Host Relative URL
+ if ( /^https?:\/\//i.test( path ) && /^\//.test( url ) ) {
+
+ path = path.replace( /(^https?:\/\/[^\/]+).*/i, '$1' );
+
+ }
+
// Absolute URL http://,https://,//
if ( /^(https?:)?\/\//i.test( url ) ) return url;
@@ -1581,19 +1512,6 @@ THREE.GLTFLoader = ( function () {
}
}
- function isObjectEqual( a, b ) {
-
- if ( Object.keys( a ).length !== Object.keys( b ).length ) return false;
-
- for ( var key in a ) {
-
- if ( a[ key ] !== b[ key ] ) return false;
-
- }
-
- return true;
-
- }
function createPrimitiveKey( primitiveDef ) {
@@ -1677,6 +1595,12 @@ THREE.GLTFLoader = ( function () {
this.fileLoader = new THREE.FileLoader( this.options.manager );
this.fileLoader.setResponseType( 'arraybuffer' );
+ if ( this.options.crossOrigin === 'use-credentials' ) {
+
+ this.fileLoader.setWithCredentials( true );
+
+ }
+
}
GLTFParser.prototype.parse = function ( onLoad, onError ) {
@@ -1711,6 +1635,8 @@ THREE.GLTFLoader = ( function () {
addUnknownExtensionsToUserData( extensions, result, json );
+ assignExtrasToUserData( result, json );
+
onLoad( result );
} ).catch( onError );
@@ -1933,26 +1859,25 @@ THREE.GLTFLoader = ( function () {
if ( bufferViewDef.extensions && bufferViewDef.extensions[ EXTENSIONS.MESHOPT_COMPRESSION ] ) {
var extension = this.extensions[ EXTENSIONS.MESHOPT_COMPRESSION ];
+ var extensionDef = bufferViewDef.extensions[ EXTENSIONS.MESHOPT_COMPRESSION ];
- return this.getDependency( 'buffer', bufferViewDef.buffer ).then( function ( buffer ) {
+ return this.getDependency( 'buffer', extensionDef.buffer ).then( function ( buffer ) {
- return extension.decodeBufferView( bufferViewDef, buffer );
+ return extension.decodeBufferView( extensionDef, buffer );
} );
- } else {
-
- return this.getDependency( 'buffer', bufferViewDef.buffer ).then( function ( buffer ) {
+ }
- var byteLength = bufferViewDef.byteLength || 0;
- var byteOffset = bufferViewDef.byteOffset || 0;
- return buffer.slice( byteOffset, byteOffset + byteLength );
+ return this.getDependency( 'buffer', bufferViewDef.buffer ).then( function ( buffer ) {
- } );
+ var byteLength = bufferViewDef.byteLength || 0;
+ var byteOffset = bufferViewDef.byteOffset || 0;
+ return buffer.slice( byteOffset, byteOffset + byteLength );
- }
+ } );
- }
+ };
/**
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
@@ -2029,7 +1954,7 @@ THREE.GLTFLoader = ( function () {
}
- bufferAttribute = new THREE.InterleavedBufferAttribute( ib, itemSize, (byteOffset % byteStride) / elementBytes, normalized );
+ bufferAttribute = new THREE.InterleavedBufferAttribute( ib, itemSize, ( byteOffset % byteStride ) / elementBytes, normalized );
} else {
@@ -2062,7 +1987,7 @@ THREE.GLTFLoader = ( function () {
if ( bufferView !== null ) {
// Avoid modifying the original ArrayBuffer, if the bufferView wasn't initialized with zeroes.
- bufferAttribute.setArray( bufferAttribute.array.slice() );
+ bufferAttribute = new THREE.BufferAttribute( bufferAttribute.array.slice(), bufferAttribute.itemSize, bufferAttribute.normalized );
}
@@ -2138,7 +2063,7 @@ THREE.GLTFLoader = ( function () {
// Load Texture resource.
- var loader = THREE.Loader.Handlers.get( sourceURI );
+ var loader = options.manager.getHandler( sourceURI );
if ( ! loader ) {
@@ -2179,7 +2104,7 @@ THREE.GLTFLoader = ( function () {
var sampler = samplers[ textureDef.sampler ] || {};
texture.magFilter = WEBGL_FILTERS[ sampler.magFilter ] || THREE.LinearFilter;
- texture.minFilter = WEBGL_FILTERS[ sampler.minFilter ] || THREE.LinearMipMapLinearFilter;
+ texture.minFilter = WEBGL_FILTERS[ sampler.minFilter ] || THREE.LinearMipmapLinearFilter;
texture.wrapS = WEBGL_WRAPPINGS[ sampler.wrapS ] || THREE.RepeatWrapping;
texture.wrapT = WEBGL_WRAPPINGS[ sampler.wrapT ] || THREE.RepeatWrapping;
@@ -2269,7 +2194,6 @@ THREE.GLTFLoader = ( function () {
THREE.Material.prototype.copy.call( pointsMaterial, material );
pointsMaterial.color.copy( material.color );
pointsMaterial.map = material.map;
- pointsMaterial.lights = false; // PointsMaterial doesn't support lights yet
pointsMaterial.sizeAttenuation = false; // glTF spec says points should be 1px
this.cache.add( cacheKey, pointsMaterial );
@@ -2289,7 +2213,6 @@ THREE.GLTFLoader = ( function () {
lineMaterial = new THREE.LineBasicMaterial();
THREE.Material.prototype.copy.call( lineMaterial, material );
lineMaterial.color.copy( material.color );
- lineMaterial.lights = false; // LineBasicMaterial doesn't support lights yet
this.cache.add( cacheKey, lineMaterial );
@@ -2654,7 +2577,6 @@ THREE.GLTFLoader = ( function () {
var parser = this;
var json = this.json;
- var extensions = this.extensions;
var meshDef = json.meshes[ meshIndex ];
var primitives = meshDef.primitives;
@@ -2698,7 +2620,7 @@ THREE.GLTFLoader = ( function () {
? new THREE.SkinnedMesh( geometry, material )
: new THREE.Mesh( geometry, material );
- if ( mesh.isSkinnedMesh === true && !mesh.geometry.attributes.skinWeight.normalized ) {
+ if ( mesh.isSkinnedMesh === true && ! mesh.geometry.attributes.skinWeight.normalized ) {
// we normalize floating point skin weight array to fix malformed assets (see #15319)
// it's important to skip this for non-float32 data since normalizeSkinWeights assumes non-normalized inputs
@@ -2986,7 +2908,7 @@ THREE.GLTFLoader = ( function () {
for ( var j = 0, jl = outputArray.length; j < jl; j ++ ) {
- scaled[j] = outputArray[j] * scale;
+ scaled[ j ] = outputArray[ j ] * scale;
}
@@ -3053,14 +2975,11 @@ THREE.GLTFLoader = ( function () {
return ( function () {
- // .isBone isn't in glTF spec. See .markDefs
- if ( nodeDef.isBone === true ) {
-
- return Promise.resolve( new THREE.Bone() );
+ var pending = [];
- } else if ( nodeDef.mesh !== undefined ) {
+ if ( nodeDef.mesh !== undefined ) {
- return parser.getDependency( 'mesh', nodeDef.mesh ).then( function ( mesh ) {
+ pending.push( parser.getDependency( 'mesh', nodeDef.mesh ).then( function ( mesh ) {
var node;
@@ -3106,25 +3025,58 @@ THREE.GLTFLoader = ( function () {
return node;
- } );
+ } ) );
- } else if ( nodeDef.camera !== undefined ) {
+ }
- return parser.getDependency( 'camera', nodeDef.camera );
+ if ( nodeDef.camera !== undefined ) {
- } else if ( nodeDef.extensions
+ pending.push( parser.getDependency( 'camera', nodeDef.camera ) );
+
+ }
+
+ if ( nodeDef.extensions
&& nodeDef.extensions[ EXTENSIONS.KHR_LIGHTS_PUNCTUAL ]
&& nodeDef.extensions[ EXTENSIONS.KHR_LIGHTS_PUNCTUAL ].light !== undefined ) {
- return parser.getDependency( 'light', nodeDef.extensions[ EXTENSIONS.KHR_LIGHTS_PUNCTUAL ].light );
+ pending.push( parser.getDependency( 'light', nodeDef.extensions[ EXTENSIONS.KHR_LIGHTS_PUNCTUAL ].light ) );
+
+ }
+
+ return Promise.all( pending );
+
+ }() ).then( function ( objects ) {
+
+ var node;
+
+ // .isBone isn't in glTF spec. See .markDefs
+ if ( nodeDef.isBone === true ) {
+
+ node = new THREE.Bone();
+
+ } else if ( objects.length > 1 ) {
+
+ node = new THREE.Group();
+
+ } else if ( objects.length === 1 ) {
+
+ node = objects[ 0 ];
} else {
- return Promise.resolve( new THREE.Object3D() );
+ node = new THREE.Object3D();
}
- }() ).then( function ( node ) {
+ if ( node !== objects[ 0 ] ) {
+
+ for ( var i = 0, il = objects.length; i < il; i ++ ) {
+
+ node.add( objects[ i ] );
+
+ }
+
+ }
if ( nodeDef.name !== undefined ) {
@@ -3208,11 +3160,9 @@ THREE.GLTFLoader = ( function () {
} ).then( function ( jointNodes ) {
- var meshes = node.isGroup === true ? node.children : [ node ];
+ node.traverse( function ( mesh ) {
- for ( var i = 0, il = meshes.length; i < il; i ++ ) {
-
- var mesh = meshes[ i ];
+ if ( ! mesh.isMesh ) return;
var bones = [];
var boneInverses = [];
@@ -3245,7 +3195,7 @@ THREE.GLTFLoader = ( function () {
mesh.bind( new THREE.Skeleton( bones, boneInverses ), mesh.matrixWorld );
- }
+ } );
return node;