My code can’t seem to load an object file of a 3d fist model:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie-edge">
<title>Trash Planet</title>
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/102/three.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.1.2/TweenMax.min.js"></script>
<script src="js/obj.js"></script>
<script src="js/mtl.js"></script>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,0.1,1000)
camera.position.z = 25;
var renderer = new THREE.WebGLRenderer({antialias: true, alpha: true});
renderer.setClearColor("#DDDDDD");
renderer.setSize(window.innerWidth,window.innerHeight);
document.body.appendChild(renderer.domElement);
window.addEventListener('resize', () => {
renderer.setSize(window.innerWidth,window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
})
var light = new THREE.PointLight(0xFFFFFF, 1.4, 1000)
light.position.set(0,15,15);
scene.add(light);
var ourObj;
var mtlLoader = new THREE.MTLLoader();
mtlLoader.load('fistmodel.mtl', function (materials) {
materials.preload();
var objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.load('fistmodel.obj', function (object) {
scene.add(object);
ourObj = object;
object.position.z -= 370;
object.rotation.x = 250;
});
});
var mtlLoader = new THREE.MTLLoader();
mtlLoader.load('fistmodel.mtl', function (materials) {
materials.preload();
var objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.load('fistmodel.obj', function (object) {
scene.add(object);
ourObj2 = object;
object.position.z -= 70;
object.rotation.x = 250;
});
});
var render = function() {
requestAnimationFrame(render);
ourObj.rotation.z -= .01;
ourObj2.rotation.z += .03;
renderer.render(scene, camera);
}
render();