123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- import { Box3, Vector3 } from 'three';
- import { UIPanel, UIRow, UIHorizontalRule, UIText } from './libs/ui.js';
- import { AddObjectCommand } from './commands/AddObjectCommand.js';
- import { RemoveObjectCommand } from './commands/RemoveObjectCommand.js';
- import { SetPositionCommand } from './commands/SetPositionCommand.js';
- import { clone } from '../../examples/jsm/utils/SkeletonUtils.js';
- function MenubarEdit( editor ) {
- const strings = editor.strings;
- const container = new UIPanel();
- container.setClass( 'menu' );
- const title = new UIPanel();
- title.setClass( 'title' );
- title.setTextContent( strings.getKey( 'menubar/edit' ) );
- container.add( title );
- const options = new UIPanel();
- options.setClass( 'options' );
- container.add( options );
- // Undo
- const undo = new UIRow();
- undo.setClass( 'option' );
- undo.setTextContent( strings.getKey( 'menubar/edit/undo' ) );
- undo.add( new UIText( 'CTRL+Z' ).setClass( 'key' ) );
- undo.onClick( function () {
- editor.undo();
- } );
- options.add( undo );
- // Redo
- const redo = new UIRow();
- redo.setClass( 'option' );
- redo.setTextContent( strings.getKey( 'menubar/edit/redo' ) );
- redo.add( new UIText( 'CTRL+SHIFT+Z' ).setClass( 'key' ) );
- redo.onClick( function () {
- editor.redo();
- } );
- options.add( redo );
- function onHistoryChanged() {
- const history = editor.history;
- undo.setClass( 'option' );
- redo.setClass( 'option' );
- if ( history.undos.length == 0 ) {
- undo.setClass( 'inactive' );
- }
- if ( history.redos.length == 0 ) {
- redo.setClass( 'inactive' );
- }
- }
- editor.signals.historyChanged.add( onHistoryChanged );
- onHistoryChanged();
- // ---
- options.add( new UIHorizontalRule() );
- // Center
- let option = new UIRow();
- option.setClass( 'option' );
- option.setTextContent( strings.getKey( 'menubar/edit/center' ) );
- option.onClick( function () {
- const 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 - center.x;
- newPosition.y = object.position.y - center.y;
- newPosition.z = object.position.z - center.z;
- editor.execute( new SetPositionCommand( editor, object, newPosition ) );
- } );
- options.add( option );
- // Clone
- option = new UIRow();
- option.setClass( 'option' );
- option.setTextContent( strings.getKey( 'menubar/edit/clone' ) );
- option.onClick( function () {
- let object = editor.selected;
- if ( object === null || object.parent === null ) return; // avoid cloning the camera or scene
- object = clone( object );
- editor.execute( new AddObjectCommand( editor, object ) );
- } );
- options.add( option );
- // Delete
- option = new UIRow();
- option.setClass( 'option' );
- option.setTextContent( strings.getKey( 'menubar/edit/delete' ) );
- option.add( new UIText( 'DEL' ).setClass( 'key' ) );
- option.onClick( function () {
- const object = editor.selected;
- if ( object !== null && object.parent !== null ) {
- editor.execute( new RemoveObjectCommand( editor, object ) );
- }
- } );
- options.add( option );
- return container;
- }
- export { MenubarEdit };
|