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.
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.
Options
World coordinates from meshes (VertexPositions->Data)
Hello,
I am trying to extract spatial meshes to an array of global coordinates, how can I extract them from mesh->VertexPositions->Data ? I don't need to render them so I don't want to do "CreateDirectXBuffer" stuff like in samples. PS: I am not using Unity.
auto options = ref new SpatialSurfaceMeshOptions(); auto formats = options->SupportedVertexPositionFormats; options->VertexPositionFormat = DirectXPixelFormat::R16G16B16A16IntNormalized; auto mapContainingSurfaceCollection = m_surfaceObserver->GetObservedSurfaces(); for (auto& pair : mapContainingSurfaceCollection) { auto const& surfaceInfo = pair->Value; auto mesh = co_await surfaceInfo->TryComputeLatestMeshAsync(1000, options); auto positions = mesh->VertexPositions->Data; //IBuffer to Vector3[]?.. }
0
Answers
IBuffer is just a WinRT Wrapper around a BYTE *, so cast it to a BYTE *, then iterate through the array of Bytes.
Each byte represents an x,y,z,w Float, if I remember correctly.
Something like this:
Dwight Goins
CAO & Founder| Independent Architect | Trainer and Consultant | Sr. Enterprise Architect
MVP | MCT | MCSD | MCPD | SharePoint TS | MS Virtual TS |Windows 8 App Store Developer | Linux Gentoo Geek | Raspberry Pi Owner | Micro .Net Developer | Kinect For Windows Device Developer
http://dgoins.wordpress.com
@Dwight_Goins_EE_MVP Thank you so much for help!!
what is verticesCount in your code? is it mesh->VertexPositions->ElementCount? if so why it's divided by m_normalStride? Thanks!
PS: do these options work with your code?:
Vertices Count is : auto verticesCount = m_surfaceMesh->VertexPositions->ElementCount;
I was doing something else - in your case don't divide by the stride. I gave a general idea on how to get the IBuffer data for the Positions. Again it's a Byte *. So that means you have to read the Byte * and for each byte convert it to the data you need. If the format is 2 byte, then that means every 2 Bytes you need to read it as 1 double.
Your format is a 2Byte value for each element. 16bits for Red, 16 for Green, 16 for Blue and 16 for alpha. Each value in the 2Byte will be a float from 0.00 to 1.00 (Normalized from 0 to 255) with 0.00 = 0 and 1.00 = 255.
HTH
Dwight Goins
CAO & Founder| Independent Architect | Trainer and Consultant | Sr. Enterprise Architect
MVP | MCT | MCSD | MCPD | SharePoint TS | MS Virtual TS |Windows 8 App Store Developer | Linux Gentoo Geek | Raspberry Pi Owner | Micro .Net Developer | Kinect For Windows Device Developer
http://dgoins.wordpress.com
I think this is what you need. I extracted it from a test project I use, so there might be some noise:;
===
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?)
===
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?)
I also found that you might have to multiply each vertex by
m_surfaceMesh->VertexPositionScale
and then transform each vertex by
where currentCoordinateSystem was obtained as a Stationary SpatialCoordinateSystem.
Finally, I was using sample code where DirectX stored the vertices in the DXGI_FORMAT_R16G16B16A16_SNORM format (not sure if you can change this), so I had to extract the actual vertices as follows:
I also found that you might have to multiply each vertex by
m_surfaceMesh->VertexPositionScale
and then transform each vertex by
where currentCoordinateSystem was obtained as a Stationary SpatialCoordinateSystem.
Finally, I was using sample code where DirectX stored the vertices in the DXGI_FORMAT_R16G16B16A16_SNORM format (not sure if you can change this), so I had to extract the actual vertices as follows:
I also found that you might have to multiply each vertex by
m_surfaceMesh->VertexPositionScale
and then transform each vertex by
where currentCoordinateSystem was obtained as a Stationary SpatialCoordinateSystem.
Finally, I was using sample code where DirectX stored the vertices in the DXGI_FORMAT_R16G16B16A16_SNORM format (not sure if you can change this), so I had to extract the actual vertices as follows:
Based on the information found in this post, I wrote some code to access the surface mesh vertex information. Problem is that I sometimes get an error "Access violation reading location 0x00E01000" (location varies) when attempting to read q[4*i] (see below). Anyone has an explanation for that error to occur?
int vertexCount = m_surfaceMesh->VertexPositions->ElementCount; short *q = (short *)m_surfaceMesh->VertexPositions->Data; for (int i = 0; i < vertexCount; i++) // goes through all vertices of the mesh { short xc = q[4 * i]; short yc = q[4 * i+1]; short zc = q[4 * i+2]; }
Is it expected to work that IBuffer can be cast to short(star)? That would be very convenient, but I don't think that you can know the memory layout of the Data object. I hope I'm wrong, because I would so much rather treat IBuffers like void(star)? 's.
I posted in this thread how I get the actual data pointer from the buffer. Do you still have the same problem if you follow that approach?
===
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?)
thank you Patrick. That was the problem. I had not noticed the IBuffer cast. It did work about 90% of the time though, which is not good enough by a long shot.