提交 ce78ddf6 编写于 作者: M Mr.doob

Player: Binding object to compiled script so we can access object via this.

上级 776a9bb9
......@@ -13,6 +13,9 @@ Menubar.Play = function ( editor ) {
player.play();
var popup = window.open( '', 'preview', 'width=800,height=600' );
popup.addEventListener( 'beforeunload', function () {
player.stop();
} );
popup.document.body.style.margin = 0;
popup.document.body.appendChild( player.dom );
......
......@@ -16,7 +16,7 @@ var Player = function ( json ) {
if ( child.script !== undefined ) {
child.script.compiled = new Function( 'object', 'scene', child.script.source );
child.script.compiled = new Function( 'scene', child.script.source ).bind( child );
scriptObjects.push( child );
......@@ -35,19 +35,27 @@ var Player = function ( json ) {
};
var request;
var play = function () {
requestAnimationFrame( play );
request = requestAnimationFrame( play );
update();
};
var stop = function () {
cancelAnimationFrame( request );
};
var update = function () {
for ( var i = 0; i < scriptObjects.length; i ++ ) {
var object = scriptObjects[ i ];
object.script.compiled( object, scene );
object.script.compiled( scene );
}
......@@ -58,7 +66,8 @@ var Player = function ( json ) {
return {
dom: renderer.domElement,
setSize: setSize,
play: play
play: play,
stop: stop
}
};
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册