Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
100
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - blender -json</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. background:#777;
  10. padding:0;
  11. margin:0;
  12. font-weight: bold;
  13. overflow:hidden;
  14. }
  15.  
  16. #info {
  17. position: absolute;
  18. top: 0px;
  19. width: 100%;
  20. color: #ffffff;
  21. padding: 5px;
  22. font-family:Monospace;
  23. font-size:13px;
  24. text-align:center;
  25. }
  26.  
  27. a {
  28. color: #ffffff;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33.  
  34. <div id="container"></div>
  35. <div id="info">
  36. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> -
  37. monster by <a href="http://www.3drt.com/downloads.htm" target="_blank" rel="noopener">3drt</a>
  38. </div>
  39.  
  40. <script src="build/three.js"></script>
  41. <script src="js/controls/OrbitControls.js"></script>
  42. <script src="js/Detector.js"></script>
  43. <script src="js/libs/stats.min.js"></script>
  44.  
  45. <script>
  46.  
  47. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  48.  
  49. var container, stats, clock;
  50. var camera, scene, renderer, objects, controls;
  51. var mixer = null;
  52. var action = {};
  53. var dragon = null;
  54. var skeleton = null;
  55. init();
  56. animate();
  57.  
  58. function init() {
  59.  
  60. container = document.getElementById( 'container' );
  61.  
  62. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 2000 );
  63. camera.position.set( 2, 4, 5 );
  64.  
  65. clock = new THREE.Clock();
  66.  
  67. scene = new THREE.Scene();
  68. scene.background = new THREE.Color( 0xdddddd );
  69.  
  70.  
  71. // grid
  72. var gridHelper = new THREE.GridHelper( 28, 28, 0x303030, 0x303030 );
  73. gridHelper.position.set( 0, - 0.04, 0 );
  74. scene.add( gridHelper );
  75.  
  76. //mixer = new THREE.AnimationMixer( scene );
  77.  
  78.  
  79. var loader = new THREE.JSONLoader();
  80.  
  81. loader.load('models/json/dragon.json', function (geometry, materials ) {
  82.  
  83.  
  84.  
  85.  
  86.  
  87. dragon = new THREE.Mesh( geometry, materials );
  88. scene.add(dragon);
  89.  
  90. skeleton = new THREE.SkeletonHelper( dragon );
  91. skeleton.visible = true;
  92. scene.add( skeleton );
  93.  
  94. console.log(dragon);
  95. mixer = new THREE.AnimationMixer( dragon );
  96. var action = mixer.clipAction( 'Flying' );
  97. console.log(action);
  98. action.play();
  99. });
  100.  
  101.  
  102.  
  103.  
  104. // lights
  105.  
  106. var ambientLight = new THREE.AmbientLight( 0xffffff );
  107. scene.add( ambientLight );
  108.  
  109.  
  110. var geometry = new THREE.BoxGeometry( 200, 0, 200 );
  111. var material = new THREE.MeshPhongMaterial( { color: 0xffffff } );
  112. var cube = new THREE.Mesh( geometry, material );
  113. scene.add( cube );
  114.  
  115. light = new THREE.DirectionalLight( 0xffffff, 0.8 );
  116. light.position.set( -80, 80, 80 );
  117. scene.add(light);
  118.  
  119. // renderer
  120.  
  121. renderer = new THREE.WebGLRenderer();
  122. renderer.setPixelRatio( window.devicePixelRatio );
  123. renderer.setSize( window.innerWidth, window.innerHeight );
  124. container.appendChild( renderer.domElement );
  125.  
  126. // stats
  127.  
  128. stats = new Stats();
  129. container.appendChild( stats.dom );
  130.  
  131. // events
  132.  
  133. window.addEventListener( 'resize', onWindowResize, false );
  134.  
  135. // controls, camera
  136. controls = new THREE.OrbitControls( camera, renderer.domElement );
  137. controls.target.set( 0, 12, 0 );
  138. camera.position.set( 2, 18, 28 );
  139. controls.update();
  140.  
  141. }
  142.  
  143. //
  144.  
  145. function onWindowResize( event ) {
  146.  
  147. renderer.setSize( window.innerWidth, window.innerHeight );
  148.  
  149. camera.aspect = window.innerWidth / window.innerHeight;
  150. camera.updateProjectionMatrix();
  151.  
  152. }
  153.  
  154. //
  155.  
  156. function animate() {
  157.  
  158. requestAnimationFrame( animate );
  159.  
  160. render();
  161. stats.update();
  162.  
  163. }
  164.  
  165. function render() {
  166.  
  167. var timer = Date.now() * 0.0005;
  168. var delta = clock.getDelta();
  169. if(mixer)mixer.update(delta);
  170.  
  171. controls.update();
  172. renderer.render( scene, camera );
  173.  
  174. }
  175.  
  176. </script>
  177. </body>
  178. </html>
Advertisement
RAW Paste Data Copied
Advertisement