在实现物体测距,使用射线时自己导致的bug。。

问题

我是想相交的到点以后,直接塞入对应交到的物体里用一个SphereGeometry显示(不测量的时候,寻找其父元素移除)。

进行一番操作以后,发现显示的位置始终不对。

经过一段时间的思考,发现使用intersects[0].object.worldToLocal()反而正确了。

解决

射线交得的就是世界坐标为什么反而要从世界坐标转化成本地坐标了呢?

因为我塞入了其object容器内,自然也就应用上了他的转换矩阵。那么原本正确的世界坐标就会变转换,反而将其转换成原本的本地坐标才正确(自然的应用容器的转换矩阵)。

js 复制代码
if (this.isMeasuring) {
      //交物体
      const intersects = this.getIntersectionsForMeature(event);
      if (intersects.length > 0) {

        console.log("看看交了啥",intersects)
        const marker = new THREE.Mesh(
          new THREE.SphereGeometry(0.1, 10, 20),
          new THREE.MeshBasicMaterial({
            color: 0xff5555,
            transparent: true,
            opacity: 0.5,
          })
        );
        marker.position.copy(intersects[0].object.worldToLocal(intersects[0].point))

marker.name = `${this.measureLinePoints.length+1}`
intersects[0].object.add(marker);
this.measureLinePoints.push(marker);
console.log("看一下存的点",this.measureLinePoints)
        }
相关推荐
@大迁世界17 小时前
如何在开发过程中减少 Bug?
bug
鸽芷咕1 天前
【bug报错已解决】ERROR: Could not find a version that satisfies the requirement
bug
鸽芷咕1 天前
【pyhont报错已解决】ERROR: Could not find a version that satisfies the requirement
python·bug
sjsjs112 天前
unity开发中使用射线交互物体修改TextMashPro出现镜头抖动及解决
unity·游戏引擎·bug
蔡斯达纳3 天前
Pycharm导入内置库或者第三方库时标红,no module named ‘xxx‘
ide·python·pycharm·bug
碎像3 天前
使用AI工具 Baidu Comate 辅助编码 快速定位修改Bug
java·前端·后端·bug·intellij idea
ganjiee00073 天前
记录bug导致测试部署出错,但是本地环境启动正常。雪花算法使用中报错。并带有源码分析。
java·bug·hutool
前端小菜鸟也有人起3 天前
小程序中echarts的bug
bug
DX_dove3 天前
点云压缩配置开发环境遇到一些bug
ubuntu·bug
空青7263 天前
关于日常开发和面试——集合List及数组避坑之一二
java·后端·面试·list·bug·跳槽·改行学it