Skip to content

Commit

Permalink
Introduce camera settings class.
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacsv committed Oct 14, 2023
1 parent 34a64b5 commit 37a21aa
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 38 deletions.
12 changes: 6 additions & 6 deletions source/engine/parameters/parameterlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export let ParameterConverter =
return cameraParameters;
},

CameraModeToString : function (projectionMode)
ProjectionModeToString : function (projectionMode)
{
if (projectionMode === ProjectionMode.Perspective) {
return 'perspective';
Expand Down Expand Up @@ -90,7 +90,7 @@ export let ParameterConverter =
return camera;
},

StringToCameraMode : function (str)
StringToProjectionMode : function (str)
{
if (str === 'perspective') {
return ProjectionMode.Perspective;
Expand Down Expand Up @@ -245,9 +245,9 @@ export class ParameterListBuilder
return this;
}

AddCameraMode (projectionMode)
AddProjectionMode (projectionMode)
{
this.AddUrlPart ('projectionmode', ParameterConverter.CameraModeToString (projectionMode));
this.AddUrlPart ('projectionmode', ParameterConverter.ProjectionModeToString (projectionMode));
return this;
}

Expand Down Expand Up @@ -317,13 +317,13 @@ export class ParameterListParser
return ParameterConverter.StringToCamera (keywordParams);
}

GetCameraMode ()
GetProjectionMode ()
{
let keywordParams = this.GetKeywordParams ('cameramode'); // for compatibility
if (keywordParams === null) {
keywordParams = this.GetKeywordParams ('projectionmode');
}
return ParameterConverter.StringToCameraMode (keywordParams);
return ParameterConverter.StringToProjectionMode (keywordParams);
}

GetEnvironmentSettings ()
Expand Down
4 changes: 2 additions & 2 deletions source/engine/viewer/embeddedviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class EmbeddedViewer
this.viewer.Resize (width, height);

if (this.parameters.projectionMode) {
this.viewer.SetCameraMode (this.parameters.projectionMode);
this.viewer.SetProjectionMode (this.parameters.projectionMode);
}

if (this.parameters.backgroundColor) {
Expand Down Expand Up @@ -260,7 +260,7 @@ export function Init3DViewerElements (onReady)
let projectionMode = null;
let cameraModeParams = element.getAttribute ('projectionmode');
if (cameraModeParams) {
projectionMode = ParameterConverter.StringToCameraMode (cameraModeParams);
projectionMode = ParameterConverter.StringToProjectionMode (cameraModeParams);
}

let backgroundColor = null;
Expand Down
2 changes: 1 addition & 1 deletion source/engine/viewer/shadingmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class ShadingModel
this.UpdateShading ();
}

SetCameraMode (projectionMode)
SetProjectionMode (projectionMode)
{
this.projectionMode = projectionMode;
this.UpdateShading ();
Expand Down
6 changes: 3 additions & 3 deletions source/engine/viewer/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export class Viewer
return this.navigation.GetCamera ();
}

GetCameraMode ()
GetProjectionMode ()
{
return this.projectionMode;
}
Expand All @@ -272,7 +272,7 @@ export class Viewer
this.Render ();
}

SetCameraMode (projectionMode)
SetProjectionMode (projectionMode)
{
if (this.projectionMode === projectionMode) {
return;
Expand All @@ -287,7 +287,7 @@ export class Viewer
this.scene.add (this.camera);

this.projectionMode = projectionMode;
this.shadingModel.SetCameraMode (projectionMode);
this.shadingModel.SetProjectionMode (projectionMode);
this.cameraValidator.ForceUpdate ();

this.AdjustClippingPlanes ();
Expand Down
4 changes: 2 additions & 2 deletions source/website/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export class Embed
let environmentSettings = new EnvironmentSettings (envMapTextures, bgIsEnvMap);
this.viewer.SetEnvironmentMapSettings (environmentSettings);

let projectionMode = this.hashHandler.GetCameraModeFromHash ();
let projectionMode = this.hashHandler.GetProjectionModeFromHash ();
if (projectionMode !== null) {
this.viewer.SetCameraMode (projectionMode);
this.viewer.SetProjectionMode (projectionMode);
}
let background = this.hashHandler.GetBackgroundFromHash ();
if (background !== null) {
Expand Down
4 changes: 2 additions & 2 deletions source/website/hashhandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ export class HashHandler
return parser.GetCamera ();
}

GetCameraModeFromHash ()
GetProjectionModeFromHash ()
{
let parser = CreateUrlParser (this.GetHash ());
return parser.GetCameraMode ();
return parser.GetProjectionMode ();
}

GetBackgroundFromHash ()
Expand Down
22 changes: 22 additions & 0 deletions source/website/settings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NavigationMode, ProjectionMode } from '../engine/viewer/camera.js';
import { RGBAColor, RGBColor } from '../engine/model/color.js';
import { EdgeSettings } from '../engine/viewer/viewermodel.js';
import { CookieGetBoolVal, CookieGetRGBColorVal, CookieGetIntVal, CookieGetStringVal, CookieSetBoolVal, CookieSetRGBColorVal, CookieSetIntVal, CookieSetStringVal, CookieSetRGBAColorVal, CookieGetRGBAColorVal } from './cookiehandler.js';
Expand Down Expand Up @@ -49,3 +50,24 @@ export class Settings
CookieSetIntVal ('ov_edge_threshold', this.edgeSettings.edgeThreshold);
}
}

