使用Three.js的地形碰撞问题 [英] Issue with Terrain Collision using Three.js
问题描述
我已经在Three.js中通过高度图创建了一个地形,并且正在使用mrdoob的misc_controls_pointerlock进行碰撞和移动.但是,当我执行 objects.push(terrainobj); 时,性能会下降到约3fps(从60左右),并且不会与地形发生冲突.碰撞是通过射线实现的.我该如何解决?
I have created a terrain via a heightmap in Three.js and am using mrdoob's misc_controls_pointerlock for collision and movement. However, when I do objects.push(terrainobj); the performance goes down to about 3fps (from around 60) and there is no collision with the terrain. The collision is achieved via rays. How can I get around this?
推荐答案
如果只是高度图,则可以避免使用ray并直接在位图中进行碰撞检查(使用canvas和imagedata).
If it's just a heightmap you could avoid using ray and do the collision checking right in the bitmap (using canvas and imagedata).
您只需要将XZ世界位置转换为高度图中的XY像素即可.然后,如果您在世界上的Y位置低于像素的颜色值,则将对象向上移动.
You just need to convert your XZ world position to the XY pixel in the heightmap. Then, if your Y position in the world is lower than the color vaue of the pixel then you move up the object.
这篇关于使用Three.js的地形碰撞问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!