Background settings is visible with orthographic camera, but it doesn't work #306

This commit is contained in:
kovacsv 2022-10-11 20:07:41 +02:00
parent 8da7f15a54
commit 76dd260801
3 changed files with 62 additions and 19 deletions

View File

@ -48,6 +48,9 @@ export class Sidebar
getShadingType : () => { getShadingType : () => {
return this.callbacks.getShadingType (); return this.callbacks.getShadingType ();
}, },
getCameraMode : () => {
return this.callbacks.getCameraMode ();
},
hasDefaultMaterial : () => { hasDefaultMaterial : () => {
return this.callbacks.hasDefaultMaterial (); return this.callbacks.hasDefaultMaterial ();
}, },
@ -73,9 +76,9 @@ export class Sidebar
}); });
} }
Update () UpdateControlsVisibility ()
{ {
this.settingsPanel.Update (); this.settingsPanel.UpdateControlsVisibility ();
} }
Resize (height) Resize (height)

View File

@ -6,6 +6,7 @@ import { PopupDialog } from './dialog.js';
import { Settings, Theme } from './settings.js'; import { Settings, Theme } from './settings.js';
import { SidebarPanel } from './sidebarpanel.js'; import { SidebarPanel } from './sidebarpanel.js';
import { ShadingType } from '../engine/threejs/threeutils.js'; import { ShadingType } from '../engine/threejs/threeutils.js';
import { CameraMode } from '../engine/viewer/viewer.js';
function AddColorPicker (parentDiv, opacity, defaultColor, predefinedColors, onChange) function AddColorPicker (parentDiv, opacity, defaultColor, predefinedColors, onChange)
{ {
@ -117,11 +118,14 @@ class EnvironmentMapPopup extends PopupDialog
}); });
} }
} else if (shadingType === ShadingType.Physical) { } else if (shadingType === ShadingType.Physical) {
let checkboxDiv = AddDiv (contentDiv, 'ov_environment_map_checkbox'); let isPerspective = (callbacks.getCameraMode () === CameraMode.Perspective);
let backgroundIsEnvMapCheckbox = AddCheckbox (checkboxDiv, 'use_as_background', 'Use as background image', settings.backgroundIsEnvMap, () => { if (isPerspective) {
settings.backgroundIsEnvMap = backgroundIsEnvMapCheckbox.checked; let checkboxDiv = AddDiv (contentDiv, 'ov_environment_map_checkbox');
callbacks.onEnvironmentMapChanged (); let backgroundIsEnvMapCheckbox = AddCheckbox (checkboxDiv, 'use_as_background', 'Use as background image', settings.backgroundIsEnvMap, () => {
}); settings.backgroundIsEnvMap = backgroundIsEnvMapCheckbox.checked;
callbacks.onEnvironmentMapChanged ();
});
}
for (let envMapImage of envMapImages) { for (let envMapImage of envMapImages) {
envMapImage.element = AddDomElement (contentDiv, 'img', 'ov_environment_map_preview'); envMapImage.element = AddDomElement (contentDiv, 'img', 'ov_environment_map_preview');
@ -143,6 +147,11 @@ class EnvironmentMapPopup extends PopupDialog
contentDiv.classList.add ('sidebar'); contentDiv.classList.add ('sidebar');
this.Open (); this.Open ();
} }
Update ()
{
}
} }
class SettingsSection class SettingsSection
@ -166,6 +175,11 @@ class SettingsSection
} }
UpdateVisibility ()
{
}
Clear () Clear ()
{ {
@ -215,6 +229,9 @@ class SettingsModelDisplaySection extends SettingsSection
this.environmentMapPhongInput.addEventListener ('click', () => { this.environmentMapPhongInput.addEventListener ('click', () => {
this.environmentMapPopup = new EnvironmentMapPopup (); this.environmentMapPopup = new EnvironmentMapPopup ();
this.environmentMapPopup.ShowPopup (this.environmentMapPhongInput, ShadingType.Phong, this.settings, { this.environmentMapPopup.ShowPopup (this.environmentMapPhongInput, ShadingType.Phong, this.settings, {
getCameraMode : () => {
return this.callbacks.getCameraMode ();
},
onEnvironmentMapChanged : () => { onEnvironmentMapChanged : () => {
this.UpdateEnvironmentMap (); this.UpdateEnvironmentMap ();
this.callbacks.onEnvironmentMapChanged (); this.callbacks.onEnvironmentMapChanged ();
@ -228,6 +245,9 @@ class SettingsModelDisplaySection extends SettingsSection
this.environmentMapPbrInput.addEventListener ('click', () => { this.environmentMapPbrInput.addEventListener ('click', () => {
this.environmentMapPopup = new EnvironmentMapPopup (); this.environmentMapPopup = new EnvironmentMapPopup ();
this.environmentMapPopup.ShowPopup (this.environmentMapPbrInput, ShadingType.Physical, this.settings, { this.environmentMapPopup.ShowPopup (this.environmentMapPbrInput, ShadingType.Physical, this.settings, {
getCameraMode : () => {
return this.callbacks.getCameraMode ();
},
onEnvironmentMapChanged : () => { onEnvironmentMapChanged : () => {
this.UpdateEnvironmentMap (); this.UpdateEnvironmentMap ();
this.callbacks.onEnvironmentMapChanged (); this.callbacks.onEnvironmentMapChanged ();
@ -308,14 +328,6 @@ class SettingsModelDisplaySection extends SettingsSection
this.UpdateEnvironmentMap (); this.UpdateEnvironmentMap ();
} }
let isPhysicallyBased = (this.callbacks.getShadingType () === ShadingType.Physical);
if (this.environmentMapPhongDiv !== null) {
ShowDomElement (this.environmentMapPhongDiv, !isPhysicallyBased);
}
if (this.environmentMapPbrDiv !== null) {
ShowDomElement (this.environmentMapPbrDiv, isPhysicallyBased);
}
if (this.edgeDisplayToggle !== null) { if (this.edgeDisplayToggle !== null) {
this.edgeDisplayToggle.SetStatus (this.settings.showEdges); this.edgeDisplayToggle.SetStatus (this.settings.showEdges);
ShowDomElement (this.edgeSettingsDiv, this.settings.showEdges); ShowDomElement (this.edgeSettingsDiv, this.settings.showEdges);
@ -326,6 +338,18 @@ class SettingsModelDisplaySection extends SettingsSection
} }
} }
UpdateVisibility ()
{
let isPhysicallyBased = (this.callbacks.getShadingType () === ShadingType.Physical);
if (this.environmentMapPhongDiv !== null) {
let isPerspective = (this.callbacks.getCameraMode () === CameraMode.Perspective);
ShowDomElement (this.environmentMapPhongDiv, !isPhysicallyBased && isPerspective);
}
if (this.environmentMapPbrDiv !== null) {
ShowDomElement (this.environmentMapPbrDiv, isPhysicallyBased);
}
}
Clear () Clear ()
{ {
if (this.environmentMapPopup !== null) { if (this.environmentMapPopup !== null) {
@ -371,6 +395,10 @@ class SettingsImportParametersSection extends SettingsSection
if (this.defaultColorPicker !== null) { if (this.defaultColorPicker !== null) {
this.defaultColorPicker.setColor ('#' + RGBColorToHexString (this.settings.defaultColor)); this.defaultColorPicker.setColor ('#' + RGBColorToHexString (this.settings.defaultColor));
} }
}
UpdateVisibility ()
{
if (this.contentDiv !== null) { if (this.contentDiv !== null) {
let hasDefaultMaterial = this.callbacks.hasDefaultMaterial (); let hasDefaultMaterial = this.callbacks.hasDefaultMaterial ();
ShowDomElement (this.contentDiv, hasDefaultMaterial); ShowDomElement (this.contentDiv, hasDefaultMaterial);
@ -417,6 +445,11 @@ class SettingsAppearanceSection extends SettingsSection
this.darkModeToggle.SetStatus (isDarkMode); this.darkModeToggle.SetStatus (isDarkMode);
} }
} }
UpdateVisibility ()
{
}
} }
export class SidebarSettingsPanel extends SidebarPanel export class SidebarSettingsPanel extends SidebarPanel
@ -467,6 +500,9 @@ export class SidebarSettingsPanel extends SidebarPanel
getShadingType : () => { getShadingType : () => {
return this.callbacks.getShadingType (); return this.callbacks.getShadingType ();
}, },
getCameraMode : () => {
return this.callbacks.getCameraMode ();
},
onEnvironmentMapChanged : () => { onEnvironmentMapChanged : () => {
this.callbacks.onEnvironmentMapChanged (); this.callbacks.onEnvironmentMapChanged ();
}, },
@ -507,10 +543,10 @@ export class SidebarSettingsPanel extends SidebarPanel
}); });
} }
Update () UpdateControlsVisibility ()
{ {
this.modelDisplaySection.Update (); this.modelDisplaySection.UpdateVisibility ();
this.importParametersSection.Update (); this.importParametersSection.UpdateVisibility ();
this.Resize (); this.Resize ();
} }

View File

@ -179,7 +179,7 @@ export class Website
this.viewer.SetMainObject (threeObject); this.viewer.SetMainObject (threeObject);
this.viewer.SetUpVector (Direction.Y, false); this.viewer.SetUpVector (Direction.Y, false);
this.navigator.FillTree (importResult); this.navigator.FillTree (importResult);
this.sidebar.Update (); this.sidebar.UpdateControlsVisibility ();
this.FitModelToWindow (true); this.FitModelToWindow (true);
} }
@ -561,6 +561,7 @@ export class Website
} else if (buttonIndex === 1) { } else if (buttonIndex === 1) {
this.viewer.SetCameraMode (CameraMode.Orthographic); this.viewer.SetCameraMode (CameraMode.Orthographic);
} }
this.sidebar.UpdateControlsVisibility ();
}); });
AddSeparator (this.toolbar, ['only_full_width', 'only_on_model']); AddSeparator (this.toolbar, ['only_full_width', 'only_on_model']);
let measureToolButton = AddPushButton (this.toolbar, 'measure', 'Measure', ['only_full_width', 'only_on_model'], (isSelected) => { let measureToolButton = AddPushButton (this.toolbar, 'measure', 'Measure', ['only_full_width', 'only_on_model'], (isSelected) => {
@ -622,6 +623,9 @@ export class Website
getShadingType : () => { getShadingType : () => {
return this.viewer.GetShadingType (); return this.viewer.GetShadingType ();
}, },
getCameraMode : () => {
return this.viewer.GetCameraMode ();
},
hasDefaultMaterial : () => { hasDefaultMaterial : () => {
return HasDefaultMaterial (this.model); return HasDefaultMaterial (this.model);
}, },