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.

150 lines
3.8 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 type="text/javascript" src="Modelos/js/jquery.min.js"></script>
  14. <script src="countrypoints.js"></script>
  15. <script src="js/three.min.js"></script>
  16. <script src="js/controls/OrbitControls.js"></script>
  17. </head>
  18. <body>
  19. </body>
  20. <script>
  21. /************** Variables *************/
  22. //Preparamos el render
  23. var Render=new THREE.WebGLRenderer();
  24. //El escenario
  25. var Escenario=new THREE.Scene();
  26. // Figura
  27. var figura;
  28. var controls;
  29. var ancho = innerWidth;
  30. var alto = innerHeight;
  31. var angulo = 45;
  32. var Aspecto = ancho / alto;
  33. var cerca = 0.1;
  34. var lejos = 10000;
  35. //La cámara
  36. Camara=new THREE.PerspectiveCamera(angulo, Aspecto, cerca, lejos);
  37. /************** Llamadas a las funciones *************/
  38. inicio();
  39. animacion();
  40. /************** Inicio *************/
  41. function inicio(){
  42. //Tamaño del render(resultado)
  43. Render.setSize( ancho, alto );
  44. //Se agrega el render al documento html
  45. document.body.appendChild(Render.domElement);
  46. //Acercamos la cámara en z es profundidad para ver el punto
  47. Camara.position.z=350;
  48. //agregando la cámara al escenario
  49. Escenario.add(Camara);
  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. $.each( country, function( key, value ) {
  60. var array_extrude = [];
  61. var ver = value.coord[0];
  62. for(j=0;j<value.coord.length;j++){
  63. if(ver.length < value.coord[j].length){
  64. ver = value.coord[j];
  65. }
  66. }
  67. var vertices = ver;
  68. var long_vertices = vertices.length;
  69. for(i=0;i<long_vertices;i++){
  70. x = vertices[i][0];
  71. y = vertices[i][1];
  72. z = i;
  73. //Agregamos vértices al vector
  74. Vector = new THREE.Vector3(x,y,z);
  75. //Agregamos el vector a la geometria
  76. Geometria.vertices.push(Vector);
  77. array_extrude.push(Vector);
  78. }
  79. //Figura
  80. var forma_figura = new THREE.Shape(array_extrude);
  81. // extrudion;
  82. var datos_extrucion = {
  83. amount: 5,
  84. bevelEnabled: false,
  85. bevelSegments: 5,
  86. steps: 5,
  87. bevelThickness: 1
  88. }
  89. var extrude_geometria = new THREE.ExtrudeGeometry(forma_figura, datos_extrucion);
  90. // la malla
  91. var malla_extrucion = new THREE.Mesh(extrude_geometria);
  92. malla_extrucion.rotation.z = (Math.PI/2);
  93. malla_extrucion.rotation.y = (Math.PI/2)*2;
  94. Escenario.add(malla_extrucion);
  95. //}
  96. /*
  97. for(j=0;j<value.coord.length;j++){
  98. var vertices = value.coord[j];
  99. var long_vertices = vertices.length;
  100. for(i=0;i<long_vertices;i++){
  101. */
  102. });
  103. /*
  104. // agregamos un material para que el punto tenga color
  105. Material = new THREE.PointsMaterial({color:0XFF0000});
  106. // creamos una partícula con la geometría y el material
  107. Figura = new THREE.Line(Geometria,Material);
  108. // agregamos la partícula al escenario
  109. Escenario.add(Figura);*/
  110. }
  111. function animacion(){
  112. requestAnimationFrame(animacion);
  113. render_modelo();
  114. }
  115. function render_modelo(){
  116. // Figura.rotation.y += 0.01
  117. Render.render(Escenario,Camara);
  118. }
  119. </script>
  120. </html>