提交 dd089570 编写于 作者: M Mr.doob

Added Texture.DEFAULT_IMAGE. Different solution for #4559.

上级 d1454b25
......@@ -3491,7 +3491,7 @@ THREE.ColladaLoader = function () {
} else {
texture = new THREE.Texture( new Image() );
texture = new THREE.Texture();
loader = new THREE.ImageLoader();
loader.load( url, function ( image ) {
......
......@@ -369,12 +369,10 @@ THREE.MTLLoader.MaterialCreator.prototype = {
if ( loader !== null ) {
texture = loader.load( url, onLoad );
texture.mapping = mapping;
} else {
texture = new THREE.Texture( new Image() );
texture.mapping = mapping;
texture = new THREE.Texture();
loader = new THREE.ImageLoader();
loader.crossOrigin = this.crossOrigin;
......
......@@ -983,7 +983,7 @@ THREE.SceneLoader.prototype = {
} else {
texture = new THREE.Texture( new Image() );
texture = new THREE.Texture();
loader = new THREE.ImageLoader();
loader.load( fullUrl, function ( image ) {
......
......@@ -231,15 +231,12 @@
// ground
var initColor = new THREE.Color( 0x497f13 );
var initTexture = THREE.ImageUtils.generateDataTexture( 1, 1, initColor );
var groundMaterial = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x111111, map: initTexture } );
var groundTexture = THREE.ImageUtils.loadTexture( "textures/terrain/grasslight-big.jpg", undefined, function() { groundMaterial.map = groundTexture } );
var groundTexture = THREE.ImageUtils.loadTexture( "textures/terrain/grasslight-big.jpg" );
groundTexture.wrapS = groundTexture.wrapT = THREE.RepeatWrapping;
groundTexture.repeat.set( 25, 25 );
groundTexture.anisotropy = 16;
var groundMaterial = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x111111, map: groundTexture } );
var mesh = new THREE.Mesh( new THREE.PlaneGeometry( 20000, 20000 ), groundMaterial );
mesh.position.y = -250;
......
......@@ -13,10 +13,12 @@ THREE.ImageUtils = {
var loader = new THREE.ImageLoader();
loader.crossOrigin = this.crossOrigin;
var texture = new THREE.Texture( undefined, mapping );
var texture = new THREE.Texture();
texture.mapping = mapping;
var image = loader.load( url, function () {
loader.load( url, function ( image ) {
texture.image = image;
texture.needsUpdate = true;
if ( onLoad ) onLoad( texture );
......@@ -27,7 +29,6 @@ THREE.ImageUtils = {
} );
texture.image = image;
texture.sourceFile = url;
return texture;
......
......@@ -66,16 +66,7 @@ THREE.SpritePlugin = function () {
alphaTest: _gl.getUniformLocation( program, 'alphaTest' )
};
var canvas = document.createElement( 'canvas' );
canvas.width = 8;
canvas.height = 8;
var context = canvas.getContext( '2d' );
context.fillStyle = '#ffffff';
context.fillRect( 0, 0, canvas.width, canvas.height );
_texture = new THREE.Texture( canvas );
_texture.needsUpdate = true;
_texture = new THREE.Texture();
};
......
......@@ -126,7 +126,7 @@ THREE.Loader.prototype = {
} else {
texture = new THREE.Texture( document.createElement( 'canvas' ) );
texture = new THREE.Texture();
loader = scope.imageLoader;
loader.crossOrigin = scope.crossOrigin;
......
......@@ -11,10 +11,10 @@ THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, f
this.name = '';
this.image = image;
this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
this.mipmaps = [];
this.mapping = mapping !== undefined ? mapping : new THREE.UVMapping();
this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
......@@ -35,11 +35,27 @@ THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, f
this.flipY = true;
this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
this._needsUpdate = false;
this._needsUpdate = true;
this.onUpdate = null;
};
THREE.Texture.DEFAULT_IMAGE = ( function () {
var canvas = document.createElement( 'canvas' );
canvas.width = 8;
canvas.height = 8;
var context = canvas.getContext( '2d' );
context.fillStyle = '#ff0000';
context.fillRect( 0, 0, canvas.width, canvas.height );
return canvas;
}() );
THREE.Texture.DEFAULT_MAPPING = new THREE.UVMapping();
THREE.Texture.prototype = {
constructor: THREE.Texture,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册