Currently diving into the world of three.js, I'm eager to grasp the concept of animating a mesh that was created by a function outside of the usual init() method.
In my experiments, I've successfully managed to create and rotate a cube within the init() function and animate() function. However, once the cube is generated by a separate function outside of init(), the console throws an error stating that 'cube' is not defined.
For reference, here's a brief 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);
}
After some online research, I've come to realize that "cube" falls out of scope for the animate() function. However, I'm struggling to find the correct approach to tackle this issue. Could someone please shed some light on the proper way to achieve this?