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.
Options

Tap To Place Bug?

Hi everyone. Im running into issues with TapToPlace that I cant seem to figure out.

I attach TapToPlace from the HoloToolkit on my object. When I launch in the emulator everything works as expected. When I launch to the device after placing and moving a couple of times all code after SpatialMappingManager.Instance.DrawVisualMeshes = true; no longer runs. Here is some code I was testing with. Im changing the color of the cube I am using to move things around to see what is happening. The first few times the cube goes back and forth between blue and red as expected but after about the third time the cube goes black and never gets to blue. The Spatial Mapping Manager draws meshes as expected. Am I missing something?

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEngine;

namespace HoloToolkit.Unity
{
///

/// The TapToPlace class is a basic way to enable users to move objects /// and place them on real world surfaces. /// Put this script on the object you want to be able to move. /// Users will be able to tap objects, gaze elsewhere, and perform the /// tap gesture again to place. /// This script is used in conjunction with GazeManager, GestureManager, /// and SpatialMappingManager. ///
/// 


public partial class TapToPlace : MonoBehaviour
{
    bool placing = false;
    public GameObject myItem;
    public GameObject myAudio;


    // Called by GazeGestureManager when the user performs a tap gesture.
    void OnSelect()
    {
        if (SpatialMappingManager.Instance != null)
        {
            // On each tap gesture, toggle whether the user is in placing mode.
            placing = !placing;

            // If the user is in placing mode, display the spatial mapping mesh.
            if (placing)
            {
                gameObject.GetComponent<Renderer>().material.color = Color.black;
                SpatialMappingManager.Instance.DrawVisualMeshes = true;
                gameObject.GetComponent<Renderer>().material.color = Color.blue;


            }
            // If the user is not in placing mode, hide the spatial mapping mesh.
            else
            {
                SpatialMappingManager.Instance.DrawVisualMeshes = false;
                gameObject.GetComponent<Renderer>().material.color = Color.red;

            }
        }
        else
        {
            Debug.Log("TapToPlace requires spatial mapping.  Try adding SpatialMapping prefab to project.");
        }
    }

    // Update is called once per frame.
    void Update()
    {

            // If the user is in placing mode,
            // update the placement to match the user's gaze.
            if (placing)
        {
            // Do a raycast into the world that will only hit the Spatial Mapping mesh.
            var headPosition = Camera.main.transform.position;
            var gazeDirection = Camera.main.transform.forward;

            RaycastHit hitInfo;
            if (Physics.Raycast(headPosition, gazeDirection, out hitInfo,
                30.0f, SpatialMappingManager.Instance.LayerMask))
            {
                // 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.
                this.transform.position = hitInfo.point;

                // Rotate this object to face the user.
                Quaternion toQuat = Camera.main.transform.localRotation;
                toQuat.x = 0;
                toQuat.z = 0;
                this.transform.rotation = toQuat;
            }
        }
    }
}

}

Best Answer

Answers

  • Options

    That did the trick! Thanks so much!

  • Options

    Thanks for reporting the issue. :)

    ===
    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?)

Sign In or Register to comment.