2015-04-02 12:38:06 +02:00
|
|
|
var Displayable = function() {
|
|
|
|
// Nothing to do here
|
|
|
|
}
|
|
|
|
|
|
|
|
Displayable.prototype.addToScene = function(scene) {
|
|
|
|
scene.add(this.mesh);
|
|
|
|
}
|
|
|
|
|
|
|
|
Displayable.prototype.translate = function(x,y,z) {
|
|
|
|
this.geometry.applyMatrix(new THREE.Matrix4().makeTranslation(x,y,z));
|
|
|
|
}
|
|
|
|
|
|
|
|
// class Cube extends Displayable
|
|
|
|
var Cube = function(size, style) {
|
|
|
|
// Super constructor call
|
|
|
|
Displayable.call(this);
|
|
|
|
|
2015-04-07 12:04:59 +02:00
|
|
|
if (size === undefined) size = 100;
|
|
|
|
if (style === undefined) style = {};
|
2015-04-02 12:38:06 +02:00
|
|
|
|
|
|
|
this.geometry = new THREE.BoxGeometry(size, size, size);
|
2015-04-07 11:13:19 +02:00
|
|
|
// this.geometry.computeVertexNormals();
|
2015-04-02 12:38:06 +02:00
|
|
|
|
|
|
|
this.material = new THREE.MeshLambertMaterial(style);
|
|
|
|
|
|
|
|
this.mesh = new THREE.Mesh(this.geometry, this.material);
|
|
|
|
this.mesh.castShadow = false;
|
|
|
|
}
|
|
|
|
Cube.prototype = Object.create(Displayable.prototype);
|
|
|
|
Cube.prototype.constructor = Cube;
|
|
|
|
|
|
|
|
// class Plane extends Displayable
|
|
|
|
var Plane = function(size1, size2, style) {
|
|
|
|
Displayable.call(this);
|
|
|
|
|
2015-04-07 12:04:59 +02:00
|
|
|
if (style === undefined) style = {};
|
2015-04-02 12:38:06 +02:00
|
|
|
|
|
|
|
this.geometry = new THREE.PlaneBufferGeometry(size1, size2);
|
|
|
|
this.material = new THREE.MeshLambertMaterial(style);
|
2015-04-14 16:58:39 +02:00
|
|
|
this.material.side = THREE.DoubleSide;
|
2015-04-02 12:38:06 +02:00
|
|
|
this.mesh = new THREE.Mesh(this.geometry, this.material);
|
|
|
|
|
|
|
|
this.mesh.receiveShadow = true;
|
|
|
|
}
|
|
|
|
Plane.prototype = Object.create(Displayable.prototype);
|
|
|
|
Plane.prototype.constructor = Plane;
|
|
|
|
|
|
|
|
Plane.prototype.addToScene = function(scene) {
|
|
|
|
scene.add(this.mesh);
|
|
|
|
}
|