Hello everyone.

We have decided to phase out the Mixed Reality Forums over the next few months in favor of other ways to connect with us.

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.

The plan between now and the beginning of May is to clean up old, unanswered questions that are no longer relevant. The forums will remain open and usable.

On May 1st we will be locking the forums to new posts and replies. They will remain available for another three months for the purposes of searching them, and then they will be closed altogether on August 1st.

So, where does that leave our awesome community to ask questions? Well, there are a few places we want to engage with you. 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. And always feel free to hit us up on Twitter @MxdRealityDev.

Distances between Camera and visual vertexes of the Spatial Mesh

Hi guys,

I guys, I need the distance for every vertex of the spatial mesh in field of view, between the vertex and the main camera. Any ideas?

Answers

  • AmerAmerAmerAmer ✭✭✭
    edited January 2017

    if you are using unity, then you should be able to do a Raycast from camera to the spatial mesh. It will have distance as a property. The cursor from the holotoolkit does this already when placing the cursor on the spatial mesh using its normal as a direction.

    Physics.Raycast(Camera.main.transform.position + camera.main.transform.forward, SpatialMesh.transform.position, , <"Whatever layer the mesh sits on">)
    the raycasthit object will have the actual vector and the distance of that vector (thus the distance you need).

    If you are developing in c++, you can do that in the shader and do distance computation once the vertex has the world_matrix applied to it. But you have to pass your camera position and forward vector to the input layout. Otherwise you have to parse out the buffer and do some basic vector math from your camera position to the vertex in world space. But to identify which vertex we're talking about, you'll have to calculate your own Raycast and use the resulting vector to get its length. Its a lot easier done in shader. I'm assuming you're doing like a heat map or setting a vertex color based on distance? Its pretty expensive trying to raycast specific vertex, consider a collider of sorts?

    http://www.redsprocketstudio.com/
    Developer | Check out my new project blog

  • Thanks for your answer. The problem is, as you mention, raycasts are far to expensive even if they would accomplish the task quite good. I also tried spherecast, but since I only have one collider for a big part of the spatial mesh I only get one result.

    The Heatmap is exactly what I want to achieve. Since I have no experience with shaders, how would I do the world matrix application and distance computation?

Sign In or Register to comment.