Skip to content

Commit 6952ffb

Browse files
authored
Merge pull request #16244 from Temdog007/editor/OrthographicCamera
Editor: Added OrthographicCamera
2 parents 7cc8d94 + 97c9def commit 6952ffb

File tree

4 files changed

+143
-9
lines changed

4 files changed

+143
-9
lines changed

editor/js/Menubar.Add.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,21 @@ Menubar.Add = function ( editor ) {
436436
} );
437437
options.add( option );
438438

439+
// OrthographicCamera
440+
441+
var option = new UI.Row();
442+
option.setClass( 'option' );
443+
option.setTextContent( strings.getKey( 'menubar/add/orthographiccamera' ) );
444+
option.onClick( function () {
445+
446+
var camera = new THREE.OrthographicCamera();
447+
camera.name = 'OrthographicCamera';
448+
449+
editor.execute( new AddObjectCommand( camera ) );
450+
451+
} );
452+
options.add( option );
453+
439454
return container;
440455

441456
};

editor/js/Sidebar.Object.js

Lines changed: 112 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,46 @@ Sidebar.Object = function ( editor ) {
146146

147147
container.add( objectFovRow );
148148

149+
// left
150+
151+
var objectLeftRow = new UI.Row();
152+
var objectLeft = new UI.Number().onChange( update );
153+
154+
objectLeftRow.add( new UI.Text( strings.getKey( 'sidebar/object/left' ) ).setWidth( '90px' ) );
155+
objectLeftRow.add( objectLeft );
156+
157+
container.add( objectLeftRow );
158+
159+
// right
160+
161+
var objectRightRow = new UI.Row();
162+
var objectRight = new UI.Number().onChange( update );
163+
164+
objectRightRow.add( new UI.Text( strings.getKey( 'sidebar/object/right' ) ).setWidth( '90px' ) );
165+
objectRightRow.add( objectRight );
166+
167+
container.add( objectRightRow );
168+
169+
// top
170+
171+
var objectTopRow = new UI.Row();
172+
var objectTop = new UI.Number().onChange( update );
173+
174+
objectTopRow.add( new UI.Text( strings.getKey( 'sidebar/object/top' ) ).setWidth( '90px' ) );
175+
objectTopRow.add( objectTop );
176+
177+
container.add( objectTopRow );
178+
179+
// bottom
180+
181+
var objectBottomRow = new UI.Row();
182+
var objectBottom = new UI.Number().onChange( update );
183+
184+
objectBottomRow.add( new UI.Text( strings.getKey( 'sidebar/object/bottom' ) ).setWidth( '90px' ) );
185+
objectBottomRow.add( objectBottom );
186+
187+
container.add( objectBottomRow );
188+
149189
// near
150190

151191
var objectNearRow = new UI.Row();
@@ -400,15 +440,53 @@ Sidebar.Object = function ( editor ) {
400440

401441
}
402442

443+
if ( object.left !== undefined && Math.abs( object.left - objectLeft.getValue() ) >= 0.01 ) {
444+
445+
editor.execute( new SetValueCommand( object, 'left', objectLeft.getValue() ) );
446+
object.updateProjectionMatrix();
447+
448+
}
449+
450+
if ( object.right !== undefined && Math.abs( object.right - objectRight.getValue() ) >= 0.01 ) {
451+
452+
editor.execute( new SetValueCommand( object, 'right', objectRight.getValue() ) );
453+
object.updateProjectionMatrix();
454+
455+
}
456+
457+
if ( object.top !== undefined && Math.abs( object.top - objectTop.getValue() ) >= 0.01 ) {
458+
459+
editor.execute( new SetValueCommand( object, 'top', objectTop.getValue() ) );
460+
object.updateProjectionMatrix();
461+
462+
}
463+
464+
if ( object.bottom !== undefined && Math.abs( object.bottom - objectBottom.getValue() ) >= 0.01 ) {
465+
466+
editor.execute( new SetValueCommand( object, 'bottom', objectBottom.getValue() ) );
467+
object.updateProjectionMatrix();
468+
469+
}
470+
403471
if ( object.near !== undefined && Math.abs( object.near - objectNear.getValue() ) >= 0.01 ) {
404472

405473
editor.execute( new SetValueCommand( object, 'near', objectNear.getValue() ) );
474+
if ( object.isOrthographicCamera ) {
475+
476+
object.updateProjectionMatrix();
477+
478+
}
406479

407480
}
408481

409482
if ( object.far !== undefined && Math.abs( object.far - objectFar.getValue() ) >= 0.01 ) {
410483

411484
editor.execute( new SetValueCommand( object, 'far', objectFar.getValue() ) );
485+
if ( object.isOrthographicCamera ) {
486+
487+
object.updateProjectionMatrix();
488+
489+
}
412490

413491
}
414492

@@ -518,17 +596,21 @@ Sidebar.Object = function ( editor ) {
518596

519597
var properties = {
520598
'fov': objectFovRow,
599+
'left': objectLeftRow,
600+
'right': objectRightRow,
601+
'top': objectTopRow,
602+
'bottom': objectBottomRow,
521603
'near': objectNearRow,
522604
'far': objectFarRow,
523605
'intensity': objectIntensityRow,
524606
'color': objectColorRow,
525607
'groundColor': objectGroundColorRow,
526-
'distance' : objectDistanceRow,
527-
'angle' : objectAngleRow,
528-
'penumbra' : objectPenumbraRow,
529-
'decay' : objectDecayRow,
530-
'castShadow' : objectShadowRow,
531-
'receiveShadow' : objectReceiveShadow,
608+
'distance': objectDistanceRow,
609+
'angle': objectAngleRow,
610+
'penumbra': objectPenumbraRow,
611+
'decay': objectDecayRow,
612+
'castShadow': objectShadowRow,
613+
'receiveShadow': objectReceiveShadow,
532614
'shadow': objectShadowRadius
533615
};
534616

@@ -617,6 +699,30 @@ Sidebar.Object = function ( editor ) {
617699

618700
}
619701

702+
if ( object.left !== undefined ) {
703+
704+
objectLeft.setValue( object.left );
705+
706+
}
707+
708+
if ( object.right !== undefined ) {
709+
710+
objectRight.setValue( object.right );
711+
712+
}
713+
714+
if ( object.top !== undefined ) {
715+
716+
objectTop.setValue( object.top );
717+
718+
}
719+
720+
if ( object.bottom !== undefined ) {
721+
722+
objectBottom.setValue( object.bottom );
723+
724+
}
725+
620726
if ( object.near !== undefined ) {
621727

622728
objectNear.setValue( object.near );

editor/js/Strings.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ var Strings = function ( config ) {
5454
'menubar/add/hemispherelight': 'HemisphereLight',
5555
'menubar/add/ambientlight': 'AmbientLight',
5656
'menubar/add/perspectivecamera': 'PerspectiveCamera',
57+
'menubar/add/orthographiccamera': 'OrthographicCamera',
5758

5859
'menubar/status/autosave': 'autosave',
5960

@@ -84,6 +85,10 @@ var Strings = function ( config ) {
8485
'sidebar/object/rotation': 'Rotation',
8586
'sidebar/object/scale': 'Scale',
8687
'sidebar/object/fov': 'Fov',
88+
'sidebar/object/left': 'Left',
89+
'sidebar/object/right': 'Right',
90+
'sidebar/object/top': 'Top',
91+
'sidebar/object/bottom': 'Bottom',
8792
'sidebar/object/near': 'Near',
8893
'sidebar/object/far': 'Far',
8994
'sidebar/object/intensity': 'Intensity',

editor/js/Viewport.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,18 @@ var Viewport = function ( editor ) {
503503

504504
signals.viewportCameraChanged.add( function ( viewportCamera ) {
505505

506-
camera = viewportCamera;
506+
if ( viewportCamera.isPerspectiveCamera ) {
507+
508+
viewportCamera.aspect = editor.camera.aspect;
509+
viewportCamera.projectionMatrix.copy( editor.camera.projectionMatrix );
510+
511+
} else if ( ! viewportCamera.isOrthographicCamera ) {
512+
513+
throw "Invalid camera set as viewport";
507514

508-
camera.aspect = editor.camera.aspect;
509-
camera.projectionMatrix.copy( editor.camera.projectionMatrix );
515+
}
516+
517+
camera = viewportCamera;
510518

511519
render();
512520

0 commit comments

Comments
 (0)