Advertisement
egasimus

Untitled

Jan 21st, 2015
279
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Arc = function (materialOptions) {
  2.   var geometry = new THREE.Geometry(),
  3.       R1       = ETHER.Config.R1,
  4.       R2       = ETHER.Config.R2,
  5.       SUBDIV   = ETHER.Config.SUBDIV,
  6.       SPEED    = ETHER.Config.SPEED,
  7.       PERIOD   = ETHER.Config.PERIOD,
  8.       SPACING  = ETHER.Config.SPACING;
  9.  
  10.   // create vertices
  11.   for (var i = 0; i <= SUBDIV; i++) {
  12.  
  13.     var
  14.       j = i - SUBDIV / 2,
  15.       s = Math.sin(2 * Math.PI * j / SUBDIV),
  16.       c = Math.cos(2 * Math.PI * j / SUBDIV);
  17.  
  18.     geometry.vertices.push(
  19.       new THREE.Vector3(R1 * s, R1 * c - 3, 0),
  20.       new THREE.Vector3(R2 * s, R2 * c - 3, 0)
  21.     );
  22.  
  23.   }
  24.  
  25.   // create faces
  26.   for (var i = 1; i <= SUBDIV; i++) {
  27.  
  28.     var ii = i * 2;
  29.  
  30.     geometry.faces.push(
  31.       new THREE.Face3(ii, ii - 1, ii - 2),
  32.       new THREE.Face3(ii, ii + 1, ii - 1)
  33.     );
  34.  
  35.   }
  36.  
  37.   // map texture
  38.   var material = new THREE.MeshBasicMaterial(materialOptions);
  39.  
  40.   geometry.faceVertexUvs[0] = [];
  41.  
  42.   for (var i = 0; i < SUBDIV; i++) {
  43.  
  44.     var j = i * 2;
  45.         k = 1 - i / SUBDIV,
  46.         l = 1 - (i + 1) / SUBDIV;
  47.  
  48.     geometry.faceVertexUvs[0][j] =
  49.       [ new THREE.Vector2(l, 0),
  50.         new THREE.Vector2(k, 1),
  51.         new THREE.Vector2(k, 0), ];
  52.  
  53.     geometry.faceVertexUvs[0][j + 1] =
  54.       [ new THREE.Vector2(l, 0),
  55.         new THREE.Vector2(l, 1),
  56.         new THREE.Vector2(k, 1), ];
  57.  
  58.   }
  59.  
  60.   // set pivot point
  61.   geometry.applyMatrix(new THREE.Matrix4().makeTranslation(0, 3, 0));
  62.  
  63.   // combine geometry and material
  64.   return new THREE.Mesh(geometry, material);
  65.  
  66. };
Advertisement
RAW Paste Data Copied
Advertisement