Skip to content

Commit 37a21aa

Browse files
committed
Introduce camera settings class.
1 parent 34a64b5 commit 37a21aa

File tree

12 files changed

+67
-38
lines changed

12 files changed

+67
-38
lines changed

source/engine/parameters/parameterlist.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export let ParameterConverter =
5656
return cameraParameters;
5757
},
5858

59-
CameraModeToString : function (projectionMode)
59+
ProjectionModeToString : function (projectionMode)
6060
{
6161
if (projectionMode === ProjectionMode.Perspective) {
6262
return 'perspective';
@@ -90,7 +90,7 @@ export let ParameterConverter =
9090
return camera;
9191
},
9292

93-
StringToCameraMode : function (str)
93+
StringToProjectionMode : function (str)
9494
{
9595
if (str === 'perspective') {
9696
return ProjectionMode.Perspective;
@@ -245,9 +245,9 @@ export class ParameterListBuilder
245245
return this;
246246
}
247247

248-
AddCameraMode (projectionMode)
248+
AddProjectionMode (projectionMode)
249249
{
250-
this.AddUrlPart ('projectionmode', ParameterConverter.CameraModeToString (projectionMode));
250+
this.AddUrlPart ('projectionmode', ParameterConverter.ProjectionModeToString (projectionMode));
251251
return this;
252252
}
253253

@@ -317,13 +317,13 @@ export class ParameterListParser
317317
return ParameterConverter.StringToCamera (keywordParams);
318318
}
319319

320-
GetCameraMode ()
320+
GetProjectionMode ()
321321
{
322322
let keywordParams = this.GetKeywordParams ('cameramode'); // for compatibility
323323
if (keywordParams === null) {
324324
keywordParams = this.GetKeywordParams ('projectionmode');
325325
}
326-
return ParameterConverter.StringToCameraMode (keywordParams);
326+
return ParameterConverter.StringToProjectionMode (keywordParams);
327327
}
328328

329329
GetEnvironmentSettings ()

source/engine/viewer/embeddedviewer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class EmbeddedViewer
4848
this.viewer.Resize (width, height);
4949

5050
if (this.parameters.projectionMode) {
51-
this.viewer.SetCameraMode (this.parameters.projectionMode);
51+
this.viewer.SetProjectionMode (this.parameters.projectionMode);
5252
}
5353

5454
if (this.parameters.backgroundColor) {
@@ -260,7 +260,7 @@ export function Init3DViewerElements (onReady)
260260
let projectionMode = null;
261261
let cameraModeParams = element.getAttribute ('projectionmode');
262262
if (cameraModeParams) {
263-
projectionMode = ParameterConverter.StringToCameraMode (cameraModeParams);
263+
projectionMode = ParameterConverter.StringToProjectionMode (cameraModeParams);
264264
}
265265

266266
let backgroundColor = null;

source/engine/viewer/shadingmodel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class ShadingModel
6060
this.UpdateShading ();
6161
}
6262

63-
SetCameraMode (projectionMode)
63+
SetProjectionMode (projectionMode)
6464
{
6565
this.projectionMode = projectionMode;
6666
this.UpdateShading ();

source/engine/viewer/viewer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export class Viewer
260260
return this.navigation.GetCamera ();
261261
}
262262

263-
GetCameraMode ()
263+
GetProjectionMode ()
264264
{
265265
return this.projectionMode;
266266
}
@@ -272,7 +272,7 @@ export class Viewer
272272
this.Render ();
273273
}
274274

