threejs editor源碼解析1
今天先看看
這個功能的實現
這個實現就是用了 javascript signals 框架 異步通信 這么做就是為了解耦 渲染和邏輯 分離 這個跟vuejs一樣
找到editor\js\commands\SetPositionCommand.js 這個文件 發布消息的
execute: function () { this.object.position.copy( this.newPosition ); this.object.updateMatrixWorld( true ); this.editor.signals.objectChanged.dispatch( this.object ); },
然后接收消息
是在viewport.js
signals.objectChanged.add( function ( object ) { if ( editor.selected === object ) { selectionBox.setFromObject( object ); } if ( object.isPerspectiveCamera ) { object.updateProjectionMatrix(); } if ( editor.helpers[ object.id ] !== undefined ) { editor.helpers[ object.id ].update(); } render(); } );