Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

Sample location for Spatial Mapping in Direct X?

Does anyone know where to find the sample mentioned in the article about Spatial Mapping in Direct X? I've searched high and low but it seems it does not exist. It constantly refers to files that don't exist in any MS owned GitHub repository or SDK.

This is the article I'm referring to:
https://developer.microsoft.com/en-us/windows/holographic/spatial_mapping_in_directx

Any help will be greatly appreciated!

Thank you,
Bret

Best Answers

Answers

  • BryanBryan ✭✭✭

    Sounds like it was supposed to be included as a sample in the SDK. I couldn't find it either though. Perhaps they forgot to ship it?

  • Yeah, that's what I figured as well. It mentions it should be part of the Windows SDK but in searching their repository for that, I couldn't find it. Hoping somebody from MS sees this and can fix it or point me in the right direction. Might just be scheduled for the next SDK update since the HoloLens has barely started shipping.

  • @InterestingHandle @Bryan Sample here is a mis-nomer. The docs are referring to the D3D template that you can install along with the emulator.

  • @CoreyGoff Thank you for your response. Unfortunately that article explicitly states that it is intended to accompany a sample that should be included in the SDK as shown from the quote below:

    This topic describes how to implement spatial mapping in your DirectX app. This includes a detailed explanation of the Spatial Mapping sample application that is included with the Universal Windows Platform SDK.

    Also, in numerous locations throughout the article, it refers back to that sample:

    NOTE: For the CreateDirectXBuffer helper function used in the previous snippet, see the Surface Mapping code sample: SurfaceMesh.cpp, GetDataFromIBuffer.h. Now the device resource creation is complete, and the mesh is considered to be loaded and ready for update and render.

    I assume they just haven't published that sample yet.

    Thanks,
    Bret

  • BryanBryan ✭✭✭

    @CoreyGoff to add to what @InterestingHandle said, the docs reference a number of files that aren't included in that D3D template.

  • In the meantime until the SDK is updated, there is a useful article Creating a holographic DirectX project

  • PatrickPatrick mod
    edited May 2016

    ``I just went through the journey of getting spatial mapping to work in the C++ template myself.

    Here's some of the missing code.

    1. Creating a buffer, I don't have the helper function referenced from the article, but this snippit is what you need to create the vertex buffer, the index buffer follows the same pattern:

       D3D11_SUBRESOURCE_DATA vertexBufferData = { 0 };
          vertexBufferData.pSysMem = GetDataFromIBuffer(m_surfaceMesh->VertexPositions->Data);
          vertexBufferData.SysMemPitch = 0;
          vertexBufferData.SysMemSlicePitch = 0;
          const CD3D11_BUFFER_DESC vertexBufferDesc(m_surfaceMesh->VertexPositions->Data->Length, D3D11_BIND_VERTEX_BUFFER);
          DX::ThrowIfFailed(
              m_deviceResources->GetD3DDevice()->CreateBuffer(
                  &vertexBufferDesc,
                  &vertexBufferData,
                  &m_vertexBuffer
              )
          );
      

    And here's GetDataFromiBuffer (I put this in pch.h):

    template <typename t = byte>
    t* GetDataFromIBuffer(Windows::Storage::Streams::IBuffer^ container)
    {
        if (container == nullptr)
        {
            return nullptr;
        }
    
        unsigned int bufferLength = container->Length;
    
        if (!(bufferLength > 0))
        {
            return nullptr;
        }
    
        HRESULT hr = S_OK;
    
        ComPtr<IUnknown> pUnknown = reinterpret_cast<IUnknown*>(container);
        ComPtr<IBufferByteAccess> spByteAccess;
        hr = pUnknown.As(&spByteAccess);
        if (FAILED(hr))
        {
            return nullptr;
        }
    
        byte* pRawData = nullptr;
        hr = spByteAccess->Buffer(&pRawData);
        if (FAILED(hr))
        {
            return nullptr;
        }
    
        return reinterpret_cast<t*>(pRawData);
    }
    

    and finally the default format of the positions is DXGI_FORMAT_R16G16B16A16_SNORM, so you'll need to make your InputLayout and VertexShader match this.

    the input layout

        static const D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
                {
                    { "POSITION", 0, DXGI_FORMAT_R16G16B16A16_SNORM , 0,  0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
                };
    
            DX::ThrowIfFailed(
                m_deviceResources->GetD3DDevice()->CreateInputLayout(
                    vertexDesc,
                    ARRAYSIZE(vertexDesc),
                    &fileData[0],
                    fileData.size(),
                    &m_inputLayout
                )
            );
    

    and in my shader:

    // Per-vertex data used as input to the vertex shader.
    struct VertexShaderInput
    {
        min16float4 pos     : POSITION;
        uint        instId  : SV_InstanceID;
    };
    

    I hard coded the output of the vertex shader to white, and I set my rasterizer state to draw wire frame.

    ===
    This post provided as-is with no warranties and confers no rights. Using information provided is done at own risk.

    (Daddy, what does 'now formatting drive C:' mean?)

  • @Patrick said:
    ``I just went through the journey of getting spatial mapping to work in the C++ template myself.

    Here's some of the missing code.

    1. Creating a buffer, I don't have the helper function referenced from the article, but this snippit is what you need to create the vertex buffer, the index buffer follows the same pattern:

       D3D11_SUBRESOURCE_DATA vertexBufferData = { 0 };
        vertexBufferData.pSysMem = GetDataFromIBuffer(m_surfaceMesh->VertexPositions->Data);
        vertexBufferData.SysMemPitch = 0;
        vertexBufferData.SysMemSlicePitch = 0;
        const CD3D11_BUFFER_DESC vertexBufferDesc(m_surfaceMesh->VertexPositions->Data->Length, D3D11_BIND_VERTEX_BUFFER);
        DX::ThrowIfFailed(
            m_deviceResources->GetD3DDevice()->CreateBuffer(
                &vertexBufferDesc,
                &vertexBufferData,
                &m_vertexBuffer
            )
        );
      

      And here's GetDataFromiBuffer (I put this in pch.h):

      template
      t* GetDataFromIBuffer(Windows::Storage::Streams::IBuffer^ container)
      {
      if (container == nullptr)
      {
      return nullptr;
      }

      unsigned int bufferLength = container->Length;

      if (!(bufferLength > 0))
      {
      return nullptr;
      }

      HRESULT hr = S_OK;

      ComPtr pUnknown = reinterpret_cast<IUnknown*>(container);
      ComPtr spByteAccess;
      hr = pUnknown.As(&spByteAccess);
      if (FAILED(hr))
      {
      return nullptr;
      }

      byte* pRawData = nullptr;
      hr = spByteAccess->Buffer(&pRawData);
      if (FAILED(hr))
      {
      return nullptr;
      }

      return reinterpret_cast<t*>(pRawData);
      }

    and finally the default format of the positions is DXGI_FORMAT_R16G16B16A16_SNORM, so you'll need to make your InputLayout and VertexShader match this.

    the input layout

        static const D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
              {
                  { "POSITION", 0, DXGI_FORMAT_R16G16B16A16_SNORM , 0,  0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
              };
        
          DX::ThrowIfFailed(
              m_deviceResources->GetD3DDevice()->CreateInputLayout(
                  vertexDesc,
                  ARRAYSIZE(vertexDesc),
                  &fileData[0],
                  fileData.size(),
                  &m_inputLayout
              )
          );
    

    and in my shader:

    // Per-vertex data used as input to the vertex shader.
    struct VertexShaderInput
    {
        min16float4 pos     : POSITION;
        uint        instId  : SV_InstanceID;
    };
    

    I hard coded the output of the vertex shader to white, and I set my rasterizer state to draw wire frame.

    Hi Can you tell me where is the processing of the Mesh, why there are many source inside the ground layer mesh? Thank you.

Sign In or Register to comment.