|
@@ -33,6 +33,9 @@ var APP = {
|
|
this.setCamera( loader.parse( json.camera ) );
|
|
this.setCamera( loader.parse( json.camera ) );
|
|
|
|
|
|
events = {
|
|
events = {
|
|
|
|
+ init: [],
|
|
|
|
+ start: [],
|
|
|
|
+ stop: [],
|
|
keydown: [],
|
|
keydown: [],
|
|
keyup: [],
|
|
keyup: [],
|
|
mousedown: [],
|
|
mousedown: [],
|
|
@@ -44,6 +47,15 @@ var APP = {
|
|
update: []
|
|
update: []
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ var scriptWrapParams = 'player,renderer,scene';
|
|
|
|
+ var scriptWrapResultObj = {};
|
|
|
|
+ for ( var eventKey in events ) {
|
|
|
|
+ scriptWrapParams += ',' + eventKey;
|
|
|
|
+ scriptWrapResultObj[ eventKey ] = eventKey;
|
|
|
|
+ }
|
|
|
|
+ var scriptWrapResult =
|
|
|
|
+ JSON.stringify( scriptWrapResultObj ).replace( /\"/g, '' );
|
|
|
|
+
|
|
for ( var uuid in json.scripts ) {
|
|
for ( var uuid in json.scripts ) {
|
|
|
|
|
|
var object = scene.getObjectByProperty( 'uuid', uuid, true );
|
|
var object = scene.getObjectByProperty( 'uuid', uuid, true );
|
|
@@ -54,7 +66,8 @@ var APP = {
|
|
|
|
|
|
var script = scripts[ i ];
|
|
var script = scripts[ i ];
|
|
|
|
|
|
- var functions = ( new Function( 'player, scene, keydown, keyup, mousedown, mouseup, mousemove, touchstart, touchend, touchmove, update', script.source + '\nreturn { keydown: keydown, keyup: keyup, mousedown: mousedown, mouseup: mouseup, mousemove: mousemove, touchstart: touchstart, touchend: touchend, touchmove: touchmove, update: update };' ).bind( object ) )( this, scene );
|
|
|
|
|
|
+ var functions = ( new Function( scriptWrapParams,
|
|
|
|
+ script.source + '\nreturn ' + scriptWrapResult+ ';' ).bind( object ) )( this, renderer, scene );
|
|
|
|
|
|
for ( var name in functions ) {
|
|
for ( var name in functions ) {
|
|
|
|
|
|
@@ -75,6 +88,8 @@ var APP = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ dispatch( events.init, arguments );
|
|
|
|
+
|
|
};
|
|
};
|
|
|
|
|
|
this.setCamera = function ( value ) {
|
|
this.setCamera = function ( value ) {
|
|
@@ -146,7 +161,15 @@ var APP = {
|
|
|
|
|
|
for ( var i = 0, l = array.length; i < l; i ++ ) {
|
|
for ( var i = 0, l = array.length; i < l; i ++ ) {
|
|
|
|
|
|
- array[ i ]( event );
|
|
|
|
|
|
+ try {
|
|
|
|
+
|
|
|
|
+ array[ i ]( event );
|
|
|
|
+
|
|
|
|
+ } catch (e) {
|
|
|
|
+
|
|
|
|
+ console.error(e.stack || e);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -186,9 +209,10 @@ var APP = {
|
|
document.addEventListener( 'touchend', onDocumentTouchEnd );
|
|
document.addEventListener( 'touchend', onDocumentTouchEnd );
|
|
document.addEventListener( 'touchmove', onDocumentTouchMove );
|
|
document.addEventListener( 'touchmove', onDocumentTouchMove );
|
|
|
|
|
|
|
|
+ dispatch( events.start, arguments );
|
|
|
|
+
|
|
request = requestAnimationFrame( animate );
|
|
request = requestAnimationFrame( animate );
|
|
prevTime = performance.now();
|
|
prevTime = performance.now();
|
|
-
|
|
|
|
};
|
|
};
|
|
|
|
|
|
this.stop = function () {
|
|
this.stop = function () {
|
|
@@ -202,8 +226,9 @@ var APP = {
|
|
document.removeEventListener( 'touchend', onDocumentTouchEnd );
|
|
document.removeEventListener( 'touchend', onDocumentTouchEnd );
|
|
document.removeEventListener( 'touchmove', onDocumentTouchMove );
|
|
document.removeEventListener( 'touchmove', onDocumentTouchMove );
|
|
|
|
|
|
- cancelAnimationFrame( request );
|
|
|
|
|
|
+ dispatch( events.stop, arguments );
|
|
|
|
|
|
|
|
+ cancelAnimationFrame( request );
|
|
};
|
|
};
|
|
|
|
|
|
//
|
|
//
|