CylinderGeometryLibrary.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import CesiumMath from './Math.js';
  2. /**
  3. * @private
  4. */
  5. var CylinderGeometryLibrary = {};
  6. /**
  7. * @private
  8. */
  9. CylinderGeometryLibrary.computePositions = function(length, topRadius, bottomRadius, slices, fill){
  10. var topZ = length * 0.5;
  11. var bottomZ = -topZ;
  12. var twoSlice = slices + slices;
  13. var size = (fill) ? 2 * twoSlice : twoSlice;
  14. var positions = new Float64Array(size*3);
  15. var i;
  16. var index = 0;
  17. var tbIndex = 0;
  18. var bottomOffset = (fill) ? twoSlice*3 : 0;
  19. var topOffset = (fill) ? (twoSlice + slices)*3 : slices*3;
  20. for (i = 0; i < slices; i++) {
  21. var angle = i / slices * CesiumMath.TWO_PI;
  22. var x = Math.cos(angle);
  23. var y = Math.sin(angle);
  24. var bottomX = x * bottomRadius;
  25. var bottomY = y * bottomRadius;
  26. var topX = x * topRadius;
  27. var topY = y * topRadius;
  28. positions[tbIndex + bottomOffset] = bottomX;
  29. positions[tbIndex + bottomOffset + 1] = bottomY;
  30. positions[tbIndex + bottomOffset + 2] = bottomZ;
  31. positions[tbIndex + topOffset] = topX;
  32. positions[tbIndex + topOffset + 1] = topY;
  33. positions[tbIndex + topOffset + 2] = topZ;
  34. tbIndex += 3;
  35. if (fill) {
  36. positions[index++] = bottomX;
  37. positions[index++] = bottomY;
  38. positions[index++] = bottomZ;
  39. positions[index++] = topX;
  40. positions[index++] = topY;
  41. positions[index++] = topZ;
  42. }
  43. }
  44. return positions;
  45. };
  46. export default CylinderGeometryLibrary;