275-
SetCameraMode (projectionMode)
275+
SetProjectionMode (projectionMode)
276276
{
277277
if (this.projectionMode === projectionMode) {
278278
return;
@@ -287,7 +287,7 @@ export class Viewer
287287
this.scene.add (this.camera);
288288

289289
this.projectionMode = projectionMode;
290-
this.shadingModel.SetCameraMode (projectionMode);
290+
this.shadingModel.SetProjectionMode (projectionMode);
291291
this.cameraValidator.ForceUpdate ();
292292

293293
this.AdjustClippingPlanes ();

source/website/embed.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ export class Embed
5151
let environmentSettings = new EnvironmentSettings (envMapTextures, bgIsEnvMap);
5252
this.viewer.SetEnvironmentMapSettings (environmentSettings);
5353

54-
let projectionMode = this.hashHandler.GetCameraModeFromHash ();
54+
let projectionMode = this.hashHandler.GetProjectionModeFromHash ();
5555
if (projectionMode !== null) {
56-
this.viewer.SetCameraMode (projectionMode);
56+
this.viewer.SetProjectionMode (projectionMode);
5757
}
5858
let background = this.hashHandler.GetBackgroundFromHash ();
5959
if (background !== null) {

source/website/hashhandler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ export class HashHandler
4848
return parser.GetCamera ();
4949
}
5050

51-
GetCameraModeFromHash ()
51+
GetProjectionModeFromHash ()
5252
{
5353
let parser = CreateUrlParser (this.GetHash ());
54-
return parser.GetCameraMode ();
54+
return parser.GetProjectionMode ();
5555
}
5656

5757
GetBackgroundFromHash ()

source/website/settings.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { NavigationMode, ProjectionMode } from '../engine/viewer/camera.js';
12
import { RGBAColor, RGBColor } from '../engine/model/color.js';
23
import { EdgeSettings } from '../engine/viewer/viewermodel.js';
34
import { CookieGetBoolVal, CookieGetRGBColorVal, CookieGetIntVal, CookieGetStringVal, CookieSetBoolVal, CookieSetRGBColorVal, CookieSetIntVal, CookieSetStringVal, CookieSetRGBAColorVal, CookieGetRGBAColorVal } from './cookiehandler.js';
@@ -49,3 +50,24 @@ export class Settings
4950
CookieSetIntVal ('ov_edge_threshold', this.edgeSettings.edgeThreshold);
5051
}
5152
}
53+
54+
export class CameraSettings
55+
{
56+
constructor ()
57+
{
58+
this.navigationMode = NavigationMode.FixedUpVector;
59+
this.projectionMode = ProjectionMode.Perspective;
60+
}
61+
62+
LoadFromCookies ()
63+
{
64+
this.navigationMode = CookieGetIntVal ('ov_navigation_mode', NavigationMode.FixedUpVector);
65+
this.projectionMode = CookieGetIntVal ('ov_projection_mode', ProjectionMode.Perspective);
66+
}
67+
68+
SaveToCookies ()
69+
{
70+
CookieSetIntVal ('ov_navigation_mode', this.navigationMode);
71+
CookieSetIntVal ('ov_projection_mode', this.projectionMode);
72+
}
73+
}

