如何使用三个js加载gltf文件

时间:2020-06-21 11:57:07

标签: three.js gltf

  var manager = new THREE.LoadingManager();
  const loader = new THREE.GLTFLoader(manager);

  // A reusable function to set up the models. We're passing in a position parameter
  // Load a glTF resource
**line90**      loader.load(
    // resource URL
    'static/ElmTree.gltf',
    // called when the resource is loaded
    function ( gltf ) {

    enter code here

        scene.add( gltf.scene );

    });

嗨,我正在学习three.js,并通过遵循discoverthree.js文件在加载文件外部gltf文件时出错。我从Google Poly下载了一个文件,但不确定我在做什么错。我在下面遇到错误,并按照文档中的说明尝试了loadmanager。

我正在使用flask运行应用程序,如果需要添加更多信息以了解问题,请告诉我。预先谢谢你:)

three.js:49037 THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.
get @ three.js:49037
(anonymous) @ GLTFLoader.js:2161
Promise.then (async)
THREE.GLTFLoader.GLTFParser.loadTexture @ GLTFLoader.js:2157
THREE.GLTFLoader.GLTFParser.getDependency @ GLTFLoader.js:1829
THREE.GLTFLoader.GLTFParser.assignTexture @ GLTFLoader.js:2223
THREE.GLTFLoader.GLTFParser.loadMaterial @ GLTFLoader.js:2308
THREE.GLTFLoader.GLTFParser.getDependency @ GLTFLoader.js:1825
THREE.GLTFLoader.GLTFParser.loadMesh @ GLTFLoader.js:2675
THREE.GLTFLoader.GLTFParser.getDependency @ GLTFLoader.js:1809
(anonymous) @ GLTFLoader.js:3146
THREE.GLTFLoader.GLTFParser.loadNode @ GLTFLoader.js:3210
THREE.GLTFLoader.GLTFParser.getDependency @ GLTFLoader.js:1805
buildNodeHierachy @ GLTFLoader.js:3269
(anonymous) @ GLTFLoader.js:3351
Promise.then (async)
buildNodeHierachy @ GLTFLoader.js:3336
(anonymous) @ GLTFLoader.js:3351
Promise.then (async)
buildNodeHierachy @ GLTFLoader.js:3336
(anonymous) @ GLTFLoader.js:3351
Promise.then (async)
buildNodeHierachy @ GLTFLoader.js:3336
loadScene @ GLTFLoader.js:3383
THREE.GLTFLoader.GLTFParser.getDependency @ GLTFLoader.js:1801
(anonymous) @ GLTFLoader.js:1877
THREE.GLTFLoader.GLTFParser.getDependencies @ GLTFLoader.js:1875
THREE.GLTFLoader.GLTFParser.getMultiDependencies @ GLTFLoader.js:1902
THREE.GLTFLoader.GLTFParser.parse @ GLTFLoader.js:1703
parse @ GLTFLoader.js:221
(anonymous) @ GLTFLoader.js:75
(anonymous) @ three.js:36378
load (async)
load @ three.js:36356
load @ GLTFLoader.js:71
loadModels @ index.js:90
init @ index.js:21
(anonymous) @ index.js:142

1 个答案:

答案 0 :(得分:1)

您的代码中的GLTFLoaderthree.js似乎来自不同的发行版。您始终必须确保库核心和示例文件(例如GLTFLoaderOrbitControls)的版本匹配。