Rotate 3D Model by only touching it's surface

I have a script which rotates the 3D model in world space using touch input. Right now, what is happening is that the model rotates from touching anywhere on the mobile screen. What i want to do is to rotate the 3D model by only touching its surface (3D model itself) and not by touching elsewhere on the mobile screen. Help me please, this is the Rotate script that i have applied on the 3D model:

void Update()
{
    Debug.Log("Inside function Update");
    HandleRotationInput();
}
void HandleRotationInput()
{
    if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved && !IsPointerOverUIObject(Input.GetTouch(0).fingerId) && !isZooming)
    {
        float rotationX = Input.GetTouch(0).deltaPosition.y * rotateSpeed * Time.deltaTime;
        float rotationY = -Input.GetTouch(0).deltaPosition.x * rotateSpeed * Time.deltaTime;

        // Rotate around the world axes instead of local axes
        transform.Rotate(Vector3.right, rotationX, Space.World);
        transform.Rotate(Vector3.up, rotationY, Space.World);
    }
    else if (Input.GetMouseButton(0) && !IsPointerOverUIObject() && !isZooming)
    {
        float rotationX = Input.GetAxis("Mouse Y") * rotateSpeed;
        float rotationY = -Input.GetAxis("Mouse X") * rotateSpeed;

        // Rotate around the world axes instead of local axes
        transform.Rotate(Vector3.right, rotationX, Space.World);
        transform.Rotate(Vector3.up, rotationY, Space.World);
    }
}

// Check if the touch is over a UI object
bool IsPointerOverUIObject(int fingerId = -1)
{
    PointerEventData eventData = new PointerEventData(EventSystem.current);
    eventData.position = (fingerId == -1) ? Input.mousePosition : Input.GetTouch(fingerId).position;

    // Raycast using the EventSystem to check if the touch is over a UI object
    List<RaycastResult> results = new List<RaycastResult>();
    EventSystem.current.RaycastAll(eventData, results);

    return results.Count > 0;
}

Note: the hierarchy of 3D model is like this:
camera object-> game object (Rotate script is applied on this game object) → actual 3D model. Kindly someone help me, i am a beginner…

Try adding an Edge Collider 2D on the object.

It does sound like you need to test a raycast to the screen point.

Here is some example code which will do what you need in the desktop. Add the component to the object you want to hit. Get it working with a mouse click first. The code you pasted above is not really anything like what I’ve worked on.

    private Camera _camera;
    
    // ----------------------------------------------------------------
    void Start()
    {
        if (_camera == null)  {  _camera = Camera.main;  }
    }

    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            Ray ray = _camera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
        
            if (Physics.Raycast(ray, out hit) != false)
            {
                if (hit.collider.gameObject != null)
                {
                    Debug.Log($"Mouse hit point: {hit.point}, on {hit.collider.gameObject}");
                }
            }
        }
    }

I coped this in from a working project I put on GitHub, you can see the whole thing here if you have any trouble running it:

Ok so i tried putting the box collider over the game object and modified my Rotate script and achieved what i wanted. This is the script that I have modified and its working fine:

public Camera mainCamera;
private bool rotationStarted = false;
void HandleRotationInput()
{
    if (Input.touchCount == 1 && !isZooming)
    {
        Touch touch = Input.GetTouch(0);

        if (touch.phase == TouchPhase.Began)
        {
            rotationStarted = IsPointerOverModel(touch.position);
        }

        if (rotationStarted && touch.phase == TouchPhase.Moved)
        {
            float rotationX = touch.deltaPosition.y * rotateSpeed * Time.deltaTime;
            float rotationY = -touch.deltaPosition.x * rotateSpeed * Time.deltaTime;

            // Rotate around the world axes instead of local axes
            transform.Rotate(Vector3.right, rotationX, Space.World);
            transform.Rotate(Vector3.up, rotationY, Space.World);
        }

        if (touch.phase == TouchPhase.Ended)
        {
            rotationStarted = false;
        }
    }
    else if (Input.GetMouseButton(0) && !IsPointerOverUIObject() && !isZooming)
    {
        if (rotationStarted || IsPointerOverModel(Input.mousePosition))
        {
            rotationStarted = true;
            float rotationX = Input.GetAxis("Mouse Y") * rotateSpeed;
            float rotationY = -Input.GetAxis("Mouse X") * rotateSpeed;

            // Rotate around the world axes instead of local axes
            transform.Rotate(Vector3.right, rotationX, Space.World);
            transform.Rotate(Vector3.up, rotationY, Space.World);
        }
        
    }
    if (Input.GetMouseButtonUp(0))
    {
        rotationStarted = false;
    }
    
}

bool IsPointerOverModel(Vector2 screenPosition)
{
    Ray ray = mainCamera.ScreenPointToRay(screenPosition);
    RaycastHit hit;

    if (Physics.Raycast(ray, out hit))
    {
        // Check if the hit collider bounds contain the hit point
        if (hit.collider != null)
        {
            Collider collider = hit.collider;
            Bounds bounds = collider.bounds;
            Vector3 hitPoint = hit.point;

            if (bounds.Contains(hitPoint))
            {
                return true;
            }
        }
    }

    return false;
}

This works perfectly for this scene (3d models scene), i am able to rotate the 3d model only when i touch its surface.
But i have another scene (AR models scene), in which i want to do the same. In that scene, i have implemented AR, in which i have used image targets that are uploaded in Vuforia, when the user scans the image target, the respective model will be shown on the screen and user can rotate it which working fine. Now, the Rotate script applied here is different. This is the script (Rotate-AR script) that is applied on this scene(AR models scene):

void Update()
{
    Debug.Log("Inside function Update");
    HandleRotationInput();
    HandleZoomInput();
}

void HandleRotationInput()
{
    if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved && !isZooming)
    {
        Vector2 touchDelta = Input.GetTouch(0).deltaPosition * rotateSpeed * Time.deltaTime;
        transform.Rotate(Camera.main.transform.up, -touchDelta.x, Space.World);
        transform.Rotate(Camera.main.transform.right, touchDelta.y, Space.World);
    }
    else if (Input.GetMouseButton(0) && !isZooming)
    {
        float rotationX = Input.GetAxis("Mouse X") * rotateSpeed; // Rotate around local z-axis
        float rotationY = Input.GetAxis("Mouse Y") * rotateSpeed; // Rotate around local x-axis
        transform.Rotate(Camera.main.transform.up, -rotationX, Space.World);
        transform.Rotate(Camera.main.transform.right, rotationY, Space.World);
    }
}

The problem is the collider script that i applied in the 3d models scene requires camera to be passed through inspector Main Camera property (which was fine as each model had its separate camera in that 3d model scene), but here in this (AR models) scene, i don’t have separate camera objects so icant pass any camera in the property.
image

My hierarchy in this scene is this: Game object (DefaultObserverEventHandler script that is some default unity script, i believe its some AR script) → point object (Rotate-AR script applied) → 3D Model (Actual 3D model).
Now how can i achieve the same result in this AR models scene that is achieved in the 3d models scene.