BufferGeometryUtils.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. import {
  5. BufferAttribute,
  6. BufferGeometry,
  7. InterleavedBuffer,
  8. InterleavedBufferAttribute,
  9. TriangleFanDrawMode,
  10. TriangleStripDrawMode,
  11. TrianglesDrawMode,
  12. Vector2,
  13. Vector3
  14. } from "../../../build/three.module.js";
  15. var BufferGeometryUtils = {
  16. computeTangents: function ( geometry ) {
  17. var index = geometry.index;
  18. var attributes = geometry.attributes;
  19. // based on http://www.terathon.com/code/tangent.html
  20. // (per vertex tangents)
  21. if ( index === null ||
  22. attributes.position === undefined ||
  23. attributes.normal === undefined ||
  24. attributes.uv === undefined ) {
  25. console.error( 'THREE.BufferGeometryUtils: .computeTangents() failed. Missing required attributes (index, position, normal or uv)' );
  26. return;
  27. }
  28. var indices = index.array;
  29. var positions = attributes.position.array;
  30. var normals = attributes.normal.array;
  31. var uvs = attributes.uv.array;
  32. var nVertices = positions.length / 3;
  33. if ( attributes.tangent === undefined ) {
  34. geometry.setAttribute( 'tangent', new BufferAttribute( new Float32Array( 4 * nVertices ), 4 ) );
  35. }
  36. var tangents = attributes.tangent.array;
  37. var tan1 = [], tan2 = [];
  38. for ( var i = 0; i < nVertices; i ++ ) {
  39. tan1[ i ] = new Vector3();
  40. tan2[ i ] = new Vector3();
  41. }
  42. var vA = new Vector3(),
  43. vB = new Vector3(),
  44. vC = new Vector3(),
  45. uvA = new Vector2(),
  46. uvB = new Vector2(),
  47. uvC = new Vector2(),
  48. sdir = new Vector3(),
  49. tdir = new Vector3();
  50. function handleTriangle( a, b, c ) {
  51. vA.fromArray( positions, a * 3 );
  52. vB.fromArray( positions, b * 3 );
  53. vC.fromArray( positions, c * 3 );
  54. uvA.fromArray( uvs, a * 2 );
  55. uvB.fromArray( uvs, b * 2 );
  56. uvC.fromArray( uvs, c * 2 );
  57. vB.sub( vA );
  58. vC.sub( vA );
  59. uvB.sub( uvA );
  60. uvC.sub( uvA );
  61. var r = 1.0 / ( uvB.x * uvC.y - uvC.x * uvB.y );
  62. // silently ignore degenerate uv triangles having coincident or colinear vertices
  63. if ( ! isFinite( r ) ) return;
  64. sdir.copy( vB ).multiplyScalar( uvC.y ).addScaledVector( vC, - uvB.y ).multiplyScalar( r );
  65. tdir.copy( vC ).multiplyScalar( uvB.x ).addScaledVector( vB, - uvC.x ).multiplyScalar( r );
  66. tan1[ a ].add( sdir );
  67. tan1[ b ].add( sdir );
  68. tan1[ c ].add( sdir );
  69. tan2[ a ].add( tdir );
  70. tan2[ b ].add( tdir );
  71. tan2[ c ].add( tdir );
  72. }
  73. var groups = geometry.groups;
  74. if ( groups.length === 0 ) {
  75. groups = [ {
  76. start: 0,
  77. count: indices.length
  78. } ];
  79. }
  80. for ( var i = 0, il = groups.length; i < il; ++ i ) {
  81. var group = groups[ i ];
  82. var start = group.start;
  83. var count = group.count;
  84. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  85. handleTriangle(
  86. indices[ j + 0 ],
  87. indices[ j + 1 ],
  88. indices[ j + 2 ]
  89. );
  90. }
  91. }
  92. var tmp = new Vector3(), tmp2 = new Vector3();
  93. var n = new Vector3(), n2 = new Vector3();
  94. var w, t, test;
  95. function handleVertex( v ) {
  96. n.fromArray( normals, v * 3 );
  97. n2.copy( n );
  98. t = tan1[ v ];
  99. // Gram-Schmidt orthogonalize
  100. tmp.copy( t );
  101. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  102. // Calculate handedness
  103. tmp2.crossVectors( n2, t );
  104. test = tmp2.dot( tan2[ v ] );
  105. w = ( test < 0.0 ) ? - 1.0 : 1.0;
  106. tangents[ v * 4 ] = tmp.x;
  107. tangents[ v * 4 + 1 ] = tmp.y;
  108. tangents[ v * 4 + 2 ] = tmp.z;
  109. tangents[ v * 4 + 3 ] = w;
  110. }
  111. for ( var i = 0, il = groups.length; i < il; ++ i ) {
  112. var group = groups[ i ];
  113. var start = group.start;
  114. var count = group.count;
  115. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  116. handleVertex( indices[ j + 0 ] );
  117. handleVertex( indices[ j + 1 ] );
  118. handleVertex( indices[ j + 2 ] );
  119. }
  120. }
  121. },
  122. /**
  123. * @param {Array<BufferGeometry>} geometries
  124. * @param {Boolean} useGroups
  125. * @return {BufferGeometry}
  126. */
  127. mergeBufferGeometries: function ( geometries, useGroups ) {
  128. var isIndexed = geometries[ 0 ].index !== null;
  129. var attributesUsed = new Set( Object.keys( geometries[ 0 ].attributes ) );
  130. var morphAttributesUsed = new Set( Object.keys( geometries[ 0 ].morphAttributes ) );
  131. var attributes = {};
  132. var morphAttributes = {};
  133. var morphTargetsRelative = geometries[ 0 ].morphTargetsRelative;
  134. var mergedGeometry = new BufferGeometry();
  135. var offset = 0;
  136. for ( var i = 0; i < geometries.length; ++ i ) {
  137. var geometry = geometries[ i ];
  138. var attributesCount = 0;
  139. // ensure that all geometries are indexed, or none
  140. if ( isIndexed !== ( geometry.index !== null ) ) {
  141. console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.' );
  142. return null;
  143. }
  144. // gather attributes, exit early if they're different
  145. for ( var name in geometry.attributes ) {
  146. if ( ! attributesUsed.has( name ) ) {
  147. console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure "' + name + '" attribute exists among all geometries, or in none of them.' );
  148. return null;
  149. }
  150. if ( attributes[ name ] === undefined ) attributes[ name ] = [];
  151. attributes[ name ].push( geometry.attributes[ name ] );
  152. attributesCount ++;
  153. }
  154. // ensure geometries have the same number of attributes
  155. if ( attributesCount !== attributesUsed.size ) {
  156. console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. Make sure all geometries have the same number of attributes.' );
  157. return null;
  158. }
  159. // gather morph attributes, exit early if they're different
  160. if ( morphTargetsRelative !== geometry.morphTargetsRelative ) {
  161. console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. .morphTargetsRelative must be consistent throughout all geometries.' );
  162. return null;
  163. }
  164. for ( var name in geometry.morphAttributes ) {
  165. if ( ! morphAttributesUsed.has( name ) ) {
  166. console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. .morphAttributes must be consistent throughout all geometries.' );
  167. return null;
  168. }
  169. if ( morphAttributes[ name ] === undefined ) morphAttributes[ name ] = [];
  170. morphAttributes[ name ].push( geometry.morphAttributes[ name ] );
  171. }
  172. // gather .userData
  173. mergedGeometry.userData.mergedUserData = mergedGeometry.userData.mergedUserData || [];
  174. mergedGeometry.userData.mergedUserData.push( geometry.userData );
  175. if ( useGroups ) {
  176. var count;
  177. if ( isIndexed ) {
  178. count = geometry.index.count;
  179. } else if ( geometry.attributes.position !== undefined ) {
  180. count = geometry.attributes.position.count;
  181. } else {
  182. console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. The geometry must have either an index or a position attribute' );
  183. return null;
  184. }
  185. mergedGeometry.addGroup( offset, count, i );
  186. offset += count;
  187. }
  188. }
  189. // merge indices
  190. if ( isIndexed ) {
  191. var indexOffset = 0;
  192. var mergedIndex = [];
  193. for ( var i = 0; i < geometries.length; ++ i ) {
  194. var index = geometries[ i ].index;
  195. for ( var j = 0; j < index.count; ++ j ) {
  196. mergedIndex.push( index.getX( j ) + indexOffset );
  197. }
  198. indexOffset += geometries[ i ].attributes.position.count;
  199. }
  200. mergedGeometry.setIndex( mergedIndex );
  201. }
  202. // merge attributes
  203. for ( var name in attributes ) {
  204. var mergedAttribute = this.mergeBufferAttributes( attributes[ name ] );
  205. if ( ! mergedAttribute ) {
  206. console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the ' + name + ' attribute.' );
  207. return null;
  208. }
  209. mergedGeometry.setAttribute( name, mergedAttribute );
  210. }
  211. // merge morph attributes
  212. for ( var name in morphAttributes ) {
  213. var numMorphTargets = morphAttributes[ name ][ 0 ].length;
  214. if ( numMorphTargets === 0 ) break;
  215. mergedGeometry.morphAttributes = mergedGeometry.morphAttributes || {};
  216. mergedGeometry.morphAttributes[ name ] = [];
  217. for ( var i = 0; i < numMorphTargets; ++ i ) {
  218. var morphAttributesToMerge = [];
  219. for ( var j = 0; j < morphAttributes[ name ].length; ++ j ) {
  220. morphAttributesToMerge.push( morphAttributes[ name ][ j ][ i ] );
  221. }
  222. var mergedMorphAttribute = this.mergeBufferAttributes( morphAttributesToMerge );
  223. if ( ! mergedMorphAttribute ) {
  224. console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the ' + name + ' morphAttribute.' );
  225. return null;
  226. }
  227. mergedGeometry.morphAttributes[ name ].push( mergedMorphAttribute );
  228. }
  229. }
  230. return mergedGeometry;
  231. },
  232. /**
  233. * @param {Array<BufferAttribute>} attributes
  234. * @return {BufferAttribute}
  235. */
  236. mergeBufferAttributes: function ( attributes ) {
  237. var TypedArray;
  238. var itemSize;
  239. var normalized;
  240. var arrayLength = 0;
  241. for ( var i = 0; i < attributes.length; ++ i ) {
  242. var attribute = attributes[ i ];
  243. if ( attribute.isInterleavedBufferAttribute ) {
  244. console.error( 'THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. InterleavedBufferAttributes are not supported.' );
  245. return null;
  246. }
  247. if ( TypedArray === undefined ) TypedArray = attribute.array.constructor;
  248. if ( TypedArray !== attribute.array.constructor ) {
  249. console.error( 'THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes.' );
  250. return null;
  251. }
  252. if ( itemSize === undefined ) itemSize = attribute.itemSize;
  253. if ( itemSize !== attribute.itemSize ) {
  254. console.error( 'THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes.' );
  255. return null;
  256. }
  257. if ( normalized === undefined ) normalized = attribute.normalized;
  258. if ( normalized !== attribute.normalized ) {
  259. console.error( 'THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes.' );
  260. return null;
  261. }
  262. arrayLength += attribute.array.length;
  263. }
  264. var array = new TypedArray( arrayLength );
  265. var offset = 0;
  266. for ( var i = 0; i < attributes.length; ++ i ) {
  267. array.set( attributes[ i ].array, offset );
  268. offset += attributes[ i ].array.length;
  269. }
  270. return new BufferAttribute( array, itemSize, normalized );
  271. },
  272. /**
  273. * @param {Array<BufferAttribute>} attributes
  274. * @return {Array<InterleavedBufferAttribute>}
  275. */
  276. interleaveAttributes: function ( attributes ) {
  277. // Interleaves the provided attributes into an InterleavedBuffer and returns
  278. // a set of InterleavedBufferAttributes for each attribute
  279. var TypedArray;
  280. var arrayLength = 0;
  281. var stride = 0;
  282. // calculate the the length and type of the interleavedBuffer
  283. for ( var i = 0, l = attributes.length; i < l; ++ i ) {
  284. var attribute = attributes[ i ];
  285. if ( TypedArray === undefined ) TypedArray = attribute.array.constructor;
  286. if ( TypedArray !== attribute.array.constructor ) {
  287. console.error( 'AttributeBuffers of different types cannot be interleaved' );
  288. return null;
  289. }
  290. arrayLength += attribute.array.length;
  291. stride += attribute.itemSize;
  292. }
  293. // Create the set of buffer attributes
  294. var interleavedBuffer = new InterleavedBuffer( new TypedArray( arrayLength ), stride );
  295. var offset = 0;
  296. var res = [];
  297. var getters = [ 'getX', 'getY', 'getZ', 'getW' ];
  298. var setters = [ 'setX', 'setY', 'setZ', 'setW' ];
  299. for ( var j = 0, l = attributes.length; j < l; j ++ ) {
  300. var attribute = attributes[ j ];
  301. var itemSize = attribute.itemSize;
  302. var count = attribute.count;
  303. var iba = new InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, attribute.normalized );
  304. res.push( iba );
  305. offset += itemSize;
  306. // Move the data for each attribute into the new interleavedBuffer
  307. // at the appropriate offset
  308. for ( var c = 0; c < count; c ++ ) {
  309. for ( var k = 0; k < itemSize; k ++ ) {
  310. iba[ setters[ k ] ]( c, attribute[ getters[ k ] ]( c ) );
  311. }
  312. }
  313. }
  314. return res;
  315. },
  316. /**
  317. * @param {Array<BufferGeometry>} geometry
  318. * @return {number}
  319. */
  320. estimateBytesUsed: function ( geometry ) {
  321. // Return the estimated memory used by this geometry in bytes
  322. // Calculate using itemSize, count, and BYTES_PER_ELEMENT to account
  323. // for InterleavedBufferAttributes.
  324. var mem = 0;
  325. for ( var name in geometry.attributes ) {
  326. var attr = geometry.getAttribute( name );
  327. mem += attr.count * attr.itemSize * attr.array.BYTES_PER_ELEMENT;
  328. }
  329. var indices = geometry.getIndex();
  330. mem += indices ? indices.count * indices.itemSize * indices.array.BYTES_PER_ELEMENT : 0;
  331. return mem;
  332. },
  333. /**
  334. * @param {BufferGeometry} geometry
  335. * @param {number} tolerance
  336. * @return {BufferGeometry>}
  337. */
  338. mergeVertices: function ( geometry, tolerance = 1e-4 ) {
  339. tolerance = Math.max( tolerance, Number.EPSILON );
  340. // Generate an index buffer if the geometry doesn't have one, or optimize it
  341. // if it's already available.
  342. var hashToIndex = {};
  343. var indices = geometry.getIndex();
  344. var positions = geometry.getAttribute( 'position' );
  345. var vertexCount = indices ? indices.count : positions.count;
  346. // next value for triangle indices
  347. var nextIndex = 0;
  348. // attributes and new attribute arrays
  349. var attributeNames = Object.keys( geometry.attributes );
  350. var attrArrays = {};
  351. var morphAttrsArrays = {};
  352. var newIndices = [];
  353. var getters = [ 'getX', 'getY', 'getZ', 'getW' ];
  354. // initialize the arrays
  355. for ( var i = 0, l = attributeNames.length; i < l; i ++ ) {
  356. var name = attributeNames[ i ];
  357. attrArrays[ name ] = [];
  358. var morphAttr = geometry.morphAttributes[ name ];
  359. if ( morphAttr ) {
  360. morphAttrsArrays[ name ] = new Array( morphAttr.length ).fill().map( () => [] );
  361. }
  362. }
  363. // convert the error tolerance to an amount of decimal places to truncate to
  364. var decimalShift = Math.log10( 1 / tolerance );
  365. var shiftMultiplier = Math.pow( 10, decimalShift );
  366. for ( var i = 0; i < vertexCount; i ++ ) {
  367. var index = indices ? indices.getX( i ) : i;
  368. // Generate a hash for the vertex attributes at the current index 'i'
  369. var hash = '';
  370. for ( var j = 0, l = attributeNames.length; j < l; j ++ ) {
  371. var name = attributeNames[ j ];
  372. var attribute = geometry.getAttribute( name );
  373. var itemSize = attribute.itemSize;
  374. for ( var k = 0; k < itemSize; k ++ ) {
  375. // double tilde truncates the decimal value
  376. hash += `${ ~ ~ ( attribute[ getters[ k ] ]( index ) * shiftMultiplier ) },`;
  377. }
  378. }
  379. // Add another reference to the vertex if it's already
  380. // used by another index
  381. if ( hash in hashToIndex ) {
  382. newIndices.push( hashToIndex[ hash ] );
  383. } else {
  384. // copy data to the new index in the attribute arrays
  385. for ( var j = 0, l = attributeNames.length; j < l; j ++ ) {
  386. var name = attributeNames[ j ];
  387. var attribute = geometry.getAttribute( name );
  388. var morphAttr = geometry.morphAttributes[ name ];
  389. var itemSize = attribute.itemSize;
  390. var newarray = attrArrays[ name ];
  391. var newMorphArrays = morphAttrsArrays[ name ];
  392. for ( var k = 0; k < itemSize; k ++ ) {
  393. var getterFunc = getters[ k ];
  394. newarray.push( attribute[ getterFunc ]( index ) );
  395. if ( morphAttr ) {
  396. for ( var m = 0, ml = morphAttr.length; m < ml; m ++ ) {
  397. newMorphArrays[ m ].push( morphAttr[ m ][ getterFunc ]( index ) );
  398. }
  399. }
  400. }
  401. }
  402. hashToIndex[ hash ] = nextIndex;
  403. newIndices.push( nextIndex );
  404. nextIndex ++;
  405. }
  406. }
  407. // Generate typed arrays from new attribute arrays and update
  408. // the attributeBuffers
  409. const result = geometry.clone();
  410. for ( var i = 0, l = attributeNames.length; i < l; i ++ ) {
  411. var name = attributeNames[ i ];
  412. var oldAttribute = geometry.getAttribute( name );
  413. var buffer = new oldAttribute.array.constructor( attrArrays[ name ] );
  414. var attribute = new BufferAttribute( buffer, oldAttribute.itemSize, oldAttribute.normalized );
  415. result.setAttribute( name, attribute );
  416. // Update the attribute arrays
  417. if ( name in morphAttrsArrays ) {
  418. for ( var j = 0; j < morphAttrsArrays[ name ].length; j ++ ) {
  419. var oldMorphAttribute = geometry.morphAttributes[ name ][ j ];
  420. var buffer = new oldMorphAttribute.array.constructor( morphAttrsArrays[ name ][ j ] );
  421. var morphAttribute = new BufferAttribute( buffer, oldMorphAttribute.itemSize, oldMorphAttribute.normalized );
  422. result.morphAttributes[ name ][ j ] = morphAttribute;
  423. }
  424. }
  425. }
  426. // indices
  427. result.setIndex( newIndices );
  428. return result;
  429. },
  430. /**
  431. * @param {BufferGeometry} geometry
  432. * @param {number} drawMode
  433. * @return {BufferGeometry>}
  434. */
  435. toTrianglesDrawMode: function ( geometry, drawMode ) {
  436. if ( drawMode === TrianglesDrawMode ) {
  437. console.warn( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.' );
  438. return geometry;
  439. }
  440. if ( drawMode === TriangleFanDrawMode || drawMode === TriangleStripDrawMode ) {
  441. var index = geometry.getIndex();
  442. // generate index if not present
  443. if ( index === null ) {
  444. var indices = [];
  445. var position = geometry.getAttribute( 'position' );
  446. if ( position !== undefined ) {
  447. for ( var i = 0; i < position.count; i ++ ) {
  448. indices.push( i );
  449. }
  450. geometry.setIndex( indices );
  451. index = geometry.getIndex();
  452. } else {
  453. console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.' );
  454. return geometry;
  455. }
  456. }
  457. //
  458. var numberOfTriangles = index.count - 2;
  459. var newIndices = [];
  460. if ( drawMode === TriangleFanDrawMode ) {
  461. // gl.TRIANGLE_FAN
  462. for ( var i = 1; i <= numberOfTriangles; i ++ ) {
  463. newIndices.push( index.getX( 0 ) );
  464. newIndices.push( index.getX( i ) );
  465. newIndices.push( index.getX( i + 1 ) );
  466. }
  467. } else {
  468. // gl.TRIANGLE_STRIP
  469. for ( var i = 0; i < numberOfTriangles; i ++ ) {
  470. if ( i % 2 === 0 ) {
  471. newIndices.push( index.getX( i ) );
  472. newIndices.push( index.getX( i + 1 ) );
  473. newIndices.push( index.getX( i + 2 ) );
  474. } else {
  475. newIndices.push( index.getX( i + 2 ) );
  476. newIndices.push( index.getX( i + 1 ) );
  477. newIndices.push( index.getX( i ) );
  478. }
  479. }
  480. }
  481. if ( ( newIndices.length / 3 ) !== numberOfTriangles ) {
  482. console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.' );
  483. }
  484. // build final geometry
  485. var newGeometry = geometry.clone();
  486. newGeometry.setIndex( newIndices );
  487. newGeometry.clearGroups();
  488. return newGeometry;
  489. } else {
  490. console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:', drawMode );
  491. return geometry;
  492. }
  493. }
  494. };
  495. export { BufferGeometryUtils };