I am trying to attach a simple image on a PlaneGeometry Mesh but it doesn't seem to work.
window.onload = function(){
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// camera
var camera = new THREE.PerspectiveCamera(95, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.y = -250;
camera.position.z = 400;
camera.rotation.x = 45 * (Math.PI / 180);
// scene
var scene = new THREE.Scene();
var img = new THREE.MeshLambertMaterial({
map:THREE.ImageUtils.loadTexture('img/front.jpg')
});
// plane
var plane = new THREE.Mesh(new THREE.PlaneGeometry(200, 200),img);
plane.overdraw = true;
scene.add(plane);
// add subtle ambient lighting
var ambientLight = new THREE.AmbientLight(0x555555);
scene.add(ambientLight);
// add directional light source
var directionalLight = new THREE.DirectionalLight(0xffffff);
directionalLight.position.set(1, 1, 1).normalize();
scene.add(directionalLight);
// create wrapper object that contains three.js objects
var three = {
renderer: renderer,
camera: camera,
scene: scene,
plane: plane
};
renderer.render(scene,camera);
};
This is my full javascript file with a canvas of 580×300
I only see a black square whenever I run it. any ideas? Thanks!
here is my reference for those who need it:
http://www.html5canvastutorials.com/webgl/html5-canvas-webgl-texture-with-three-js/
Best Solution
After downloading latest tag from github and playing with examples it became clear that the CORS is the one to blame. If I open the Chrome Developper Tools and look at the console there are many error messages:
If you are using Chrome, start it with flag -allow-file-access-from-files
Tested with Chrome 17.0.963.79.