提交 c6011f2b 编写于 作者: M Mugen87

Editor: Add center option.

上级 4d90e23c
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();
......
......@@ -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': '修复颜色贴图',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册