mrdoob/three.js — Issue #877: Problem adding a texture to a sphere
Author: interactiveluke
Created: 2011-12-08 16:29:27+00:00
State: open

Hi, I'm trying to add a simple texture to a sphere although it doesn't seem to be working.

I'm using a jpg image and setting within a lambert material. If I remove the map, the sphere works and shows in white, although with the map the canvas is entirely black.

Sorry, there's probably a really simple solution but I'm new to all this 3D code!

My code is below, thanks!

function addEarth() {
// create the sphere's material

var earthTexture = new THREE.MeshLambertMaterial({
color: 0xffffff,
map: THREE.ImageUtils.loadTexture("textures/earthTexture.jpg")
});

// set up the sphere vars
var radius = 50, segments = 32, rings = 32;

// create a new mesh with sphere geometry -
// we will cover the sphereMaterial next!
var sphere = new THREE.Mesh(
new THREE.SphereGeometry(radius, segments, rings),
earthTexture);

sphere.overdraw = true;

// add the sphere to the scene
scene.add(sphere);
}