【问题标题】:Three.js GLTFLoader cant load gltf files on my computerThree.js GLTFLoader 无法在我的电脑上加载 gltf 文件
【发布时间】:2021-11-10 17:39:06
【问题描述】:

我不熟悉使用 three.js、JavaScript、html 和 CSS,我正在加载 3d 模型。当我在线提取 gltf 文件时,我有一个正在运行的程序,例如:

loader.load('https://threejsfundamentals.org/threejs/resources/models/cartoon_lowpoly_small_city_free_pack/scene.gltf', function ( gltf ) 
{console.log(gltf);
scene.add( gltf.scene );
}, undefined, function ( error ) {console.error( error );} );

但是当我尝试从我的计算机上提取一个 gltf 文件时它不起作用,例如:

loader.load('C:\Models\scene.gltf', function ( gltf ) 
{console.log(gltf);
scene.add( gltf.scene );
}, undefined, function ( error ) {console.error( error );} );

知道我做错了什么吗?我也在使用 Dreamweaver。

【问题讨论】:

    标签: javascript html three.js gltf


    【解决方案1】:

    Web 浏览器无法从本地磁盘加载图像或模型等文件(除非您禁用安全限制)。要解决此问题,您必须在开发期间运行本地服务器,请参阅 three.js 文档中的 how to run things locally

    【讨论】:

    • 我目前正在使用 Servez 在您发布的链接上运行它,但即使在此之后它仍然无法正常工作。
    • URL 不能是C:\Models\scene.gltf,它需要类似于http://localhost:8888/path/to/model.gltf,具体取决于您运行本地服务器的目录和端口号。无法提供该目录之外的文件。
    猜你喜欢
    • 1970-01-01
    • 2021-02-01
    • 2020-04-13
    • 1970-01-01
    • 2018-10-27
    • 1970-01-01
    • 1970-01-01
    • 2011-12-22
    • 1970-01-01
    相关资源
    最近更新 更多