在 UWP 中的给定网格内显示 3D 分子模型



我有一个POSCAR文件,其中包含分子的原子位置(x,y,z)。我正在使用这个应用程序来编辑这个POSCAR文件。

现在我想显示一个分子模型来选择一个原子并更改参数或删除选定的原子。

现在我的问题是:显示此模型的最佳方式是什么?UWP 或类似的东西中是否有 3D 模型库?

谢谢 阿格雷多

编辑:

在谢泽维尔的帮助下 - MSFT 我使用了这个例子: english.r2d2rigo.es/2014/09/06/initializing-direct3d-in-windowswindows-phone-8-1-cxaml-universal-apps-with-sharpdx/

using (SharpDX.Direct3D11.Device defaultDevice = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.Debug))
{
this.Device = defaultDevice.QueryInterface<SharpDX.Direct3D11.Device2> ();
}
this.DeviceContext = this.Device.ImmediateContext2;
PixelScale = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi;
SharpDX.DXGI.SwapChainDescription1 swapChainDescription = new SharpDX.DXGI.SwapChainDescription1()
{
//No transparency 
AlphaMode = SharpDX.DXGI.AlphaMode.Ignore,
//Double buffer
BufferCount = 2,
//BGRA 32bit Pixelformat
Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
//setting dimension
Height = (int)(this.MySwapChainPanel.RenderSize.Height * PixelScale),
Width = (int)(this.MySwapChainPanel.RenderSize.Width * PixelScale),
//default Multisampling
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
//in case of streching the swapchain
Scaling = SharpDX.DXGI.Scaling.Stretch,
//No SteroeDisplay
Stereo = false,
//Sequential displaying for double buffering
SwapEffect = SharpDX.DXGI.SwapEffect.FlipSequential,
// This swapchain is going to be used as the back buffer
Usage = SharpDX.DXGI.Usage.BackBuffer | SharpDX.DXGI.Usage.RenderTargetOutput
};
using (SharpDX.DXGI.Device3 dxgiDevice3 = this.Device.QueryInterface<SharpDX.DXGI.Device3>())
{
// Get the DXGI factory automatically created when initializing the Direct3D device.
using (SharpDX.DXGI.Factory3 dxgiFactory3 = dxgiDevice3.Adapter.GetParent<SharpDX.DXGI.Factory3>())
{
// Create the swap chain and get the highest version available.
SharpDX.DXGI.SwapChain1 swapChain1 = new SharpDX.DXGI.SwapChain1(dxgiFactory3, this.Device, ref swapChainDescription);
this.swapChain = swapChain1.QueryInterface<SharpDX.DXGI.SwapChain2>();
}
}

using (SharpDX.DXGI.ISwapChainPanelNative nativeSwapChainPanel = ComObject.As<SharpDX.DXGI.ISwapChainPanelNative>(this.MySwapChainPanel))
{
//Set its Swap chain
nativeSwapChainPanel.SwapChain = this.swapChain;
}

this.BackBufferTexture = SharpDX.Direct3D11.Texture2D.FromSwapChain<SharpDX.Direct3D11.Texture2D>(this.swapChain, 0);
this.BackBufferView = new SharpDX.Direct3D11.RenderTargetView(this.Device, this.BackBufferTexture);
CompositionTarget.Rendering += CompositionTarget_Rendering;
}
private void CompositionTarget_Rendering(object sender, object e)
{
//Set the active back buffer and clear it. 
this.DeviceContext.OutputMerger.SetRenderTargets(BackBufferView);
this.DeviceContext.ClearRenderTargetView(this.BackBufferView, Color.LimeGreen);
//present the buffer in swap chain
this.swapChain.Present(1, SharpDX.DXGI.PresentFlags.None, new SharpDX.DXGI.PresentParameters());
}

现在我在这一行中得到一个错误

SharpDX.DXGI.SwapChain1 swapChain1 = new SharpDX.DXGI.SwapChain1(dxgiFactory3, this.Device, ref swapChainDescription);

这是错误(是德语)

SharpDX.SharpDXException HResult=0x887A0001 Nachricht = HRESULT: [0x887A0001], Module: [SharpDX.DXGI], ApiCode: [DXGI_ERROR_INVALID_CALL/InvalidCall], Message: Von der Anwendung wurde ein ungültiger Aufruf ausgeführt.Entweder waren die Parameter des Aufrufs oder der Status einiger Objekte falsch. Aktivieren Sie die D3D-Debugschicht, um Details mithilfe der Debugmeldungen anzuzeigen.

奎尔 = 夏普DX Stapelüberwachung: bei SharpDX.Result.CheckError() bei SharpDX.DXGI.Factory2.CreateSwapChainForComposition(ComObject deviceRef, SwapChainDescription1& descRef, Output restrictToOutputRef, SwapChain1 swapChainOut) bei SharpDX.DXGI.SwapChain1..ctor(Factory2 factory, ComObject device, SwapChainDescription1&description, Output restrictToOutput) bei SharpDXTest.MainPage..ctor() in C:\Users\chris\Documents\Projects\SharpDXTest\SharpDXTest\MainPage.xaml.cs: Zeile82 bei SharpDXTest.SharpDXTest_XamlTypeInfo.XamlTypeInfoProvider.Activate_0_MainPage() in C:\Users\chris\Documents\Projects\SharpDXTest\SharpDXTest\obj\x86\Debug\XamlTypeInfo.g.cs: Zeile246 bei SharpDXTest.SharpDXTest_XamlTypeInfo.XamlUserType.ActivateInstance() in C:\Users\chris\Documents\Projects\SharpDXTest\SharpDXTest\obj\x86\Debug\XamlTypeInfo.g.cs: Zeile507

您可以使用SwapChainPanel控件。它提供了一个宿主图面,其中Microsoft DirectX 交换链提供可呈现为 XAML UI 的内容。

有关使用 SwapChainPanel的代码示例,请参阅 XAML SwapChainPanel DirectX 互操作示例。

最新更新