Reputation: 6202
Is it possible to cast rays from the camera and know if it intersects the model?
On the same note, is it possible to calculate distances to the intersection points this way?
I want this so I'll be able to know programmatically if a wall has a window or is it flat, if it has a window then there will be a jump in the distances of the intersections.
Upvotes: 0
Views: 612
Reputation: 2659
Is it possible to cast rays from the camera and know if it intersects the model? There is several options you can use:
If you want to intersect anything, you can use the viewer built-in api
let posClientCoords = new THREE.Vector3(x, y, 1.0)
let result =this.viewer.utilities.viewerImpl.hitTestViewport(posClientCoords , false);
if ( result !== null && result.fragId >= 0 ) {
// here you go
}
If you prefer to ray cast a selection of objects, you can use the Three.js raycaster
let vray =new THREE.Vector3( ptarget.x - psource.x, ptarget.y - psource.y, ptarget.z - psource.z )
vray.normalize ()
let ray =new THREE.Raycaster( psource, vray, 0, max_dist )
let intersectResults = ray.intersectObjects ( wallMeshes, true )
wallMeshes is an array of proxy graphics that you get from the viewer
viewer.impl.getRenderProxy(viewer.model, fragId), null, null, null )
On the same note, is it possible to calculate distances to the intersection points this way? Each of these API will return the hit point (intersection point between the ray and the object)
An example is posted here
Upvotes: 2
Reputation: 8314
It absolutely is. Here is an example, ForgeFader, demonstrating exactly what you are asking for:
http://thebuildingcoder.typepad.com/blog/2017/04/work-half-aks-opener-rvtfader-and-forgefader.html#9
Source on GitHub:
https://github.com/jeremytammik/forgefader
Upvotes: 1