首页 > 解决方案 > 使用nodejs express将gltf结果加载到404(未找到)的threejs

问题描述

我知道这是常见错误,但我尝试了 stackoverflow 中的答案,但它不起作用。我正在从本教程加载一个 gltf 文件:https ://threejsfundamentals.org/threejs/lessons/threejs-load-gltf.html

我使用 nodejs express 作为我的服务器,我的目录结构是 在此处输入图像描述

where in public 设置为这样的公用文件夹

app.use(express.static('public'));

公共文件夹内包含必要的threejs库文件和GLTF加载器,因此由于公共文件夹已经是“公共”并且公开了它还包含资产或gltf文件 在此处输入图像描述

但是,从该目录加载 gltf 文件时,结果为 404。

在此处输入图像描述

const loader = new GLTFLoader();
  
  loader.load('assets/city/scene.gtlf',
     (gltf) => {
        const root = gltf.scene;
        scene.add(root);
     },
     (xhr)=>{

     },
     (error)=>{
       console.log(error);
     });

我在这里缺少什么?

标签: expressthree.jswebglgltf

解决方案


推荐阅读