void OnButtonDown(byte controller_id, MLInputControllerButton button)
    {
        if (button == MLInputControllerButton.Bumper)
        {
            if (bubble)
            {
                Destroy(bubble);
            }

            Debug.Log("Place bubble");
            // Create a raycast parameters variable
            MLWorldRays.QueryParams _raycastParams = new MLWorldRays.QueryParams
            {
                // Update the parameters with our Camera's transform
                Position  = Controller.position,
                Direction = Controller.forward,
                UpVector  = Controller.up,
                // Provide a size of our raycasting array (1x1)
                Width  = 1,
                Height = 1
            };

            // Feed our modified raycast parameters and handler to our raycast request
            MLWorldRays.GetWorldRays(_raycastParams, HandleOnReceiveRaycast);
        }
    }
 void OnDestroy()
 {
     MLHands.Stop();
     MLInput.Stop();
     MLWorldPlanes.Stop();
     MLWorldRays.Stop();
 }
Example #3
0
 /// <summary>
 /// Initializes component.
 /// </summary>
 virtual protected void OnEnable()
 {
     _isReady = true;
     if (!MLWorldRays.Start())
     {
         Debug.LogError("Error BaseRaycast starting MLWorldRays, disabling script.");
         enabled = false;
         return;
     }
 }
Example #4
0
 // Update is called once per frame
 void Update()
 {
     MLWorldRays.QueryParams _raycastParams = new MLWorldRays.QueryParams
     {
         Position  = cTransform.position,
         Direction = cTransform.forward,
         UpVector  = cTransform.up,
         Width     = 1,
         Height    = 1
     };
     MLWorldRays.GetWorldRays(_raycastParams, HandleOnReceiveRaycast);
 }
Example #5
0
 // Update is called once per frame
 void Update()
 {
     // Create a raycast parameters variable
     MLWorldRays.QueryParams _raycastParams = new MLWorldRays.QueryParams {
         // Update the parameters with our Camera's transform
         Position  = ctransform.position,
         Direction = ctransform.forward,
         UpVector  = ctransform.up,
         // Provide a size of our raycasting array (1x1)
         Width  = 1,
         Height = 1
     };
     // Feed our modified raycast parameters and handler to our raycast request
     MLWorldRays.GetWorldRays(_raycastParams, HandleOnReceiveRaycast);
 }
Example #6
0
 private void CastRay(Vector3 position, Vector3 direction)
 {
     MLWorldRays.QueryParams _raycastParams = new MLWorldRays.QueryParams
     {
         // Update the parameters with our Hand's transform
         Position  = position,
         Direction = direction,
         UpVector  = new Vector3(0, 1, 0),
         // Provide a size of our raycasting array (1x1)
         Width  = 1,
         Height = 1
     };
     // Feed our modified raycast parameters and handler to our raycast request
     MLWorldRays.GetWorldRays(_raycastParams, HandleOnReceiveRaycast);
 }
    void Awake()
    {
        MLResult result = MLWorldRays.Start();

        if (!result.IsOk)
        {
            Debug.LogError("Error BaseRaycast starting MLWorldRays, disabling script.");
            enabled = false;
            return;
        }
        var raycastParams = new MLWorldRays.QueryParams();

        raycastParams.Position  = POSITION;
        raycastParams.Direction = DIRECTION;
        MLWorldRays.GetWorldRays(raycastParams, HandleOnReceiveRaycast);
    }
Example #8
0
        /// <summary>
        /// Continuously casts rays using _raycastParams.
        /// </summary>
        private void Update()
        {
            if (_isReady)
            {
                _isReady = false;

                _raycastParams.Position              = Position;
                _raycastParams.Direction             = Direction;
                _raycastParams.UpVector              = Up;
                _raycastParams.Width                 = Width;
                _raycastParams.Height                = Height;
                _raycastParams.HorizontalFovDegrees  = HorizontalFovDegrees;
                _raycastParams.CollideWithUnobserved = CollideWithUnobserved;

                MLWorldRays.GetWorldRays(_raycastParams, HandleOnReceiveRaycast);
            }
        }
Example #9
0
    // Start is called before the first frame update

    void Start()
    {
        MLWorldRays.Start();
        obj = Instantiate(prefab);
        obj.transform.localScale = new Vector3(0.02f, 0.02f, 0.02f);
        //obj.SetActive(false);

        /*
         * MLResult result = MLHands.Start();
         * if (!result.IsOk)
         * {
         *  Debug.LogErrorFormat("Error: HandTrackingVisualizer failed starting MLHands, disabling script. Reason: {0}", result);
         *  enabled = false;
         *  return;
         * }
         */
    }
