webgl_geometry_colors_blender.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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/Stats.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.setSize( window.innerWidth, window.innerHeight );
  57. container.appendChild( renderer.domElement );
  58. stats = new Stats();
  59. stats.domElement.style.position = 'absolute';
  60. stats.domElement.style.top = '0px';
  61. container.appendChild( stats.domElement );
  62. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  63. //
  64. window.addEventListener( 'resize', onWindowResize, false );
  65. }
  66. function onWindowResize() {
  67. windowHalfX = window.innerWidth / 2;
  68. windowHalfY = window.innerHeight / 2;
  69. camera.aspect = window.innerWidth / window.innerHeight;
  70. camera.updateProjectionMatrix();
  71. renderer.setSize( window.innerWidth, window.innerHeight );
  72. }
  73. function createScene1( geometry ) {
  74. geometry.materials[ 0 ].shading = THREE.FlatShading;
  75. mesh = new THREE.Object3D();
  76. mesh.position.x = 400;
  77. mesh.scale.x = mesh.scale.y = mesh.scale.z = 250;
  78. scene.add( mesh );
  79. var part1 = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial() );
  80. mesh.add( part1 );
  81. var part2 = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: 0xffffff, opacity: 0.9, shading: THREE.FlatShading, wireframe: true, wireframeLinewidth: 2, transparent: true } ) );
  82. mesh.add( part2 );
  83. }
  84. function createScene2( geometry ) {
  85. geometry.materials[ 0 ].shading = THREE.FlatShading;
  86. var material = new THREE.MeshFaceMaterial();
  87. mesh2 = new THREE.Mesh( geometry, material );
  88. mesh2.position.x = - 400;
  89. mesh2.scale.x = mesh2.scale.y = mesh2.scale.z = 250;
  90. scene.add( mesh2 );
  91. }
  92. function onDocumentMouseMove( event ) {
  93. mouseX = ( event.clientX - windowHalfX );
  94. mouseY = ( event.clientY - windowHalfY );
  95. }
  96. //
  97. function animate() {
  98. requestAnimationFrame( animate );
  99. render();
  100. stats.update();
  101. }
  102. function render() {
  103. camera.position.x += ( mouseX - camera.position.x ) * 0.05;
  104. camera.position.y += ( - mouseY - camera.position.y ) * 0.05;
  105. camera.lookAt( scene.position );
  106. if ( mesh ) {
  107. mesh.rotation.x += 0.01;
  108. mesh.rotation.y += 0.01;
  109. }
  110. if ( mesh2 ) {
  111. mesh2.rotation.x += 0.01;
  112. mesh2.rotation.y += 0.01;
  113. }
  114. renderer.render( scene, camera );
  115. }
  116. </script>
  117. </body>
  118. </html>