Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Allow GLTFLoader to use ImageBitmapLoader #19518

Merged
merged 5 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions examples/js/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,15 @@ THREE.GLTFLoader = ( function () {
// BufferGeometry caching
this.primitiveCache = {};

this.textureLoader = new THREE.TextureLoader( this.options.manager );
this.useImageBitmap = typeof createImageBitmap !== 'undefined';

// Use an ImageBitmapLoader if imageBitmaps are supported. Moves much of the
// expensive work of uploading a texture to the GPU off the main thread.
if ( this.useImageBitmap ) {
this.textureLoader = new THREE.ImageBitmapLoader( this.options.manager );
} else {
this.textureLoader = new THREE.TextureLoader( this.options.manager );
}
this.textureLoader.setCrossOrigin( this.options.crossOrigin );

this.fileLoader = new THREE.FileLoader( this.options.manager );
Expand Down Expand Up @@ -1832,6 +1840,7 @@ THREE.GLTFLoader = ( function () {
var parser = this;
var json = this.json;
var options = this.options;
var useImageBitmap = this.useImageBitmap;
var textureLoader = this.textureLoader;

var URL = self.URL || self.webkitURL;
Expand Down Expand Up @@ -1886,7 +1895,19 @@ THREE.GLTFLoader = ( function () {

return new Promise( function ( resolve, reject ) {

loader.load( resolveURL( sourceURI, options.path ), resolve, undefined, reject );
var onLoad = resolve;

if ( useImageBitmap ) {

onLoad = function ( imageBitmap ) {

resolve( new THREE.CanvasTexture( imageBitmap ) );

};

}

loader.load( resolveURL( sourceURI, options.path ), onLoad, undefined, reject );

} );

Expand Down
27 changes: 25 additions & 2 deletions examples/jsm/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import {
Box3,
BufferAttribute,
BufferGeometry,
CanvasTexture,
ClampToEdgeWrapping,
Color,
DirectionalLight,
DoubleSide,
FileLoader,
FrontSide,
Group,
ImageBitmapLoader,
InterleavedBuffer,
InterleavedBufferAttribute,
Interpolant,
Expand Down Expand Up @@ -1476,7 +1478,15 @@ var GLTFLoader = ( function () {
// BufferGeometry caching
this.primitiveCache = {};

this.textureLoader = new TextureLoader( this.options.manager );
this.useImageBitmap = typeof createImageBitmap !== 'undefined';

// Use an ImageBitmapLoader if imageBitmaps are supported. Moves much of the
// expensive work of uploading a texture to the GPU off the main thread.
if ( this.useImageBitmap ) {
this.textureLoader = new ImageBitmapLoader( this.options.manager );
} else {
this.textureLoader = new TextureLoader( this.options.manager );
}
donmccurdy marked this conversation as resolved.
Show resolved Hide resolved
this.textureLoader.setCrossOrigin( this.options.crossOrigin );

this.fileLoader = new FileLoader( this.options.manager );
Expand Down Expand Up @@ -1895,6 +1905,7 @@ var GLTFLoader = ( function () {
var parser = this;
var json = this.json;
var options = this.options;
var useImageBitmap = this.useImageBitmap;
var textureLoader = this.textureLoader;

var URL = self.URL || self.webkitURL;
Expand Down Expand Up @@ -1949,7 +1960,19 @@ var GLTFLoader = ( function () {

return new Promise( function ( resolve, reject ) {

loader.load( resolveURL( sourceURI, options.path ), resolve, undefined, reject );
var onLoad = resolve;

if ( useImageBitmap ) {

onLoad = function ( imageBitmap ) {

resolve( new CanvasTexture( imageBitmap ) );

};

}

loader.load( resolveURL( sourceURI, options.path ), onLoad, undefined, reject );

} );

Expand Down