I have a piece of code I am writing that should animate a 3D scene. I do this having the 3D scene structured neatly in code using classes and functions. This works on itself as a text out-putting thing.
Logically it needs to not spit out just text. The library Threejs should interact with what I build.
I want to do something like this for example:
class Tile extends SuperSpace
height: 2
sideLength: 10
class Plain extends Tile
constructor: ( { @color = 'lightgreen', @height = @height, @heightPlacement = 2 } = {} ) ->
console.log """
New plain:
color: '#{@color}'
sideLength: #{@sideLength}
height: #{@height}
heightPlacement: #{@heightPlacement}
"""
mesh: ->
geometry = new THREE.BoxGeometry 10/10, 2/10, 10/10
material = new THREE.MeshBasicMaterial { color: 0x22ff22 }
cube = new THREE.Mesh geometry, material
return cube
And call it in the scene simply like this:
scene.add plain.mesh
Which is nothing more and less than a altered existing example from the docs. plain.mesh should be the returned cube
Somehow the object doesn't get trough. I either get undefined or I get my entire function back in the console:
function () {
var cube, geometry, material;
geometry = new THREE.BoxGeometry(10 / 10, 2 / 10, 10 / 10);
material = new THREE.MeshBasicMaterial({
color: 0x22ff22
});
cube …
Hardly satisfying. Any suggestions?
plain.mesh. This is a function call:plain.mesh(). The parentheses are required when there aren't any arguments.