Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Point cloud Interaction through the meta quest controller

Discussion in 'VR' started by stutikafle, Nov 29, 2023.

  1. stutikafle

    stutikafle

    Joined:
    Sep 11, 2023
    Posts:
    7
    I am facing issue where I have 33 million points of point cloud. I imported it to unity using point cloud free viewer from the asset store of unity where a single gameObject holds the poinclouds. Now I am trying to have my player be able to select the point in the point cloud and be able to calculate distance and display in UI.
    this is the script that I wrote. Does writing a script works or do I need to do something else??


    using UnityEngine;
    using UnityEngine.UI;
    using UnityEngine.XR.Interaction.Toolkit;
    using TMPro;

    public class PointSelection : MonoBehaviour
    {
    public XRRayInteractor rayInteractor;
    private Vector3 firstPoint, secondPoint;
    private bool firstPointSelected = false;

    void Update()
    {
    // Use the XR Interaction Toolkit's input handling
    if (rayInteractor && rayInteractor.isSelectActive)
    {
    RaycastHit hit;
    if (rayInteractor.TryGetCurrent3DRaycastHit(out hit))
    {
    if (!firstPointSelected)
    {
    firstPoint = hit.point;
    firstPointSelected = true;
    }
    else
    {
    secondPoint = hit.point;
    DisplayDistance();
    firstPointSelected = false; // Reset for next selection
    }
    }
    }
    }

    void DisplayDistance()
    {
    float distance = Vector3.Distance(firstPoint, secondPoint);
    distanceText.text = "Distance: " + distance.ToString("F2") + " units";
    }
    }
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,285
    not sure how the free viewer displays points, is it particles or point meshes or something else?

    but using raycast would require points to have colliders.
     
  3. stutikafle

    stutikafle

    Joined:
    Sep 11, 2023
    Posts:
    7
    How do I add collider to the point cloud?? A single gameobject is holding all the points of the pointcloud.
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,285
    yes, cannot add collider if its particles or using mesh with point rendering.

    so at that point need to create algorithm for point picking,
    like get closest point on ray. (it would allow you to pick points).
    or, get point inside Oriented Bounding Box (would allow getting all points inside 3d box)
    or, get point inside convex mesh (would allow finding all points inside convex collider)

    can find some info about those in google.

    one option is also to try this,
    https://github.com/staggartcreations/Graphics-Raycast