I am learning three.js and would like to understand how to animate a mesh created by a function outside the regular init().
I'm able to create a cube inside init() and rotate it inside animate(), but if the cube is created by a function outside init() the console says that cube is not defined.
Here's a quick example : http://jsfiddle.net/mattsparrer/yqbp5hx4/10/
function createCube(size) {
var geometry = new THREE.CubeGeometry(size, size, size);
var material = new THREE.MeshNormalMaterial();
cube = new THREE.Mesh(geometry, material);
scene.add(cube);
}
By searching on the web I understand "cube" is not in the scope of animate(), but I can't find the proper way to do it. Please can someone explain the way to go ?