Преглед изворни кода

Merge pull request #21340 from Mugen87/dev48

Editor: Add center option.
Mr.doob пре 4 година
родитељ
комит
b34af4665b
2 измењених фајлова са 31 додато и 1 уклоњено
  1. 28 1
      editor/js/Menubar.Edit.js
  2. 3 0
      editor/js/Strings.js

+ 28 - 1
editor/js/Menubar.Edit.js

@@ -1,7 +1,10 @@
+import { Box3, Vector3 } from '../../build/three.module.js';
+
 import { UIPanel, UIRow, UIHorizontalRule } from './libs/ui.js';
 
 import { AddObjectCommand } from './commands/AddObjectCommand.js';
 import { RemoveObjectCommand } from './commands/RemoveObjectCommand.js';
+import { SetPositionCommand } from './commands/SetPositionCommand.js';
 
 function MenubarEdit( editor ) {
 
@@ -85,6 +88,30 @@ function MenubarEdit( editor ) {
 
 	options.add( new UIHorizontalRule() );
 
+	// Center
+
+	var option = new UIRow();
+	option.setClass( 'option' );
+	option.setTextContent( strings.getKey( 'menubar/edit/center' ) );
+	option.onClick( function () {
+
+		var object = editor.selected;
+
+		if ( object === null || object.parent === null ) return; // avoid centering the camera or scene
+
+		const aabb = new Box3().setFromObject( object );
+		const center = aabb.getCenter( new Vector3() );
+		const newPosition = new Vector3();
+
+		newPosition.x = object.position.x + ( object.position.x - center.x );
+		newPosition.y = object.position.y + ( object.position.y - center.y );
+		newPosition.z = object.position.z + ( object.position.z - center.z );
+
+		editor.execute( new SetPositionCommand( editor, object, newPosition ) );
+
+	} );
+	options.add( option );
+
 	// Clone
 
 	var option = new UIRow();
@@ -94,7 +121,7 @@ function MenubarEdit( editor ) {
 
 		var object = editor.selected;
 
-		if ( object.parent === null ) return; // avoid cloning the camera or scene
+		if ( object === null || object.parent === null ) return; // avoid cloning the camera or scene
 
 		object = object.clone();
 

+ 3 - 0
editor/js/Strings.js

@@ -28,6 +28,7 @@ function Strings( config ) {
 			'menubar/edit/undo': 'Undo (Ctrl+Z)',
 			'menubar/edit/redo': 'Redo (Ctrl+Shift+Z)',
 			'menubar/edit/clear_history': 'Clear History',
+			'menubar/edit/center': 'Center',
 			'menubar/edit/clone': 'Clone',
 			'menubar/edit/delete': 'Delete (Del)',
 			'menubar/edit/fixcolormaps': 'Fix Color Maps',
@@ -354,6 +355,7 @@ function Strings( config ) {
 			'menubar/edit/undo': 'Annuler (Ctrl+Z)',
 			'menubar/edit/redo': 'Refaire (Ctrl+Shift+Z)',
 			'menubar/edit/clear_history': 'Supprimer Historique',
+			'menubar/edit/center': 'Center',
 			'menubar/edit/clone': 'Cloner',
 			'menubar/edit/delete': 'Supprimer (Supp)',
 			'menubar/edit/fixcolormaps': 'Correction des couleurs',
@@ -680,6 +682,7 @@ function Strings( config ) {
 			'menubar/edit/undo': '撤销 (Ctrl+Z)',
 			'menubar/edit/redo': '重做 (Ctrl+Shift+Z)',
 			'menubar/edit/clear_history': '清空历史记录',
+			'menubar/edit/center': 'Center',
 			'menubar/edit/clone': '拷贝',
 			'menubar/edit/delete': '删除 (Del)',
 			'menubar/edit/fixcolormaps': '修复颜色贴图',