78 lines
2.6 KiB
C#
78 lines
2.6 KiB
C#
using System;
|
|
using System.Reactive.Disposables;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using Intromat.Graphics;
|
|
using Intromat.Pipelines;
|
|
using Intromat.ViewModels.Previews;
|
|
using ReactiveUI;
|
|
using SharpDX.Direct3D11;
|
|
using Splat;
|
|
|
|
namespace Intromat.Views
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for Preview3DView.xaml
|
|
/// </summary>
|
|
public partial class Preview3DView : IViewFor<DxMeshPreviewViewModel>
|
|
{
|
|
private DisplayMeshPipeline? _pipeline;
|
|
|
|
public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel),
|
|
typeof(DxMeshPreviewViewModel), typeof(Preview3DView), new PropertyMetadata(null));
|
|
|
|
public Preview3DView()
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.WhenActivated(d =>
|
|
{
|
|
_pipeline = Locator.Current.GetService<DisplayMeshPipeline>()!;
|
|
this.WhenAnyObservable(v => v.ViewModel!.MeshValue).Subscribe(textureValue =>
|
|
{
|
|
//var srv = textureValue?.ShaderResourceView;
|
|
//if (srv != null)
|
|
//{
|
|
// _pipeline.ShaderResourceView = srv;
|
|
// _dxView.Render();
|
|
//}
|
|
}).DisposeWith(d);
|
|
_dxView.SetUpdateHandler(UpdateFrameAction);
|
|
});
|
|
}
|
|
|
|
private void UpdateFrameAction(Device device, DeviceContext context)
|
|
{
|
|
var graphicsAnalysis = Locator.Current.GetService<DxHost>()?._graphicsAnalysis;
|
|
graphicsAnalysis?.BeginCapture();
|
|
_pipeline?.Apply();
|
|
graphicsAnalysis?.EndCapture();
|
|
}
|
|
|
|
private void OnDxViewMouseWheel(object sender, MouseWheelEventArgs e)
|
|
{
|
|
var element = (UIElement)sender;
|
|
var position = e.GetPosition(element);
|
|
var transform = (MatrixTransform)element.RenderTransform;
|
|
var matrix = transform.Matrix;
|
|
var scale = e.Delta >= 0 ? 1.1 : (1.0 / 1.1); // choose appropriate scaling factor
|
|
|
|
matrix.ScaleAtPrepend(scale, scale, position.X, position.Y);
|
|
transform.Matrix = matrix;
|
|
}
|
|
|
|
object? IViewFor.ViewModel
|
|
{
|
|
get => ViewModel;
|
|
set => ViewModel = (DxMeshPreviewViewModel?)value;
|
|
}
|
|
|
|
public DxMeshPreviewViewModel? ViewModel
|
|
{
|
|
get => (DxMeshPreviewViewModel?)GetValue(ViewModelProperty);
|
|
set => SetValue(ViewModelProperty, value);
|
|
}
|
|
}
|
|
}
|