Exploring Three.js, I'm working on creating a basic model of the solar system. My current task involves building constructor functions for planets and moons. However, I keep encountering an error message:
The function setShadow() is not recognized.
var celestialBody = function(size, color) {
this.sphere = new THREE.Mesh(new THREE.SphereGeometry(size, 32, 32),
new THREE.MeshLambertMaterial({color:color}))
return this.sphere
}
celestialBody.prototype = Object.create(THREE.Mesh.prototype);
celestialBody.prototype.constructor = celestialBody;
celestialBody.prototype.setShadow = function() {
this.sphere.castShadow = true
this.sphere.receiveShadow = true
}
I also attempted using
THREE.MESH.call(this, geometry, material)
, defining THREE.SphereGeometry = geometry
and THREE.MeshLambertMaterial = material
outside the constructor function. Is there anything specific I should be cautious about when working with Three.js, or is my approach flawed?
Edit: Another approach attempted -
var celestialBody = function() {
THREE.Mesh.call(this)
return this
}
celestialBody.prototype.setShadow = function() {
this.castShadow = true
this.receiveShadow = true
return this
}
celestialBody.prototype = Object.create(THREE.Mesh.prototype);
celestialBody.prototype.constructor = celestialBody;
var samplePlanet = new celestialBody(new THREE.SphereGeometry(70, 32, 32), new THREE.MeshLambertMaterial({color:this.getRandColor()}))
It appears that everything is inheriting correctly, but I am puzzled by the malfunctioning setShadow function.
EDIT 2: Upon trying .call(this)
, the following error was encountered:
this.updateMorphTargets is not a function