BufferGeometry.js 19 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  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. getIndex: function () {
  21. return this.index;
  22. },
  23. setIndex: function ( index ) {
  24. this.index = index;
  25. },
  26. addAttribute: function ( name, attribute ) {
  27. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  28. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  29. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  30. return;
  31. }
  32. if ( name === 'index' ) {
  33. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  34. this.setIndex( attribute );
  35. return;
  36. }
  37. this.attributes[ name ] = attribute;
  38. },
  39. getAttribute: function ( name ) {
  40. return this.attributes[ name ];
  41. },
  42. removeAttribute: function ( name ) {
  43. delete this.attributes[ name ];
  44. },
  45. addGroup: function ( start, count, materialIndex ) {
  46. this.groups.push( {
  47. start: start,
  48. count: count,
  49. materialIndex: materialIndex !== undefined ? materialIndex : 0
  50. } );
  51. },
  52. clearGroups: function () {
  53. this.groups = [];
  54. },
  55. setDrawRange: function ( start, count ) {
  56. this.drawRange.start = start;
  57. this.drawRange.count = count;
  58. },
  59. applyMatrix: function ( matrix ) {
  60. var position = this.attributes.position;
  61. if ( position !== undefined ) {
  62. matrix.applyToVector3Array( position.array );
  63. position.needsUpdate = true;
  64. }
  65. var normal = this.attributes.normal;
  66. if ( normal !== undefined ) {
  67. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  68. normalMatrix.applyToVector3Array( normal.array );
  69. normal.needsUpdate = true;
  70. }
  71. if ( this.boundingBox !== null ) {
  72. this.computeBoundingBox();
  73. }
  74. if ( this.boundingSphere !== null ) {
  75. this.computeBoundingSphere();
  76. }
  77. },
  78. rotateX: function () {
  79. // rotate geometry around world x-axis
  80. var m1;
  81. return function rotateX( angle ) {
  82. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  83. m1.makeRotationX( angle );
  84. this.applyMatrix( m1 );
  85. return this;
  86. };
  87. }(),
  88. rotateY: function () {
  89. // rotate geometry around world y-axis
  90. var m1;
  91. return function rotateY( angle ) {
  92. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  93. m1.makeRotationY( angle );
  94. this.applyMatrix( m1 );
  95. return this;
  96. };
  97. }(),
  98. rotateZ: function () {
  99. // rotate geometry around world z-axis
  100. var m1;
  101. return function rotateZ( angle ) {
  102. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  103. m1.makeRotationZ( angle );
  104. this.applyMatrix( m1 );
  105. return this;
  106. };
  107. }(),
  108. translate: function () {
  109. // translate geometry
  110. var m1;
  111. return function translate( x, y, z ) {
  112. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  113. m1.makeTranslation( x, y, z );
  114. this.applyMatrix( m1 );
  115. return this;
  116. };
  117. }(),
  118. scale: function () {
  119. // scale geometry
  120. var m1;
  121. return function scale( x, y, z ) {
  122. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  123. m1.makeScale( x, y, z );
  124. this.applyMatrix( m1 );
  125. return this;
  126. };
  127. }(),
  128. lookAt: function () {
  129. var obj;
  130. return function lookAt( vector ) {
  131. if ( obj === undefined ) obj = new THREE.Object3D();
  132. obj.lookAt( vector );
  133. obj.updateMatrix();
  134. this.applyMatrix( obj.matrix );
  135. };
  136. }(),
  137. center: function () {
  138. this.computeBoundingBox();
  139. var offset = this.boundingBox.center().negate();
  140. this.translate( offset.x, offset.y, offset.z );
  141. return offset;
  142. },
  143. setFromObject: function ( object ) {
  144. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  145. var geometry = object.geometry;
  146. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  147. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  148. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  149. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  150. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  151. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  152. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  153. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  154. }
  155. if ( geometry.boundingSphere !== null ) {
  156. this.boundingSphere = geometry.boundingSphere.clone();
  157. }
  158. if ( geometry.boundingBox !== null ) {
  159. this.boundingBox = geometry.boundingBox.clone();
  160. }
  161. } else if ( object instanceof THREE.Mesh ) {
  162. if ( geometry instanceof THREE.Geometry ) {
  163. this.fromGeometry( geometry );
  164. }
  165. }
  166. return this;
  167. },
  168. updateFromObject: function ( object ) {
  169. var geometry = object.geometry;
  170. if ( object instanceof THREE.Mesh ) {
  171. var direct = geometry.__directGeometry;
  172. if ( direct === undefined ) {
  173. return this.fromGeometry( geometry );
  174. }
  175. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  176. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  177. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  178. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  179. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  180. geometry.verticesNeedUpdate = false;
  181. geometry.normalsNeedUpdate = false;
  182. geometry.colorsNeedUpdate = false;
  183. geometry.uvsNeedUpdate = false;
  184. geometry.groupsNeedUpdate = false;
  185. geometry = direct;
  186. }
  187. if ( geometry.verticesNeedUpdate === true ) {
  188. var attribute = this.attributes.position;
  189. if ( attribute !== undefined ) {
  190. attribute.copyVector3sArray( geometry.vertices );
  191. attribute.needsUpdate = true;
  192. }
  193. geometry.verticesNeedUpdate = false;
  194. }
  195. if ( geometry.normalsNeedUpdate === true ) {
  196. var attribute = this.attributes.normal;
  197. if ( attribute !== undefined ) {
  198. attribute.copyVector3sArray( geometry.normals );
  199. attribute.needsUpdate = true;
  200. }
  201. geometry.normalsNeedUpdate = false;
  202. }
  203. if ( geometry.colorsNeedUpdate === true ) {
  204. var attribute = this.attributes.color;
  205. if ( attribute !== undefined ) {
  206. attribute.copyColorsArray( geometry.colors );
  207. attribute.needsUpdate = true;
  208. }
  209. geometry.colorsNeedUpdate = false;
  210. }
  211. if ( geometry.uvsNeedUpdate ) {
  212. var attribute = this.attributes.uv;
  213. if ( attribute !== undefined ) {
  214. attribute.copyVector2sArray( geometry.uvs );
  215. attribute.needsUpdate = true;
  216. }
  217. geometry.uvsNeedUpdate = false;
  218. }
  219. if ( geometry.lineDistancesNeedUpdate ) {
  220. var attribute = this.attributes.lineDistance;
  221. if ( attribute !== undefined ) {
  222. attribute.copyArray( geometry.lineDistances );
  223. attribute.needsUpdate = true;
  224. }
  225. geometry.lineDistancesNeedUpdate = false;
  226. }
  227. if ( geometry.groupsNeedUpdate ) {
  228. geometry.computeGroups( object.geometry );
  229. this.groups = geometry.groups;
  230. geometry.groupsNeedUpdate = false;
  231. }
  232. return this;
  233. },
  234. fromGeometry: function ( geometry ) {
  235. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  236. return this.fromDirectGeometry( geometry.__directGeometry );
  237. },
  238. fromDirectGeometry: function ( geometry ) {
  239. var positions = new Float32Array( geometry.vertices.length * 3 );
  240. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  241. if ( geometry.normals.length > 0 ) {
  242. var normals = new Float32Array( geometry.normals.length * 3 );
  243. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  244. }
  245. if ( geometry.colors.length > 0 ) {
  246. var colors = new Float32Array( geometry.colors.length * 3 );
  247. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  248. }
  249. if ( geometry.uvs.length > 0 ) {
  250. var uvs = new Float32Array( geometry.uvs.length * 2 );
  251. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  252. }
  253. if ( geometry.uvs2.length > 0 ) {
  254. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  255. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  256. }
  257. if ( geometry.indices.length > 0 ) {
  258. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  259. var indices = new TypeArray( geometry.indices.length * 3 );
  260. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  261. }
  262. // groups
  263. this.groups = geometry.groups;
  264. // morphs
  265. for ( var name in geometry.morphTargets ) {
  266. var array = [];
  267. var morphTargets = geometry.morphTargets[ name ];
  268. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  269. var morphTarget = morphTargets[ i ];
  270. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  271. array.push( attribute.copyVector3sArray( morphTarget ) );
  272. }
  273. this.morphAttributes[ name ] = array;
  274. }
  275. // skinning
  276. if ( geometry.skinIndices.length > 0 ) {
  277. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  278. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  279. }
  280. if ( geometry.skinWeights.length > 0 ) {
  281. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  282. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  283. }
  284. //
  285. if ( geometry.boundingSphere !== null ) {
  286. this.boundingSphere = geometry.boundingSphere.clone();
  287. }
  288. if ( geometry.boundingBox !== null ) {
  289. this.boundingBox = geometry.boundingBox.clone();
  290. }
  291. return this;
  292. },
  293. computeBoundingBox: function () {
  294. var vector = new THREE.Vector3();
  295. return function () {
  296. if ( this.boundingBox === null ) {
  297. this.boundingBox = new THREE.Box3();
  298. }
  299. var positions = this.attributes.position.array;
  300. if ( positions ) {
  301. var bb = this.boundingBox;
  302. bb.makeEmpty();
  303. var minX = +Infinity;
  304. var minY = +Infinity;
  305. var minZ = +Infinity;
  306. var maxX = -Infinity;
  307. var maxY = -Infinity;
  308. var maxZ = -Infinity;
  309. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  310. var x = positions[ i ];
  311. var y = positions[ i + 1 ];
  312. var z = positions[ i + 2 ];
  313. minX = Math.min( minX, x );
  314. minY = Math.min( minY, y );
  315. minZ = Math.min( minZ, z );
  316. maxX = Math.max( maxX, x );
  317. maxY = Math.max( maxY, y );
  318. maxZ = Math.max( maxZ, z );
  319. }
  320. this.boundingBox.min.set( minX, minY, minZ );
  321. this.boundingBox.max.set( maxX, maxY, maxZ );
  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 array = attributes.normal.array;
  376. for ( var i = 0, il = array.length; i < il; i ++ ) {
  377. array[ 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. merge: function ( geometry, offset ) {
  443. if ( geometry instanceof THREE.BufferGeometry === false ) {
  444. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  445. return;
  446. }
  447. if ( offset === undefined ) offset = 0;
  448. var attributes = this.attributes;
  449. for ( var key in attributes ) {
  450. if ( geometry.attributes[ key ] === undefined ) continue;
  451. var attribute1 = attributes[ key ];
  452. var attributeArray1 = attribute1.array;
  453. var attribute2 = geometry.attributes[ key ];
  454. var attributeArray2 = attribute2.array;
  455. var attributeSize = attribute2.itemSize;
  456. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  457. attributeArray1[ j ] = attributeArray2[ i ];
  458. }
  459. }
  460. return this;
  461. },
  462. normalizeNormals: function () {
  463. var normals = this.attributes.normal.array;
  464. var x, y, z, n;
  465. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  466. x = normals[ i ];
  467. y = normals[ i + 1 ];
  468. z = normals[ i + 2 ];
  469. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  470. normals[ i ] *= n;
  471. normals[ i + 1 ] *= n;
  472. normals[ i + 2 ] *= n;
  473. }
  474. },
  475. toJSON: function () {
  476. var data = {
  477. metadata: {
  478. version: 4.4,
  479. type: 'BufferGeometry',
  480. generator: 'BufferGeometry.toJSON'
  481. }
  482. };
  483. // standard BufferGeometry serialization
  484. data.uuid = this.uuid;
  485. data.type = this.type;
  486. if ( this.name !== '' ) data.name = this.name;
  487. if ( this.parameters !== undefined ) {
  488. var parameters = this.parameters;
  489. for ( var key in parameters ) {
  490. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  491. }
  492. return data;
  493. }
  494. data.data = { attributes: {} };
  495. var index = this.index;
  496. if ( index !== null ) {
  497. var array = Array.prototype.slice.call( index.array );
  498. data.data.index = {
  499. type: index.array.constructor.name,
  500. array: array
  501. };
  502. }
  503. var attributes = this.attributes;
  504. for ( var key in attributes ) {
  505. var attribute = attributes[ key ];
  506. var array = Array.prototype.slice.call( attribute.array );
  507. data.data.attributes[ key ] = {
  508. itemSize: attribute.itemSize,
  509. type: attribute.array.constructor.name,
  510. array: array
  511. };
  512. }
  513. var groups = this.groups;
  514. if ( groups.length > 0 ) {
  515. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  516. }
  517. var boundingSphere = this.boundingSphere;
  518. if ( boundingSphere !== null ) {
  519. data.data.boundingSphere = {
  520. center: boundingSphere.center.toArray(),
  521. radius: boundingSphere.radius
  522. };
  523. }
  524. return data;
  525. },
  526. clone: function () {
  527. /*
  528. // Handle primitives
  529. var parameters = this.parameters;
  530. if ( parameters !== undefined ) {
  531. var values = [];
  532. for ( var key in parameters ) {
  533. values.push( parameters[ key ] );
  534. }
  535. var geometry = Object.create( this.constructor.prototype );
  536. this.constructor.apply( geometry, values );
  537. return geometry;
  538. }
  539. return new this.constructor().copy( this );
  540. */
  541. return new THREE.BufferGeometry().copy( this );
  542. },
  543. copy: function ( source ) {
  544. var index = source.index;
  545. if ( index !== null ) {
  546. this.setIndex( index.clone() );
  547. }
  548. var attributes = source.attributes;
  549. for ( var name in attributes ) {
  550. var attribute = attributes[ name ];
  551. this.addAttribute( name, attribute.clone() );
  552. }
  553. var groups = source.groups;
  554. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  555. var group = groups[ i ];
  556. this.addGroup( group.start, group.count );
  557. }
  558. return this;
  559. },
  560. dispose: function () {
  561. this.dispatchEvent( { type: 'dispose' } );
  562. }
  563. };
  564. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  565. THREE.BufferGeometry.MaxIndex = 65535;
粤ICP备19079148号