BufferGeometryUtils.js 19 KB

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