misc_geometry2_sandbox.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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="js/wip/PlaneGeometry.js"></script>
  19. <script src="js/wip/Geometry2.js"></script>
  20. <script src="js/wip/BoxGeometry2.js"></script>
  21. <script src="js/wip/PlaneGeometry2.js"></script>
  22. <script src="js/wip/PlaneGeometry2b.js"></script>
  23. <script src="js/wip/Geometry3.js"></script>
  24. <script src="js/wip/PlaneGeometry3.js"></script>
  25. <script src="js/wip/Geometry5.js"></script>
  26. <script src="js/wip/PlaneGeometry5.js"></script>
  27. <script src="js/wip/IndexedGeometry5.js"></script>
  28. <script src="js/wip/IndexedPlaneGeometry5.js"></script>
  29. <script src="js/wip/PlaneBufferGeometry.js"></script>
  30. <script src="js/wip/PlaneGeometry6.js"></script>
  31. <script src="js/wip/PlaneGeometry99.js"></script>
  32. <script src="js/libs/stats.min.js"></script>
  33. <script>
  34. var container, stats;
  35. var camera, scene, renderer;
  36. var cube, plane;
  37. init();
  38. animate();
  39. var test = new THREE.PlaneGeometry99( 200, 200, 200, 200 );
  40. function init() {
  41. container = document.createElement( 'div' );
  42. document.body.appendChild( container );
  43. camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
  44. camera.position.y = 150;
  45. camera.position.z = 500;
  46. scene = new THREE.Scene();
  47. var light = new THREE.PointLight( 0xffffff );
  48. light.position.set( 0, 200, - 50 );
  49. scene.add( light );
  50. //
  51. addGeometries( 'PlaneGeometry', 'BoxGeometry', -100 );
  52. // addGeometries( 'IndexedPlaneGeometry5', 'BoxGeometry', 0 );
  53. // addGeometries( 'PlaneGeometry2', 'BoxGeometry2', 0 );
  54. // addGeometries( 'PlaneGeometry3', 'BoxGeometry2', 0 );
  55. addGeometries( 'PlaneGeometry5', 'BoxGeometry2', -50 );
  56. addGeometries( 'PlaneBufferGeometry', 'BoxGeometry2', 0 );
  57. addGeometries( 'PlaneGeometry6', 'BoxGeometry2', 50 );
  58. addGeometries( 'PlaneGeometry99', 'BoxGeometry2', 100 );
  59. //
  60. renderer = new THREE.WebGLRenderer();
  61. renderer.setClearColor( 0xf0f0f0 );
  62. renderer.setSize( window.innerWidth, window.innerHeight );
  63. container.appendChild( renderer.domElement );
  64. stats = new Stats();
  65. stats.domElement.style.position = 'absolute';
  66. stats.domElement.style.top = '0px';
  67. container.appendChild( stats.domElement );
  68. //
  69. window.addEventListener( 'resize', onWindowResize, false );
  70. /*
  71. setInterval( function () {
  72. console.log( '---' );
  73. createGeometry( 'PlaneGeometry' );
  74. createGeometry( 'PlaneGeometry2' );
  75. createGeometry( 'PlaneGeometry2b' );
  76. createGeometry( 'PlaneGeometry5' );
  77. createGeometry( 'PlaneGeometryB' );
  78. }, 2000 );
  79. */
  80. }
  81. function createGeometry( primitive ) {
  82. console.time( primitive );
  83. new THREE[ primitive ]( 200, 200, 60, 60 );
  84. console.timeEnd( primitive );
  85. }
  86. function addGeometries( PlaneGeometry, BoxGeometry, y ) {
  87. // Plane
  88. console.time( PlaneGeometry );
  89. var geometry = new THREE[ PlaneGeometry ]( 200, 200, 200, 200 );
  90. console.timeEnd( PlaneGeometry );
  91. geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
  92. var material = new THREE.MeshPhongMaterial( { color: 0xff0000/*, wireframe: true*/ } );
  93. plane = new THREE.Mesh( geometry, material );
  94. plane.position.y = y;
  95. scene.add( plane );
  96. /*
  97. // Cube
  98. var geometry = new THREE[ BoxGeometry ]( 200, 200, 200, 10, 10, 10 );
  99. var material = new THREE.MeshBasicMaterial( { color: 0x000000, wireframe: true } );
  100. cube = new THREE.Mesh( geometry, material );
  101. cube.position.y = 150;
  102. plane.add( cube );
  103. */
  104. }
  105. function onWindowResize() {
  106. camera.aspect = window.innerWidth / window.innerHeight;
  107. camera.updateProjectionMatrix();
  108. renderer.setSize( window.innerWidth, window.innerHeight );
  109. }
  110. //
  111. function animate() {
  112. requestAnimationFrame( animate );
  113. render();
  114. stats.update();
  115. }
  116. function render() {
  117. for ( var i = 0, l = scene.children.length; i < l; i ++ ) {
  118. var object = scene.children[ i ];
  119. object.rotation.y = Date.now() * 0.001;
  120. }
  121. renderer.render( scene, camera );
  122. }
  123. </script>
  124. </body>
  125. </html>