123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgl - LWO 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> - LWOLoader
- <P>Lightwave Object loader by <a href="https://discoverthreejs.com/" target="_blank" rel="noopener">Discover three.js</a></P>
- Models by <a href="https://onthez.com/" target="_blank" rel="noopener">on the z</a> - Environment images by <a href="https://hdrihaven.com/" target="_blank" rel="noopener">HDRI Haven</a>
- </div>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- import { OrbitControls } from './jsm/controls/OrbitControls.js';
- import { LWOLoader } from './jsm/loaders/LWOLoader.js';
- var container, controls;
- var camera, scene, renderer;
- function init() {
- container = document.createElement( 'div' );
- document.body.appendChild( container );
- camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 200 );
- camera.position.set( - 0.7, 14.6, 43.2 );
- scene = new THREE.Scene();
- scene.background = new THREE.Color( 0xa0a0a0 );
- var ambientLight = new THREE.AmbientLight( 0xaaaaaa, 1.75 );
- scene.add( ambientLight );
- var light = new THREE.DirectionalLight( 0xffffff, 1 );
- light.position.set( 0, 200, 100 );
- light.castShadow = true;
- light.shadow.camera.top = 180;
- light.shadow.camera.bottom = - 100;
- light.shadow.camera.left = - 120;
- light.shadow.camera.right = 120;
- scene.add( light );
- light = new THREE.DirectionalLight( 0xffffff, 0.7 );
- light.position.set( - 100, 200, - 100 );
- scene.add( light );
- light = new THREE.DirectionalLight( 0xffffff, 0.4 );
- light.position.set( 100, - 200, 100 );
- scene.add( light );
- light = new THREE.DirectionalLight( 0xffffff, 1 );
- light.position.set( - 100, - 100, 100 );
- scene.add( light );
- var grid = new THREE.GridHelper( 200, 20, 0x000000, 0x000000 );
- grid.material.opacity = 0.3;
- grid.material.transparent = true;
- scene.add( grid );
- var loader = new LWOLoader();
- loader.load( 'models/lwo/Objects/LWO3/Demo.lwo', function ( object ) {
- var phong = object.meshes[ 0 ];
- phong.position.set( - 2, 12, 0 );
- var standard = object.meshes[ 1 ];
- standard.position.set( 2, 12, 0 );
- var rocket = object.meshes[ 2 ];
- rocket.position.set( 0, 10.5, - 1 );
- scene.add( phong, standard, rocket );
- } );
- renderer = new THREE.WebGLRenderer( { antialias: true, alpha: true } );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- renderer.shadowMap.enabled = true;
- renderer.physicallyCorrectLights = true;
- renderer.gammaFactor = 1.18;
- renderer.outputEncoding = THREE.sRGBEncoding;
- container.appendChild( renderer.domElement );
- controls = new OrbitControls( camera, renderer.domElement );
- controls.target.set( 1.33, 10, - 6.7 );
- controls.update();
- renderer.setAnimationLoop( function () {
- renderer.render( scene, camera );
- } );
- window.addEventListener( 'resize', onWindowResize, false );
- }
- function onWindowResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- }
- init();
- </script>
- </body>
- </html>
|