GameLib.D3.Entity = function( meshId, componentIds ) { this.meshId = meshId; if (typeof componentIds == 'undefined') { componentIds = []; } this.componentIds = componentIds; this.parentScene = null; this.mesh = null; }; GameLib.D3.Entity.prototype.onUpdate = function( deltaTime ) { for(var c in this.componentIds) { var componentId = this.componentIds[c]; if(this.parentScene.componentIdToComponent[componentId]) { this.parentScene.componentIdToComponent[componentId].onUpdate(deltaTime, this); } } }; GameLib.D3.Entity.prototype.onLateUpdate = function( deltaTime ) { for(var c in this.componentIds) { var componentId = this.componentIds[c]; if(this.parentScene.componentIdToComponent[componentId]) { this.parentScene.componentIdToComponent[componentId].onLateUpdate(deltaTime, this); } } }; GameLib.D3.Entity.prototype.onRegistered = function( parentScene ) { this.parentScene = parentScene; if(this.meshId != null && parentScene.meshIdToMesh[this.meshId]) { parentScene.threeScene.add(parentScene.meshIdToMesh[this.meshId]); this.mesh = parentScene.meshIdToMesh[this.meshId]; } }; GameLib.D3.Entity.prototype.addComponentId = function( componentId ) { this.componentIds.push(componentId); }; GameLib.D3.Entity.prototype.addComponent = function( component ) { this.parentScene.registerComponent(component); this.componentIds.push(component.componentId); component.setParentEntity(this); component.onSetParentEntity(this.parentScene, this); };