Example #1
0
        // Update is called once per frame
        void Update()
        {
            //
            //  Normally, once we are anchored to a PCF, we should not un-anchor.
            //
            //  But for demonstration purposes, we allow this GameObject to be un-anchored
            //  and moved and re-anchored.
            //
            //  Remove anchor when the GameObject is being moved by
            //  the ActsAsPickerManipulator
            //  and re-anchor when the GameObject has stopped being moved
            //  by the ActsAsPickerManipulator
            //
            if (this.actsAsManipulatable.isBeingMoved && this.isAnchoredToPCF)
            {
                this.isMovedByPickerManipulator = true;
                this.transformBinding.UnBind();
                this.transformBinding = null;
                return;
            }
            else if (!this.isAnchoredToPCF && !this.actsAsManipulatable.isBeingMoved && isMovedByPickerManipulator)
            {
                this.isMovedByPickerManipulator = false;
                createNewBindingToPCFAnchor();
            }
            else if (isMovedByPickerManipulator)
            {
                return;
            }

            //
            // Color the GameObject according to map quality and PCF status
            //
            if (this.mapQualityResult != MLResult.Code.Ok)
            {
                this.meshRenderer.material.color = this.colorOfMapQuality;
            }
            else if (this.meshRenderer.material.color == this.colorOfStatus)
            {
                return;
            }
            this.meshRenderer.material.color = this.colorOfStatus;
        }
Example #2
0
        #pragma warning restore 414


        /// <summary>
        /// Starts the MLPersistentCoordinateFrames api and initializes bindings.
        /// </summary>
        void Start()
        {
            #if PLATFORM_LUMIN
            MLResult result = MLPersistentCoordinateFrames.Start();
            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error: PCFVisual failed starting MLPersistentCoordinateFrames, disabling script. Reason: {0}", result);
                enabled = false;
                return;
            }

            MLPersistentCoordinateFrames.FindClosestPCF(transform.position, out MLPersistentCoordinateFrames.PCF pcf);

            _visualTransformBinding = new TransformBinding(isPersistent: false);
            _visualTransformBinding.Bind(pcf, transform);

            _visualTextBinding = new TextMeshBinding();
            _visualTextBinding.Bind(pcf, _statusText);
            #endif
        }
Example #3
0
        private bool locateAndReBindToPCFAnchor()
        {
            bool result = false;

            ///
            /// Iterate the persisted bindings that are stored locally on the device
            ///
            TransformBinding.storage.LoadFromFile();
            List <TransformBinding> storedBindings = TransformBinding.storage.Bindings;
            List <TransformBinding> staleBindings  = new List <TransformBinding>();

            foreach (TransformBinding storedBinding in storedBindings)
            {
                ///
                /// Get the Coordinate Frame Unique Identifier
                ///
                this.coordinateFrameUID = storedBinding.PCF.CFUID;

                ///
                /// Find the PCF (Persistent Coordinate Frame) aka "The Anchor"
                ///
                MLPersistentCoordinateFrames.FindPCFByCFUID(coordinateFrameUID, out MLPersistentCoordinateFrames.PCF pcf);

                /// Gets the MLResult from the last query for the PCF's pose. It could be one of the following:
                /// <c>MLResult.Code.Pending</c> -
                /// <c>MLResult.Code.Ok</c> - Position/Orientation is reliable.
                /// Otherwise - Position/Orientation is unreliable.
                switch (pcf.CurrentResultCode)
                {
                case MLResult.Code.Pending:     // Position/Orientation does not exist.
                    staleBindings.Add(storedBinding);
                    break;

                case MLResult.Code.Ok:      // Position/Orientation is reliable, but pcf may be null
                {
                    if (pcf == null)
                    {
                        staleBindings.Add(storedBinding);
                        continue;
                    }
                    else
                    {
                        print("Found stored PCF -- Rebinding");
                        this.transformBinding = storedBinding;
                        this.transformBinding.Bind(pcf, this.transform, true);
                        this.pcf = pcf;

                        result = true;
                    }
                }
                break;

                default:        // Position/Orientation is unreliable.
                {
                    staleBindings.Add(storedBinding);
                    continue;
                }
                }
            }


            foreach (TransformBinding staleBinding in staleBindings)
            {
                staleBinding.UnBind();
            }

            if (!result)
            {
                print("Failed to locate stored binding.");
            }

            return(result);
        }
