threejs加载obj报错

  • Post author:
  • Post category:其他




threejs加载obj报错



原加载方式

three.module.js:11098 THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The “position” attribute is likely to have NaN values.

       // 使用 Three.js 的加载器加载模型
      const objLoader = new OBJLoader();
      // debugger
      objLoader.load('./xxx.obj', (root) => {
        this.scene.add(root)
      })



新加载方式

  1. webpack需要配置 raw-loader 处理obj文件加载
  2. objUrl 为相对obj模型路径
      try {
        let loader = new OBJLoader();
        const geo = loader.parse(objUrl)
        const geometry = geo.children[0].geometry
        const material = new THREE.MeshBasicMaterial({color: 0x00ff00});
        const mesh = new THREE.Mesh(geometry, material);
        this.scene.add(mesh)
      } catch (e){
          console.log(e, '---error');
      }



版权声明:本文为weixin_39531565原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。