2016-02-12 08:47:08 +00:00
|
|
|
import EventEmitter from 'eventemitter3';
|
|
|
|
import THREE from 'three';
|
|
|
|
import Scene from '../engine/Scene';
|
|
|
|
|
|
|
|
class Layer extends EventEmitter {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this._layer = new THREE.Object3D();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add layer to world instance and store world reference
|
|
|
|
addTo(world) {
|
|
|
|
world.addLayer(this);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Internal method called by World.addLayer to actually add the layer
|
|
|
|
_addToWorld(world) {
|
|
|
|
this._world = world;
|
2016-02-14 19:10:28 +00:00
|
|
|
this._onAdd(world);
|
2016-02-12 08:47:08 +00:00
|
|
|
this.emit('added');
|
|
|
|
}
|
2016-02-18 19:33:12 +00:00
|
|
|
|
|
|
|
// Destroys the layer and removes it from the scene and memory
|
|
|
|
destroy() {
|
|
|
|
this._world = null;
|
|
|
|
this._layer = null;
|
|
|
|
}
|
2016-02-12 08:47:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Layer;
|