I am testing how three.js works with 3d objects in a web page with a .obj file, I am using OBJLoader to load my obj file into the HTML view. I however cannot seem to get OBJLoader to work, I have tried different loaders as well but to no avail.
I am using Visual Studio Code and its extension called Live Server to host my local files.
I converted a .stl file with blender to a .obj file.
Here is the documentation I followed from three.js. (I haven't imported the objloader.js file yet because I don't understand how I am supposed to import it.) https://threejs.org/docs/#examples/en/loaders/OBJLoader
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Three.js APP</title>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<script src="js/three.js"></script>
<script>
const loader = new OBJLoader();
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 );
loader.load(
'models/car.obj',
function ( object ) {
scene.add( object );
},
function ( xhr ) {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
},
function ( error ) {
console.log( 'An error happened' );
}
);
</script>
</body>
</html>
imports rather than referencing JS files from script tags, but the usage in the code hasn't changed. - TheJim01