Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
"webgl_loader_mdd",
"webgl_loader_nrrd",
"webgl_loader_obj",
"webgl_loader_obj_mtl",
"webgl_loader_pcd",
"webgl_loader_pdb",
"webgl_loader_ply",
Expand Down
Binary file modified examples/screenshots/webgl_loader_obj.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed examples/screenshots/webgl_loader_obj_mtl.jpg
Binary file not shown.
71 changes: 20 additions & 51 deletions examples/webgl_loader_obj.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - loaders - OBJ loader</title>
<title>three.js webgl - loaders - OBJ/MTL loader</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link type="text/css" rel="stylesheet" href="main.css">
</head>

<body>
<div id="info">
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - OBJLoader test
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - OBJ/MTL loader
</div>

<script type="importmap">
Expand All @@ -25,16 +25,15 @@

import * as THREE from 'three';

import { MTLLoader } from 'three/addons/loaders/MTLLoader.js';
import { OBJLoader } from 'three/addons/loaders/OBJLoader.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

let camera, scene, renderer;

let object;
let camera, scene, renderer, controls;

init();

function init() {
async function init() {

camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 20 );
camera.position.z = 2.5;
Expand All @@ -50,67 +49,35 @@
camera.add( pointLight );
scene.add( camera );

// manager

function loadModel() {

object.traverse( function ( child ) {

if ( child.isMesh ) child.material.map = texture;

} );

object.position.y = - 0.95;
object.scale.setScalar( 0.01 );
scene.add( object );

render();

}

const manager = new THREE.LoadingManager( loadModel );

// texture

const textureLoader = new THREE.TextureLoader( manager );
const texture = textureLoader.load( 'textures/uv_grid_opengl.jpg', render );
texture.colorSpace = THREE.SRGBColorSpace;

// model

function onProgress( xhr ) {

if ( xhr.lengthComputable ) {

const percentComplete = xhr.loaded / xhr.total * 100;
console.log( 'model ' + percentComplete.toFixed( 2 ) + '% downloaded' );
const mtlLoader = new MTLLoader().setPath( 'models/obj/male02/' );
const materials = await mtlLoader.loadAsync( 'male02.mtl' );
materials.preload();

}
const objLoader = new OBJLoader().setPath( 'models/obj/male02/' );
objLoader.setMaterials( materials ); // optional since OBJ asstes can be loaded without an accompanying MTL file

}

function onError() {}

const loader = new OBJLoader( manager );
loader.load( 'models/obj/male02/male02.obj', function ( obj ) {
const object = await objLoader.loadAsync( 'male02.obj' );

object = obj;

}, onProgress, onError );
object.position.y = - 0.95;
object.scale.setScalar( 0.01 );
scene.add( object );

//

renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
document.body.appendChild( renderer.domElement );

//

const controls = new OrbitControls( camera, renderer.domElement );
controls = new OrbitControls( camera, renderer.domElement );
controls.enableDamping = true;
controls.minDistance = 2;
controls.maxDistance = 5;
controls.addEventListener( 'change', render );

//

Expand All @@ -127,7 +94,9 @@

}

function render() {
function animate() {

controls.update();

renderer.render( scene, camera );

Expand Down
125 changes: 0 additions & 125 deletions examples/webgl_loader_obj_mtl.html

This file was deleted.