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

src/buffer/cylinderimpostor-buffer.js

  1. /**
  2. * @file Cylinder Impostor Buffer
  3. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  4. * @private
  5. */
  6.  
  7. import { Matrix4 } from '../../lib/three.es6.js'
  8.  
  9. import '../shader/CylinderImpostor.vert'
  10. import '../shader/CylinderImpostor.frag'
  11.  
  12. import { defaults } from '../utils.js'
  13. import MappedAlignedBoxBuffer from './mappedalignedbox-buffer.js'
  14.  
  15. /**
  16. * Cylinder impostor buffer.
  17. *
  18. * @example
  19. * var cylinderimpostorBuffer = new CylinderImpostorBuffer({
  20. * position1: new Float32Array([ 0, 0, 0 ]),
  21. * position2: new Float32Array([ 1, 1, 1 ]),
  22. * color: new Float32Array([ 1, 0, 0 ]),
  23. * color2: new Float32Array([ 0, 1, 0 ]),
  24. * radius: new Float32Array([ 1 ])
  25. * });
  26. */
  27. class CylinderImpostorBuffer extends MappedAlignedBoxBuffer {
  28. /**
  29. * make cylinder impostor buffer
  30. * @param {Object} data - attribute object
  31. * @param {Float32Array} data.position1 - from positions
  32. * @param {Float32Array} data.position2 - to positions
  33. * @param {Float32Array} data.color - from colors
  34. * @param {Float32Array} data.color2 - to colors
  35. * @param {Float32Array} data.radius - radii
  36. * @param {Picker} data.picking - picking ids
  37. * @param {BufferParameters} params - parameter object
  38. */
  39. constructor (data, params) {
  40. super(data, params)
  41.  
  42. var p = params || {}
  43.  
  44. this.openEnded = defaults(p.openEnded, false)
  45.  
  46. this.addUniforms({
  47. 'modelViewMatrixInverse': { value: new Matrix4() },
  48. 'ortho': { value: 0.0 }
  49. })
  50.  
  51. this.addAttributes({
  52. 'position1': { type: 'v3', value: null },
  53. 'position2': { type: 'v3', value: null },
  54. 'color2': { type: 'c', value: null },
  55. 'radius': { type: 'f', value: null }
  56. })
  57.  
  58. this.setAttributes(data)
  59. this.makeMapping()
  60. }
  61.  
  62. get parameters () {
  63. return Object.assign({
  64.  
  65. openEnded: { updateShader: true }
  66.  
  67. }, super.parameters)
  68. }
  69.  
  70. getDefines (type) {
  71. var defines = MappedAlignedBoxBuffer.prototype.getDefines.call(this, type)
  72.  
  73. if (!this.openEnded) {
  74. defines.CAP = 1
  75. }
  76.  
  77. return defines
  78. }
  79.  
  80. get isImpostor () { return true }
  81. get vertexShader () { return 'CylinderImpostor.vert' }
  82. get fragmentShader () { return 'CylinderImpostor.frag' }
  83. }
  84.  
  85. export default CylinderImpostorBuffer