InstancedBufferGeometry.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { BufferGeometry } from './BufferGeometry';
  2. /**
  3. * @author benaadams / https://twitter.com/ben_a_adams
  4. */
  5. function InstancedBufferGeometry() {
  6. BufferGeometry.call( this );
  7. this.type = 'InstancedBufferGeometry';
  8. this.maxInstancedCount = undefined;
  9. }
  10. InstancedBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  11. InstancedBufferGeometry.prototype.constructor = InstancedBufferGeometry;
  12. InstancedBufferGeometry.prototype.isInstancedBufferGeometry = true;
  13. InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  14. this.groups.push( {
  15. start: start,
  16. count: count,
  17. instances: instances
  18. } );
  19. };
  20. InstancedBufferGeometry.prototype.copy = function ( source ) {
  21. var index = source.index;
  22. if ( index !== null ) {
  23. this.setIndex( index.clone() );
  24. }
  25. var attributes = source.attributes;
  26. for ( var name in attributes ) {
  27. var attribute = attributes[ name ];
  28. this.addAttribute( name, attribute.clone() );
  29. }
  30. var groups = source.groups;
  31. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  32. var group = groups[ i ];
  33. this.addGroup( group.start, group.count, group.instances );
  34. }
  35. return this;
  36. };
  37. export { InstancedBufferGeometry };