Created
April 5, 2023 08:03
-
-
Save onslauth/ec064f898d348077d9777049eb9c9a68 to your computer and use it in GitHub Desktop.
C# AppSDK HelixToolkit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Copyright (c) Microsoft Corporation. All rights reserved. --> | |
<!-- Licensed under the MIT License. See LICENSE in the project root for license information. --> | |
<Window | |
x:Class="TestHelix.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:local="using:TestHelix" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:hx="using:HelixToolkit.WinUI" | |
mc:Ignorable="d"> | |
<Grid> | |
<Grid.ColumnDefinitions> | |
<ColumnDefinition Width="Auto" /> | |
<ColumnDefinition Width="*" /> | |
</Grid.ColumnDefinitions> | |
<StackPanel Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center"> | |
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button> | |
</StackPanel> | |
<Grid Grid.Column="1"> | |
<hx:Viewport3DX x:Name="MainSwapChainPanel" | |
Background="Blue" | |
FXAALevel="None" | |
EffectsManager="{x:Bind EffectsManager }" | |
ModelUpDirection="{x:Bind UpDirection}" | |
ShowCoordinateSystem="True" | |
BackgroundColor="White" | |
ShowFrameDetails="True" | |
ShowCameraInfo="True" | |
ShowFrameRate="True" | |
> | |
<hx:AmbientLight3D Color="White" /> | |
<hx:DirectionalLight3D Direction="{ Binding ElementName=MainSwapChainPanel, Path=Camera.LookDirection}" Color="White" /> | |
<hx:LineGeometryModel3D x:Name="grid" | |
Geometry="{ x:Bind Grid}" | |
Color="{x:Bind GridColor}" | |
> | |
</hx:LineGeometryModel3D> | |
</hx:Viewport3DX> | |
</Grid> | |
</Grid> | |
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using HelixToolkit.SharpDX.Core; | |
using HelixToolkit.WinUI; | |
using Microsoft.UI; | |
using Microsoft.UI.Xaml; | |
using Microsoft.UI.Xaml.Controls; | |
using Microsoft.UI.Xaml.Controls.Primitives; | |
using Microsoft.UI.Xaml.Data; | |
using Microsoft.UI.Xaml.Input; | |
using Microsoft.UI.Xaml.Media; | |
using Microsoft.UI.Xaml.Media.Media3D; | |
using Microsoft.UI.Xaml.Navigation; | |
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel.DataAnnotations; | |
using System.IO; | |
using System.Linq; | |
using System.Runtime.InteropServices.WindowsRuntime; | |
using Windows.Foundation; | |
using Windows.Foundation.Collections; | |
using Windows.UI; | |
// To learn more about WinUI, the WinUI project structure, | |
// and more about our project templates, see: http://aka.ms/winui-project-info. | |
namespace TestHelix | |
{ | |
/// <summary> | |
/// An empty window that can be used on its own or navigated to within a Frame. | |
/// </summary> | |
public sealed partial class MainWindow : Window | |
{ | |
public Camera Camera = new OrthographicCamera( ) { | |
NearPlaneDistance = 1e-2, | |
FarPlaneDistance = 1e4, | |
Position = new SharpDX.Vector3( 0, -5, 0 ), | |
}; | |
public EffectsManager EffectsManager; | |
public SharpDX.Vector3 UpDirection = new SharpDX.Vector3( 0, 0, 1 ); | |
public LineGeometry3D Grid; | |
public Windows.UI.Color GridColor; | |
public MainWindow( ) | |
{ | |
this.InitializeComponent( ); | |
this.EffectsManager = new DefaultEffectsManager( ); | |
this.Grid = LineBuilder.GenerateGrid( new SharpDX.Vector3( 0, 0, 1 ), -5, 5, -5, 5 ); | |
this.GridColor = Colors.Red; | |
var blue = PhongMaterials.Blue; | |
blue.EnableFlatShading = true; | |
var p1 = new SharpDX.Vector3( 0, 0, 0 ); | |
var p2 = new SharpDX.Vector3( 5, 0, 0 ); | |
var s1 = new MeshBuilder( ); | |
s1.AddCylinder( p1, p2, 0.25, 120 ); | |
var mesh_geometry = s1.ToMeshGeometry3D( ); | |
MeshGeometryModel3D mesh = new MeshGeometryModel3D( ) | |
{ | |
Geometry = mesh_geometry, | |
Material = blue, | |
}; | |
this.MainSwapChainPanel.Items.Add( mesh ); | |
this.MainSwapChainPanel.LookAt( new SharpDX.Vector3( 0, 0, 0 ) ); | |
} | |
private void myButton_Click( object sender, RoutedEventArgs e ) | |
{ | |
myButton.Content = "Clicked"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment