I've encountered an issue with my JavaScript code. I'm getting an error related to the line:
this.color = cubeMaterial.color.getHex();
As a beginner, I'm having trouble understanding what I'm doing wrong.
I attempted declaring the variable "var cubeMaterial;" outside of the function "createCube," but it resulted in the error "Can't read property 'color' of undefined." Any help would be appreciated!
var scene,camera,renderer;
function createScene() {
// Setting up the scene and camera.
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(45, window.innerWidth/ window.innerHeight, 0.1, 1000);
camera.updateProjectionMatrix();
...
// Function to add GUI controls
....
}
// More functions for creating lights, objects like plane, cube, sphere
...
// Defining rendering logic
}
function init(){
createScene();
createLights();
createPlane();
createCube();
createSphere();
addControlGui(controls);
render();
}
window.addEventListener('load', init, false);