I am trying to render an stl with three js here is my code: index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My first three.js app</title>
<style>
body { margin: 0; }
</style>
</head>
<body>
<script src="./STLLoader.js"></script>
<script type="module" src="/main.js"></script>
</body>
</html>
main.js
import * as THREE from 'three';
const scene = new THREE.Scene();
scene.background = new THREE.Color( 0xff0000 );
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 );
const geometry = new THREE.BoxGeometry( 1, 1, 1 );
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
//const cube = new THREE.Mesh( geometry, material );
//scene.add( cube );
const loadObject = () => {
const loader = new STLLoader()
loader.load("./public/3dbenchy.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)
})
}
camera.position.z = 5;
function animate() {
requestAnimationFrame( animate );
//cube.rotation.x += 0.01;
//cube.rotation.y += 0.01;
renderer.render( scene, camera );
}
animate();
I tried to import the package in multiple different ways, but none of them rendered anything. I have also tried multiple different 3-D models but none of them worked either.