function addEvent( obj, type, fn ) {
if ( obj.attachEvent ) {
obj['e'+type+fn] = fn;
obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
obj.attachEvent( 'on'+type, obj[type+fn] );
} else
obj.addEventListener(type, fn, false);
}
function init()
{
container = document.createElement('div');
document.body.appendChild(container);
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(65,window.innerWidth / window.innerHeight,1,10000);
camera.position.z = 8000;
camera.position.y = 0;
camera.position.x = 0;
var spherGeometry = new THREE.SphereGeometry(1300,40,40);
var texture = new THREE.Texture();
var loader = new THREE.ImageLoader();
/*loader.addEventListener('load',function(event)
{
texture.image = event.content;
texture.needsUpdate = true;
});*/
addEvent(loader,'load',function(event)
{
texture.image = event.content;
texture.needsUpdate = true;
});
loader.load('earth.jpg');
var spherTexture = new THREE.MeshBasicMaterial({map:texture,overdrow:true});
var spher = new THREE.Mesh(spherGeometry,spherTexture);
scene.add(spher);
render = new THREE.CanvasRenderer();
render.setSize(window.innerWidth,window.innerHeight);
container.appendChild(render.domElement);
animation();
function animation()
{
requestAnimationFrame(animation);
spher.rotation.y += 0.01;
render.render(scene,camera);
}
}
TypeError: obj.addEventListener is not a function
Примеры ниже не работают.
1 пример - черный экран, фигуры нет:
loader.onload = function(texture)
{
texture.image = texture;
texture.needsUpdate = true;
}
2 пример - белый экран, такой функции addEventListener нет!
/*loader.addEventListener('load',function(event)
{
texture.image = event.content;
texture.needsUpdate = true;
});*/