Skip to content

Commit c985826

Browse files
authored
add appearance submenu (#28421)
1 parent 64a25dd commit c985826

File tree

6 files changed

+166
-32
lines changed

6 files changed

+166
-32
lines changed

editor/css/main.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,21 @@ select {
414414
background: transparent;
415415
}
416416

417+
#menubar .menu .options .option.toggle::before {
418+
419+
content: ' ';
420+
display: inline-block;
421+
width: 16px;
422+
423+
}
424+
425+
#menubar .menu .options .option.toggle-on::before {
426+
427+
content: '✓';
428+
font-size: 12px;
429+
430+
}
431+
417432
#menubar .submenu-title::after {
418433
content: '⏵';
419434
float: right;
@@ -427,6 +442,8 @@ select {
427442
cursor: not-allowed;
428443
}
429444

445+
446+
430447
#sidebar {
431448
position: absolute;
432449
right: 0;

editor/js/Editor.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ function Editor() {
8282

8383
windowResize: new Signal(),
8484

85-
showGridChanged: new Signal(),
8685
showHelpersChanged: new Signal(),
8786
refreshSidebarObject3D: new Signal(),
8887
refreshSidebarEnvironment: new Signal(),

editor/js/Menubar.View.js

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UIPanel, UIRow } from './libs/ui.js';
1+
import { UIHorizontalRule, UIPanel, UIRow } from './libs/ui.js';
22

