You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
earthquake_3d_viewer_front/three/examples/webgl_loader_3ds.html

104 lines
2.5 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - loaders - 3DS 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> - 3DS loader
</div>
<script type="importmap">
{
"imports": {
"three": "../build/three.module.js",
"three/addons/": "./jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { TrackballControls } from 'three/addons/controls/TrackballControls.js';
import { TDSLoader } from 'three/addons/loaders/TDSLoader.js';
let container, controls;
let camera, scene, renderer;
init();
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 10 );
camera.position.z = 2;
scene = new THREE.Scene();
scene.add( new THREE.AmbientLight( 0xffffff, 3 ) );
const directionalLight = new THREE.DirectionalLight( 0xffeedd, 3 );
directionalLight.position.set( 0, 0, 2 );
scene.add( directionalLight );
//3ds files dont store normal maps
const normal = new THREE.TextureLoader().load( 'models/3ds/portalgun/textures/normal.jpg' );
const loader = new TDSLoader( );
loader.setResourcePath( 'models/3ds/portalgun/textures/' );
loader.load( 'models/3ds/portalgun/portalgun.3ds', function ( object ) {
object.traverse( function ( child ) {
if ( child.isMesh ) {
child.material.specular.setScalar( 0.1 );
child.material.normalMap = normal;
}
} );
scene.add( object );
} );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
container.appendChild( renderer.domElement );
controls = new TrackballControls( camera, renderer.domElement );
window.addEventListener( 'resize', resize );
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
controls.update();
renderer.render( scene, camera );
}
</script>
</body>
</html>