[SOLVED] How to convert raycast to texture coordinates?

Hi, thanks for reading.

I am building a menu system using a textured plane. I am using raycasting to determine if a laser pointer is intersecting the plane. the plane could potentially appear anywhere in the world in any orientation. I would like to be able to convert the result.point provided by the raycasting function into coordinates on the plane surface.

Anybody done anything like that and could give me a steer?

Use worldToScreen method from camera to convert world space point into screen space.

Hi Max,
It’s not a screen point as such but more a case of where a laser comming from a vive controller intersects a plane in terms of the local plane coordinates. I have managed to get this far

var self = this;
        this.app.systems.rigidbody.raycastFirst(start, end, function (result) {
            var pickedEntity = result.entity;
            if (pickedEntity.getName() == "Menu"){
                console.log('clicked menu at');
                var localOffset = new pc.Vec3();
                var mat = pickedEntity.getWorldTransform().clone();
                mat.transformPoint(result.point, localOffset);


which is the beginning of a solution and I think the next bit is fairly trivial since you only need to take into account the origin is at the centre of the texture.

BUT thinking about it further I am considering abandoning this approach in favor of simply building the UI as an object and simply turning it on and off which I think will be simpler and more flexible in the long run.I am thinking of a simple script that I can attach to any object which has ID and Text attributes which simply apply to any entity which subscribe to a laserclick event.

you can mark this as solved as I went with a totally different approach

1 Like