You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.3 KiB

4 years ago
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - teapot buffer geometry</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. margin: 0px;
  10. overflow: hidden;
  11. }
  12. </style>
  13. <script src="js/three.min.js"></script>
  14. <script src="js/controls/OrbitControls.js"></script>
  15. </head>
  16. <body>
  17. </body>
  18. <script>
  19. /************** Variables *************/
  20. //Preparamos el render
  21. var Render=new THREE.WebGLRenderer();
  22. //El escenario
  23. var Escenario=new THREE.Scene();
  24. // Figura
  25. var figura;
  26. var controls;
  27. var ancho = innerWidth;
  28. var alto = innerHeight;
  29. var angulo = 45;
  30. var Aspecto = ancho / alto;
  31. var cerca = 0.1;
  32. var lejos = 10000;
  33. //La cámara
  34. Camara=new THREE.PerspectiveCamera(angulo, Aspecto, cerca, lejos);
  35. /************** Llamadas a las funciones *************/
  36. inicio();
  37. animacion();
  38. /************** Inicio *************/
  39. function inicio(){
  40. //Tamaño del render(resultado)
  41. Render.setSize( ancho, alto );
  42. //Se agrega el render al documento html
  43. document.body.appendChild(Render.domElement);
  44. //Acercamos la cámara en z es profundidad para ver el punto
  45. Camara.position.z=150;
  46. //agregando la cámara al escenario
  47. Escenario.add(Camara);
  48. //Terrirorio
  49. crear_plano();
  50. //Cargar modelos
  51. cargar_modelo();
  52. // agregamos todo el escenario y la cámara al render
  53. controls = new THREE.OrbitControls( Camara, Render.domElement );
  54. }
  55. function cargar_modelo(){
  56. // Geometría
  57. Geometria=new THREE.Geometry();
  58. // vector a dibujar
  59. vertices = [
  60. [2,7,0], [7,2,0],[12, 7, 0], [12, 17, 0], [7, 12, 0], [2, 17, 0], [2,7,0],
  61. [2,7,2], [7,2,2],[12, 7, 2], [12, 17, 2], [7, 12, 2], [2, 17, 2], [2,7,2],
  62. ];
  63. long_vertices = vertices.length;
  64. for(i=0;i<long_vertices;i++){
  65. x = vertices[i][0];
  66. y = vertices[i][1];
  67. z = vertices[i][2];
  68. //Agregamos vértices al vector
  69. Vector = new THREE.Vector3(x,y,z);
  70. //Agregamos el vector a la geometria
  71. Geometria.vertices.push(Vector);
  72. }
  73. // agregamos un material para que el punto tenga color
  74. Material = new THREE.PointsMaterial({color:0XFF0000});
  75. // creamos una partícula con la geometría y el material
  76. Figura = new THREE.Line(Geometria,Material);
  77. // agregamos la partícula al escenario
  78. Escenario.add(Figura);
  79. }
  80. function crear_plano(){
  81. //Geometria del plano
  82. geometria_plano= new THREE.PlaneGeometry(1000, 1000, 10, 10);
  83. // Textura
  84. textura_plano = new THREE.ImageUtils.loadTexture("texturas/cesped.jpg");
  85. textura_plano.wrapS = textura_plano.wrapT = THREE.RepeatWrapping;
  86. textura_plano.repeat.set(10,10);
  87. //Material
  88. material_plano = new THREE.MeshBasicMaterial({map: textura_plano, side: THREE.DoubleSide})
  89. // El plano (territorio)
  90. territorio = new THREE.Mesh(geometria_plano, material_plano);;
  91. territorio.rotation.y = -0.5;
  92. territorio.rotation.x = Math.PI/2;
  93. Escenario.add(territorio);
  94. }
  95. function animacion(){
  96. requestAnimationFrame(animacion);
  97. render_modelo();
  98. }
  99. function render_modelo(){
  100. Figura.rotation.y += 0.01
  101. Render.render(Escenario,Camara);
  102. }
  103. </script>
  104. </html>