@Jacon

Как исправить ошибку CORS в GLTFLoader???

Вот файл index.html:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    

    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r123/three.min.js"></script>
    <script src="https://cdn.rawgit.com/mrdoob/three.js/master/examples/js/loaders/GLTFLoader.js"></script>
    <script>
        scene = new THREE.Scene();
        camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
        camera.position.z = 10;

        renderer = new THREE.WebGLRenderer({alpha: true, antialias: true});
        renderer.setClearColor(0x000000, 0);
        renderer.setSize(1280, 720);

        renderer.domElement.setAttribute("id", "Minecraft3DObj");
        document.head.insertBefore(renderer.domElement, document.head.firstChild);

        const aLight = new THREE.AmbientLight(0x404040, 1.2);
        scene.add(aLight);

        const pLight = new THREE.PointLight(0xFFFFFF, 1.2);
        pLight.position.set(0, -3, 7);
        scene.add(pLight);

        const helper = new THREE.PointLightHelper(pLight);
        scene.add(helper);


        let loader = new THREE.GLTFLoader();
        let obj = null;

        loader.load('/minecraft_diamond-pickaxe/scene.gltf', function(gltf) {
            obj = gltf;
            obj.scene.scale.set(1.3, 1.3, 1.3);

            scene.add(obj.scene);
        });

        function animate() {
            requestAnimationFrame(animate);

            if(obj)
                obj.scene.rotation.y += 0.03;
            renderer.render(scene, camera);
        }
        animate();

    </script>
</head>
<body>

</body>
</html>

Вот ошибка: Access to XMLHttpRequest at 'file:///C:/minecraft_diamond-pickaxe/scene.gltf' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.
Заранее спасибо всем.
  • Вопрос задан
  • 166 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы