webgl_loader_vtk.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - loaders - vtk loader</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <style>
  8. body {
  9. font-family: Monospace;
  10. background-color: #000;
  11. color: #fff;
  12. margin: 0px;
  13. overflow: hidden;
  14. }
  15. #info {
  16. color: #fff;
  17. position: absolute;
  18. top: 10px;
  19. width: 100%;
  20. text-align: center;
  21. z-index: 100;
  22. display:block;
  23. }
  24. #info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
  25. </style>
  26. </head>
  27. <body>
  28. <div id="info">
  29. <a href="http://threejs.org" target="_blank">three.js</a> -
  30. vtk format loader test -
  31. model from <a href="http://www.cc.gatech.edu/projects/large_models/" target="_blank">The GeorgiaTech Lagre Geometric Model Archive</a>,
  32. </div>
  33. <script src="../build/three.min.js"></script>
  34. <script src="js/controls/TrackballControls.js"></script>
  35. <script src="js/loaders/VTKLoader.js"></script>
  36. <script src="js/Detector.js"></script>
  37. <script src="js/libs/stats.min.js"></script>
  38. <script>
  39. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  40. var container, stats;
  41. var camera, controls, scene, renderer, material;
  42. var cross;
  43. init();
  44. animate();
  45. function init() {
  46. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.01, 1e10 );
  47. camera.position.z = 0.2;
  48. controls = new THREE.TrackballControls( camera );
  49. controls.rotateSpeed = 5.0;
  50. controls.zoomSpeed = 5;
  51. controls.panSpeed = 2;
  52. controls.noZoom = false;
  53. controls.noPan = false;
  54. controls.staticMoving = true;
  55. controls.dynamicDampingFactor = 0.3;
  56. scene = new THREE.Scene();
  57. scene.add( camera );
  58. // light
  59. var dirLight = new THREE.DirectionalLight( 0xffffff );
  60. dirLight.position.set( 200, 200, 1000 ).normalize();
  61. camera.add( dirLight );
  62. camera.add( dirLight.target );
  63. var path = "textures/cube/pisa/";
  64. var format = '.png';
  65. var urls = [
  66. path + 'px' + format, path + 'nx' + format,
  67. path + 'py' + format, path + 'ny' + format,
  68. path + 'pz' + format, path + 'nz' + format
  69. ];
  70. var reflectionCube = THREE.ImageUtils.loadTextureCube( urls );
  71. reflectionCube.format = THREE.RGBFormat;
  72. var diffuseColor = new THREE.Color( 1, 1, 1 );
  73. material = new THREE.MeshPhysicalMaterial( { color: diffuseColor, metalness: 1.0, roughness: 0.2, shading: THREE.SmoothShading, envMap: reflectionCube } );
  74. var loader = new THREE.VTKLoader();
  75. loader.load( "models/vtk/bunny.vtk", function ( geometry ) {
  76. geometry.computeVertexNormals();
  77. var mesh = new THREE.Mesh( geometry, material );
  78. mesh.position.setY( - 0.09 );
  79. scene.add( mesh );
  80. } );
  81. // renderer
  82. renderer = new THREE.WebGLRenderer( { antialias: false } );
  83. renderer.setPixelRatio( window.devicePixelRatio );
  84. renderer.setSize( window.innerWidth, window.innerHeight );
  85. container = document.createElement( 'div' );
  86. document.body.appendChild( container );
  87. container.appendChild( renderer.domElement );
  88. stats = new Stats();
  89. stats.domElement.style.position = 'absolute';
  90. stats.domElement.style.top = '0px';
  91. container.appendChild( stats.domElement );
  92. //
  93. window.addEventListener( 'resize', onWindowResize, false );
  94. }
  95. function onWindowResize() {
  96. camera.aspect = window.innerWidth / window.innerHeight;
  97. camera.updateProjectionMatrix();
  98. renderer.setSize( window.innerWidth, window.innerHeight );
  99. controls.handleResize();
  100. }
  101. function animate() {
  102. requestAnimationFrame( animate );
  103. var timer = Date.now() * 0.001;
  104. if( material ) {
  105. material.roughness = Math.cos( timer ) * 0.5 + 0.5;
  106. material.needsUpdate = true;
  107. }
  108. controls.update();
  109. renderer.render( scene, camera );
  110. stats.update();
  111. }
  112. </script>
  113. </body>
  114. </html>