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

src/buffer/hyperballstickimpostor-buffer.js

  1. /**
  2. * @file Hyperball Stick 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/HyperballStickImpostor.vert'
  10. import '../shader/HyperballStickImpostor.frag'
  11.  
  12. import { defaults } from '../utils.js'
  13. import MappedBoxBuffer from './mappedbox-buffer.js'
  14.  
  15. /**
  16. * Hyperball stick impostor buffer.
  17. *
  18. * @example
  19. * var hyperballStickImpostorBuffer = new HyperballStickImpostorBuffer( {
  20. * position1: new Float32Array( [ 0, 0, 0 ] ),
  21. * position2: new Float32Array( [ 2, 2, 2 ] ),
  22. * color: new Float32Array( [ 1, 0, 0 ] ),
  23. * color2: new Float32Array( [ 0, 1, 0 ] ),
  24. * radius1: new Float32Array( [ 1 ] ),
  25. * radius2: new Float32Array( [ 2 ] )
  26. * } );
  27. */
  28. class HyperballStickImpostorBuffer extends MappedBoxBuffer {
  29. /**
  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.radius1 - from radii
  36. * @param {Float32Array} data.radius2 - to radii
  37. * @param {Picker} data.picking - picking ids
  38. * @param {BufferParameters} params - parameter object
  39. */
  40. constructor (data, params) {
  41. super(data, params)
  42.  
  43. var d = data || {}
  44. var p = params || {}
  45.  
  46. var shrink = defaults(p.shrink, 0.14)
  47.  
  48. this.addUniforms({
  49. 'modelViewProjectionMatrix': { value: new Matrix4() },
  50. 'modelViewProjectionMatrixInverse': { value: new Matrix4() },
  51. 'modelViewMatrixInverseTranspose': { value: new Matrix4() },
  52. 'shrink': { value: shrink }
  53. })
  54.  
  55. this.addAttributes({
  56. 'position1': { type: 'v3', value: null },
  57. 'position2': { type: 'v3', value: null },
  58. 'color2': { type: 'c', value: null },
  59. 'radius': { type: 'f', value: null },
  60. 'radius2': { type: 'f', value: null }
  61. })
  62.  
  63. this.setAttributes(d)
  64.  
  65. this.makeMapping()
  66. }
  67.  
  68. get parameters () {
  69. return Object.assign({
  70.  
  71. shrink: { uniform: true }
  72.  
  73. }, super.parameters)
  74. }
  75.  
  76. get isImpostor () { return true }
  77. get vertexShader () { return 'HyperballStickImpostor.vert' }
  78. get fragmentShader () { return 'HyperballStickImpostor.frag' }
  79. }
  80.  
  81. export default HyperballStickImpostorBuffer