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

Building Visual Studio Unity C# Projects problem Mixed Reality 250

Hey, I've been following the Mixed Reality 250 tutorial (https://developer.microsoft.com/en-us/windows/mixed-reality/mixed_reality_250) and I finished chapter 3. I wanted to check how it plays out in the Holo Lens Emulator so I tried to build it (Universal Windows Platform, target device Holo Lens, build type D3D, SDK 10.0.15063.0, checked Unity C# projects) but received only a handful of errors.

They're all associated with the ControllerVisualizer script which is attached to Controllers object under MixedRealityCameraParent->MixedRealityCamera. There are 2 blocks of code which, if commented out, allow me to build the project but I'm pretty sure that's not the best way to solve things and that's why I ask you for an explanation. Are they necessary? Am I doing something wrong? Is the Microsoft tutorial simply unfinished?
I've tested it on the newest beta of Unity 2017.3.0b3 and on the newest release candidate 2017.2.0f2.

if !UNITY_EDITOR

        if (GLTFMaterial == null)
        {
            if (LeftControllerOverride == null && RightControllerOverride == null)
            {
                Debug.Log("If using glTF, please specify a material on " + name + ". Otherwise, please specify controller overrides.");
            }
            else if (LeftControllerOverride == null || RightControllerOverride == null)
            {
                Debug.Log("Only one override is specified, and no material is specified for the glTF model. Please set the material or the " + ((LeftControllerOverride == null) ? "left" : "right") + " controller override on " + name + ".");
            }
        }

        // Since the SpatialInteractionManager exists in the current CoreWindow, this call needs to run on the UI thread.
        UnityEngine.WSA.Application.InvokeOnUIThread(() =>
        {
            spatialInteractionManager = SpatialInteractionManager.GetForCurrentView();
            if (spatialInteractionManager != null)
            {
                spatialInteractionManager.SourceDetected += SpatialInteractionManager_SourceDetected;
                spatialInteractionManager.SourceLost += SpatialInteractionManager_SourceLost;
            }
        }, true);

and

if !UNITY_EDITOR && UNITY_WSA

    /// 
/// When a controller is detected, the model is spawned and the controller object /// is added to the tracking dictionary. ///
    /// <param name="sender">The SpatialInteractionManager which sent this event.</param>
    /// <param name="args">The source event data to be used to set up our controller model.</param>
    private void SpatialInteractionManager_SourceDetected(SpatialInteractionManager sender, SpatialInteractionSourceEventArgs args)
    {
        SpatialInteractionSource source = args.State.Source;
        // We only want to attempt loading a model if this source is actually a controller.
        if (source.Kind == SpatialInteractionSourceKind.Controller && controllerDictionary != null && !controllerDictionary.ContainsKey(source.Id))
        {
            SpatialInteractionController controller = source.Controller;
            if (controller != null)
            {
                // Since this is a Unity call and will create a GameObject, this must run on Unity's app thread.
                UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                {
                    // LoadControllerModel is a coroutine in order to handle/wait for async calls.
                    StartCoroutine(LoadControllerModel(controller, source));
                }, false);
            }
        }
    }

    private void SpatialInteractionManager_SourceLost(SpatialInteractionManager sender, SpatialInteractionSourceEventArgs args)
    {
        SpatialInteractionSource source = args.State.Source;
        if (source.Kind == SpatialInteractionSourceKind.Controller)
        {
            ControllerInfo controller;
            if (controllerDictionary != null && controllerDictionary.TryGetValue(source.Id, out controller))
            {
                controllerDictionary.Remove(source.Id);

                UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                {
                    Destroy(controller);
                }, false);
            }
        }
    }

    private IEnumerator LoadControllerModel(SpatialInteractionController controller, SpatialInteractionSource source)
    {
        GameObject controllerModelGameObject;
        if (source.Handedness == SpatialInteractionSourceHandedness.Left && LeftControllerOverride != null)
        {
            controllerModelGameObject = Instantiate(LeftControllerOverride);
        }
        else if (source.Handedness == SpatialInteractionSourceHandedness.Right && RightControllerOverride != null)
        {
            controllerModelGameObject = Instantiate(RightControllerOverride);
        }
        else
        {
            if (GLTFMaterial == null)
            {
                Debug.Log("If using glTF, please specify a material on " + name + ".");
                yield break;
            }

            // This API returns the appropriate glTF file according to the motion controller you're currently using, if supported.
            IAsyncOperation<IRandomAccessStreamWithContentType> modelTask = controller.TryGetRenderableModelAsync();

            if (modelTask == null)
            {
                Debug.Log("Model task is null.");
                yield break;
            }

            while (modelTask.Status == AsyncStatus.Started)
            {
                yield return null;
            }

            IRandomAccessStreamWithContentType modelStream = modelTask.GetResults();

            if (modelStream == null)
            {
                Debug.Log("Model stream is null.");
                yield break;
            }

            if (modelStream.Size == 0)
            {
                Debug.Log("Model stream is empty.");
                yield break;
            }

            byte[] fileBytes = new byte[modelStream.Size];

            using (DataReader reader = new DataReader(modelStream))
            {
                DataReaderLoadOperation loadModelOp = reader.LoadAsync((uint)modelStream.Size);

                while (loadModelOp.Status == AsyncStatus.Started)
                {
                    yield return null;
                }

                reader.ReadBytes(fileBytes);
            }

            controllerModelGameObject = new GameObject();
            GLTFComponentStreamingAssets gltfScript = controllerModelGameObject.AddComponent<GLTFComponentStreamingAssets>();
            gltfScript.ColorMaterial = GLTFMaterial;
            gltfScript.NoColorMaterial = GLTFMaterial;
            gltfScript.GLTFData = fileBytes;

            yield return gltfScript.LoadModel();
        }

        FinishControllerSetup(controllerModelGameObject, source.Handedness.ToString(), source.Id);
    }

endif

Sign In or Register to comment.