123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgl - loaders - vtk 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> -
- vtk formats loader test<br />
- Legacy vtk model from <a href="http://www.cc.gatech.edu/projects/large_models/" target="_blank" rel="noopener">The GeorgiaTech Lagre Geometric Model Archive</a>
- </div>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- import Stats from './jsm/libs/stats.module.js';
- import { TrackballControls } from './jsm/controls/TrackballControls.js';
- import { VTKLoader } from './jsm/loaders/VTKLoader.js';
- var container, stats;
- var camera, controls, scene, renderer;
- init();
- animate();
- function init() {
- camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.01, 1e10 );
- camera.position.z = 0.2;
- scene = new THREE.Scene();
- scene.add( camera );
- // light
- var dirLight = new THREE.DirectionalLight( 0xffffff );
- dirLight.position.set( 200, 200, 1000 ).normalize();
- camera.add( dirLight );
- camera.add( dirLight.target );
- var material = new THREE.MeshLambertMaterial( { color: 0xffffff, side: THREE.DoubleSide } );
- var loader = new VTKLoader();
- loader.load( "models/vtk/bunny.vtk", function ( geometry ) {
- geometry.center();
- geometry.computeVertexNormals();
- var mesh = new THREE.Mesh( geometry, material );
- mesh.position.set( - 0.075, 0.005, 0 );
- mesh.scale.multiplyScalar( 0.2 );
- scene.add( mesh );
- } );
- var loader1 = new VTKLoader();
- loader1.load( 'models/vtk/cube_ascii.vtp', function ( geometry ) {
- geometry.computeVertexNormals();
- geometry.center();
- var material = new THREE.MeshLambertMaterial( { color: 0x00ff00, side: THREE.DoubleSide } );
- var mesh = new THREE.Mesh( geometry, material );
- mesh.position.set( - 0.025, 0, 0 );
- mesh.scale.multiplyScalar( 0.01 );
- scene.add( mesh );
- } );
- var loader2 = new VTKLoader();
- loader2.load( 'models/vtk/cube_binary.vtp', function ( geometry ) {
- geometry.computeVertexNormals();
- geometry.center();
- var material = new THREE.MeshLambertMaterial( { color: 0x0000ff, side: THREE.DoubleSide } );
- var mesh = new THREE.Mesh( geometry, material );
- mesh.position.set( 0.025, 0, 0 );
- mesh.scale.multiplyScalar( 0.01 );
- scene.add( mesh );
- } );
- var loader3 = new VTKLoader();
- loader3.load( 'models/vtk/cube_no_compression.vtp', function ( geometry ) {
- geometry.computeVertexNormals();
- geometry.center();
- var material = new THREE.MeshLambertMaterial( { color: 0xff0000, side: THREE.DoubleSide } );
- var mesh = new THREE.Mesh( geometry, material );
- mesh.position.set( 0.075, 0, 0 );
- mesh.scale.multiplyScalar( 0.01 );
- scene.add( mesh );
- } );
- // renderer
- renderer = new THREE.WebGLRenderer();
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- container = document.createElement( 'div' );
- document.body.appendChild( container );
- container.appendChild( renderer.domElement );
- // controls
- controls = new TrackballControls( camera, renderer.domElement );
- controls.rotateSpeed = 5.0;
- controls.zoomSpeed = 5;
- controls.panSpeed = 2;
- controls.staticMoving = true;
- stats = new Stats();
- container.appendChild( stats.dom );
- //
- window.addEventListener( 'resize', onWindowResize, false );
- }
- function onWindowResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- controls.handleResize();
- }
- function animate() {
- requestAnimationFrame( animate );
- controls.update();
- renderer.render( scene, camera );
- stats.update();
- }
- </script>
- </body>
- </html>
|