Example #10
0
    void Awake()
    {
        MLResult hResult  = MLHands.Start();
        MLResult iResult  = MLInput.Start();
        MLResult pResult  = MLWorldPlanes.Start();
        MLResult wrResult = MLWorldRays.Start();

        if (
            !hResult.IsOk ||
            !iResult.IsOk ||
            !pResult.IsOk ||
            !wrResult.IsOk
            )
        {
            Debug.LogError("Error starting ML APIs, disabling script.");
            enabled = false;
            return;
        }

        // HANDS
        var enabledPoses = new MLHandKeyPose[] {
            MLHandKeyPose.Fist,
        };

        MLHands.KeyPoseManager.EnableKeyPoses(enabledPoses, true);

        // INPUT
        _iController = MLInput.GetController(MLInput.Hand.Left);

        // WORLD PLANES
        var queryParams = new MLWorldPlanesQueryParams();
        var queryFlags  = MLWorldPlanesQueryFlags.Horizontal | MLWorldPlanesQueryFlags.SemanticFloor;

        queryParams.Flags      = queryFlags;
        queryParams.MaxResults = WP_MAX_PLANES;
        MLWorldPlanes.GetPlanes(queryParams, HandleOnReceivedPlanes);

        // WORLD RAYS
        _wrBaseHeight      = transform.position.y;
        _wrLastCentimeters = (int)Math.Truncate(_wrBaseHeight * 100);
    }
Example #11
0
 /// <summary>
 /// Cleans up component.
 /// </summary>
 virtual protected void OnDisable()
 {
     MLWorldRays.Stop();
 }
Example #12
0
    void Update()
    {
        if (!_iController.Connected)
        {
            Debug.Log("Error controller not connected");
            return;
        }
        float deltaTime = Time.deltaTime;

        // HANDS
        var keypose = false;
        var hand    = MLHands.Right;

        if (hand.KeyPose == H_KEYPOSE && hand.KeyPoseConfidence > H_KEYPOSE_CONFIDENCE_THRESHOLD)
        {
            keypose = true;
        }
        if (_hFirst)
        {
            _hFirst       = false;
            _hLastKeypose = !_hLastKeypose;
        }
        if (keypose != _hLastKeypose)
        {
            _hLastKeypose = keypose;
            if (keypose)
            {
                _wrChangingHeight = false;
                gameObject.AddComponent <Rigidbody>();
            }
            else
            {
                var rb = GetComponent <Rigidbody>();
                if (rb != null)
                {
                    Destroy(rb);
                }
                Vector3 position = transform.position;
                position.y         = _wrBaseHeight;
                transform.position = position;
            }
        }

        // INPUT
        if (!_hLastKeypose)
        {
            var touch    = _iController.State.TouchPosAndForce[I_TOUCH_CONTROL];
            var position = transform.position;
            position.x        += I_SPEED_HORZ * touch.x * deltaTime;
            position.z        += I_SPEED_HORZ * touch.y * deltaTime;
            transform.position = position;
        }

        // WORLD RAYS
        if (!_wrPending && !_hLastKeypose)
        {
            _wrPending = true;
            var raycastParams = new MLWorldRays.QueryParams();
            raycastParams.Position  = transform.position;
            raycastParams.Direction = WR_DIRECTION;
            MLWorldRays.GetWorldRays(raycastParams, HandleOnReceiveRaycast);
        }
        if (_wrChangingHeight)
        {
            var targetY  = _wrLastCentimeters / 100.0f;
            var position = transform.position;
            if (position.y <= targetY)
            {
                position.y += WR_SPEED_VERT * deltaTime;
                if (targetY - position.y <= WR_CENTIMETER)
                {
                    _wrChangingHeight = false;
                    position.y        = targetY;
                }
            }
            else
            {
                position.y -= WR_SPEED_VERT * deltaTime;
                if (position.y - targetY <= WR_CENTIMETER)
                {
                    _wrChangingHeight = false;
                    position.y        = targetY;
                }
            }
            transform.position = position;
        }
    }
Example #13
0
 private void OnDestroy()
 {
     MLWorldRays.Stop();
 }
Example #14
0
 // Start is called before the first frame update
 void Start()
 {
     MLWorldRays.Start();
 }
 // When the prefab is destroyed, stop MLWorldRays API from running.
 private void OnDestroy()
 {
     MLInput.OnControllerButtonDown -= OnButtonDown;
     MLInput.Stop();
     MLWorldRays.Stop();
 }
 // Use this for initialization
 void Start()
 {
     // Start accessing the ML World Ray API.
     MLWorldRays.Start();
 }