Ver código fonte

Editor: Undo/Redo object transforms.

Mr.doob 10 anos atrás
pai
commit
f23fc90490
2 arquivos alterados com 31 adições e 5 exclusões
  1. 2 4
      editor/js/History.js
  2. 29 1
      editor/js/Viewport.js

+ 2 - 4
editor/js/History.js

@@ -51,8 +51,7 @@ History.prototype = {
 
 
 		this.isRecording = false;
 		this.isRecording = false;
 
 
-		this.array[ this.current ].undo();
-		this.current --;
+		this.array[ this.current -- ].undo();
 
 
 		this.isRecording = true;
 		this.isRecording = true;
 
 
@@ -64,8 +63,7 @@ History.prototype = {
 
 
 		this.isRecording = false;
 		this.isRecording = false;
 
 
-		this.current ++;
-		this.array[ this.current ].redo();
+		this.array[ ++ this.current ].redo();
 
 
 		this.isRecording = true;
 		this.isRecording = true;
 
 

+ 29 - 1
editor/js/Viewport.js

@@ -36,6 +36,8 @@ var Viewport = function ( editor ) {
 	selectionBox.visible = false;
 	selectionBox.visible = false;
 	sceneHelpers.add( selectionBox );
 	sceneHelpers.add( selectionBox );
 
 
+	var matrix = new THREE.Matrix4();
+
 	var transformControls = new THREE.TransformControls( camera, container.dom );
 	var transformControls = new THREE.TransformControls( camera, container.dom );
 	transformControls.addEventListener( 'change', function () {
 	transformControls.addEventListener( 'change', function () {
 
 
@@ -58,12 +60,37 @@ var Viewport = function ( editor ) {
 	} );
 	} );
 	transformControls.addEventListener( 'mouseDown', function () {
 	transformControls.addEventListener( 'mouseDown', function () {
 
 
+		var object = transformControls.object;
+
+		matrix.copy( object.matrix );
+
 		controls.enabled = false;
 		controls.enabled = false;
 
 
 	} );
 	} );
 	transformControls.addEventListener( 'mouseUp', function () {
 	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;
 		controls.enabled = true;
 
 
 	} );
 	} );
@@ -375,6 +402,7 @@ var Viewport = function ( editor ) {
 
 
 	signals.objectChanged.add( function ( object ) {
 	signals.objectChanged.add( function ( object ) {
 
 
+		selectionBox.update( object );
 		transformControls.update();
 		transformControls.update();
 
 
 		if ( object instanceof THREE.PerspectiveCamera ) {
 		if ( object instanceof THREE.PerspectiveCamera ) {