source/website/sharingdialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function ShowSharingDialog (fileList, settings, viewer)
6363
builder.AddModelUrls (modelFiles);
6464
if (useCurrentSettings) {
6565
builder.AddCamera (viewer.GetCamera ());
66-
builder.AddCameraMode (viewer.GetCameraMode ());
66+
builder.AddProjectionMode (viewer.GetProjectionMode ());
6767
let environmentSettings = {
6868
environmentMapName : settings.environmentMapName,
6969
backgroundIsEnvMap : settings.backgroundIsEnvMap

source/website/sidebar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export class Sidebar
4545
getShadingType : () => {
4646
return this.callbacks.getShadingType ();
4747
},
48-
getCameraMode : () => {
49-
return this.callbacks.getCameraMode ();
48+
getProjectionMode : () => {
49+
return this.callbacks.getProjectionMode ();
5050
},
5151
hasDefaultMaterial : () => {
5252
return this.callbacks.hasDefaultMaterial ();

source/website/sidebarsettingspanel.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class EnvironmentMapPopup extends PopupDialog
121121
});
122122
}
123123
} else if (shadingType === ShadingType.Physical) {
124-
let isPerspective = (callbacks.getCameraMode () === ProjectionMode.Perspective);
124+
let isPerspective = (callbacks.getProjectionMode () === ProjectionMode.Perspective);
125125
if (isPerspective) {
126126
let checkboxDiv = AddDiv (contentDiv, 'ov_environment_map_checkbox');
127127
let backgroundIsEnvMapCheckbox = AddCheckbox (checkboxDiv, 'use_as_background', 'Use as background image', settings.backgroundIsEnvMap, () => {
@@ -232,8 +232,8 @@ class SettingsModelDisplaySection extends SettingsSection
232232
this.environmentMapPhongInput.addEventListener ('click', () => {
233233
this.environmentMapPopup = new EnvironmentMapPopup ();
234234
this.environmentMapPopup.ShowPopup (this.environmentMapPhongInput, ShadingType.Phong, this.settings, {
235-
getCameraMode : () => {
236-
return this.callbacks.getCameraMode ();
235+
getProjectionMode : () => {
236+
return this.callbacks.getProjectionMode ();
237237
},
238238
onEnvironmentMapChanged : () => {
239239
this.UpdateEnvironmentMap ();
@@ -248,8 +248,8 @@ class SettingsModelDisplaySection extends SettingsSection
248248
this.environmentMapPbrInput.addEventListener ('click', () => {
249249
this.environmentMapPopup = new EnvironmentMapPopup ();
250250
this.environmentMapPopup.ShowPopup (this.environmentMapPbrInput, ShadingType.Physical, this.settings, {
251-
getCameraMode : () => {
252-
return this.callbacks.getCameraMode ();
251+
getProjectionMode : () => {
252+
return this.callbacks.getProjectionMode ();
253253
},
254254
onEnvironmentMapChanged : () => {
255255
this.UpdateEnvironmentMap ();
@@ -345,7 +345,7 @@ class SettingsModelDisplaySection extends SettingsSection
345345
{
346346
let isPhysicallyBased = (this.callbacks.getShadingType () === ShadingType.Physical);
347347
if (this.environmentMapPhongDiv !== null) {
348-
let isPerspective = (this.callbacks.getCameraMode () === ProjectionMode.Perspective);
348+
let isPerspective = (this.callbacks.getProjectionMode () === ProjectionMode.Perspective);
349349
ShowDomElement (this.environmentMapPhongDiv, !isPhysicallyBased && isPerspective);
350350
}
351351
if (this.environmentMapPbrDiv !== null) {
@@ -462,8 +462,8 @@ export class SidebarSettingsPanel extends SidebarPanel
462462
getShadingType : () => {
463463
return this.callbacks.getShadingType ();
464464
},
465-
getCameraMode : () => {
466-
return this.callbacks.getCameraMode ();
465+
getProjectionMode : () => {
466+
return this.callbacks.getProjectionMode ();
467467
},
468468
onEnvironmentMapChanged : () => {
469469
this.callbacks.onEnvironmentMapChanged ();

source/website/website.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { CalculatePopupPositionToScreen, ShowListPopup } from './dialogs.js';
99
import { HandleEvent } from './eventhandler.js';
1010
import { HashHandler } from './hashhandler.js';
1111
import { Navigator, Selection, SelectionType } from './navigator.js';
12-
import { Settings, Theme } from './settings.js';
12+
import { CameraSettings, Settings, Theme } from './settings.js';
1313
import { Sidebar } from './sidebar.js';
1414
import { ThemeHandler } from './themehandler.js';
1515
import { ThreeModelLoaderUI } from './threemodelloaderui.js';
@@ -187,6 +187,7 @@ export class Website
187187
{
188188
this.parameters = parameters;
189189
this.settings = new Settings (Theme.Light);
190+
this.cameraSettings = new CameraSettings ();
190191
this.viewer = new Viewer ();
191192
this.measureTool = new MeasureTool (this.viewer, this.settings);
192193
this.hashHandler = new HashHandler ();
@@ -204,6 +205,8 @@ export class Website
204205
Load ()
205206
{
206207
this.settings.LoadFromCookies ();
208+
this.cameraSettings.LoadFromCookies ();
209+
207210
this.SwitchTheme (this.settings.themeId, false);
208211
HandleEvent ('theme_on_load', this.settings.themeId === Theme.Light ? 'light' : 'dark');
209212

@@ -675,18 +678,22 @@ export class Website
675678
AddSeparator (this.toolbar, ['only_full_width', 'only_on_model']);
676679
AddRadioButton (this.toolbar, ['fix_up_on', 'fix_up_off'], ['Fixed up vector', 'Free orbit'], 0, ['only_full_width', 'only_on_model'], (buttonIndex) => {
677680
if (buttonIndex === 0) {
678-
this.viewer.SetNavigationMode (NavigationMode.FixedUpVector);
681+
this.cameraSettings.navigationMode = NavigationMode.FixedUpVector;
679682
} else if (buttonIndex === 1) {
680-
this.viewer.SetNavigationMode (NavigationMode.FreeOrbit);
683+
this.cameraSettings.navigationMode = NavigationMode.FreeOrbit;
681684
}
685+
this.cameraSettings.SaveToCookies ();
686+
this.viewer.SetNavigationMode (this.cameraSettings.navigationMode);
682687
});
683688
AddSeparator (this.toolbar, ['only_full_width', 'only_on_model']);
684689
AddRadioButton (this.toolbar, ['camera_perspective', 'camera_orthographic'], ['Perspective camera', 'Orthographic camera'], 0, ['only_full_width', 'only_on_model'], (buttonIndex) => {
685690
if (buttonIndex === 0) {
686-
this.viewer.SetCameraMode (ProjectionMode.Perspective);
691+
this.cameraSettings.projectionMode = ProjectionMode.Perspective;
687692
} else if (buttonIndex === 1) {
688-
this.viewer.SetCameraMode (ProjectionMode.Orthographic);
693+
this.cameraSettings.projectionMode = ProjectionMode.Orthographic;
689694
}
695+
this.cameraSettings.SaveToCookies ();
696+
this.viewer.SetProjectionMode (this.cameraSettings.projectionMode);
690697
this.sidebar.UpdateControlsVisibility ();
691698
});
692699
AddSeparator (this.toolbar, ['only_full_width', 'only_on_model']);
@@ -780,8 +787,8 @@ export class Website
780787
getShadingType : () => {
781788
return this.viewer.GetShadingType ();
782789
},
783-
getCameraMode : () => {
784-
return this.viewer.GetCameraMode ();
790+
getProjectionMode : () => {
791+
return this.viewer.GetProjectionMode ();
785792
},
786793
hasDefaultMaterial : () => {
787794
return HasDefaultMaterial (this.model);

test/tests/parameterlist_test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ describe ('Parameter List', function () {
4545
assert.strictEqual (urlParams, 'edgesettings=on,1,2,3,15');
4646
}
4747
{
48-
let urlParams = OV.CreateUrlBuilder ().AddCameraMode (OV.ProjectionMode.Perspective).GetParameterList ();
48+
let urlParams = OV.CreateUrlBuilder ().AddProjectionMode (OV.ProjectionMode.Perspective).GetParameterList ();
4949
assert.strictEqual (urlParams, 'projectionmode=perspective');
5050
}
5151
{
52-
let urlParams = OV.CreateUrlBuilder ().AddCameraMode (OV.ProjectionMode.Orthographic).GetParameterList ();
52+
let urlParams = OV.CreateUrlBuilder ().AddProjectionMode (OV.ProjectionMode.Orthographic).GetParameterList ();
5353
assert.strictEqual (urlParams, 'projectionmode=orthographic');
5454
}
5555
});
@@ -124,11 +124,11 @@ describe ('Parameter List', function () {
124124
}
125125
{
126126
let parser = OV.CreateUrlParser ('projectionmode=perspective');
127-
assert.deepStrictEqual (parser.GetCameraMode (), OV.ProjectionMode.Perspective);
127+
assert.deepStrictEqual (parser.GetProjectionMode (), OV.ProjectionMode.Perspective);
128128
}
129129
{
130130
let parser = OV.CreateUrlParser ('projectionmode=orthographic');
131-
assert.deepStrictEqual (parser.GetCameraMode (), OV.ProjectionMode.Orthographic);
131+
assert.deepStrictEqual (parser.GetProjectionMode (), OV.ProjectionMode.Orthographic);
132132
}
133133
});
134134
});

0 commit comments

Comments
 (0)