在实现物体测距,使用射线时自己导致的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)
        }
相关推荐
e***98574 小时前
Bug悬案侦破大会:高效解决技术难题
bug
f***24115 小时前
Bug悬案侦破:技术团队的破案指南
bug
Lxinccode5 小时前
BUG(20) : response.text耗时很久, linux耗时十几秒, Windows耗时零点几秒
python·bug·requests·response.text·response.text慢
深念Y7 小时前
夸克网盘 应用程序无法启动,因为应用程序的并行配置不正确。有关详细信息,请参阅应用程序事件日志,或使用命令行sxstrace.exe 工具。
windows·bug·报错·系统·更新·网盘·夸克
万粉变现经纪人10 小时前
如何解决 pip install mysqlclient 报错 ‘mysql_config’ not found 问题
数据库·python·mysql·pycharm·bug·pandas·pip
f***241110 小时前
Bug悬案:技术侦探的破案指南
算法·bug
前端大波13 小时前
avue-crud 操作列透明 bug
bug
hui函数1 天前
Python系列Bug修复|如何解决 pip install 安装报错 invalid command ‘bdist_wheel’(缺少 wheel)问题
python·bug·pip
hui函数1 天前
Python系列Bug修复|如何解决 pip install -r requirements.txt 私有索引未设为 trusted-host 导致拒绝 问题
python·bug·pip
hui函数1 天前
Python系列Bug修复|如何解决 pip install 安装报错 Backend ‘setuptools.build_meta’ 不可用 问题
python·bug·pip