webgl_loader_awd.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - collada</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: #000000;
  11. margin: 0px;
  12. overflow: hidden;
  13. }
  14. #info {
  15. color: #fff;
  16. position: absolute;
  17. top: 10px;
  18. width: 100%;
  19. text-align: center;
  20. z-index: 100;
  21. display:block;
  22. }
  23. a { color: skyblue }
  24. </style>
  25. </head>
  26. <body>
  27. <div id="info">
  28. <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> -
  29. simple AWD loader
  30. </div>
  31. <script src="../build/three.js"></script>
  32. <script src="js/loaders/AWDLoader.js"></script>
  33. <script src="js/controls/OrbitControls.js"></script>
  34. <script src="js/WebGL.js"></script>
  35. <script src="js/libs/stats.min.js"></script>
  36. <script>
  37. if ( WEBGL.isWebGLAvailable() === false ) {
  38. document.body.appendChild( WEBGL.getWebGLErrorMessage() );
  39. }
  40. var container, stats;
  41. var camera, scene, renderer;
  42. var pointLight;
  43. var trunk;
  44. var loader = new THREE.AWDLoader();
  45. loader.materialFactory = createMaterial;
  46. loader.load( './models/awd/simple/simple.awd', function ( _trunk ) {
  47. trunk = _trunk;
  48. init();
  49. render();
  50. } );
  51. function createMaterial() {
  52. // console.log( name );
  53. // var mat = new THREE.MeshPhongMaterial({
  54. // color: 0xaaaaaa,
  55. // shininess: 20
  56. // });
  57. // return mat;
  58. return null;
  59. }
  60. function init() {
  61. container = document.createElement( 'div' );
  62. document.body.appendChild( container );
  63. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
  64. camera.position.set( 70, 50, - 100 );
  65. var controls = new THREE.OrbitControls( camera );
  66. scene = new THREE.Scene();
  67. // Add the AWD SCENE
  68. scene.add( trunk );
  69. // Lights
  70. scene.add( new THREE.AmbientLight( 0x606060 ) );
  71. var directionalLight = new THREE.DirectionalLight( /*Math.random() * 0xffffff*/0xeeeeee );
  72. directionalLight.position.set( .2, - 1, .2 );
  73. directionalLight.position.normalize();
  74. scene.add( directionalLight );
  75. pointLight = new THREE.PointLight( 0xffffff, .6 );
  76. scene.add( pointLight );
  77. renderer = new THREE.WebGLRenderer();
  78. renderer.setPixelRatio( window.devicePixelRatio );
  79. renderer.setSize( window.innerWidth, window.innerHeight );
  80. container.appendChild( renderer.domElement );
  81. stats = new Stats();
  82. container.appendChild( stats.dom );
  83. //
  84. window.addEventListener( 'resize', onWindowResize, false );
  85. }
  86. function onWindowResize() {
  87. camera.aspect = window.innerWidth / window.innerHeight;
  88. camera.updateProjectionMatrix();
  89. renderer.setSize( window.innerWidth, window.innerHeight );
  90. }
  91. function render() {
  92. requestAnimationFrame( render );
  93. var timer = Date.now() * 0.0005;
  94. pointLight.position.x = Math.sin( timer * 4 ) * 3000;
  95. pointLight.position.y = 600;
  96. pointLight.position.z = Math.cos( timer * 4 ) * 3000;
  97. renderer.render( scene, camera );
  98. stats.update();
  99. }
  100. </script>
  101. </body>
  102. </html>