33
function MenubarView( editor ) {
44

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

2020
// Fullscreen
2121

22-
const option = new UIRow();
22+
let option = new UIRow();
2323
option.setClass( 'option' );
2424
option.setTextContent( strings.getKey( 'menubar/view/fullscreen' ) );
2525
option.onClick( function () {
@@ -103,6 +103,100 @@ function MenubarView( editor ) {
103103

104104
}
105105

106+
//
107+
108+
options.add( new UIHorizontalRule() );
109+
110+
// Appearance
111+
112+
const appearanceStates = {
113+
114+
gridHelper: true,
115+
cameraHelpers: true,
116+
lightHelpers: true,
117+
skeletonHelpers: true
118+
119+
};
120+
121+
const appearanceSubmenuTitle = new UIRow().setTextContent( 'Appearance' ).addClass( 'option' ).addClass( 'submenu-title' );
122+
appearanceSubmenuTitle.onMouseOver( function () {
123+
124+
const { top, right } = appearanceSubmenuTitle.dom.getBoundingClientRect();
125+
const { paddingTop } = getComputedStyle( this.dom );
126+
appearanceSubmenu.setLeft( right + 'px' );
127+
appearanceSubmenu.setTop( top - parseFloat( paddingTop ) + 'px' );
128+
appearanceSubmenu.setStyle( 'max-height', [ `calc( 100vh - ${top}px )` ] );
129+
appearanceSubmenu.setDisplay( 'block' );
130+
131+
} );
132+
appearanceSubmenuTitle.onMouseOut( function () {
133+
134+
appearanceSubmenu.setDisplay( 'none' );
135+
136+
} );
137+
options.add( appearanceSubmenuTitle );
138+
139+
const appearanceSubmenu = new UIPanel().setPosition( 'fixed' ).addClass( 'options' ).setDisplay( 'none' );
140+
appearanceSubmenuTitle.add( appearanceSubmenu );
141+
142+
// Appearance / Grid Helper
143+
144+
option = new UIRow().addClass( 'option' ).addClass( 'toggle' ).setTextContent( 'Grid Helper' ).onClick( function () {
145+
146+
appearanceStates.gridHelper = ! appearanceStates.gridHelper;
147+
148+
this.toggleClass( 'toggle-on', appearanceStates.gridHelper );
149+
150+
signals.showHelpersChanged.dispatch( appearanceStates );
151+
152+
} ).toggleClass( 'toggle-on', appearanceStates.gridHelper );
153+
154+
appearanceSubmenu.add( option );
155+
156+
// Appearance / Camera Helpers
157+
158+
option = new UIRow().addClass( 'option' ).addClass( 'toggle' ).setTextContent( 'Camera Helpers' ).onClick( function () {
159+
160+
appearanceStates.cameraHelpers = ! appearanceStates.cameraHelpers;
161+
162+
this.toggleClass( 'toggle-on', appearanceStates.cameraHelpers );
163+
164+
signals.showHelpersChanged.dispatch( appearanceStates );
165+
166+
} ).toggleClass( 'toggle-on', appearanceStates.cameraHelpers );
167+
168+
appearanceSubmenu.add( option );
169+
170+
// Appearance / Light Helpers
171+
172+
option = new UIRow().addClass( 'option' ).addClass( 'toggle' ).setTextContent( 'Light Helpers' ).onClick( function () {
173+
174+
appearanceStates.lightHelpers = ! appearanceStates.lightHelpers;
175+
176+
this.toggleClass( 'toggle-on', appearanceStates.lightHelpers );
177+
178+
signals.showHelpersChanged.dispatch( appearanceStates );
179+
180+
} ).toggleClass( 'toggle-on', appearanceStates.lightHelpers );
181+
182+
appearanceSubmenu.add( option );
183+
184+
// Appearance / Skeleton Helpers
185+
186+
option = new UIRow().addClass( 'option' ).addClass( 'toggle' ).setTextContent( 'Skeleton Helpers' ).onClick( function () {
187+
188+
appearanceStates.skeletonHelpers = ! appearanceStates.skeletonHelpers;
189+
190+
this.toggleClass( 'toggle-on', appearanceStates.skeletonHelpers );
191+
192+
signals.showHelpersChanged.dispatch( appearanceStates );
193+
194+
} ).toggleClass( 'toggle-on', appearanceStates.skeletonHelpers );
195+
196+
appearanceSubmenu.add( option );
197+
198+
//
199+
106200
return container;
107201

108202
}

editor/js/Viewport.Controls.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,15 @@
11
import { UIPanel, UISelect } from './libs/ui.js';
2-
import { UIBoolean } from './libs/ui.three.js';
32

43
function ViewportControls( editor ) {
54

65
const signals = editor.signals;
7-
const strings = editor.strings;
86

97
const container = new UIPanel();
108
container.setPosition( 'absolute' );
119
container.setRight( '10px' );
1210
container.setTop( '10px' );
1311
container.setColor( '#ffffff' );
1412

15-
// grid
16-
17-
const gridCheckbox = new UIBoolean( true, strings.getKey( 'viewport/controls/grid' ) );
18-
gridCheckbox.onChange( function () {
19-
20-
signals.showGridChanged.dispatch( this.getValue() );
21-
22-
} );
23-
container.add( gridCheckbox );
24-
25-
// helpers
26-
27-
const helpersCheckbox = new UIBoolean( true, strings.getKey( 'viewport/controls/helpers' ) );
28-
helpersCheckbox.onChange( function () {
29-
30-
signals.showHelpersChanged.dispatch( this.getValue() );
31-
32-
} );
33-
container.add( helpersCheckbox );
34-
3513
// camera
3614

3715
const cameraSelect = new UISelect();

editor/js/Viewport.js

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -697,18 +697,56 @@ function Viewport( editor ) {
697697

698698
} );
699699

700-
signals.showGridChanged.add( function ( value ) {
700+
signals.showHelpersChanged.add( function ( appearanceStates ) {
701701

702-
grid.visible = value;
702+
grid.visible = appearanceStates.gridHelper;
703703

704-
render();
704+
sceneHelpers.traverse( function ( object ) {
705705

706-
} );
706+
switch ( object.type ) {
707+
708+
case 'CameraHelper':
709+
710+
{
711+
712+
object.visible = appearanceStates.cameraHelpers;
713+
break;
714+
715+
}
716+
717+
case 'PointLightHelper':
718+
case 'DirectionalLightHelper':
719+
case 'SpotLightHelper':
720+
case 'HemisphereLightHelper':
721+
722+
{
723+
724+
object.visible = appearanceStates.lightHelpers;
725+
break;
726+
727+
}
707728

708-
signals.showHelpersChanged.add( function ( value ) {
729+
case 'SkeletonHelper':
730+
731+
{
732+
733+
object.visible = appearanceStates.skeletonHelpers;
734+
break;
735+
736+
}
737+
738+
default:
739+
740+
{
741+
742+
// not a helper, skip.
743+
744+
}
745+
746+
}
747+
748+
} );
709749

710-
sceneHelpers.visible = value;
711-
transformControls.enabled = value;
712750

713751
render();
714752

editor/js/libs/ui.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ class UIElement {
9898

9999
}
100100

101+
toggleClass( name, toggle ) {
102+
103+
this.dom.classList.toggle( name, toggle );
104+
105+
return this;
106+
107+
}
108+
101109
setStyle( style, array ) {
102110

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

0 commit comments

Comments
 (0)