webgl_loader_xml_vtk.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. <script src="../build/three.min.js"></script>
  7. <script src="js/controls/OrbitControls.js"></script>
  8. <script src='js/libs/inflate.min.js'></script>
  9. <script src="js/loaders/VTKLoader.js"></script>
  10. <script src="js/Detector.js"></script>
  11. <script src="js/libs/stats.min.js"></script>
  12. <style>
  13. body {
  14. font-family: Monospace;
  15. background-color: #000000;
  16. margin: 0px;
  17. overflow: hidden;
  18. }
  19. #info {
  20. color: #fff;
  21. position: absolute;
  22. top: 10px;
  23. width: 100%;
  24. text-align: center;
  25. z-index: 100;
  26. display:block;
  27. }
  28. a { color: skyblue }
  29. .button { background:#999; color:#eee; padding:0.2em 0.5em; cursor:pointer }
  30. .highlight { background:orange; color:#fff; }
  31. span {
  32. display: inline-block;
  33. width: 60px;
  34. float: left;
  35. text-align: center;
  36. }
  37. </style>
  38. </head>
  39. <body>
  40. <script>
  41. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  42. var container, stats, camera, cameraTarget, scene, renderer, controls;
  43. init();
  44. animate();
  45. function init() {
  46. scene = new THREE.Scene();
  47. scene.fog = new THREE.FogExp2( 0x2d2d2d, 0.002 );
  48. // renderer
  49. renderer = new THREE.WebGLRenderer( { antialias: false } );
  50. renderer.setClearColor( scene.fog.color );
  51. renderer.setPixelRatio( window.devicePixelRatio );
  52. renderer.setSize( window.innerWidth, window.innerHeight );
  53. container = document.createElement( 'div' );
  54. document.body.appendChild(container);
  55. container.appendChild( renderer.domElement );
  56. camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 1, 15 );
  57. camera.position.set( 1, 1, 1 );
  58. controls = new THREE.OrbitControls( camera, renderer.domElement );
  59. controls.enableDamping = true;
  60. controls.dampingFactor = 0.25;
  61. controls.enableZoom = true;
  62. // vtk file
  63. var loader = new THREE.VTKLoader();
  64. loader.load( 'models/vtk/cube_ascii.vtp', function ( geometry ) {
  65. //geometry.mergeVertices();
  66. geometry.computeFaceNormals();
  67. geometry.computeVertexNormals();
  68. //geometry.center();
  69. var material = new THREE.MeshLambertMaterial( { color: 0x00ff00 } );
  70. var mesh = new THREE.Mesh( geometry, material );
  71. mesh.position.set(0,0,0);
  72. mesh.rotation.set(Math.PI/2,0,0);
  73. mesh.scale.multiplyScalar( 0.1 );
  74. mesh.updateMatrix();
  75. mesh.matrixAutoUpdate = false;
  76. scene.add( mesh );
  77. });
  78. loader.load( 'models/vtk/cube_binary.vtp', function ( geometry1 ) {
  79. //geometry.mergeVertices();
  80. geometry1.computeFaceNormals();
  81. geometry1.computeVertexNormals();
  82. //geometry.center();
  83. var material1 = new THREE.MeshLambertMaterial( { color: 0x0000ff } );
  84. var mesh1 = new THREE.Mesh( geometry1, material1 );
  85. mesh1.position.set(0.5,0,0);
  86. mesh1.rotation.set(Math.PI/2,0,0);
  87. mesh1.scale.multiplyScalar( 0.1 );
  88. mesh1.updateMatrix();
  89. mesh1.matrixAutoUpdate = false;
  90. scene.add( mesh1 );
  91. });
  92. loader.load( 'models/vtk/cube_no_compression.vtp', function ( geometry2 ) {
  93. //geometry.mergeVertices();
  94. geometry2.computeFaceNormals();
  95. geometry2.computeVertexNormals();
  96. //geometry.center();
  97. var material2 = new THREE.MeshLambertMaterial( { color: 0xff0000 } );
  98. var mesh2 = new THREE.Mesh( geometry2, material2 );
  99. mesh2.position.set(-0.5,0,0);
  100. mesh2.scale.multiplyScalar( 0.1 );
  101. mesh2.matrixAutoUpdate = true;
  102. scene.add( mesh2 );
  103. });
  104. // Lights
  105. light = new THREE.DirectionalLight( 0xffffff );
  106. light.position.set( 5, 5, 5 );
  107. scene.add( light );
  108. light = new THREE.DirectionalLight( 0xffffff );
  109. light.position.set( -5, -5, -5 );
  110. scene.add( light );
  111. light = new THREE.AmbientLight( 0x222222 );
  112. scene.add( light );
  113. // stats
  114. stats = new Stats();
  115. stats.domElement.style.position = 'absolute';
  116. stats.domElement.style.top = '0px';
  117. stats.domElement.style.zIndex = 100;
  118. container.appendChild( stats.domElement );
  119. // resize
  120. window.addEventListener( 'resize', onWindowResize, false );
  121. }
  122. function onWindowResize() {
  123. camera.aspect = window.innerWidth / window.innerHeight;
  124. camera.updateProjectionMatrix();
  125. renderer.setSize( window.innerWidth, window.innerHeight );
  126. }
  127. function animate() {
  128. requestAnimationFrame( animate );
  129. stats.update();
  130. controls.update();
  131. render();
  132. }
  133. function render() {
  134. renderer.render( scene, camera );
  135. }
  136. </script>
  137. </body>
  138. </html>