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

Editor: Undo/Redo object transforms.

上级 109393ce
......@@ -51,8 +51,7 @@ History.prototype = {
this.isRecording = false;
this.array[ this.current ].undo();
this.current --;
this.array[ this.current -- ].undo();
this.isRecording = true;
......@@ -64,8 +63,7 @@ History.prototype = {
this.isRecording = false;
this.current ++;
this.array[ this.current ].redo();
this.array[ ++ this.current ].redo();
this.isRecording = true;
......
......@@ -36,6 +36,8 @@ var Viewport = function ( editor ) {
selectionBox.visible = false;
sceneHelpers.add( selectionBox );
var matrix = new THREE.Matrix4();
var transformControls = new THREE.TransformControls( camera, container.dom );
transformControls.addEventListener( 'change', function () {
......@@ -58,12 +60,37 @@ var Viewport = function ( editor ) {
} );
transformControls.addEventListener( 'mouseDown', function () {
var object = transformControls.object;
matrix.copy( object.matrix );
controls.enabled = false;
} );
transformControls.addEventListener( 'mouseUp', function () {
signals.objectChanged.dispatch( transformControls.object );
var object = transformControls.object;
if ( matrix.equals( object.matrix ) === false ) {
( function ( matrix1, matrix2 ) {
editor.history.add(
function () {
matrix1.decompose( object.position, object.quaternion, object.scale );
signals.objectChanged.dispatch( object );
},
function () {
matrix2.decompose( object.position, object.quaternion, object.scale );
signals.objectChanged.dispatch( object );
}
);
} )( matrix.clone(), object.matrix.clone() );
}
signals.objectChanged.dispatch( object );
controls.enabled = true;
} );
......@@ -375,6 +402,7 @@ var Viewport = function ( editor ) {
signals.objectChanged.add( function ( object ) {
selectionBox.update( object );
transformControls.update();
if ( object instanceof THREE.PerspectiveCamera ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册