canvas_geometry2_sandbox.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js canvas - geometry2 - sandbox</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: #f0f0f0;
  11. margin: 0px;
  12. overflow: hidden;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <script src="../build/three.min.js"></script>
  18. <script src="../src/extras/geometries/BoxGeometry2.js"></script>
  19. <script src="../src/extras/geometries/PlaneGeometry2.js"></script>
  20. <script src="../src/extras/geometries/PlaneGeometry2b.js"></script>
  21. <script src="../src/core/Geometry3.js"></script>
  22. <script src="../src/extras/geometries/PlaneGeometry3.js"></script>
  23. <script src="../src/extras/geometries/PlaneGeometryB.js"></script>
  24. <script src="js/libs/stats.min.js"></script>
  25. <script>
  26. var container, stats;
  27. var camera, scene, renderer;
  28. var cube, plane;
  29. init();
  30. animate();
  31. function init() {
  32. container = document.createElement( 'div' );
  33. document.body.appendChild( container );
  34. camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
  35. camera.position.y = 150;
  36. camera.position.z = 500;
  37. scene = new THREE.Scene();
  38. var light = new THREE.PointLight( 0xffffff );
  39. light.position.set( 0, 200, - 50 );
  40. scene.add( light );
  41. //
  42. addGeometries( 'PlaneGeometry', 'BoxGeometry', 0 );
  43. // addGeometries( 'PlaneGeometry2', 'BoxGeometry2', 0 );
  44. // addGeometries( 'PlaneGeometry3', 'BoxGeometry2', 0 );
  45. // addGeometries( 'PlaneGeometryB', 'BoxGeometry2', 0 );
  46. //
  47. renderer = new THREE.WebGLRenderer();
  48. renderer.setClearColor( 0xf0f0f0 );
  49. renderer.setSize( window.innerWidth, window.innerHeight );
  50. container.appendChild( renderer.domElement );
  51. stats = new Stats();
  52. stats.domElement.style.position = 'absolute';
  53. stats.domElement.style.top = '0px';
  54. container.appendChild( stats.domElement );
  55. //
  56. window.addEventListener( 'resize', onWindowResize, false );
  57. setInterval( function () {
  58. console.log( '---' );
  59. createGeometry( 'PlaneGeometry' );
  60. createGeometry( 'PlaneGeometry2' );
  61. createGeometry( 'PlaneGeometry2b' );
  62. createGeometry( 'PlaneGeometryB' );
  63. }, 2000 );
  64. }
  65. function createGeometry( primitive ) {
  66. console.time( primitive );
  67. new THREE[ primitive ]( 200, 200, 60, 60 );
  68. console.timeEnd( primitive );
  69. }
  70. function addGeometries( PlaneGeometry, BoxGeometry, x ) {
  71. // Plane
  72. console.time( PlaneGeometry );
  73. var geometry = new THREE[ PlaneGeometry ]( 200, 200, 100, 100 );
  74. console.timeEnd( PlaneGeometry );
  75. geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
  76. var material = new THREE.MeshPhongMaterial( { color: 0xffffff /*, wireframe: true*/ } );
  77. plane = new THREE.Mesh( geometry, material );
  78. plane.position.x = x;
  79. scene.add( plane );
  80. /*
  81. // Cube
  82. var geometry = new THREE[ BoxGeometry ]( 200, 200, 200, 10, 10, 10 );
  83. var material = new THREE.MeshBasicMaterial( { color: 0x000000, wireframe: true } );
  84. cube = new THREE.Mesh( geometry, material );
  85. cube.position.y = 150;
  86. plane.add( cube );
  87. */
  88. }
  89. function onWindowResize() {
  90. camera.aspect = window.innerWidth / window.innerHeight;
  91. camera.updateProjectionMatrix();
  92. renderer.setSize( window.innerWidth, window.innerHeight );
  93. }
  94. //
  95. function animate() {
  96. requestAnimationFrame( animate );
  97. render();
  98. stats.update();
  99. }
  100. function render() {
  101. for ( var i = 0, l = scene.children.length; i < l; i ++ ) {
  102. var object = scene.children[ i ];
  103. object.rotation.y = Date.now() * 0.001;
  104. }
  105. renderer.render( scene, camera );
  106. }
  107. </script>
  108. </body>
  109. </html>