question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Align to spatial mesh?

See original GitHub issue

I want to align gameobjects that use “TapToPlace” to the mesh created by spatial mapping.

I think I’m on the right track by modifying the TapToPlace.cs script. I have added a public gameobject which I drag the cursor object to, and then I have modified the following code:

if (Physics.Raycast(headPosition, gazeDirection, out hitInfo, 30.0f, spatialMappingManager.LayerMask))
                {
                    // Rotate this object to face the user.
                    Quaternion toQuat = Camera.main.transform.localRotation;
                    toQuat.x = 0;
                    toQuat.z = 0;

                    var cursorRotation = cursor.transform.localRotation; // get cursors rotation

                    // Move this object to where the raycast
                    // hit the Spatial Mapping mesh.
                    // Here is where you might consider adding intelligence
                    // to how the object is placed.  For example, consider
                    // placing based on the bottom of the object's
                    // collider so it sits properly on surfaces.
                    if (PlaceParentOnTap)
                    {
                        // Place the parent object as well but keep the focus on the current game object
                        Vector3 currentMovement = hitInfo.point - gameObject.transform.position;
                        ParentGameObjectToPlace.transform.position += currentMovement;
                        ParentGameObjectToPlace.transform.rotation = toQuat;
                    }
                    else
                    {
                        gameObject.transform.position = hitInfo.point;
                        //gameObject.transform.rotation = toQuat; // old code
                        gameObject.transform.rotation = cursorRotation; // new rotation
                    }
                }

However, it just doesn’t seem quite right. Especially, when trying to place an object on a ceiling, it does not face downwards.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
angelaHilliercommented, Apr 27, 2017

You might need to call RecalculateNormals() for the SpatialMapping mesh in order to tell the difference between a floor/ceiling/wall, etc.

In the Holograms 230 Academy version of the HoloToolkit, SpatialMappingObserver.cs will call this after creating a new mesh when you set the ‘RecalculateNormals’ option to ‘true’. This is done in the SurfaceObserver_OnDataReady() function:

if (RecalculateNormals)
{
    MeshFilter filter = surface.GetComponent<MeshFilter>();
    if(filter != null && filter.sharedMesh != null)
    {
          filter.sharedMesh.RecalculateNormals();
    }
}

I don’t believe this option was ever added to the official HoloToolkit, but it might be a good addition for cases when the meshes need to have the correct normals.

0reactions
StephenHodgsoncommented, Oct 28, 2017

Going to close this. It’s probably been archived by google by now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Align to spatial mesh? - microsoft/MixedRealityToolkit-Unity
I want to align gameobjects that use "TapToPlace" to the mesh created by spatial mapping. ... However, it just doesn't seem quite right....
Read more >
Spatial mapping - Mixed Reality
Spatial mapping provides a detailed representation of real-world surfaces in the environment around the HoloLens.
Read more >
Configuring mesh observers for device - MRTK 2
This guide will walk through configuring the out-of-box Spatial Mesh Observer in MRTK which supports the Windows Mixed Reality platform (for ...
Read more >
Align to surface normal - Mixed Reality Developer Forum
My cuestion is: When I am placing one object, this object is face to face with camera and works nicely with spatial surfaces,...
Read more >
Aligning Point Clouds to other Clouds,Meshes or CAD - SA
1. Right-click on the object you want to align (either Point Cloud or Mesh) and select Align N Points to Objects, choosing Cloud,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found