123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgl - 3MF</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">
- <style>
- body {
- background-color: #a0a0a0;
- }
- </style>
- </head>
- <body>
- <div id="info">
- <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> -
- <a href="http://3mf.io" target="_blank" rel="noopener">3MF</a> file with materials
- </div>
- <script src="js/libs/jszip.min.js"></script>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- import { OrbitControls } from './jsm/controls/OrbitControls.js';
- import { ThreeMFLoader } from './jsm/loaders/3MFLoader.js';
- var camera, scene, renderer;
- init();
- function init() {
- scene = new THREE.Scene();
- scene.background = new THREE.Color( 0xa0a0a0 );
- scene.fog = new THREE.Fog( 0xa0a0a0, 10, 500 );
- camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 1, 500 );
- camera.position.set( - 50, 40, 50 );
- scene.add( camera );
- //
- var hemiLight = new THREE.HemisphereLight( 0xffffff, 0x444444 );
- hemiLight.position.set( 0, 100, 0 );
- scene.add( hemiLight );
- var dirLight = new THREE.DirectionalLight( 0xffffff );
- dirLight.position.set( - 0, 40, 50 );
- dirLight.castShadow = true;
- dirLight.shadow.camera.top = 50;
- dirLight.shadow.camera.bottom = - 25;
- dirLight.shadow.camera.left = - 25;
- dirLight.shadow.camera.right = 25;
- dirLight.shadow.camera.near = 0.1;
- dirLight.shadow.camera.far = 200;
- dirLight.shadow.mapSize.set( 1024, 1024 );
- scene.add( dirLight );
- // scene.add( new CameraHelper( dirLight.shadow.camera ) );
- //
- var manager = new THREE.LoadingManager();
- var loader = new ThreeMFLoader( manager );
- loader.load( './models/3mf/truck.3mf', function ( object ) {
- object.quaternion.setFromEuler( new THREE.Euler( - Math.PI / 2, 0, 0 ) ); // z-up conversion
- object.traverse( function ( child ) {
- child.castShadow = true;
- } );
- scene.add( object );
- } );
- //
- manager.onLoad = function () {
- render();
- };
- //
- var ground = new THREE.Mesh( new THREE.PlaneBufferGeometry( 1000, 1000 ), new THREE.MeshPhongMaterial( { color: 0x999999, depthWrite: false } ) );
- ground.rotation.x = - Math.PI / 2;
- ground.position.y = 11;
- ground.receiveShadow = true;
- scene.add( ground );
- //
- renderer = new THREE.WebGLRenderer( { antialias: true } );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- renderer.outputEncoding = THREE.sRGBEncoding;
- renderer.shadowMap.enabled = true;
- renderer.shadowMap.type = THREE.PCFSoftShadowMap;
- document.body.appendChild( renderer.domElement );
- //
- var controls = new OrbitControls( camera, renderer.domElement );
- controls.addEventListener( 'change', render );
- controls.minDistance = 50;
- controls.maxDistance = 200;
- controls.enablePan = false;
- controls.target.set( 0, 20, 0 );
- controls.update();
- window.addEventListener( 'resize', onWindowResize, false );
- render();
- }
- function onWindowResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- render();
- }
- function render() {
- renderer.render( scene, camera );
- }
- </script>
- </body>
- </html>
|