2017-08-24 22:20:40 +02:00
/ * *
* Controls Superset - The apiControls properties get moved into the Controls object itself , and then the instance is created
* @ param graphics GameLib . D3 . Graphics
* @ param apiControls GameLib . D3 . API . Controls
* @ param raycaster
2017-10-08 03:17:36 +02:00
* @ param camera
2017-08-24 22:20:40 +02:00
* @ constructor
* /
GameLib . D3 . Controls . Editor = function (
graphics ,
apiControls ,
raycaster ,
2017-10-08 03:17:36 +02:00
camera
2017-08-24 22:20:40 +02:00
) {
this . graphics = graphics ;
this . graphics . isNotThreeThrow ( ) ;
if ( GameLib . Utils . UndefinedOrNull ( raycaster ) ) {
raycaster = null ;
}
this . raycaster = raycaster ;
2017-10-08 03:17:36 +02:00
if ( GameLib . Utils . UndefinedOrNull ( camera ) ) {
camera = null ;
2017-08-24 22:20:40 +02:00
}
2017-10-08 03:17:36 +02:00
this . camera = camera ;
2017-08-24 22:20:40 +02:00
if ( this . raycaster instanceof GameLib . D3 . API . Raycaster ) {
this . raycaster = new GameLib . D3 . Raycaster (
this . graphics ,
this . raycaster
) ;
}
2017-10-08 03:17:36 +02:00
if ( this . camera instanceof GameLib . D3 . API . Camera ) {
this . camera = new GameLib . D3 . Camera (
2017-08-24 22:20:40 +02:00
this . graphics ,
2017-10-08 03:17:36 +02:00
this . camera
2017-08-24 22:20:40 +02:00
)
}
GameLib . D3 . Controls . call (
this ,
this . graphics ,
apiControls
) ;
} ;
/ * *
* Inheritance
* @ type { GameLib . D3 . Controls }
* /
GameLib . D3 . Controls . Editor . prototype = Object . create ( GameLib . D3 . Controls . prototype ) ;
GameLib . D3 . Controls . Editor . prototype . constructor = GameLib . D3 . Controls . Editor ;
/ * *
* Create Instance
* @ returns { THREE . EditorControls }
* /
GameLib . D3 . Controls . Editor . prototype . createInstance = function ( ) {
console . log ( 'delaying controls instance creation - call GameLib.D3.Controls.Editor.delayInstance() to create the instance' ) ;
} ;
GameLib . D3 . Controls . Editor . prototype . delayedInstance = function ( ) {
console . log ( 'GameLib.D3.Controls.Editor.delayedInstance() called' ) ;
2017-10-08 03:17:36 +02:00
if ( ! this . camera || ! this . camera . instance ) {
2017-08-24 22:20:40 +02:00
throw new Error ( 'No camera at time of instance' ) ;
}
2017-10-08 03:17:36 +02:00
if ( ! this . domElement || ! this . domElement . instance ) {
2017-08-24 22:20:40 +02:00
throw new Error ( 'No dom element at time of instance' ) ;
}
var instance = new THREE . EditorControls (
2017-10-08 03:17:36 +02:00
this . camera . instance ,
this . domElement . instance
2017-08-24 22:20:40 +02:00
) ;
return instance ;
} ;
/ * *
* Update Instance
* /
GameLib . D3 . Controls . Editor . prototype . updateInstance = function ( ) {
console . warn ( 'an update instance was called on editor controls - which, if not called from within a running system at the right time will affect the order of input event handling and cause system instability' ) ;
if ( this . instance ) {
this . instance . dispose ( ) ;
delete this . instance ;
}
this . instance = this . delayedInstance ( ) ;
GameLib . D3 . Controls . prototype . updateInstance . call ( this ) ;
} ;
/ * *
2017-09-27 14:38:58 +02:00
* Converts a GameLib . D3 . Controls . Editor to a GameLib . D3 . API . Mesh
* @ returns { GameLib . D3 . API . Controls }
2017-08-24 22:20:40 +02:00
* /
GameLib . D3 . Controls . Editor . prototype . toApiObject = function ( ) {
2017-08-29 21:58:11 +02:00
var apiControls = GameLib . D3 . Controls . prototype . toApiObject . call ( this ) ;
2017-08-24 22:20:40 +02:00
2017-10-08 03:17:36 +02:00
apiControls . raycaster = GameLib . Utils . IdOrNull ( this . raycaster ) ;
apiControls . camera = GameLib . Utils . IdOrNull ( this . camera ) ;
2017-08-24 22:20:40 +02:00
2017-08-29 21:58:11 +02:00
return apiControls ;
2017-08-24 22:20:40 +02:00
} ;
/ * *
* Construct an Editor Controls object from data
* @ param graphics
2017-08-29 21:58:11 +02:00
* @ param objectControls
2017-08-24 22:20:40 +02:00
* @ returns { GameLib . D3 . Controls . Editor }
* @ constructor
* /
2017-08-29 21:58:11 +02:00
GameLib . D3 . Controls . Editor . FromObject = function ( graphics , objectControls ) {
2017-08-24 22:20:40 +02:00
2017-09-27 14:38:58 +02:00
var apiControls = GameLib . D3 . API . Controls . FromObject ( objectControls ) ;
2017-08-24 22:20:40 +02:00
return new GameLib . D3 . Controls . Editor (
graphics ,
2017-10-08 03:17:36 +02:00
apiControls ,
apiControls . raycaster ,
apiControls . camera
2017-08-24 22:20:40 +02:00
) ;
} ;