namespace NT { /**
     * Represents a single entity in the world. TEntities themselves do not get rendered or have behaviors.
     * The do, however, have transforms and may have child TEntities. Components and behaviors may be
     * attached to TEntities to decorate functionality.
     */ export class TEntity extends TObject { private _children : TEntity [ ] = [ ] ; private _parent : TEntity ; private _isLoaded : boolean = false ; private _sceneGraph : SceneGraph ; private _components : IComponent [ ] = [ ] ; private _behaviors : IBehavior [ ] = [ ] ; private _isVisible : boolean = true ; private _localMatrix : Matrix4x4 = Matrix4x4 . identity ( ) ; private _worldMatrix : Matrix4x4 = Matrix4x4 . identity ( ) ; /** The name of this object. */ public name : string ; /** The transform of this entity. */ public transform : Transform = new Transform ( ) ; param name param sceneGraph public constructor ( name , sceneGraph ? ) { super ( ) ; this . name = name ; this . _sceneGraph = sceneGraph ; } /** Returns the parent of this entity. */ public get parent ( ) : TEntity { return this . _parent ; } /** Returns the world transformation matrix of this entity. */ public get worldMatrix ( ) : Matrix4x4 { return this . _worldMatrix ; } /** Indicates if this entity has been loaded. */ public get isLoaded ( ) : boolean { return this . _isLoaded ; } /** Indicates if this entity is currently visible. */ public get isVisible ( ) : boolean { return this . _isVisible ; } /** Sets visibility of this entity. */ public set isVisible ( value ) { this . _isVisible = value ; } param child public addChild ( child ) { child . _parent = this ; this . _children . push ( child ) ; child . onAdded ( this . _sceneGraph ) ; } param child public removeChild ( child ) { let index = this . _children . indexOf ( child ) ; if ( index !== - 1 ) { child . _parent = undefined ; this . _children . splice ( index , 1 ) ; } } param name public getComponentByName ( name ) { for ( let component of this . _components ) { if ( component . name === name ) { return component ; } } for ( let child of this . _children ) { let component = child . getComponentByName ( name ) ; if ( component !== undefined ) { return component ; } } return undefined ; } param name public getBehaviorByName ( name ) { for ( let behavior of this . _behaviors ) { if ( behavior . name === name ) { return behavior ; } } for ( let child of this . _children ) { let behavior = child . getBehaviorByName ( name ) ; if ( behavior !== undefined ) { return behavior ; } } return undefined ; } param name public getEntityByName ( name ) { if ( this . name === name ) { return this ; } for ( let child of this . _children ) { let result = child . getEntityByName ( name ) ; if ( result !== undefined ) { return result ; } } return undefined ; } param component public addComponent ( component ) { this . _components . push ( component ) ; component . setOwner ( this ) ; } param behavior public addBehavior ( behavior ) { this . _behaviors . push ( behavior ) ; behavior . setOwner ( this ) ; } /** Performs loading procedures on this entity. */ public load ( ) { this . _isLoaded = true ; for ( let c of this . _components ) { c . load ( ) ; } for ( let c of this . _children ) { c . load ( ) ; } } /** Performs pre-update procedures on this entity. */ public updateReady ( ) { for ( let c of this . _components ) { c . updateReady ( ) ; } for ( let b of this . _behaviors ) { b . updateReady ( ) ; } for ( let c of this . _children ) { c . updateReady ( ) ; } } param time public update ( time ) { this . _localMatrix = this . transform . getTransformationMatrix ( ) ; this . updateWorldMatrix ( ( this . _parent !== undefined ) ? this . _parent . worldMatrix : undefined ) ; for ( let c of this . _components ) { c . update ( time ) ; } for ( let b of this . _behaviors ) { b . update ( time ) ; } for ( let c of this . _children ) { c . update ( time ) ; } } /**
         * Renders this entity and its children.
         */ public render ( renderView ) { if ( ! this . _isVisible ) { return ; } for ( let c of this . _components ) { c . render ( renderView ) ; } for ( let c of this . _children ) { c . render ( renderView ) ; } } /** Returns the world position of this entity. */ public getWorldPosition ( ) { return new Vector3 ( this . _worldMatrix . data [ 12 ] , this . _worldMatrix . data [ 13 ] , this . _worldMatrix . data [ 14 ] ) ; } param sceneGraph protected onAdded ( sceneGraph ) { this . _sceneGraph = sceneGraph ; } private updateWorldMatrix ( parentWorldMatrix ) { if ( parentWorldMatrix !== undefined ) { this . _worldMatrix = Matrix4x4 . multiply ( parentWorldMatrix , this . _localMatrix ) ; } else { this . _worldMatrix . copyFrom ( this . _localMatrix ) ; } } } }