gpt4 book ai didi

three.js - 检查点是否在自定义网格几何图形内

转载 作者:行者123 更新时间:2023-12-04 14:29:51 24 4
gpt4 key购买 nike

检查点是否在自定义(不规则)网格几何图形内的最简单方法是什么?

最佳答案

如果您的网格是特写镜头。您可以使用 THREE.js 内置的 ray-caster。示例代码如下

const point = new THREE.Vector3(2,2,2) // Your point
const geometry = new THREE.BoxBufferGeometry( 5, 5, 5 )
const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } )
const mesh = new THREE.Mesh( geometry, material )
const raycaster = new THREE.Raycaster()
raycaster.set(point, new THREE.Vector3(1,1,1))
const intersects = raycaster.intersectObject(mesh)
if( intersects.length %2 === 1) { // Points is in objet
console.log(`Point is in object`)
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/89/three.js"></script>

关于three.js - 检查点是否在自定义网格几何图形内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16361327/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com