|
@@ -9,6 +9,7 @@ THREE.GLTFLoader = ( function () {
|
|
|
this.dracoLoader = null;
|
|
|
this.ddsLoader = null;
|
|
|
this.ktx2Loader = null;
|
|
|
+ this.meshoptDecoder = null;
|
|
|
|
|
|
this.pluginCallbacks = [];
|
|
|
|
|
@@ -36,6 +37,12 @@ THREE.GLTFLoader = ( function () {
|
|
|
|
|
|
} );
|
|
|
|
|
|
+ this.register( function ( parser ) {
|
|
|
+
|
|
|
+ return new GLTFMeshoptCompression( parser );
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
}
|
|
|
|
|
|
GLTFLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype ), {
|
|
@@ -134,6 +141,13 @@ THREE.GLTFLoader = ( function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
+ setMeshoptDecoder: function ( meshoptDecoder ) {
|
|
|
+
|
|
|
+ this.meshoptDecoder = meshoptDecoder;
|
|
|
+ return this;
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
register: function ( callback ) {
|
|
|
|
|
|
if ( this.pluginCallbacks.indexOf( callback ) === - 1 ) {
|
|
@@ -209,7 +223,8 @@ THREE.GLTFLoader = ( function () {
|
|
|
path: path || this.resourcePath || '',
|
|
|
crossOrigin: this.crossOrigin,
|
|
|
manager: this.manager,
|
|
|
- ktx2Loader: this.ktx2Loader
|
|
|
+ ktx2Loader: this.ktx2Loader,
|
|
|
+ meshoptDecoder: this.meshoptDecoder
|
|
|
|
|
|
} );
|
|
|
|
|
@@ -334,6 +349,7 @@ THREE.GLTFLoader = ( function () {
|
|
|
KHR_TEXTURE_BASISU: 'KHR_texture_basisu',
|
|
|
KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform',
|
|
|
KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization',
|
|
|
+ EXT_MESHOPT_COMPRESSION: 'EXT_meshopt_compression',
|
|
|
MSFT_TEXTURE_DDS: 'MSFT_texture_dds'
|
|
|
};
|
|
|
|
|
@@ -668,7 +684,6 @@ THREE.GLTFLoader = ( function () {
|
|
|
* BasisU Texture Extension
|
|
|
*
|
|
|
* Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_basisu
|
|
|
- * (draft PR https://github.com/KhronosGroup/glTF/pull/1751)
|
|
|
*/
|
|
|
function GLTFTextureBasisUExtension( parser ) {
|
|
|
|
|
@@ -704,6 +719,59 @@ THREE.GLTFLoader = ( function () {
|
|
|
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * meshopt BufferView Compression Extension
|
|
|
+ *
|
|
|
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_meshopt_compression
|
|
|
+ */
|
|
|
+ function GLTFMeshoptCompression( parser ) {
|
|
|
+
|
|
|
+ this.name = EXTENSIONS.EXT_MESHOPT_COMPRESSION;
|
|
|
+ this.parser = parser;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ GLTFMeshoptCompression.prototype.loadBufferView = function ( index ) {
|
|
|
+
|
|
|
+ var bufferView = this.parser.json.bufferViews[ index ];
|
|
|
+
|
|
|
+ if ( bufferView.extensions && bufferView.extensions[ this.name ] ) {
|
|
|
+
|
|
|
+ var extensionDef = bufferView.extensions[ this.name ];
|
|
|
+
|
|
|
+ var buffer = this.parser.getDependency( 'buffer', extensionDef.buffer );
|
|
|
+ var decoder = this.parser.options.meshoptDecoder;
|
|
|
+
|
|
|
+ if ( !decoder ) {
|
|
|
+
|
|
|
+ throw new Error( 'THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files' );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return Promise.all( [ buffer, decoder.ready ] ).then( function ( res ) {
|
|
|
+
|
|
|
+ var byteOffset = extensionDef.byteOffset || 0;
|
|
|
+ var byteLength = extensionDef.byteLength || 0;
|
|
|
+
|
|
|
+ var count = extensionDef.count;
|
|
|
+ var stride = extensionDef.byteStride;
|
|
|
+
|
|
|
+ var result = new ArrayBuffer( count * stride );
|
|
|
+ var source = new Uint8Array( res[ 0 ], byteOffset, byteLength );
|
|
|
+
|
|
|
+ decoder.decodeGltfBuffer( new Uint8Array( result ), count, stride, source, extensionDef.mode, extensionDef.filter );
|
|
|
+ return result;
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ return null;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
/* BINARY EXTENSION */
|
|
|
var BINARY_EXTENSION_HEADER_MAGIC = 'glTF';
|
|
|
var BINARY_EXTENSION_HEADER_LENGTH = 12;
|
|
@@ -1397,7 +1465,7 @@ THREE.GLTFLoader = ( function () {
|
|
|
|
|
|
var INTERPOLATION = {
|
|
|
CUBICSPLINE: undefined, // We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
|
|
|
- // keyframe track will be initialized with a default interpolation type, then modified.
|
|
|
+ // keyframe track will be initialized with a default interpolation type, then modified.
|
|
|
LINEAR: THREE.InterpolateLinear,
|
|
|
STEP: THREE.InterpolateDiscrete
|
|
|
};
|