I've been diving into webgl tutorials on udacity, but I've hit a snag. In the examples they use material.ambient
for MeshLambertMaterial, which is working fine.
However, when I tried to implement a basic cube from scratch using MeshLambertMaterial instead of MeshBasicMaterial, I can't seem to get the cube to display. What am I missing here?
Why doesn't the ambient method work on the material object as shown in the udacity tutorials? I checked the threejs docs but couldn't find any reference to an ambient method on material. Has the API changed?
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshLambertMaterial( { color: 0x00ff00 } );
var kv = 0.4;
//this line gets error: app.js:36 Uncaught TypeError: Cannot read property 'setRGB' of undefined
material.ambient.setRGB(kv * material.color.r, kv * material.color.g, kv * material.color.b);
var cube = new THREE.Mesh( geometry, material );
scene.add( cube );
camera.position.z = 5;
function render() {
requestAnimationFrame( render );
renderer.render( scene, camera );
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
}
render();