Skip to content

Commit

Permalink
add appearance submenu (#28421)
Browse files Browse the repository at this point in the history
  • Loading branch information
ycw committed May 21, 2024
1 parent 64a25dd commit c985826
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 32 deletions.
17 changes: 17 additions & 0 deletions editor/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,21 @@ select {
background: transparent;
}

#menubar .menu .options .option.toggle::before {

content: ' ';
display: inline-block;
width: 16px;

}

#menubar .menu .options .option.toggle-on::before {

content: '✓';
font-size: 12px;

}

#menubar .submenu-title::after {
content: '⏵';
float: right;
Expand All @@ -427,6 +442,8 @@ select {
cursor: not-allowed;
}



#sidebar {
position: absolute;
right: 0;
Expand Down
1 change: 0 additions & 1 deletion editor/js/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ function Editor() {

windowResize: new Signal(),

showGridChanged: new Signal(),
showHelpersChanged: new Signal(),
refreshSidebarObject3D: new Signal(),
refreshSidebarEnvironment: new Signal(),
Expand Down
98 changes: 96 additions & 2 deletions editor/js/Menubar.View.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UIPanel, UIRow } from './libs/ui.js';
import { UIHorizontalRule, UIPanel, UIRow } from './libs/ui.js';

function MenubarView( editor ) {

Expand All @@ -19,7 +19,7 @@ function MenubarView( editor ) {

// Fullscreen

const option = new UIRow();
let option = new UIRow();
option.setClass( 'option' );
option.setTextContent( strings.getKey( 'menubar/view/fullscreen' ) );
option.onClick( function () {
Expand Down Expand Up @@ -103,6 +103,100 @@ function MenubarView( editor ) {

}

//

options.add( new UIHorizontalRule() );

// Appearance

const appearanceStates = {

gridHelper: true,
cameraHelpers: true,
lightHelpers: true,
skeletonHelpers: true

};

const appearanceSubmenuTitle = new UIRow().setTextContent( 'Appearance' ).addClass( 'option' ).addClass( 'submenu-title' );
appearanceSubmenuTitle.onMouseOver( function () {

const { top, right } = appearanceSubmenuTitle.dom.getBoundingClientRect();
const { paddingTop } = getComputedStyle( this.dom );
appearanceSubmenu.setLeft( right + 'px' );
appearanceSubmenu.setTop( top - parseFloat( paddingTop ) + 'px' );
appearanceSubmenu.setStyle( 'max-height', [ `calc( 100vh - ${top}px )` ] );
appearanceSubmenu.setDisplay( 'block' );

} );
appearanceSubmenuTitle.onMouseOut( function () {

appearanceSubmenu.setDisplay( 'none' );

} );
options.add( appearanceSubmenuTitle );

const appearanceSubmenu = new UIPanel().setPosition( 'fixed' ).addClass( 'options' ).setDisplay( 'none' );
appearanceSubmenuTitle.add( appearanceSubmenu );

// Appearance / Grid Helper

option = new UIRow().addClass( 'option' ).addClass( 'toggle' ).setTextContent( 'Grid Helper' ).onClick( function () {

appearanceStates.gridHelper = ! appearanceStates.gridHelper;

this.toggleClass( 'toggle-on', appearanceStates.gridHelper );

signals.showHelpersChanged.dispatch( appearanceStates );

} ).toggleClass( 'toggle-on', appearanceStates.gridHelper );

appearanceSubmenu.add( option );

// Appearance / Camera Helpers

option = new UIRow().addClass( 'option' ).addClass( 'toggle' ).setTextContent( 'Camera Helpers' ).onClick( function () {

appearanceStates.cameraHelpers = ! appearanceStates.cameraHelpers;

this.toggleClass( 'toggle-on', appearanceStates.cameraHelpers );

signals.showHelpersChanged.dispatch( appearanceStates );

} ).toggleClass( 'toggle-on', appearanceStates.cameraHelpers );

appearanceSubmenu.add( option );

// Appearance / Light Helpers

option = new UIRow().addClass( 'option' ).addClass( 'toggle' ).setTextContent( 'Light Helpers' ).onClick( function () {

appearanceStates.lightHelpers = ! appearanceStates.lightHelpers;

this.toggleClass( 'toggle-on', appearanceStates.lightHelpers );

signals.showHelpersChanged.dispatch( appearanceStates );

} ).toggleClass( 'toggle-on', appearanceStates.lightHelpers );

appearanceSubmenu.add( option );

// Appearance / Skeleton Helpers

option = new UIRow().addClass( 'option' ).addClass( 'toggle' ).setTextContent( 'Skeleton Helpers' ).onClick( function () {

appearanceStates.skeletonHelpers = ! appearanceStates.skeletonHelpers;

this.toggleClass( 'toggle-on', appearanceStates.skeletonHelpers );

signals.showHelpersChanged.dispatch( appearanceStates );

} ).toggleClass( 'toggle-on', appearanceStates.skeletonHelpers );

appearanceSubmenu.add( option );

//

return container;

}
Expand Down
22 changes: 0 additions & 22 deletions editor/js/Viewport.Controls.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,15 @@
import { UIPanel, UISelect } from './libs/ui.js';
import { UIBoolean } from './libs/ui.three.js';

function ViewportControls( editor ) {

const signals = editor.signals;
const strings = editor.strings;

const container = new UIPanel();
container.setPosition( 'absolute' );
container.setRight( '10px' );
container.setTop( '10px' );
container.setColor( '#ffffff' );

// grid

const gridCheckbox = new UIBoolean( true, strings.getKey( 'viewport/controls/grid' ) );
gridCheckbox.onChange( function () {

signals.showGridChanged.dispatch( this.getValue() );

} );
container.add( gridCheckbox );

// helpers

const helpersCheckbox = new UIBoolean( true, strings.getKey( 'viewport/controls/helpers' ) );
helpersCheckbox.onChange( function () {

signals.showHelpersChanged.dispatch( this.getValue() );

} );
container.add( helpersCheckbox );

// camera

const cameraSelect = new UISelect();
Expand Down
52 changes: 45 additions & 7 deletions editor/js/Viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,18 +697,56 @@ function Viewport( editor ) {

} );

signals.showGridChanged.add( function ( value ) {
signals.showHelpersChanged.add( function ( appearanceStates ) {

grid.visible = value;
grid.visible = appearanceStates.gridHelper;

render();
sceneHelpers.traverse( function ( object ) {

} );
switch ( object.type ) {

case 'CameraHelper':

{

object.visible = appearanceStates.cameraHelpers;
break;

}

case 'PointLightHelper':
case 'DirectionalLightHelper':
case 'SpotLightHelper':
case 'HemisphereLightHelper':

{

object.visible = appearanceStates.lightHelpers;
break;

}

signals.showHelpersChanged.add( function ( value ) {
case 'SkeletonHelper':

{

object.visible = appearanceStates.skeletonHelpers;
break;

}

default:

{

// not a helper, skip.

}

}

} );

sceneHelpers.visible = value;
transformControls.enabled = value;

render();

Expand Down
8 changes: 8 additions & 0 deletions editor/js/libs/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ class UIElement {

}

toggleClass( name, toggle ) {

this.dom.classList.toggle( name, toggle );

return this;

}

setStyle( style, array ) {

for ( let i = 0; i < array.length; i ++ ) {
Expand Down

0 comments on commit c985826

Please sign in to comment.