Skip to content

Visual Improvements to Maps3D demo #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 38 additions & 9 deletions src/XRSharpSamplesGallery/XRSharpSamplesGallery/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public partial class MainPage : Page
private readonly CameraAnimation _cameraAnimation;
private readonly MenuViewModel _menuViewModel;
private bool _inXRMode;
private Menu.MenuItem _selectedItem;

public MainPage()
{
Expand All @@ -34,16 +35,23 @@ public MainPage()

private void OnSelectionChanged(object sender, Menu.MenuItem menuItem)
{
if (menuItem.IsRoomVisible)
{
EnvironmentInstance.Visibility = Visibility.Visible;
_selectedItem = menuItem;
if (Root3DInstance.IsInARMode)
EnvironmentInstance.Visibility = Visibility.Collapsed;
else
EnvironmentInstance.Visibility = menuItem.IsRoomVisible ? Visibility.Visible : Visibility.Collapsed;

MainDirectionalLight.CastShadows = menuItem.EnableShadows;

Renderer.SetEnableShadows(Root3DInstance, menuItem.EnableShadows);

EnvironmentInstance.IsHitTestVisible = EnvironmentInstance.Visibility == Visibility.Visible;
if (EnvironmentInstance.Visibility == Visibility.Visible)
Interop.ExecuteJavaScriptVoid($"{EnvironmentInstance.JsElement}.firstChild.setAttribute('interactable', '')");
}
else
{
EnvironmentInstance.Visibility = Visibility.Collapsed;
Interop.ExecuteJavaScriptVoid($"{EnvironmentInstance.JsElement}.firstChild.removeAttribute('interactable')");
}

Interop.ExecuteJavaScriptVoid($"{EnvironmentInstance.JsElement}.firstChild.setAttribute('visible', {menuItem.IsRoomVisible.ToString().ToLower()})");

OrbitControls.SetEnabled(Root3DInstance, menuItem.IsOrbitControlsEnabled);

Expand Down Expand Up @@ -75,14 +83,35 @@ private void OnEnterXR(object sender, EventArgs e)
{
_inXRMode = true;
Menu3DInstance.Visibility = Visibility.Visible;
EnableSoftShadows();
bool shadow = _selectedItem?.EnableShadows ?? true;
if (shadow)
{
EnableSoftShadows();
Renderer.SetEnableShadows(Root3DInstance, true);
}
else
{
MainDirectionalLight.CastShadows = false;
Renderer.SetEnableShadows(Root3DInstance, false);
}
}

private void OnExitXR(object sender, EventArgs e)
{
_inXRMode = false;
Menu3DInstance.Visibility = Visibility.Collapsed;
EnableProgressiveShadows();

bool shadow = _selectedItem?.EnableShadows ?? true;
if (shadow)
{
EnableProgressiveShadows();
Renderer.SetEnableShadows(Root3DInstance, true);
}
else
{
MainDirectionalLight.CastShadows = false;
Renderer.SetEnableShadows(Root3DInstance, false);
}
}

private void OnAllNodesLoaded(object sender, EventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
SelectedItem="{Binding SelectedMenuItem, Mode=TwoWay}">
<xr:ListBox3D.ItemsPanel>
<ItemsPanelTemplate>
<xr:WrapPanel3D Orientation="XY" RevertSecondDirection="True" SizeX="0.20" SizeY="0.2" SizeZ="0.1"/>
<xr:WrapPanel3D Orientation="XY" RevertSecondDirection="True" SizeX="0.20" SizeY="0.2" SizeZ="0.002"/>
</ItemsPanelTemplate>
</xr:ListBox3D.ItemsPanel>

Expand Down Expand Up @@ -88,14 +88,18 @@
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Foreground="{TemplateBinding Foreground}"/>
<xr:RoundedBox Name="BackgroundBox"
xr:Canvas3D.Z="-0.002"
Opacity="0.75"
Radius="0.005"
SizeX="{Binding ActualSizeX, RelativeSource={RelativeSource Mode=TemplatedParent}}"
SizeY="{Binding ActualSizeY, RelativeSource={RelativeSource Mode=TemplatedParent}}"
SizeZ="0.003"
Color="{TemplateBinding Background}"/>
<xr:Canvas3D>
<xr:RoundedBox Name="BackgroundBox"
xr:Canvas3D.Z="-0.002"
xr:Canvas3D.X="-0.035"
xr:Canvas3D.Y="-0.025"
Opacity="0.75"
Radius="0.005"
SizeX="{Binding ActualSizeX, RelativeSource={RelativeSource Mode=TemplatedParent}}"
SizeY="{Binding ActualSizeY, RelativeSource={RelativeSource Mode=TemplatedParent}}"
SizeZ="0.003"
Color="{TemplateBinding Background}"/>
</xr:Canvas3D>
</xr:Grid3D>
</ControlTemplate>
</Setter.Value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal class MenuItem
public string ThumbnailUri { get; set; }
public bool IsRoomVisible { get; set; } = true;
public bool IsOrbitControlsEnabled { get; set; } = true;
public bool EnableShadows { get; set; } = true;

public Type PageToNavigateTo { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public MenuItems()
Title = "Primitives",
PageToNavigateTo = typeof(Primitives),
ThumbnailUri = "/Menu/Thumbnails/Primitives.jpg",
EnableShadows = false,
CameraOptions = new CameraOptions
{
Position = new Point3D(0, 1, 0),
Expand Down Expand Up @@ -101,12 +102,13 @@ public MenuItems()
ThumbnailUri = "/Menu/Thumbnails/Maps3D.png",
CameraOptions = new CameraOptions
{
Position = new Point3D(0, 0, 0),
Position = new Point3D(0, 1, 0),
Rotation = new Point3D(0, 0, 0),
TargetPoint = new Point3D(0, 0, 0),
TargetPoint = new Point3D(0, 0, -5),
},
IsOrbitControlsEnabled = false,
IsRoomVisible = false,
EnableShadows = false,
ViewSourceFilesLocation = new[]
{
new ViewSourceFileInfo() { TabHeader = "Maps3DSample.xaml", FilePathOnGitHub = "github/XRSharp/XRSharpSamplesGallery/blob/main/src/XRSharpSamplesGallery/XRSharpSamplesGallery/Samples/Maps3D/Maps3D.xaml" },
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xr="http://xrsharp.io/xr"
xmlns:local="clr-namespace:XRSharpSamplesGallery.Samples">
xmlns:local="clr-namespace:XRSharpSamplesGallery.Samples"
>

<xr:Canvas3D>
<xr:Maps3D Name="map" ViewportCenter="36.8065, 10.1815" xr:Canvas3D.Z="-5" ServerURL="https://userwareapiproxy.azurewebsites.net/tiles/3dtiles/root.json"/>

<xr:Grid3D Name="infoPanel" xr:Canvas3D.Z="-1" xr:Canvas3D.X="-1" xr:Canvas3D.Y="1">
<xr:RoundedBox Color="Black" Opacity="0.5"/>
<xr:StackPanel3D Orientation="YAxis" Margin="0.075">
<xr:Text3D Text=" - Right Stick to Zoom In/Out"/>
<xr:Text3D Text=" - Right Grab to Rotate the globe"/>
<xr:Text3D Text=" - Right Trigger to Orbit around the globe"/>
<xr:Text3D Text="VR Controls:"/>
</xr:StackPanel3D>
</xr:Grid3D>
<xr:Maps3D CastShadows="False" ReceiveShadows="False" Name="map" ViewportCenter="36.8065, 10.1815" xr:Canvas3D.Z="-2" ServerURL="https://userwareapiproxy.azurewebsites.net/tiles/3dtiles/root.json"/>
</xr:Canvas3D>
</xr:UserControl3D>
Original file line number Diff line number Diff line change
@@ -1,15 +1,69 @@
using System;
// filepath: d:\userware\XRSharpSamplesGallery\src\XRSharpSamplesGallery\XRSharpSamplesGallery\Samples\Maps3D\Maps3D.xaml.cs
using System;
using System.Windows;
using XRSharp;
using XRSharp.Components;
using XRSharp.Controls;
using XRSharp.Controls.Extras;
using XRSharp.Core;

namespace XRSharpSamplesGallery.Samples
{
public partial class Maps3D : UserControl3D
{
private Grid3D _infoPanel;
private Root3D _root;

public Maps3D()
{
InitializeComponent();

// Find the root element to subscribe to XR events
_root = Root3D.Current;

// Get the info panel reference
_infoPanel = this.FindName("infoPanel") as Grid3D;

// Hide info panel by default (not in XR mode initially)
if (_infoPanel != null)
{
_infoPanel.Visibility = Visibility.Collapsed;
}

// Subscribe to XR events
if (_root != null)
{
_root.EnterXR += OnEnterXR;
_root.ExitXR += OnExitXR;
}
}

private void OnEnterXR(object sender, EventArgs e)
{
// Show the info panel when entering XR mode
if (_infoPanel != null)
{
_infoPanel.Visibility = Visibility.Visible;
}
}

private void OnExitXR(object sender, EventArgs e)
{
// Hide the info panel when exiting XR mode
if (_infoPanel != null)
{
_infoPanel.Visibility = Visibility.Collapsed;
}
}

private void OnUnloaded(object sender, EventArgs e)
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OnUnloaded event handler is defined but not wired to the control's Unloaded event; consider subscribing to it to ensure proper cleanup of event handlers.

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@medbensalah could you check if it can be removed, or better to subscribe to Unloaded event

{
// Clean up event handlers when control is unloaded
if (_root != null)
{
_root.EnterXR -= OnEnterXR;
_root.ExitXR -= OnExitXR;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="XRSharp" Version="0.1.7-preview-2025-05-13-104524-18f2ed3e" />
<PackageReference Include="XRSharp" Version="0.1.7-preview-2025-05-26-150613-40142922" />
</ItemGroup>

<ItemGroup>
Expand Down