After deciding to have some fun by creating an STL loader, I've hit a roadblock. Despite trying various solutions found online, I'm still facing issues, mainly due to CDN errors. Currently, I'm following the tutorial on the Three.js site and also referencing this guide.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>STL</title>
<style>
body { margin: 0; }
</style>
</head>
<body>
<script async src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1772643a7a7873627b723a647f7e7a64572639213924">[email protected]</a>/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="45312d37202005756b7470716b75">[email protected]</a>/build/three.module.js",
"stl-loader": "https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0271766e2f6e6d6366677042332c322c32">[email protected]</a>/STLLoader.min.js",
"three/addons/": "https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9febf7edfafadfafb1aeaaabb1af">[email protected]</a>/examples/jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { STLLoader } from 'stl-loader';
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
scene.background = new THREE.Color('#cc0000');
const loadObject = () => {
const loader = new STLLoader()
loader.load("stl_file.stl", function (geometry) {
group = new THREE.Group()
scene.add(group)
const material = new THREE.MeshPhongMaterial({ color: 0xaaaaaa, specular: 0x111111, shininess: 200 })
mesh = new THREE.Mesh(geometry, material)
mesh.position.set(0, 0, 0)
mesh.scale.set(10, 10, 10)
mesh.castShadow = true
mesh.receiveShadow = true
geometry.center()
group.add(mesh)
})
}
loadObject();
camera.position.z = 5;
renderer.render( scene, camera );
</script>
</body>
</html>
The majority of the code was sourced from here, as mentioned earlier. However, upon checking the console, I encountered this error message:
Uncaught SyntaxError: The requested module 'stl-loader' does not provide an export named 'STLLoader'
. This issue is just one of several that I need to address...