射线与模型相交

Ray intersect with the model

是否可以从相机投射光线并知道它是否与模型相交?

同理,是否可以这样计算到交点的距离?

我想要这个,这样我就可以通过编程知道墙是 window 还是平坦的,如果它有 window 那么距离就会跳跃的交叉路口。

绝对是。这是一个例子,ForgeFader,准确地展示了您的要求:

http://thebuildingcoder.typepad.com/blog/2017/04/work-half-aks-opener-rvtfader-and-forgefader.html#9

GitHub 上的来源:

https://github.com/jeremytammik/forgefader

Is it possible to cast rays from the camera and know if it intersects the model? There is several options you can use:

如果你想交叉任何东西,你可以使用内置的查看器 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 }

如果您更喜欢对选定对象进行光线投射,可以使用 Three.js 光线投射器 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 是您从查看器获得的代理图形数组 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)

示例已发布here