BufferGeometry.js 19 KB

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