Example #4
0
        private ActsAsGlobalOrigin.AnchorResult anchorToClosestPCF(ActsAsGlobalOrigin.AnchorAttempt anchorAttempt, MLPersistentCoordinateFrames.PCF.Types type)
        {
            if (MLPersistentCoordinateFrames.IsLocalized == false)
            {
                print("Localized map must first be created before finding a PCF");
                return(ActsAsGlobalOrigin.AnchorResult.GeneralFail);
            }

            MLResult resultFindClosestSecondaryPCFType = MLPersistentCoordinateFrames.FindClosestPCF(transform.position, out MLPersistentCoordinateFrames.PCF closestPCF, type);

            switch (resultFindClosestSecondaryPCFType.Result)
            {
            case MLResult.Code.Ok:
            {
                if (closestPCF == null)
                {
                    return(resultFailFrom(anchorAttempt));
                }
                else
                {
                    ///
                    /// Bind this GameObject's transform to the PCF
                    ///
                    this.transformBinding = new TransformBinding(this.GetInstanceID().ToString(), "ActsAsGlobalOrigin");
                    if (this.transformBinding == null)
                    {
                        return(resultFailFrom(anchorAttempt));
                    }

                    if (this.transformBinding.Bind(closestPCF, transform))
                    {
                        closestPCF.AddBinding(this);
                        this.pcf = closestPCF;

                        print("Added Binding");

                        return(resultSuccessFrom(anchorAttempt));
                    }
                    else
                    {
                        return(resultFailFrom(anchorAttempt));
                    }
                }
            }

            case MLResult.Code.InvalidParam:
                throw new System.NotImplementedException();

            case MLResult.Code.PrivilegeDenied:
                throw new System.NotImplementedException();

            case MLResult.Code.UnspecifiedFailure:
                print("UnspecifiedFailure");
                return(ActsAsGlobalOrigin.AnchorResult.GeneralFail);

            case MLResult.Code.PassableWorldLowMapQuality:
                print("PassableWorldLowMapQuality - quality of the room map is too low, re-map room");
                return(ActsAsGlobalOrigin.AnchorResult.PassableWorldLowMapQuality);

            case MLResult.Code.PassableWorldUnableToLocalize:
                print("PassableWorldUnableToLocalize - room layout has changed, re-map room or adjust lighting");
                return(ActsAsGlobalOrigin.AnchorResult.PassableWorldUnableToLocalize);
            }
            return(ActsAsGlobalOrigin.AnchorResult.GeneralFail);
        }
Example #5
0
        protected void LoadWasm(WasmFile file, ContentsStore store = null, List <string> args = null)
        {
            if (store == null)
            {
                store = new ContentsStore();
            }

            var importer = new PredefinedImporter();

            var wasiFunctions = new List <string>()
            {
                //"proc_exit",
                "fd_prestat_get",
                "fd_prestat_dir_name",
                // "random_get",
                "abort",
            };

            importer.DefineFunction("proc_exit",
                                    new DelegateFunctionDefinition(
                                        new WasmValueType[] { WasmValueType.Int32 },
                                        new WasmValueType[] { },
                                        x => new object[0]
                                        ));
            importer.DefineFunction("clock_time_get",
                                    new DelegateFunctionDefinition(
                                        new WasmValueType[] { WasmValueType.Int32, WasmValueType.Int64, WasmValueType.Int32 },
                                        new WasmValueType[] { WasmValueType.Int32 },
                                        GetTime
                                        ));
            foreach (var wasiFunction in wasiFunctions)
            {
                importer.DefineFunction(wasiFunction,
                                        new DelegateFunctionDefinition(
                                            new WasmValueType[] { },
                                            new WasmValueType[] { },
                                            x => ReturnValue.FromObject(0)
                                            ));
            }
            importer.DefineFunction("random_get",
                                    new DelegateFunctionDefinition(
                                        ValueType.PointerAndPointer,
                                        ValueType.Int,
                                        x => ReturnValue.FromObject(0)
                                        ));

            var element = new Element()
            {
                GameObject = gameObject
            };

            // WASI functions
            if (args == null)
            {
                args = new List <string>();
            }
            var scriptName = "";

            args.Insert(0, scriptName);
            var envs        = new List <string>();
            var argsBinding = new ArgsBinding(element, store, args, envs);

            importer.IncludeDefinitions(argsBinding.Importer);

            var fileDescriptorBinding = new FileDescriptorBinding(element, store);

            importer.IncludeDefinitions(fileDescriptorBinding.Importer);


            // Spirare functions
            var debugBinding = new DebugBinding(element, store);

            importer.IncludeDefinitions(debugBinding.Importer);

            var gameObjectBinding = new GameObjectBinding(element, store, context, mainThread);

            importer.IncludeDefinitions(gameObjectBinding.Importer);

            var transformBinding = new TransformBinding(element, store, context, mainThread);

            importer.IncludeDefinitions(transformBinding.Importer);

            var physicsBinding = new PhysicsBinding(element, store, context, mainThread);

            importer.IncludeDefinitions(physicsBinding.Importer);

            var textBinding = new TextBinding(element, store, context, mainThread);

            importer.IncludeDefinitions(textBinding.Importer);

            var timeBinding = new TimeBinding(element, store);

            importer.IncludeDefinitions(timeBinding.Importer);

            try
            {
                module = ModuleInstance.Instantiate(file, importer);

                argsBinding.ModuleInstance           = module;
                fileDescriptorBinding.ModuleInstance = module;

                gameObjectBinding.ModuleInstance = module;
                debugBinding.ModuleInstance      = module;
                textBinding.ModuleInstance       = module;

                var exportedFunctions = module.ExportedFunctions;
                exportedFunctions.TryGetValue("start", out startFunction);
                exportedFunctions.TryGetValue("update", out updateFunction);
                exportedFunctions.TryGetValue("on_use", out onUseFunction);
                exportedFunctions.TryGetValue("on_select", out onSelectFunction);
                exportedFunctions.TryGetValue("on_equip", out onEquipFunction);
                exportedFunctions.TryGetValue("on_unequip", out onEquipFunction);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
        }