Hello everyone,
I am currently moving an old project of mine from threejs to babylonjs and now need help to translate one of my old tricks into babylon:
I have a game board, that is just a virtual plane and translate screenYX to a PointXYZ on that plane with a trick: In ThreeJS the raycaster can find intersections with Geometries not just meshes (because i am currently under the opinion babylon can only pick actual meshes added to the scene). Also Planes in ThreeJS are infinite and the raycaster has a intersectPlane method.
So what i do to translate ScreenCoordinates to XYZ coordinates on that plane is just
creating that plane - but never add it as a mesh - and then use the raycaster to find the ScreenXY on that plane, like this:
this.plane = new THREE.Plane(new THREE.Vector3(0,0,1), 0);
x = ( x / this.container.clientWidth ) * 2 - 1;
y = - ( y / this.container.clientHeight ) * 2 + 1;
this.re.raycaster.setFromCamera(new THREE.Vector2(x, y), this.re.camera);
return this.re.raycaster.ray.intersectPlane(this.plane, new THREE.Vector3());
Sorry to annoy you with threeJS code, i just think i am confusing basic concepts of those two libraries and wanted to show how i dealt with this till now. After trying arround a few hours i think i need a completly different approach to this with babylon.
For example i do not understand the difference between plane and ground. Both are limited to a width and height.
When i add a plane or ground to a scene and do a scene.pick, it works as described. I get a pickInfo, there is a pickedPoint and i can do my game math with it. But:
How can i make that Plane/Ground infinite?
How can i make it invisible or virtual?
I found a infiniteDistance
property, but when i add that to plane or ground it disappears from the scene completly and scene.pick acts like its not there.
Can you intersect geometries somehow without adding them with meshes to the scene?
Or is there a completly different technique in babylon to achieve this?
Regards