webgl_loader_awd.html 3.1 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">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/Detector.js"></script>
  35. <script src="js/libs/stats.min.js"></script>
  36. <script>
  37. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  38. var container, stats;
  39. var camera, scene, renderer, objects, controls;
  40. var particleLight, pointLight;
  41. var trunk;
  42. var loader = new THREE.AWDLoader();
  43. loader.materialFactory = createMaterial;
  44. loader.load( './models/awd/simple/simple.awd', function ( _trunk ) {
  45. trunk = _trunk;
  46. init();
  47. render();
  48. } );
  49. function createMaterial( name ){
  50. // console.log( name );
  51. // var mat = new THREE.MeshPhongMaterial({
  52. // color: 0xaaaaaa,
  53. // shininess: 20
  54. // });
  55. // return mat;
  56. return null;
  57. }
  58. function init() {
  59. container = document.createElement( 'div' );
  60. document.body.appendChild( container );
  61. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
  62. camera.position.set( 70, 50, -100 );
  63. controls = new THREE.OrbitControls( camera );
  64. scene = new THREE.Scene();
  65. // Add the AWD SCENE
  66. scene.add( trunk );
  67. // Lights
  68. scene.add( new THREE.AmbientLight( 0x606060 ) );
  69. var directionalLight = new THREE.DirectionalLight(/*Math.random() * 0xffffff*/0xeeeeee );
  70. directionalLight.position.set( .2, -1, .2 );
  71. directionalLight.position.normalize();
  72. scene.add( directionalLight );
  73. pointLight = new THREE.PointLight( 0xffffff, .6 );
  74. scene.add( pointLight );
  75. renderer = new THREE.WebGLRenderer();
  76. renderer.setPixelRatio( window.devicePixelRatio );
  77. renderer.setSize( window.innerWidth, window.innerHeight );
  78. container.appendChild( renderer.domElement );
  79. stats = new Stats();
  80. container.appendChild( stats.dom );
  81. //
  82. window.addEventListener( 'resize', onWindowResize, false );
  83. }
  84. function onWindowResize() {
  85. camera.aspect = window.innerWidth / window.innerHeight;
  86. camera.updateProjectionMatrix();
  87. renderer.setSize( window.innerWidth, window.innerHeight );
  88. }
  89. function render() {
  90. requestAnimationFrame( render );
  91. var timer = Date.now() * 0.0005;
  92. pointLight.position.x = Math.sin( timer * 4 ) * 3000;
  93. pointLight.position.y = 600;
  94. pointLight.position.z = Math.cos( timer * 4 ) * 3000;
  95. renderer.render( scene, camera );
  96. stats.update();
  97. }
  98. </script>
  99. </body>
  100. </html>