io_blender_colors.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>three.js - io - blender - vertex colors - webgl</title>
  5. <meta charset="utf-8">
  6. <style type="text/css">
  7. body {
  8. color: #eee;
  9. font-family:Monospace;
  10. font-size:13px;
  11. text-align:center;
  12. background-color: #000;
  13. margin: 0px;
  14. overflow: hidden;
  15. }
  16. #info {
  17. position: absolute;
  18. top: 0px; width: 100%;
  19. padding: 5px;
  20. }
  21. a {
  22. color: #0080ff;
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <div id="container"></div>
  28. <div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - vertex colors - blender export - webgl</div>
  29. <script type="text/javascript" src="../build/ThreeExtras.js"></script>
  30. <script type="text/javascript" src="js/Stats.js"></script>
  31. <script type="text/javascript">
  32. if ( ! THREE.Detector.webgl ) THREE.Detector.addGetWebGLMessage();
  33. var container, stats;
  34. var camera, scene, renderer;
  35. var mesh, mesh2, mesh3, light;
  36. var mouseX = 0, mouseY = 0;
  37. var windowHalfX = window.innerWidth / 2;
  38. var windowHalfY = window.innerHeight / 2;
  39. init();
  40. setInterval( loop, 1000 / 60 );
  41. function init() {
  42. container = document.getElementById( 'container' );
  43. camera = new THREE.Camera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
  44. camera.position.z = 1800;
  45. scene = new THREE.Scene();
  46. //scene.addLight( new THREE.AmbientLight( 0x333333 ) );
  47. light = new THREE.DirectionalLight( 0xffffff );
  48. light.position.set( 0, 0, 1 );
  49. light.position.normalize();
  50. scene.addLight( light );
  51. var loader = new THREE.Loader();
  52. loader.loadAscii( { model: "obj/cubecolors/cubecolors.js", callback: createScene } );
  53. renderer = new THREE.WebGLRenderer();
  54. renderer.setSize( window.innerWidth, window.innerHeight );
  55. container.appendChild( renderer.domElement );
  56. stats = new Stats();
  57. stats.domElement.style.position = 'absolute';
  58. stats.domElement.style.top = '0px';
  59. container.appendChild( stats.domElement );
  60. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  61. }
  62. function createScene( geometry ) {
  63. geometry.materials[0][0].shading = THREE.FlatShading;
  64. var material = [ new THREE.MeshFaceMaterial(),
  65. new THREE.MeshLambertMaterial( { color: 0xffffff, opacity:0.9, shading:THREE.FlatShading, wireframe: true, wireframe_linewidth: 2 } )
  66. ];
  67. mesh = SceneUtils.addMesh( scene, geometry, 250, 0, 0, 0, 0, 0, 0, material );
  68. }
  69. function onDocumentMouseMove( event ) {
  70. mouseX = ( event.clientX - windowHalfX );
  71. mouseY = ( event.clientY - windowHalfY );
  72. }
  73. function loop() {
  74. camera.position.x += ( mouseX - camera.position.x ) * 0.05;
  75. camera.position.y += ( - mouseY - camera.position.y ) * 0.05;
  76. if ( mesh ) {
  77. mesh.rotation.x += 0.01;
  78. mesh.rotation.y += 0.01;
  79. }
  80. renderer.render( scene, camera );
  81. stats.update();
  82. }
  83. </script>
  84. </body>
  85. </html>