Hey guys, I’m a super newbie and following a tutorial but I’m getting a blank scene, can you tell me what I’m doing wrong? (I also tried leaving ‘scene’ inside the init() and call the createBox() and scene.add(box) calls within init(), but it didn’t work either)
Many thanks!
var scene;
function init() {
scene = new THREE.Scene();
var aspect = window.innerWidth / window.innerHeight;
var camera = new THREE.PerspectiveCamera(75, aspect, 0.1, 1000);
camera.position.z = 5;
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.getElementById('webgl').appendChild(renderer.domElement);
renderer.render(scene, camera);
}
function createBox(w, h, d){
var box = new THREE.BoxGeometry(w, h, d);
var material = new THREE.MeshBasicMaterial({
color:0x00ff00
});
var mesh = new THREE.Mesh(box, material);
return mesh;
}
init();
var aBox = createBox(1, 1, 1);
scene.add(aBox);