123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <!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: #333;
- }
- </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 File format</a>
- <div>3MF loader test by <a href="https://github.com/technohippy" target="_blank" rel="noopener">technohippy</a></div>
- <div>Cube gears file from <a href="https://github.com/3MFConsortium/3mf-samples" target="_blank" rel="noopener">3mf-samples</a></div>
- </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() {
- renderer = new THREE.WebGLRenderer( { antialias: true } );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- document.body.appendChild( renderer.domElement );
- scene = new THREE.Scene();
- scene.background = new THREE.Color( 0x333333 );
- scene.add( new THREE.AmbientLight( 0xffffff, 0.2 ) );
- camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 1, 500 );
- // Z is up for objects intended to be 3D printed.
- camera.up.set( 0, 0, 1 );
- camera.position.set( - 80, - 90, 150 );
- scene.add( camera );
- var controls = new OrbitControls( camera, renderer.domElement );
- controls.addEventListener( 'change', render );
- controls.minDistance = 50;
- controls.maxDistance = 300;
- controls.enablePan = false;
- controls.target.set( 80, 65, 20 );
- controls.update();
- var pointLight = new THREE.PointLight( 0xffffff, 0.8 );
- camera.add( pointLight );
- var loader = new ThreeMFLoader();
- loader.load( './models/3mf/cube_gears.3mf', function ( object ) {
- scene.add( object );
- render();
- } );
- window.addEventListener( 'resize', onWindowResize, false );
- }
- 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>
|