webgl_geometry_colors_blender.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - io blender - vertex colors</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. color: #eee;
  10. font-family:Monospace;
  11. font-size:13px;
  12. text-align:center;
  13. background-color: #000;
  14. margin: 0px;
  15. padding: 0px;
  16. overflow: hidden;
  17. }
  18. #info {
  19. position: absolute;
  20. top: 0px; width: 100%;
  21. padding: 5px;
  22. }
  23. a {
  24. color: #0080ff;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <div id="container"></div>
  30. <div id="info"><a href="http://threejs.org" target="_blank">three.js</a> webgl - io blender - vertex colors</div>
  31. <script src="../build/three.min.js"></script>
  32. <script src="js/Detector.js"></script>
  33. <script src="js/libs/stats.min.js"></script>
  34. <script>
  35. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  36. var container, stats;
  37. var camera, scene, renderer;
  38. var mesh, mesh2, mesh3, light;
  39. var mouseX = 0, mouseY = 0;
  40. var windowHalfX = window.innerWidth / 2;
  41. var windowHalfY = window.innerHeight / 2;
  42. init();
  43. animate();
  44. function init() {
  45. container = document.getElementById( 'container' );
  46. camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
  47. camera.position.z = 1800;
  48. scene = new THREE.Scene();
  49. light = new THREE.DirectionalLight( 0xffffff );
  50. light.position.set( 0, 0, 1 ).normalize();
  51. scene.add( light );
  52. var loader = new THREE.JSONLoader();
  53. loader.load( "obj/cubecolors/cubecolors.js", createScene1 );
  54. loader.load( "obj/cubecolors/cube_fvc.js", createScene2 );
  55. renderer = new THREE.WebGLRenderer( { antialias: true } );
  56. renderer.setPixelRatio( window.devicePixelRatio );
  57. renderer.setSize( window.innerWidth, window.innerHeight );
  58. container.appendChild( renderer.domElement );
  59. stats = new Stats();
  60. stats.domElement.style.position = 'absolute';
  61. stats.domElement.style.top = '0px';
  62. container.appendChild( stats.domElement );
  63. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  64. //
  65. window.addEventListener( 'resize', onWindowResize, false );
  66. }
  67. function onWindowResize() {
  68. windowHalfX = window.innerWidth / 2;
  69. windowHalfY = window.innerHeight / 2;
  70. camera.aspect = window.innerWidth / window.innerHeight;
  71. camera.updateProjectionMatrix();
  72. renderer.setSize( window.innerWidth, window.innerHeight );
  73. }
  74. function createScene1( geometry, materials ) {
  75. materials[ 0 ].shading = THREE.FlatShading;
  76. mesh = new THREE.Mesh( geometry, new THREE.MultiMaterial( materials ) );
  77. mesh.position.x = 400;
  78. mesh.scale.x = mesh.scale.y = mesh.scale.z = 250;
  79. scene.add( mesh );
  80. }
  81. function createScene2( geometry, materials ) {
  82. materials[ 0 ].shading = THREE.FlatShading;
  83. mesh2 = new THREE.Mesh( geometry, new THREE.MultiMaterial( materials ) );
  84. mesh2.position.x = - 400;
  85. mesh2.scale.x = mesh2.scale.y = mesh2.scale.z = 250;
  86. scene.add( mesh2 );
  87. }
  88. function onDocumentMouseMove( event ) {
  89. mouseX = ( event.clientX - windowHalfX );
  90. mouseY = ( event.clientY - windowHalfY );
  91. }
  92. //
  93. function animate() {
  94. requestAnimationFrame( animate );
  95. render();
  96. stats.update();
  97. }
  98. function render() {
  99. camera.position.x += ( mouseX - camera.position.x ) * 0.05;
  100. camera.position.y += ( - mouseY - camera.position.y ) * 0.05;
  101. camera.lookAt( scene.position );
  102. if ( mesh ) {
  103. mesh.rotation.x += 0.01;
  104. mesh.rotation.y += 0.01;
  105. }
  106. if ( mesh2 ) {
  107. mesh2.rotation.x += 0.01;
  108. mesh2.rotation.y += 0.01;
  109. }
  110. renderer.render( scene, camera );
  111. }
  112. </script>
  113. </body>
  114. </html>