Let's take a look at the function I've created.
function Planet(radius, c) {
var sphere = new THREE.Mesh(
new THREE.SphereGeometry(radius, 64, 64),
new THREE.MeshLambertMaterial({ color: c })
);
}
Using this function, I then instantiate an object.
var planet = new Planet(1, 0xffffff);
Next, I try to add the sphere mesh of the newly created planet object to the three.js scene.
scene.add(planet.sphere);
Although there are no errors in the Chrome JavaScript console, the sphere doesn't appear. Interestingly, if I create a sphere mesh outside of the Planet function and add it to the scene, it works perfectly fine. However, placing everything outside functions might not be ideal for managing multiple planets in the future. I'll need to figure out how to handle organizing arrays within functions moving forward.