Babylonjs 如何获取模型中心点位

获取模型中心首先获取模型的跟节点,一般名为root的结点,然后获取模型的boundingBox的最大值和最小值,可以得出元素的宽、高、深,根据宽、高、深等数据即可获取元素中心点位。

例如:

const getRootNode = (mesh: BABYLON.Node) => {
  let currentNode = mesh

  // 逐级向上查找,直到找到没有父节点的根节点
  while (currentNode.parent) {
    currentNode = currentNode.parent
  }
  return currentNode
}

const currentNode = getRootNode(mesh)
const boundingBox = currentNode.getHierarchyBoundingVectors()
const centerPoint = mesh.getBoundingInfo().boundingBox.center
const { _x, _z } = centerPoint
const { _x: currentNodeX, _y: currentNodeY, _z: currentNodeZ } = boundingBox.max
const width = boundingBox.max.x - boundingBox.min.x //宽
const height = boundingBox.max.y - boundingBox.min.y //高
const depth = boundingBox.max.z - boundingBox.min.z //深

如图圈中所示:
在这里插入图片描述

  • 6
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值