export class CameraSettings
{
constructor ()
{
this.navigationMode = NavigationMode.FixedUpVector;
this.projectionMode = ProjectionMode.Perspective;
}

LoadFromCookies ()
{
this.navigationMode = CookieGetIntVal ('ov_navigation_mode', NavigationMode.FixedUpVector);
this.projectionMode = CookieGetIntVal ('ov_projection_mode', ProjectionMode.Perspective);
}

SaveToCookies ()
{
CookieSetIntVal ('ov_navigation_mode', this.navigationMode);
CookieSetIntVal ('ov_projection_mode', this.projectionMode);
}
}
2 changes: 1 addition & 1 deletion source/website/sharingdialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function ShowSharingDialog (fileList, settings, viewer)
builder.AddModelUrls (modelFiles);
if (useCurrentSettings) {
builder.AddCamera (viewer.GetCamera ());
builder.AddCameraMode (viewer.GetCameraMode ());
builder.AddProjectionMode (viewer.GetProjectionMode ());
let environmentSettings = {
environmentMapName : settings.environmentMapName,
backgroundIsEnvMap : settings.backgroundIsEnvMap
Expand Down
4 changes: 2 additions & 2 deletions source/website/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export class Sidebar
getShadingType : () => {
return this.callbacks.getShadingType ();
},
getCameraMode : () => {
return this.callbacks.getCameraMode ();
getProjectionMode : () => {
return this.callbacks.getProjectionMode ();
},
hasDefaultMaterial : () => {
return this.callbacks.hasDefaultMaterial ();
Expand Down
16 changes: 8 additions & 8 deletions source/website/sidebarsettingspanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class EnvironmentMapPopup extends PopupDialog
});
}
} else if (shadingType === ShadingType.Physical) {
let isPerspective = (callbacks.getCameraMode () === ProjectionMode.Perspective);
let isPerspective = (callbacks.getProjectionMode () === ProjectionMode.Perspective);
if (isPerspective) {
let checkboxDiv = AddDiv (contentDiv, 'ov_environment_map_checkbox');
let backgroundIsEnvMapCheckbox = AddCheckbox (checkboxDiv, 'use_as_background', 'Use as background image', settings.backgroundIsEnvMap, () => {
Expand Down Expand Up @@ -232,8 +232,8 @@ class SettingsModelDisplaySection extends SettingsSection
this.environmentMapPhongInput.addEventListener ('click', () => {
this.environmentMapPopup = new EnvironmentMapPopup ();
this.environmentMapPopup.ShowPopup (this.environmentMapPhongInput, ShadingType.Phong, this.settings, {
getCameraMode : () => {
return this.callbacks.getCameraMode ();
getProjectionMode : () => {
return this.callbacks.getProjectionMode ();
},
onEnvironmentMapChanged : () => {
this.UpdateEnvironmentMap ();
Expand All @@ -248,8 +248,8 @@ class SettingsModelDisplaySection extends SettingsSection
this.environmentMapPbrInput.addEventListener ('click', () => {
this.environmentMapPopup = new EnvironmentMapPopup ();
this.environmentMapPopup.ShowPopup (this.environmentMapPbrInput, ShadingType.Physical, this.settings, {
getCameraMode : () => {
return this.callbacks.getCameraMode ();
getProjectionMode : () => {
return this.callbacks.getProjectionMode ();
},
onEnvironmentMapChanged : () => {
this.UpdateEnvironmentMap ();
Expand Down Expand Up @@ -345,7 +345,7 @@ class SettingsModelDisplaySection extends SettingsSection
{
let isPhysicallyBased = (this.callbacks.getShadingType () === ShadingType.Physical);
if (this.environmentMapPhongDiv !== null) {
let isPerspective = (this.callbacks.getCameraMode () === ProjectionMode.Perspective);
let isPerspective = (this.callbacks.getProjectionMode () === ProjectionMode.Perspective);
ShowDomElement (this.environmentMapPhongDiv, !isPhysicallyBased && isPerspective);
}
if (this.environmentMapPbrDiv !== null) {
Expand Down Expand Up @@ -462,8 +462,8 @@ export class SidebarSettingsPanel extends SidebarPanel
getShadingType : () => {
return this.callbacks.getShadingType ();
},
getCameraMode : () => {
return this.callbacks.getCameraMode ();
getProjectionMode : () => {
return this.callbacks.getProjectionMode ();
},
onEnvironmentMapChanged : () => {
this.callbacks.onEnvironmentMapChanged ();
Expand Down
21 changes: 14 additions & 7 deletions source/website/website.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CalculatePopupPositionToScreen, ShowListPopup } from './dialogs.js';
import { HandleEvent } from './eventhandler.js';
import { HashHandler } from './hashhandler.js';
import { Navigator, Selection, SelectionType } from './navigator.js';
import { Settings, Theme } from './settings.js';
import { CameraSettings, Settings, Theme } from './settings.js';
import { Sidebar } from './sidebar.js';
import { ThemeHandler } from './themehandler.js';
import { ThreeModelLoaderUI } from './threemodelloaderui.js';
Expand Down Expand Up @@ -187,6 +187,7 @@ export class Website
{
this.parameters = parameters;
this.settings = new Settings (Theme.Light);
this.cameraSettings = new CameraSettings ();
this.viewer = new Viewer ();
this.measureTool = new MeasureTool (this.viewer, this.settings);
this.hashHandler = new HashHandler ();
Expand All @@ -204,6 +205,8 @@ export class Website
Load ()
{
this.settings.LoadFromCookies ();
this.cameraSettings.LoadFromCookies ();

this.SwitchTheme (this.settings.themeId, false);
HandleEvent ('theme_on_load', this.settings.themeId === Theme.Light ? 'light' : 'dark');

Expand Down Expand Up @@ -675,18 +678,22 @@ export class Website
AddSeparator (this.toolbar, ['only_full_width', 'only_on_model']);
AddRadioButton (this.toolbar, ['fix_up_on', 'fix_up_off'], ['Fixed up vector', 'Free orbit'], 0, ['only_full_width', 'only_on_model'], (buttonIndex) => {
if (buttonIndex === 0) {
this.viewer.SetNavigationMode (NavigationMode.FixedUpVector);
this.cameraSettings.navigationMode = NavigationMode.FixedUpVector;
} else if (buttonIndex === 1) {
this.viewer.SetNavigationMode (NavigationMode.FreeOrbit);
this.cameraSettings.navigationMode = NavigationMode.FreeOrbit;
}
this.cameraSettings.SaveToCookies ();
this.viewer.SetNavigationMode (this.cameraSettings.navigationMode);
});
AddSeparator (this.toolbar, ['only_full_width', 'only_on_model']);
AddRadioButton (this.toolbar, ['camera_perspective', 'camera_orthographic'], ['Perspective camera', 'Orthographic camera'], 0, ['only_full_width', 'only_on_model'], (buttonIndex) => {
if (buttonIndex === 0) {
this.viewer.SetCameraMode (ProjectionMode.Perspective);
this.cameraSettings.projectionMode = ProjectionMode.Perspective;
} else if (buttonIndex === 1) {
this.viewer.SetCameraMode (ProjectionMode.Orthographic);
this.cameraSettings.projectionMode = ProjectionMode.Orthographic;
}
this.cameraSettings.SaveToCookies ();
this.viewer.SetProjectionMode (this.cameraSettings.projectionMode);
this.sidebar.UpdateControlsVisibility ();
});
AddSeparator (this.toolbar, ['only_full_width', 'only_on_model']);
Expand Down Expand Up @@ -780,8 +787,8 @@ export class Website
getShadingType : () => {
return this.viewer.GetShadingType ();
},
getCameraMode : () => {
return this.viewer.GetCameraMode ();
getProjectionMode : () => {
return this.viewer.GetProjectionMode ();
},
hasDefaultMaterial : () => {
return HasDefaultMaterial (this.model);
Expand Down
8 changes: 4 additions & 4 deletions test/tests/parameterlist_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ describe ('Parameter List', function () {
assert.strictEqual (urlParams, 'edgesettings=on,1,2,3,15');
}
{
let urlParams = OV.CreateUrlBuilder ().AddCameraMode (OV.ProjectionMode.Perspective).GetParameterList ();
let urlParams = OV.CreateUrlBuilder ().AddProjectionMode (OV.ProjectionMode.Perspective).GetParameterList ();
assert.strictEqual (urlParams, 'projectionmode=perspective');
}
{
let urlParams = OV.CreateUrlBuilder ().AddCameraMode (OV.ProjectionMode.Orthographic).GetParameterList ();
let urlParams = OV.CreateUrlBuilder ().AddProjectionMode (OV.ProjectionMode.Orthographic).GetParameterList ();
assert.strictEqual (urlParams, 'projectionmode=orthographic');
}
});
Expand Down Expand Up @@ -124,11 +124,11 @@ describe ('Parameter List', function () {
}
{
let parser = OV.CreateUrlParser ('projectionmode=perspective');
assert.deepStrictEqual (parser.GetCameraMode (), OV.ProjectionMode.Perspective);
assert.deepStrictEqual (parser.GetProjectionMode (), OV.ProjectionMode.Perspective);
}
{
let parser = OV.CreateUrlParser ('projectionmode=orthographic');
assert.deepStrictEqual (parser.GetCameraMode (), OV.ProjectionMode.Orthographic);
assert.deepStrictEqual (parser.GetProjectionMode (), OV.ProjectionMode.Orthographic);
}
});
});
Expand Down

0 comments on commit 37a21aa

Please sign in to comment.