Skip to content

Commit ec73e0c

Browse files
committed
Editor: Refactored viewport camera code.
1 parent adc32cf commit ec73e0c

File tree

9 files changed

+115
-160
lines changed

9 files changed

+115
-160
lines changed

editor/css/dark.css

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -225,23 +225,6 @@ select {
225225
height: 24px;
226226
}
227227

228-
#cameraSelect {
229-
position: absolute;
230-
z-index: 1;
231-
padding: 10px;
232-
}
233-
234-
#cameraSelect * {
235-
width: 100%;
236-
}
237-
238-
#cameraSelect{
239-
margin-top: 32px;
240-
margin-right: 300px;
241-
right: 0;
242-
top : 0;
243-
}
244-
245228
.Outliner {
246229
color: #888;
247230
background: #222;
@@ -311,7 +294,7 @@ select {
311294
#toolbar {
312295
left: calc(50% - 140px);
313296
width: 280px;
314-
top: 52px;
297+
top: 68px;
315298
}
316299

317300
}

editor/css/light.css

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -218,24 +218,6 @@ select {
218218
height: 24px;
219219
}
220220

221-
#cameraSelect {
222-
position: absolute;
223-
z-index: 1;
224-
padding: 10px;
225-
}
226-
227-
#cameraSelect * {
228-
width: 100%;
229-
}
230-
231-
#cameraSelect{
232-
margin-top: 32px;
233-
margin-right: 300px;
234-
right: 0;
235-
top : 0;
236-
}
237-
238-
239221
.Outliner {
240222
color: #444;
241223
background-color: #fff;
@@ -305,7 +287,7 @@ select {
305287
#toolbar {
306288
left: calc(50% - 140px);
307289
width: 280px;
308-
top: 52px;
290+
top: 68px;
309291
}
310292

311293
}

editor/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
<script src="js/Strings.js"></script>
144144
<script src="js/Toolbar.js"></script>
145145
<script src="js/Viewport.js"></script>
146+
<script src="js/Viewport.Camera.js"></script>
146147
<script src="js/Viewport.Info.js"></script>
147148

148149
<script src="js/Command.js"></script>

