InterleavedBuffer.js 758 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. export class InterleavedBufferAttribute{
  2. constructor(name, bytes, numElements, type, normalized){
  3. this.name = name;
  4. this.bytes = bytes;
  5. this.numElements = numElements;
  6. this.normalized = normalized;
  7. this.type = type; // gl type without prefix, e.g. "FLOAT", "UNSIGNED_INT"
  8. }
  9. };
  10. export class InterleavedBuffer{
  11. constructor(data, attributes, numElements){
  12. this.data = data;
  13. this.attributes = attributes;
  14. this.stride = attributes.reduce( (a, att) => a + att.bytes, 0);
  15. this.stride = Math.ceil(this.stride / 4) * 4;
  16. this.numElements = numElements;
  17. }
  18. offset(name){
  19. let offset = 0;
  20. for(let att of this.attributes){
  21. if(att.name === name){
  22. return offset;
  23. }
  24. offset += att.bytes;
  25. }
  26. return null;
  27. }
  28. };