webgl_loader_vrml.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - loaders - vrml 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 {
  25. color: #f00;
  26. font-weight: bold;
  27. text-decoration: underline;
  28. cursor: pointer
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <div id="info">
  34. <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> -
  35. vrml format loader test -
  36. <!--model from <a href="http://cs.iupui.edu/~aharris/webDesign/vrml/" target="_blank" rel="noopener">VRML 2.0 Tutorial</a>,-->
  37. </div>
  38. <script src="../build/three.js"></script>
  39. <script src="js/controls/OrbitControls.js"></script>
  40. <script src="js/loaders/VRMLLoader.js"></script>
  41. <script src="js/WebGL.js"></script>
  42. <script src="js/libs/stats.min.js"></script>
  43. <script>
  44. if ( WEBGL.isWebGLAvailable() === false ) {
  45. document.body.appendChild( WEBGL.getWebGLErrorMessage() );
  46. }
  47. var container, stats;
  48. var camera, controls, scene, renderer;
  49. init();
  50. animate();
  51. function init() {
  52. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.01, 1e10 );
  53. camera.position.z = 6;
  54. controls = new THREE.OrbitControls( camera );
  55. scene = new THREE.Scene();
  56. scene.add( camera );
  57. // light
  58. var dirLight = new THREE.DirectionalLight( 0xffffff );
  59. dirLight.position.set( 200, 200, 1000 ).normalize();
  60. camera.add( dirLight );
  61. camera.add( dirLight.target );
  62. var loader = new THREE.VRMLLoader();
  63. loader.load( 'models/vrml/house.wrl', function ( object ) {
  64. scene.add( object );
  65. } );
  66. // renderer
  67. renderer = new THREE.WebGLRenderer();
  68. renderer.setPixelRatio( window.devicePixelRatio );
  69. renderer.setSize( window.innerWidth, window.innerHeight );
  70. container = document.createElement( 'div' );
  71. document.body.appendChild( container );
  72. container.appendChild( renderer.domElement );
  73. stats = new Stats();
  74. container.appendChild( stats.dom );
  75. //
  76. window.addEventListener( 'resize', onWindowResize, false );
  77. }
  78. function onWindowResize() {
  79. camera.aspect = window.innerWidth / window.innerHeight;
  80. camera.updateProjectionMatrix();
  81. renderer.setSize( window.innerWidth, window.innerHeight );
  82. }
  83. function animate() {
  84. requestAnimationFrame( animate );
  85. renderer.render( scene, camera );
  86. stats.update();
  87. }
  88. </script>
  89. </body>
  90. </html>