BufferGeometryUtils.js 19 KB

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