繁体   English   中英

找不到 GLTF 文件 404

[英]GLTF file 404 not found

所以我正在尝试加载 GLTF 文件,但收到此错误: 在此处输入图片说明

我不知道为什么它无法找到并打开文件。 我必须设置本地服务器吗? 我在网上查了其他例子, 这个例子包括一个 DRACOLoader。 诚然,我不知道这是为了什么,并且想知道我是否需要实现它才能加载它。

这是我的代码:

<html>

    <head>
        <meta charset="utf-8">
        <title>Website first attempt</title>


        <style>
            body { margin: 0;
                background: linear-gradient(to bottom, #33ccff 0%, #ffffff 20%);}
            canvas { display: block; }
        </style>

    </head>

    <body>

      <!-- <script type = "module" src="build/myScript.js"></script>-->
       <script type = "module">
        import * as THREE from '../build/three.module.js';

          import { GLTFLoader } from '../build/GLTFLoader.js';

            let scene, camera, renderer, hlight;


            function init () {
                //scene
                scene = new THREE.Scene();

                //camera
                camera = new THREE.PerspectiveCamera(40, window.innerWidth/ window.innerHeight, 1, 5000);

                //light
                hlight = new THREE.AmbientLight (0x404040, 100);
                scene.add(hlight);


                //render                
                renderer = new THREE.WebGLRenderer({antialias:true});
                renderer.setPixelRatio( window.devicePixelRatio );
                renderer.setClearColor( 0x000000, 0 );
                renderer.setSize(window.innerWidth, window.innerHeight);

                document.body.appendChild(renderer.domElement);

                //3d
                let loader = new GLTFLoader();
                loader.load('assets/londonmap.gltf', function(gltf){
                    scene.add(gltf.scene);

                })


            }


            function onWindowResize () {

                camera.aspect = window.innerWidth / window.innerHeight;
                camera.updateProjectionMatrix();
                renderer.setSize(window.innerWidth, window.innerHeight);
                }

                window.addEventListener('resize', onWindowResize, false);

            function animate () {

                requestAnimationFrame(animate);

                render();

            }

            function render() {

                renderer.render( scene, camera );

            }

            init ();
            animate();


       </script>
    </body>
</html>

DracoLoader如果只需要glTF资产与相同名称的压缩算法进行压缩。

HTTP 404 意味着无法从给定路径加载文件(在您的情况下assets/londonmap.gltf )。 因此,您必须确保资产实际存在于相应的目录中。

是的,强烈建议使用本地 Web 服务器。 特别是为了避免任何与安全相关的浏览器问题。 该项目实际上提供了一个关于这个主题的小指南: How to run things local

我遇到了同样的错误,我在本地使用了 IIS,我在配置中添加了“.gltf”。 在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM