|
@@ -228,7 +228,7 @@ THREE.MTLLoader.MaterialCreator.prototype = {
|
|
|
break;
|
|
|
case 'map_kd':
|
|
|
// Diffuse texture map
|
|
|
- params['map'] = this.loadTexture( this.baseUrl + value );
|
|
|
+ params['map'] = THREE.MTLLoader.loadTexture( this.baseUrl + value );
|
|
|
params['map'].wrapS = this.wrap;
|
|
|
params['map'].wrapT = this.wrap;
|
|
|
break;
|
|
@@ -256,19 +256,20 @@ THREE.MTLLoader.MaterialCreator.prototype = {
|
|
|
}
|
|
|
this.materials[materialName] = new THREE.MeshPhongMaterial(params);
|
|
|
return this.materials[materialName];
|
|
|
- },
|
|
|
+ }
|
|
|
+};
|
|
|
|
|
|
- loadTexture: function ( url, mapping, onLoad, onError ) {
|
|
|
+THREE.MTLLoader.loadTexture = function ( url, mapping, onLoad, onError ) {
|
|
|
var image = new Image();
|
|
|
var texture = new THREE.Texture( image, mapping );
|
|
|
|
|
|
var loader = new THREE.ImageLoader();
|
|
|
|
|
|
loader.addEventListener( 'load', function ( event ) {
|
|
|
- texture.image = this.ensurePowerOfTwo(event.content);
|
|
|
+ texture.image = THREE.MTLLoader.ensurePowerOfTwo_(event.content);
|
|
|
texture.needsUpdate = true;
|
|
|
if ( onLoad ) onLoad( texture );
|
|
|
- }.bind(this) );
|
|
|
+ } );
|
|
|
|
|
|
loader.addEventListener( 'error', function ( event ) {
|
|
|
if ( onError ) onError( event.message );
|
|
@@ -278,34 +279,33 @@ THREE.MTLLoader.MaterialCreator.prototype = {
|
|
|
loader.load( url, image );
|
|
|
|
|
|
return texture;
|
|
|
- },
|
|
|
+ };
|
|
|
|
|
|
- ensurePowerOfTwo: function(image)
|
|
|
+THREE.MTLLoader.ensurePowerOfTwo_ = function (image)
|
|
|
+{
|
|
|
+ if (!THREE.MTLLoader.isPowerOfTwo_(image.width) || !THREE.MTLLoader.isPowerOfTwo_(image.height))
|
|
|
{
|
|
|
- if (!this.isPowerOfTwo(image.width) || !this.isPowerOfTwo(image.height))
|
|
|
- {
|
|
|
- var canvas = document.createElement("canvas");
|
|
|
- canvas.width = this.nextHighestPowerOfTwo(image.width);
|
|
|
- canvas.height = this.nextHighestPowerOfTwo(image.height);
|
|
|
- var ctx = canvas.getContext("2d");
|
|
|
- ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height);
|
|
|
- return canvas;
|
|
|
- }
|
|
|
- return image;
|
|
|
- },
|
|
|
+ var canvas = document.createElement("canvas");
|
|
|
+ canvas.width = THREE.MTLLoader.nextHighestPowerOfTwo_(image.width);
|
|
|
+ canvas.height = THREE.MTLLoader.nextHighestPowerOfTwo_(image.height);
|
|
|
+ var ctx = canvas.getContext("2d");
|
|
|
+ ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height);
|
|
|
+ return canvas;
|
|
|
+ }
|
|
|
+ return image;
|
|
|
+};
|
|
|
|
|
|
- isPowerOfTwo: function (x)
|
|
|
- {
|
|
|
- return (x & (x - 1)) == 0;
|
|
|
- },
|
|
|
+THREE.MTLLoader.isPowerOfTwo_ = function (x)
|
|
|
+{
|
|
|
+ return (x & (x - 1)) == 0;
|
|
|
+};
|
|
|
|
|
|
- nextHighestPowerOfTwo: function(x)
|
|
|
- {
|
|
|
- --x;
|
|
|
- for (var i = 1; i < 32; i <<= 1) {
|
|
|
- x = x | x >> i;
|
|
|
- }
|
|
|
- return x + 1;
|
|
|
+THREE.MTLLoader.nextHighestPowerOfTwo_ = function(x)
|
|
|
+{
|
|
|
+ --x;
|
|
|
+ for (var i = 1; i < 32; i <<= 1) {
|
|
|
+ x = x | x >> i;
|
|
|
}
|
|
|
+ return x + 1;
|
|
|
};
|
|
|
|