You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何计算.dae模型中心位置并重新定位?

3D模型原点居中解决方案

完全可以通过计算模型的**包围盒(Bounding Box)**来获取尺寸并定位到中心,具体实现如下:

核心思路

借助Three.js的Box3工具类计算模型的整体包围盒,从包围盒中直接提取尺寸和中心坐标,再调整模型位置让自身中心对齐到目标原点。

修改后的代码实现

let loaderDae = new ColladaLoader();
loaderDae.load(`model.dae`, (dae: any) => {
      this.buildingModel = dae.scene;
      
      // 计算模型的整体包围盒(自动遍历所有子物体)
      const boundingBox = new THREE.Box3().setFromObject(this.buildingModel);
      // 获取模型在三个轴向上的尺寸
      const modelSize = new THREE.Vector3();
      boundingBox.getSize(modelSize);
      // 获取模型的中心坐标
      const modelCenter = new THREE.Vector3();
      boundingBox.getCenter(modelCenter);
      
      // 调整模型位置,让自身中心对齐到父物体原点
      this.buildingModel.position.set(-modelCenter.x, -modelCenter.y, -modelCenter.z);
      
      this.sceneS.add(this.buildingModel);
});

关键说明

  • setFromObject()会遍历模型的所有子网格,计算出覆盖整个模型的包围盒,适合处理包含多个部件的复杂模型
  • getSize()返回的modelSize中,modelSize.x对应x轴长度、modelSize.y对应y轴高度、modelSize.z对应z轴宽度
  • 用-modelCenter设置位置,是因为模型位置是相对于父物体的偏移量,反向偏移才能让自身中心和父原点重合
  • 如果后续需要对模型做缩放操作,务必在缩放完成后再计算包围盒,否则尺寸和中心坐标会出现偏差

内容的提问来源于stack exchange,提问作者Finn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 06:15:40