BufferGeometry.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. THREE.BufferGeometry = function () {
  6. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  7. this.uuid = THREE.Math.generateUUID();
  8. this.name = '';
  9. this.type = 'BufferGeometry';
  10. this.index = null;
  11. this.attributes = {};
  12. this.morphAttributes = {};
  13. this.groups = [];
  14. this.boundingBox = null;
  15. this.boundingSphere = null;
  16. };
  17. THREE.BufferGeometry.prototype = {
  18. constructor: THREE.BufferGeometry,
  19. addIndex: function ( attribute ) {
  20. this.index = attribute;
  21. },
  22. addAttribute: function ( name, attribute ) {
  23. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  24. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  25. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  26. return;
  27. }
  28. if ( name === 'index' ) {
  29. console.warn( 'THREE.BufferGeometry.addAttribute: Use .addIndex() for index attribute.' );
  30. this.addIndex( attribute );
  31. }
  32. this.attributes[ name ] = attribute;
  33. },
  34. getAttribute: function ( name ) {
  35. return this.attributes[ name ];
  36. },
  37. removeAttribute: function ( name ) {
  38. delete this.attributes[ name ];
  39. },
  40. get drawcalls() {
  41. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  42. return this.groups;
  43. },
  44. get offsets() {
  45. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  46. return this.groups;
  47. },
  48. addDrawCall: function ( start, count, indexOffset ) {
  49. if ( indexOffset !== undefined ) {
  50. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  51. }
  52. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  53. this.addGroup( start, count );
  54. },
  55. clearDrawCalls: function () {
  56. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  57. this.clearGroups();
  58. },
  59. addGroup: function ( start, count, materialIndex ) {
  60. this.groups.push( {
  61. start: start,
  62. count: count,
  63. materialIndex: materialIndex !== undefined ? materialIndex : 0
  64. } );
  65. },
  66. clearGroups: function () {
  67. this.groups = [];
  68. },
  69. applyMatrix: function ( matrix ) {
  70. var position = this.attributes.position;
  71. if ( position !== undefined ) {
  72. matrix.applyToVector3Array( position.array );
  73. position.needsUpdate = true;
  74. }
  75. var normal = this.attributes.normal;
  76. if ( normal !== undefined ) {
  77. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  78. normalMatrix.applyToVector3Array( normal.array );
  79. normal.needsUpdate = true;
  80. }
  81. if ( this.boundingBox !== null ) {
  82. this.computeBoundingBox();
  83. }
  84. if ( this.boundingSphere !== null ) {
  85. this.computeBoundingSphere();
  86. }
  87. },
  88. rotateX: function () {
  89. // rotate geometry around world x-axis
  90. var m1;
  91. return function rotateX( angle ) {
  92. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  93. m1.makeRotationX( angle );
  94. this.applyMatrix( m1 );
  95. return this;
  96. };
  97. }(),
  98. rotateY: function () {
  99. // rotate geometry around world y-axis
  100. var m1;
  101. return function rotateY( angle ) {
  102. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  103. m1.makeRotationY( angle );
  104. this.applyMatrix( m1 );
  105. return this;
  106. };
  107. }(),
  108. rotateZ: function () {
  109. // rotate geometry around world z-axis
  110. var m1;
  111. return function rotateZ( angle ) {
  112. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  113. m1.makeRotationZ( angle );
  114. this.applyMatrix( m1 );
  115. return this;
  116. };
  117. }(),
  118. translate: function () {
  119. // translate geometry
  120. var m1;
  121. return function translate( x, y, z ) {
  122. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  123. m1.makeTranslation( x, y, z );
  124. this.applyMatrix( m1 );
  125. return this;
  126. };
  127. }(),
  128. scale: function () {
  129. // scale geometry
  130. var m1;
  131. return function scale( x, y, z ) {
  132. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  133. m1.makeScale( x, y, z );
  134. this.applyMatrix( m1 );
  135. return this;
  136. };
  137. }(),
  138. lookAt: function () {
  139. var obj;
  140. return function lookAt( vector ) {
  141. if ( obj === undefined ) obj = new THREE.Object3D();
  142. obj.lookAt( vector );
  143. obj.updateMatrix();
  144. this.applyMatrix( obj.matrix );
  145. };
  146. }(),
  147. center: function () {
  148. this.computeBoundingBox();
  149. var offset = this.boundingBox.center().negate();
  150. this.translate( offset.x, offset.y, offset.z );
  151. return offset;
  152. },
  153. setFromObject: function ( object ) {
  154. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  155. var geometry = object.geometry;
  156. if ( object instanceof THREE.PointCloud || object instanceof THREE.Line ) {
  157. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  158. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  159. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  160. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  161. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  162. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  163. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  164. }
  165. if ( geometry.boundingSphere !== null ) {
  166. this.boundingSphere = geometry.boundingSphere.clone();
  167. }
  168. if ( geometry.boundingBox !== null ) {
  169. this.boundingBox = geometry.boundingBox.clone();
  170. }
  171. } else if ( object instanceof THREE.Mesh ) {
  172. if ( geometry instanceof THREE.Geometry ) {
  173. this.fromGeometry( geometry );
  174. }
  175. }
  176. return this;
  177. },
  178. updateFromObject: function ( object ) {
  179. var geometry = object.geometry;
  180. if ( object instanceof THREE.Mesh ) {
  181. var direct = geometry.__directGeometry;
  182. if ( direct === undefined ) {
  183. return this.fromGeometry( geometry );
  184. }
  185. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  186. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  187. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  188. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  189. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  190. geometry.verticesNeedUpdate = false;
  191. geometry.normalsNeedUpdate = false;
  192. geometry.colorsNeedUpdate = false;
  193. geometry.uvsNeedUpdate = false;
  194. geometry.groupsNeedUpdate = false;
  195. geometry = direct;
  196. }
  197. if ( geometry.verticesNeedUpdate === true ) {
  198. var attribute = this.attributes.position;
  199. if ( attribute !== undefined ) {
  200. attribute.copyVector3sArray( geometry.vertices );
  201. attribute.needsUpdate = true;
  202. }
  203. geometry.verticesNeedUpdate = false;
  204. }
  205. if ( geometry.normalsNeedUpdate === true ) {
  206. var attribute = this.attributes.normal;
  207. if ( attribute !== undefined ) {
  208. attribute.copyVector3sArray( geometry.normals );
  209. attribute.needsUpdate = true;
  210. }
  211. geometry.normalsNeedUpdate = false;
  212. }
  213. if ( geometry.colorsNeedUpdate === true ) {
  214. var attribute = this.attributes.color;
  215. if ( attribute !== undefined ) {
  216. attribute.copyColorsArray( geometry.colors );
  217. attribute.needsUpdate = true;
  218. }
  219. geometry.colorsNeedUpdate = false;
  220. }
  221. if ( geometry.lineDistancesNeedUpdate ) {
  222. var attribute = this.attributes.lineDistance;
  223. if ( attribute !== undefined ) {
  224. attribute.copyArray( geometry.lineDistances );
  225. attribute.needsUpdate = true;
  226. }
  227. geometry.lineDistancesNeedUpdate = false;
  228. }
  229. if ( geometry.groupsNeedUpdate ) {
  230. geometry.computeGroups( object.geometry );
  231. this.groups = geometry.groups;
  232. geometry.groupsNeedUpdate = false;
  233. }
  234. return this;
  235. },
  236. fromGeometry: function ( geometry ) {
  237. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  238. return this.fromDirectGeometry( geometry.__directGeometry );
  239. },
  240. fromDirectGeometry: function ( geometry ) {
  241. var positions = new Float32Array( geometry.vertices.length * 3 );
  242. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  243. if ( geometry.normals.length > 0 ) {
  244. var normals = new Float32Array( geometry.normals.length * 3 );
  245. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  246. }
  247. if ( geometry.colors.length > 0 ) {
  248. var colors = new Float32Array( geometry.colors.length * 3 );
  249. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  250. }
  251. if ( geometry.uvs.length > 0 ) {
  252. var uvs = new Float32Array( geometry.uvs.length * 2 );
  253. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  254. }
  255. if ( geometry.uvs2.length > 0 ) {
  256. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  257. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  258. }
  259. if ( geometry.indices.length > 0 ) {
  260. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  261. var indices = new TypeArray( geometry.indices.length * 3 );
  262. this.addIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  263. }
  264. // groups
  265. this.groups = geometry.groups;
  266. // morphs
  267. for ( var name in geometry.morphTargets ) {
  268. var array = [];
  269. var morphTargets = geometry.morphTargets[ name ];
  270. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  271. var morphTarget = morphTargets[ i ];
  272. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  273. array.push( attribute.copyVector3sArray( morphTarget ) );
  274. }
  275. this.morphAttributes[ name ] = array;
  276. }
  277. // skinning
  278. if ( geometry.skinIndices.length > 0 ) {
  279. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  280. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  281. }
  282. if ( geometry.skinWeights.length > 0 ) {
  283. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  284. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  285. }
  286. //
  287. if ( geometry.boundingSphere !== null ) {
  288. this.boundingSphere = geometry.boundingSphere.clone();
  289. }
  290. if ( geometry.boundingBox !== null ) {
  291. this.boundingBox = geometry.boundingBox.clone();
  292. }
  293. return this;
  294. },
  295. computeBoundingBox: function () {
  296. var vector = new THREE.Vector3();
  297. return function () {
  298. if ( this.boundingBox === null ) {
  299. this.boundingBox = new THREE.Box3();
  300. }
  301. var positions = this.attributes.position.array;
  302. if ( positions ) {
  303. var bb = this.boundingBox;
  304. bb.makeEmpty();
  305. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  306. vector.fromArray( positions, i );
  307. bb.expandByPoint( vector );
  308. }
  309. }
  310. if ( positions === undefined || positions.length === 0 ) {
  311. this.boundingBox.min.set( 0, 0, 0 );
  312. this.boundingBox.max.set( 0, 0, 0 );
  313. }
  314. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  315. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  316. }
  317. };
  318. }(),
  319. computeBoundingSphere: function () {
  320. var box = new THREE.Box3();
  321. var vector = new THREE.Vector3();
  322. return function () {
  323. if ( this.boundingSphere === null ) {
  324. this.boundingSphere = new THREE.Sphere();
  325. }
  326. var positions = this.attributes.position.array;
  327. if ( positions ) {
  328. box.makeEmpty();
  329. var center = this.boundingSphere.center;
  330. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  331. vector.fromArray( positions, i );
  332. box.expandByPoint( vector );
  333. }
  334. box.center( center );
  335. // hoping to find a boundingSphere with a radius smaller than the
  336. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  337. var maxRadiusSq = 0;
  338. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  339. vector.fromArray( positions, i );
  340. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  341. }
  342. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  343. if ( isNaN( this.boundingSphere.radius ) ) {
  344. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  345. }
  346. }
  347. };
  348. }(),
  349. computeFaceNormals: function () {
  350. // backwards compatibility
  351. },
  352. computeVertexNormals: function () {
  353. var index = this.index;
  354. var attributes = this.attributes;
  355. var groups = this.groups;
  356. if ( attributes.position ) {
  357. var positions = attributes.position.array;
  358. if ( attributes.normal === undefined ) {
  359. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  360. } else {
  361. // reset existing normals to zero
  362. var normals = attributes.normal.array;
  363. for ( var i = 0, il = normals.length; i < il; i ++ ) {
  364. normals[ i ] = 0;
  365. }
  366. }
  367. var normals = attributes.normal.array;
  368. var vA, vB, vC,
  369. pA = new THREE.Vector3(),
  370. pB = new THREE.Vector3(),
  371. pC = new THREE.Vector3(),
  372. cb = new THREE.Vector3(),
  373. ab = new THREE.Vector3();
  374. // indexed elements
  375. if ( index ) {
  376. var indices = index.array;
  377. if ( groups.length === 0 ) {
  378. this.addGroup( 0, indices.length );
  379. }
  380. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  381. var group = groups[ j ];
  382. var start = group.start;
  383. var count = group.count;
  384. for ( var i = start, il = start + count; i < il; i += 3 ) {
  385. vA = indices[ i + 0 ] * 3;
  386. vB = indices[ i + 1 ] * 3;
  387. vC = indices[ i + 2 ] * 3;
  388. pA.fromArray( positions, vA );
  389. pB.fromArray( positions, vB );
  390. pC.fromArray( positions, vC );
  391. cb.subVectors( pC, pB );
  392. ab.subVectors( pA, pB );
  393. cb.cross( ab );
  394. normals[ vA ] += cb.x;
  395. normals[ vA + 1 ] += cb.y;
  396. normals[ vA + 2 ] += cb.z;
  397. normals[ vB ] += cb.x;
  398. normals[ vB + 1 ] += cb.y;
  399. normals[ vB + 2 ] += cb.z;
  400. normals[ vC ] += cb.x;
  401. normals[ vC + 1 ] += cb.y;
  402. normals[ vC + 2 ] += cb.z;
  403. }
  404. }
  405. } else {
  406. // non-indexed elements (unconnected triangle soup)
  407. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  408. pA.fromArray( positions, i );
  409. pB.fromArray( positions, i + 3 );
  410. pC.fromArray( positions, i + 6 );
  411. cb.subVectors( pC, pB );
  412. ab.subVectors( pA, pB );
  413. cb.cross( ab );
  414. normals[ i ] = cb.x;
  415. normals[ i + 1 ] = cb.y;
  416. normals[ i + 2 ] = cb.z;
  417. normals[ i + 3 ] = cb.x;
  418. normals[ i + 4 ] = cb.y;
  419. normals[ i + 5 ] = cb.z;
  420. normals[ i + 6 ] = cb.x;
  421. normals[ i + 7 ] = cb.y;
  422. normals[ i + 8 ] = cb.z;
  423. }
  424. }
  425. this.normalizeNormals();
  426. attributes.normal.needsUpdate = true;
  427. }
  428. },
  429. computeTangents: function () {
  430. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  431. },
  432. computeOffsets: function ( size ) {
  433. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.')
  434. },
  435. merge: function ( geometry, offset ) {
  436. if ( geometry instanceof THREE.BufferGeometry === false ) {
  437. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  438. return;
  439. }
  440. if ( offset === undefined ) offset = 0;
  441. var attributes = this.attributes;
  442. for ( var key in attributes ) {
  443. if ( geometry.attributes[ key ] === undefined ) continue;
  444. var attribute1 = attributes[ key ];
  445. var attributeArray1 = attribute1.array;
  446. var attribute2 = geometry.attributes[ key ];
  447. var attributeArray2 = attribute2.array;
  448. var attributeSize = attribute2.itemSize;
  449. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  450. attributeArray1[ j ] = attributeArray2[ i ];
  451. }
  452. }
  453. return this;
  454. },
  455. normalizeNormals: function () {
  456. var normals = this.attributes.normal.array;
  457. var x, y, z, n;
  458. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  459. x = normals[ i ];
  460. y = normals[ i + 1 ];
  461. z = normals[ i + 2 ];
  462. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  463. normals[ i ] *= n;
  464. normals[ i + 1 ] *= n;
  465. normals[ i + 2 ] *= n;
  466. }
  467. },
  468. toJSON: function () {
  469. var data = {
  470. metadata: {
  471. version: 4.4,
  472. type: 'BufferGeometry',
  473. generator: 'BufferGeometry.toJSON'
  474. }
  475. };
  476. // standard BufferGeometry serialization
  477. data.uuid = this.uuid;
  478. data.type = this.type;
  479. if ( this.name !== '' ) data.name = this.name;
  480. if ( this.parameters !== undefined ) {
  481. var parameters = this.parameters;
  482. for ( var key in parameters ) {
  483. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  484. }
  485. return data;
  486. }
  487. data.data = { attributes: {} };
  488. var index = this.index;
  489. if ( index !== null ) {
  490. var array = Array.prototype.slice.call( index.array );
  491. data.data.index = {
  492. type: index.array.constructor.name,
  493. array: array
  494. };
  495. }
  496. var attributes = this.attributes;
  497. for ( var key in attributes ) {
  498. var attribute = attributes[ key ];
  499. var array = Array.prototype.slice.call( attribute.array );
  500. data.data.attributes[ key ] = {
  501. itemSize: attribute.itemSize,
  502. type: attribute.array.constructor.name,
  503. array: array
  504. };
  505. }
  506. var groups = this.groups;
  507. if ( groups.length > 0 ) {
  508. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  509. }
  510. var boundingSphere = this.boundingSphere;
  511. if ( boundingSphere !== null ) {
  512. data.data.boundingSphere = {
  513. center: boundingSphere.center.toArray(),
  514. radius: boundingSphere.radius
  515. };
  516. }
  517. return data;
  518. },
  519. clone: function () {
  520. return new this.constructor().copy( this );
  521. },
  522. copy: function ( source ) {
  523. var index = source.index;
  524. if ( index !== null ) {
  525. this.addIndex( index.clone() );
  526. }
  527. var attributes = source.attributes;
  528. for ( var name in attributes ) {
  529. var attribute = attributes[ name ];
  530. this.addAttribute( name, attribute.clone() );
  531. }
  532. var groups = source.groups;
  533. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  534. var group = groups[ i ];
  535. this.addGroup( group.start, group.count );
  536. }
  537. return this;
  538. },
  539. dispose: function () {
  540. this.dispatchEvent( { type: 'dispose' } );
  541. }
  542. };
  543. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  544. THREE.BufferGeometry.MaxIndex = 65535;