Skip to content

Commit 2c6716c

Browse files
committed
fbx2three: Restore ImageUtils, move getDataURL method.
1 parent 5350a3c commit 2c6716c

File tree

5 files changed

+87
-69
lines changed

5 files changed

+87
-69
lines changed

src/Three.Legacy.js

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import { WebGLRenderer } from './renderers/WebGLRenderer.js';
7373
import { WebGLRenderTarget } from './renderers/WebGLRenderTarget.js';
7474
import { WebGLShadowMap } from './renderers/webgl/WebGLShadowMap.js';
7575
import { WebVRManager } from './renderers/webvr/WebVRManager.js';
76+
import { ImageUtils } from './extras/ImageUtils.js';
7677
import { Shape } from './extras/core/Shape.js';
7778
import { CubeCamera } from './cameras/CubeCamera.js';
7879

@@ -1757,51 +1758,47 @@ export var GeometryUtils = {
17571758

17581759
};
17591760

1760-
export var ImageUtils = {
1761+
ImageUtils.crossOrigin = undefined;
17611762

1762-
crossOrigin: undefined,
1763+
ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
17631764

1764-
loadTexture: function ( url, mapping, onLoad, onError ) {
1765+
console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
17651766

1766-
console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
1767+
var loader = new TextureLoader();
1768+
loader.setCrossOrigin( this.crossOrigin );
17671769

1768-
var loader = new TextureLoader();
1769-
loader.setCrossOrigin( this.crossOrigin );
1770+
var texture = loader.load( url, onLoad, undefined, onError );
17701771

1771-
var texture = loader.load( url, onLoad, undefined, onError );
1772+
if ( mapping ) texture.mapping = mapping;
17721773

1773-
if ( mapping ) texture.mapping = mapping;
1774+
return texture;
17741775

1775-
return texture;
1776-
1777-
},
1778-
1779-
loadTextureCube: function ( urls, mapping, onLoad, onError ) {
1776+
};
17801777

1781-
console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
1778+
ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
17821779

1783-
var loader = new CubeTextureLoader();
1784-
loader.setCrossOrigin( this.crossOrigin );
1780+
console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
17851781

1786-
var texture = loader.load( urls, onLoad, undefined, onError );
1782+
var loader = new CubeTextureLoader();
1783+
loader.setCrossOrigin( this.crossOrigin );
17871784

1788-
if ( mapping ) texture.mapping = mapping;
1785+
var texture = loader.load( urls, onLoad, undefined, onError );
17891786

1790-
return texture;
1787+
if ( mapping ) texture.mapping = mapping;
17911788

1792-
},
1789+
return texture;
17931790

1794-
loadCompressedTexture: function () {
1791+
};
17951792

1796-
console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
1793+
ImageUtils.loadCompressedTexture = function () {
17971794

1798-
},
1795+
console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
17991796

1800-
loadCompressedTextureCube: function () {
1797+
};
18011798

1802-
console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
1799+
ImageUtils.loadCompressedTextureCube = function () {
18031800

1804-
}
1801+
console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
18051802

18061803
};
18071804

src/Three.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export { ShapePath } from './extras/core/ShapePath.js';
145145
export { Font } from './extras/core/Font.js';
146146
export { CurvePath } from './extras/core/CurvePath.js';
147147
export { Curve } from './extras/core/Curve.js';
148+
export { ImageUtils } from './extras/ImageUtils.js';
148149
export { ShapeUtils } from './extras/ShapeUtils.js';
149150
export { WebGLUtils } from './renderers/webgl/WebGLUtils.js';
150151
export * from './constants.js';

src/extras/ImageUtils.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* @author mrdoob / http://mrdoob.com/
3+
* @author alteredq / http://alteredqualia.com/
4+
* @author szimek / https://github.com/szimek/
5+
*/
6+
7+
var ImageUtils = {
8+
9+
getDataURL: function ( image ) {
10+
11+
var canvas;
12+
13+
if ( image instanceof HTMLCanvasElement ) {
14+
15+
canvas = image;
16+
17+
} else {
18+
19+
if ( typeof OffscreenCanvas !== 'undefined' ) {
20+
21+
canvas = new OffscreenCanvas( image.width, image.height );
22+
23+
} else {
24+
25+
canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
26+
canvas.width = image.width;
27+
canvas.height = image.height;
28+
29+
}
30+
31+
var context = canvas.getContext( '2d' );
32+
33+
if ( image instanceof ImageData ) {
34+
35+
context.putImageData( image, 0, 0 );
36+
37+
} else {
38+
39+
context.drawImage( image, 0, 0, image.width, image.height );
40+
41+
}
42+
43+
}
44+
45+
if ( canvas.width > 2048 || canvas.height > 2048 ) {
46+
47+
return canvas.toDataURL( 'image/jpeg', 0.6 );
48+
49+
} else {
50+
51+
return canvas.toDataURL( 'image/png' );
52+
53+
}
54+
55+
}
56+
57+
};
58+
59+
export { ImageUtils };

src/textures/Texture.js

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping, LinearEnco
1010
import { _Math } from '../math/Math.js';
1111
import { Vector2 } from '../math/Vector2.js';
1212
import { Matrix3 } from '../math/Matrix3.js';
13+
import { ImageUtils } from '../extras/ImageUtils.js';
1314

1415
var textureId = 0;
1516

@@ -183,15 +184,15 @@ Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
183184

184185
for ( var i = 0, l = image.length; i < l; i ++ ) {
185186

186-
url.push( this._getDataURL( image ) );
187+
url.push( ImageUtils.getDataURL( image ) );
187188

188189
}
189190

190191
} else {
191192

192193
// process single image
193194

194-
url = this._getDataURL( image );
195+
url = ImageUtils.getDataURL( image );
195196

196197
}
197198

@@ -216,46 +217,6 @@ Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
216217

217218
},
218219

219-
_getDataURL: function ( image ) {
220-
221-
var canvas;
222-
223-
if ( image instanceof HTMLCanvasElement ) {
224-
225-
canvas = image;
226-
227-
} else {
228-
229-
canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
230-
canvas.width = image.width;
231-
canvas.height = image.height;
232-
233-
var context = canvas.getContext( '2d' );
234-
235-
if ( image instanceof ImageData ) {
236-
237-
context.putImageData( image, 0, 0 );
238-
239-
} else {
240-
241-
context.drawImage( image, 0, 0, image.width, image.height );
242-
243-
}
244-
245-
}
246-
247-
if ( canvas.width > 2048 || canvas.height > 2048 ) {
248-
249-
return canvas.toDataURL( 'image/jpeg', 0.6 );
250-
251-
} else {
252-
253-
return canvas.toDataURL( 'image/png' );
254-
255-
}
256-
257-
},
258-
259220
dispose: function () {
260221

261222
this.dispatchEvent( { type: 'dispose' } );

utils/converters/fbx2three.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ THREE.ImageLoader.prototype.load = function ( url, onLoad ) {
5252
};
5353

5454
// Convert image buffer to data URL.
55-
THREE.Texture.prototype._getDataURL = function ( image ) {
55+
THREE.ImageUtils.getDataURL = function ( image ) {
5656

5757
if ( !( image instanceof Buffer ) ) {
5858

0 commit comments

Comments
 (0)