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

替换Potree示例中的OBJ模型为GLTF时遇GLTFLoader加载错误

Fixing "Cannot read property 'extractUrlBase' of undefined" in Potree When Replacing OBJ with GLTF

Let's break down how to resolve this error step by step—this is a common issue when mixing native Three.js loaders with Potree's environment, so let's start with the most likely fixes:

1. Match GLTFLoader Version to Potree's Built-in Three.js

Potree relies on a specific version of Three.js under the hood, and using a mismatched GLTFLoader will cause property/method mismatches like extractUrlBase being undefined. Here's how to fix this:

  • Open your Potree project's potree.js file, search for THREE.REVISION to find the exact Three.js version it uses (e.g., r158).
  • Download the same version of GLTFLoader from the official Three.js repository (look in the examples/jsm/loaders folder for your revision).
  • Replace your current GLTFLoader.js with this version—this ensures all dependencies like LoaderUtils.extractUrlBase are properly aligned.

2. Adjust Your GLTFLoader Loading Code

Potree's scene setup is a bit different from vanilla Three.js, so your loading code needs to account for that. Replace your existing OBJ loading code with something like this:

// Wait for Potree to finish initializing first
potree.initialize().then(() => {
  const loader = new THREE.GLTFLoader();
  
  // Set the base path to where your GLTF file lives (match the original OBJ's location)
  loader.setPath('./'); // Adjust if your file is in a subfolder like 'examples/'
  
  loader.load(
    'DamagedHelmet.gltf',
    (gltf) => {
      // Extract the model from the GLTF object
      const helmetModel = gltf.scene;
      
      // Position/scale the model to fit the Potree scene (adjust values as needed)
      helmetModel.position.set(0, 0, 0);
      helmetModel.scale.set(1, 1, 1);
      
      // Add the model to Potree's viewer scene
      potree.viewer.scene.add(helmetModel);
    },
    (progress) => {
      console.log(`Loading progress: ${Math.round(progress.loaded / progress.total * 100)}%`);
    },
    (error) => {
      console.error('GLTF Load Error:', error);
    }
  );
});

The key here is ensuring you initialize the loader after Potree is ready, and using setPath to avoid relative path issues.

3. Verify All GLTF Assets Are Present

GLTF files often rely on additional assets like .bin (binary geometry data) or texture images (.png, .jpg). Make sure:

  • All these files are placed in the same directory as DamagedHelmet.gltf.
  • The file names in the GLTF match exactly (case-sensitive on most servers!).

4. Fix LoaderUtils Reference (If Needed)

If you still see the error after matching versions, double-check that GLTFLoader is correctly referencing LoaderUtils:

  • Open your GLTFLoader.js file, and confirm it starts with an import or reference to THREE.LoaderUtils. For example:
    import { LoaderUtils } from '../Three.js';
    
    Or if you're using the non-module version, ensure THREE.LoaderUtils is available in the global scope (Potree should expose this if you're using the correct Three.js version).

These steps should resolve the extractUrlBase undefined error and get your DamagedHelmet model loading in Potree successfully.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 06:48:30