NGL@1.0.0-beta.7 Home Manual Reference Source Gallery

src/buffer/spheregeometry-buffer.js

  1. /**
  2. * @file Sphere Geometry Buffer
  3. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  4. * @private
  5. */
  6.  
  7. import { IcosahedronBufferGeometry, Vector3 } from '../../lib/three.es6.js'
  8.  
  9. import { defaults } from '../utils.js'
  10. import GeometryBuffer from './geometry-buffer.js'
  11.  
  12. const scale = new Vector3()
  13.  
  14. /**
  15. * Sphere geometry buffer.
  16. *
  17. * @example
  18. * var sphereGeometryBuffer = new SphereGeometryBuffer({
  19. * position: new Float32Array([ 0, 0, 0 ]),
  20. * color: new Float32Array([ 1, 0, 0 ]),
  21. * radius: new Float32Array([ 1 ])
  22. * });
  23. */
  24. class SphereGeometryBuffer extends GeometryBuffer {
  25. /**
  26. * @param {Object} data - attribute object
  27. * @param {Float32Array} data.position - positions
  28. * @param {Float32Array} data.color - colors
  29. * @param {Float32Array} data.radius - radii
  30. * @param {Picker} [data.picking] - picking ids
  31. * @param {BufferParameters} params - parameter object
  32. */
  33. constructor (data, params) {
  34. const p = params || {}
  35. const detail = defaults(p.sphereDetail, 1)
  36. const geo = new IcosahedronBufferGeometry(1, detail)
  37.  
  38. super(data, p, geo)
  39.  
  40. this.setAttributes(data, true)
  41. }
  42.  
  43. applyPositionTransform (matrix, i) {
  44. const r = this._radius[ i ]
  45. scale.set(r, r, r)
  46. matrix.scale(scale)
  47. }
  48.  
  49. setAttributes (data, initNormals) {
  50. if (data.radius) this._radius = data.radius
  51.  
  52. super.setAttributes(data, initNormals)
  53. }
  54. }
  55.  
  56. export default SphereGeometryBuffer