BufferGeometryUtils.js 19 KB

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