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.

Reposition Hologram with Voice Command

Hello guys and gals,

I have an application where the user manipulates an object (moves and rotates it) with an XBOX controller. The object interacts with the environment (e.g. when a collision with the spatial mesh occurs the object changes its color and stops moving).
Further to that I want to achieve the following: The user should to able to "reposition" a hologram using a voice command (e.g. "Reset"). By "reposition" I mean, placing the hologram 1m in front of him and 30cm above the ground (above the spatial mesh of the ground). These values are fixed/predefined.

TapToPlace could somehow work if the following requirement is met: I do not want to airtap the object and move it with gaze and airtap it again to place. I want to "obey" the spatial mesh and upon saying "Reset" the object moves automatically to the specified position (30cm above ground and 1m from user)

Any ideas?

Many thanks,
Michael

Comments

  • Holograms 240 Chapter 5, shows how to find the "ground" between multiple players. It's in HologramPlacement.cs in the ProposeTransformPosition method. Maybe you could do something similar? Just start from the users position (the camera position) and go out 1 meter on the Z axis. Then, raycast down to find the "ground" position. From there, move back up on the Y axis 30 cm and you should be set.

    Our Holographic world is here

    RoadToHolo.com      WikiHolo.net      @jbienz
    I work in Developer Experiences at Microsoft. My posts are based on my own experience and don't represent Microsoft or HoloLens.

  • @jbienzms
    thanks for the reply. Based on the Tutorial, I came up with the following script:

    `public GameObject go;

    public Vector3 Reset()
    {
    Vector3 retval;
    RaycastHit hitInfo;
    
    if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hitInfo, 10, SpatialMappingManager.Instance.LayerMask))
        {
            retval = hitInfo.point;
        }
    else
        {
            retval = Camera.main.transform.position + Camera.main.transform.forward * 2;
        }
    return retval;
    
    //Position reset
    go.transform.position = retval;
    
    //Rotation reset
    Quaternion rot = transform.localRotation;
    rot.eulerAngles = new Vector3 (0.0f, 0.0f, 0.0f);
    go.transform.localRotation = rot;
    }`
    

    In parallel I have implemented the Voice command "Reset" with KeywordManager from HoloToolkit, where I call Reset().

    However nothing happens...my GO wont move.
    Any ideas on what I may be doing wrong?

  • How are you connecting the KeywordManager to a specific object instance? Are you sure this Reset method is getting called? Have you set a breakpoint in Visual Studio and made sure the code is getting triggered?

    Also, where does the GameObject go get set? I see it's a public field. Is this script in the scene and have you assigned this field through the inspector?

    Make sure the code is running and make sure go is not null when Reset is called. If an exception is thrown in the code, the parent GameObject that contains this behavior will get disabled.

    Our Holographic world is here

    RoadToHolo.com      WikiHolo.net      @jbienz
    I work in Developer Experiences at Microsoft. My posts are based on my own experience and don't represent Microsoft or HoloLens.

  • Yes KeywordManager calls the method. I am calling also another method in the same script with KeywordManager and that works just fine. The GO is also assigned in the inspector. Finally I see the code being called with a breakpoint and it moreover goes past the breakpoint.
    This is why I am so buffled...
    What else can go wrong? The script does what it is supposed to do correct?
    Thanks in advance.

  • @jbienzms
    Thanks! I have succeeded in repositioning the GO using the VoiceCommand. I have a follow-up question though:
    Apart from the position, I want to also change the rotation of the GO so that it faces me (the camera). The code above does not do that. I have also tried the following without luck:
    rot.eulerAngles = new Vector3 (Camera.main.transform.localRotation.x, Camera.main.transform.localRotation.y, Camera.main.transform.localRotation.z);
    Any suggestions on this problem?

  • Ah, math and transforms. One of the dark arts I doubt I will ever fully grasp. :)

    For this I always recommend looking at reference implementations that do what you want. For example, see Billboard or TapToPlace.

    Our Holographic world is here

    RoadToHolo.com      WikiHolo.net      @jbienz
    I work in Developer Experiences at Microsoft. My posts are based on my own experience and don't represent Microsoft or HoloLens.

  • I have been using Billboard since December but it never crossed my mind to look inside...I borrowed a part of the script and now it works. Thanks for the help!

  • Awesome! Glad it helped. :)

    Our Holographic world is here

    RoadToHolo.com      WikiHolo.net      @jbienz
    I work in Developer Experiences at Microsoft. My posts are based on my own experience and don't represent Microsoft or HoloLens.

  • For those having the same question, below the code:

    `using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using HoloToolkit.Unity;

    public class ResetGO : MonoBehaviour {

    public GameObject model;
    Vector3 retval;
    Vector3 reposition;
    RaycastHit hitInfo;
    
    public enum PivotAxis
    {
        // Rotate about all axes or about an individual axis
        Free, Y
    }
    public void Reset()
    {
    if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hitInfo, 4, SpatialMappingManager.Instance.LayerMask))
        {
            retval = hitInfo.point;
            reposition = new Vector3 (retval.x, retval.y + 0.6f, retval.z);
        }
    else
        {
            retval = Camera.main.transform.position + Camera.main.transform.forward * 2;
            reposition = new Vector3 (retval.x, retval.y + 0.6f, retval.z);
        }
        //Position reset
        Schablone.transform.position = reposition;
        PivotAxis PivotAxis = PivotAxis.Free;
        // Get a Vector that points from the target to the main camera
        Vector3 directionToTarget = Camera.main.transform.position - transform.position;
        // Adjust for the pivot axis
        switch (PivotAxis)
        {
        case PivotAxis.Y:
            directionToTarget.y = 0.0f;
            break;
    
        case PivotAxis.Free:
        default:
            // No changes needed
            break;
        }
        // If we are right next to the camera the rotation is undefined
        if (directionToTarget.sqrMagnitude < 0.001f)
        {
            return;
        }
        // Calculate and apply the rotation required to reorient the object
        transform.rotation = Quaternion.LookRotation(-directionToTarget);
    }
    

    }`

  • I would like to have the following implementation in my application:

    When the user is moving, the hologram does NOT continuously change orientation to face the user. However, as soon at the user stops moving, and fixes position, the hologram should now orient to user's direction, facing the user. I went through bill boarding. I would like to confirm if bill boarding continuously reorients holograms to face the user. or does so only when user becomes stationary at a position?

    Thanks in advance!
    John

Sign In or Register to comment.