Show 3D molecule model within a given grid in UWP

0

I have a POSCAR file containing atom positions (x,y,z) for a molecule. I am using this app to edit this POSCAR file.

Now I want to display a model of the molecule to select a atom and changing parameters or deleting the selected atom.

Now is my question: what is the best way to display this model? Is there a maybe a library for 3d models in UWP or something similar?

Thanks Agredo

edit:

with help of Xavier Xie - MSFT I Used this example: 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());
    }

Now I get a error in this Line

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

here is the error (it is in German)

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.

Quelle = SharpDX 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

3d
uwp
direct3d
direct2d
3d-modelling
asked on Stack Overflow Mar 13, 2018 by Agredo • edited Mar 14, 2018 by Agredo

1 Answer

0

You could use SwapChainPanel control. It provides a hosting surface, where Microsoft DirectX swap chains provide content that can be rendered into a XAML UI.

For code examples that use SwapChainPanel, see XAML SwapChainPanel DirectX interop sample.

answered on Stack Overflow Mar 14, 2018 by Xie Steven

User contributions licensed under CC BY-SA 3.0