editor/js/Config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ var Config = function () {
1818
'project/renderer': 'WebGLRenderer',
1919
'project/renderer/antialias': true,
2020
'project/renderer/shadows': true,
21-
'project/renderer/showHelpers': true,
22-
'project/renderer/showSceneCameras': true,
2321

2422
'project/vr': false,
2523

@@ -29,7 +27,7 @@ var Config = function () {
2927
'settings/shortcuts/rotate': 'e',
3028
'settings/shortcuts/scale': 'r',
3129
'settings/shortcuts/undo': 'z',
32-
'settings/shortcuts/focus': 'f',
30+
'settings/shortcuts/focus': 'f'
3331
};
3432

3533
if ( window.localStorage[ name ] === undefined ) {

editor/js/Editor.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ var Editor = function () {
5151
objectChanged: new Signal(),
5252
objectRemoved: new Signal(),
5353

54+
cameraAdded: new Signal(),
55+
cameraRemoved: new Signal(),
56+
5457
helperAdded: new Signal(),
5558
helperRemoved: new Signal(),
5659

@@ -66,7 +69,7 @@ var Editor = function () {
6669
refreshSidebarObject3D: new Signal(),
6770
historyChanged: new Signal(),
6871

69-
sceneCamerasChanged: new Signal()
72+
viewportCameraChanged: new Signal()
7073

7174
};
7275

@@ -97,6 +100,11 @@ var Editor = function () {
97100
this.selected = null;
98101
this.helpers = {};
99102

103+
this.cameras = {};
104+
this.viewportCamera = this.camera;
105+
106+
this.addCamera( this.camera );
107+
100108
};
101109

102110
Editor.prototype = {
@@ -147,6 +155,7 @@ Editor.prototype = {
147155
if ( child.geometry !== undefined ) scope.addGeometry( child.geometry );
148156
if ( child.material !== undefined ) scope.addMaterial( child.material );
149157

158+
scope.addCamera( child );
150159
scope.addHelper( child );
151160

152161
} );
@@ -197,6 +206,7 @@ Editor.prototype = {
197206

198207
object.traverse( function ( child ) {
199208

209+
scope.removeCamera( child );
200210
scope.removeHelper( child );
201211

202212
} );
@@ -252,6 +262,32 @@ Editor.prototype = {
252262

253263
//
254264

265+
addCamera: function ( camera ) {
266+
267+
if ( camera.isCamera ) {
268+
269+
this.cameras[ camera.uuid ] = camera;
270+
271+
this.signals.cameraAdded.dispatch( camera );
272+
273+
}
274+
275+
},
276+
277+
removeCamera: function ( camera ) {
278+
279+
if ( this.cameras[ camera.uuid ] !== undefined ) {
280+
281+
delete this.cameras[ camera.uuid ];
282+
283+
this.signals.cameraRemoved.dispatch( camera );
284+
285+
}
286+
287+
},
288+
289+
//
290+
255291
addHelper: function () {
256292

257293
var geometry = new THREE.SphereBufferGeometry( 2, 4, 2 );
@@ -381,6 +417,13 @@ Editor.prototype = {
381417

382418
},
383419

420+
setViewportCamera: function ( uuid ) {
421+
422+
this.viewportCamera = this.cameras[ uuid ];
423+
this.signals.viewportCameraChanged.dispatch( this.viewportCamera );
424+
425+
},
426+
384427
//
385428

386429
select: function ( object ) {

editor/js/Sidebar.Settings.js

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -72,35 +72,7 @@ Sidebar.Settings = function ( editor ) {
7272
themeRow.add( new UI.Text( strings.getKey( 'sidebar/settings/theme' ) ).setWidth( '90px' ) );
7373
themeRow.add( theme );
7474

75-
container.add( themeRow );
76-
77-
// scene camera visible
78-
79-
var sceneShowCameraRow = new UI.Row();
80-
container.add( sceneShowCameraRow );
81-
82-
var sceneCameraCheckbox = new UI.Checkbox( config.getKey( 'project/renderer/showSceneCameras' ) || false ).onChange( function () {
83-
84-
config.setKey( 'project/renderer/showSceneCameras', this.getValue() );
85-
signals.sceneCamerasChanged.dispatch();
86-
87-
} );
88-
89-
sceneShowCameraRow.add( new UI.Text( strings.getKey( 'sidebar/settings/showSceneCameras' ) ).setWidth( '90px' ), sceneCameraCheckbox );
90-
91-
// show helpers
92-
93-
var showHelpersRow = new UI.Row();
94-
container.add( showHelpersRow );
95-
96-
var showHelpersCheckbox = new UI.Checkbox( config.getKey( 'project/renderer/showHelpers' ) || false ).onChange( function () {
97-
98-
config.setKey( 'project/renderer/showHelpers', this.getValue() );
99-
signals.sceneGraphChanged.dispatch();
100-
101-
} );
102-
103-
showHelpersRow.add( new UI.Text( strings.getKey( 'sidebar/settings/showHelpers' ) ).setWidth( '90px' ), showHelpersCheckbox );
75+
container.add( themeRow );
10476

10577
container.add( new Sidebar.Settings.Shortcuts( editor ) );
10678
container.add( new Sidebar.Settings.Viewport( editor ) );

editor/js/Strings.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ var Strings = function ( config ) {
242242
'sidebar/settings/theme': 'Theme',
243243
'sidebar/settings/theme/light': 'light',
244244
'sidebar/settings/theme/dark': 'dark',
245-
'sidebar/settings/showSceneCameras': 'Cameras',
246-
'sidebar/settings/showHelpers': 'Helpers',
247245

248246
'sidebar/settings/shortcuts/translate': 'Translate',
249247
'sidebar/settings/shortcuts/rotate': 'Rotate',

editor/js/Viewport.Camera.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @author mrdoob / http://mrdoob.com/
3+
*/
4+
5+
Viewport.Camera = function ( editor ) {
6+
7+
var signals = editor.signals;
8+
9+
//
10+
11+
var cameraSelect = new UI.Select();
12+
cameraSelect.setPosition( 'absolute' );
13+
cameraSelect.setRight( '10px' );
14+
cameraSelect.setTop( '10px' );
15+
cameraSelect.onChange( function () {
16+
17+
editor.setViewportCamera( this.getValue() );
18+
19+
} );
20+
21+
signals.cameraAdded.add( update );
22+
signals.cameraRemoved.add( update );
23+
24+
update();
25+
26+
//
27+
28+
function update() {
29+
30+
var options = {};
31+
32+
var cameras = editor.cameras;
33+
34+
for ( var key in cameras ) {
35+
36+
var camera = cameras[ key ];
37+
options[ camera.uuid ] = camera.name;
38+
39+
}
40+
41+
cameraSelect.setOptions( options );
42+
cameraSelect.setValue( editor.viewportCamera.uuid );
43+
44+
}
45+
46+
return cameraSelect;
47+
48+
};

0 commit comments

Comments
 (0)