DynamicBufferAttribute.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { _Math } from '../math/Math.js';
  2. /**
  3. * @author raub / https://github.com/raub
  4. */
  5. function DynamicBufferAttribute( gl, buffer, type, itemSize, count ) {
  6. this.sizes = [
  7. [gl.FLOAT, 4],
  8. [gl.UNSIGNED_SHORT, 2],
  9. [gl.SHORT, 2],
  10. [gl.UNSIGNED_INT, 4],
  11. [gl.INT, 4],
  12. [gl.BYTE, 1],
  13. [gl.UNSIGNED_BYTE, 1],
  14. ].reduce(function (accum, current) {
  15. accum[current[0]] = current[1];
  16. return accum;
  17. }, {});
  18. if ( ! this.sizes[type] ) {
  19. throw new TypeError( 'THREE.DynamicBufferAttribute: unsupported GL data type.' );
  20. }
  21. this.uuid = _Math.generateUUID();
  22. this.buffer = buffer;
  23. this.type = type;
  24. this.itemSize = itemSize;
  25. this.elementSize = this.sizes[type];
  26. this.count = count;
  27. this.version = 0;
  28. }
  29. Object.defineProperty( DynamicBufferAttribute.prototype, 'needsUpdate', {
  30. set: function ( value ) {
  31. if ( value === true ) this.version ++;
  32. }
  33. } );
  34. Object.assign( DynamicBufferAttribute.prototype, {
  35. isDynamicBufferAttribute: true,
  36. setBuffer: function ( buffer ) {
  37. this.buffer = buffer;
  38. return this;
  39. },
  40. setType: function ( type ) {
  41. if ( ! sizes[type] ) {
  42. throw new TypeError( 'THREE.DynamicBufferAttribute: unsupported GL data type.' );
  43. }
  44. this.type = type;
  45. this.elementSize = this.sizes[type];
  46. return this;
  47. },
  48. setItemSize: function ( itemSize ) {
  49. this.itemSize = itemSize;
  50. return this;
  51. },
  52. setCount: function ( count ) {
  53. this.count = count;
  54. return this;
  55. },
  56. } );
  57. export { DynamicBufferAttribute };