I am just learning THREE.js, and have a gltf file that I want to load into a file.
Here is my html file:
<html>
<head>
<title>Liftoff!!</title>
<style>
body { margin: 0; }
canvas { display: block; }
</style>
</head>
<body>
<script type="module">
import { GLTFLoader } from 'file:///Users/name/Desktop/three.js-practice/node_modules/three/examples/jsm/loaders/GLTFLoader.js';
import * as THREE from "file:///Users/name/Desktop/three.js-practice/node_modules/three/build/three.js"
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var loader = new GLTFLoader.GLTFLoader();
loader.load( 'gltf.html', function (gltf) {
scene.add( gltf.scene )
}, undefined, function ( error ) {
console.error( error )
} )
</script>
</body>
</html>
I am opening my file in google chrome, and when I open it, it doesn't work, and the JavaScript console returns this error:
"gltf.html:1 Access to script at 'file:///Users/isaac/Desktop/three.js-practice/node_modules/three/examples/jsm/loaders/GLTFLoader.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
GLTFLoader.js:1 Failed to load resource: net::ERR_FAILED
gltf.html:1 Access to script at 'file:///Users/isaac/Desktop/three.js-practice/node_modules/three/build/three.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
three.js:1 Failed to load resource: net::ERR_FAILED"
I have tried to do this in localhost, but that also doesn't work.