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.
How do you get the vertex data from the spatial meshes?
I'm trying to be able to do a couple of things.
- know where a point intersects the spatial meshes.
- place a virtual object on the floor.
I'm not using Unity.
I found the example in the Universal Windows Samples that shows the mesh.
How do I get any of the vertex data out of it, in order to, I guess, do triangle/ray intersection on it? (if this is the best way to find a point on the floor).
This is what I'm trying, but my array is just filled with mostly 0s and extremely large exponent numbers (mostly zeros though).
m_PositionFloats = ToArray(m_surfaceMesh->VertexPositions->Data, &m_PositionFloatsLength);
My ToArray function is defined by:
`
float* ToArray(Windows::Storage::Streams::IBuffer^ buffer, int* len)
{
auto reader = ::Windows::Storage::Streams::DataReader::FromBuffer(buffer);
int length = reader->UnconsumedBufferLength; unsigned char* data = new unsigned char[length]; memset(data, 0, length); reader->ReadBytes(Platform::ArrayReference<unsigned char>(&data[0], length)); float* floats = ToFloats(data, length); *len = length / 2; delete[]data; return floats;
}
`
My ToFloats function is defined by:
`
float* ToFloats(unsigned char* data, int length) { int floatLength = length / 2; float* floats = new float[floatLength]; uint16_t * p = reinterpret_cast<uint16_t *>(data); for (int i = 0; i < floatLength /2; i++) { uint16_t temp = p[i]; uint16_t in = temp; uint32_t t1; uint32_t t2; uint32_t t3; t1 = in & 0x7fff; // Non-sign bits t2 = in & 0x8000; // Sign bit t3 = in & 0x7c00; // Exponent t1 <<= 13; // Align mantissa on MSB t2 <<= 16; // Shift sign bit into position t3 >>= 8; t1 += 0x38000000; // Adjust bias t1 = (t3 == 0 ? 0 : t1); // Denormals-as-zero if (t3 > 0) { t3 -= 15; // remove exponent bias for 16bit t3 += 127; // add exponent bias for 32bit t3 <<= 23; t1 |= t3; } t1 |= t2; // Re-insert sign bit float f = *reinterpret_cast<float*>(&t1); floats[i] = f; } return floats;
}
`
Best Answer
-
OptionsPatrick mod
I've done this recently. I tried to do the SHORTN4 conversion myself, but wasn't successful. The XMxxx apis know how to handle this though. I'm sure there's a better way than this, but this is what I've got working:
XMSHORTN4* rawVertexData = (XMSHORTN4*)GetDataFromIBuffer(m_surfaceMesh->VertexPositions->Data); float3 vertexScale = m_surfaceMesh->VertexPositionScale; int InputVertexCount = m_surfaceMesh->VertexPositions->ElementCount; for (int index = 0;index < InputVertexCount;index++) { // read the currentPos as an XMSHORTN4. XMSHORTN4 currentPos = XMSHORTN4(rawVertexData[index]); XMFLOAT4 xmfloat; // XMVECTOR knows how to convert the XMSHORTN4 to actual floating point coordinates. XMVECTOR xmvec = XMLoadShortN4(¤tPos); // STore that into an XMFLOAT4 so we can read the values. XMStoreFloat4(&xmfloat, xmvec); // Which need to be scaled by the vertex scale. XMFLOAT4 scaledVector = XMFLOAT4(xmfloat.x*vertexScale.x, xmfloat.y*vertexScale.y, xmfloat.z*vertexScale.z, xmfloat.w); float4 nextFloat = float4(scaledVector .x, scaledVector .y, scaledVector .z, scaledVector .w); }
===
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?)
5
Answers
I've done this recently. I tried to do the SHORTN4 conversion myself, but wasn't successful. The XMxxx apis know how to handle this though. I'm sure there's a better way than this, but this is what I've got working:
===
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?)
BTW, writing your own physics can be a pretty daunting task. The UWP Marble Maze sample might help. I haven't tried, but you might be able to get the Bullet physics engine to work.
===
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. Huge help.
Any idea how to do this in c#? I"m trying to port the spatial meshes example to c# ....
I'm looking for FBX model import into c++ so that I'm not relying on Unity, and I'm interested to hear from anyone doing the same.