BufferGeometry.tests.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. /* global QUnit */
  2. import { BufferGeometry } from '../../../../src/core/BufferGeometry';
  3. import {
  4. BufferAttribute,
  5. Uint16BufferAttribute,
  6. Uint32BufferAttribute
  7. } from '../../../../src/core/BufferAttribute';
  8. import { Vector3 } from '../../../../src/math/Vector3';
  9. import { Matrix4 } from '../../../../src/math/Matrix4';
  10. import { Sphere } from '../../../../src/math/Sphere';
  11. import {
  12. x,
  13. y,
  14. z
  15. } from '../math/Constants.tests';
  16. import { CONSOLE_LEVEL } from '../../utils/console-wrapper';
  17. var DegToRad = Math.PI / 180;
  18. function bufferAttributeEquals( a, b, tolerance ) {
  19. tolerance = tolerance || 0.0001;
  20. if ( a.count !== b.count || a.itemSize !== b.itemSize ) {
  21. return false;
  22. }
  23. for ( var i = 0, il = a.count * a.itemSize; i < il; i ++ ) {
  24. var delta = a[ i ] - b[ i ];
  25. if ( delta > tolerance ) {
  26. return false;
  27. }
  28. }
  29. return true;
  30. }
  31. function getBBForVertices( vertices ) {
  32. var geometry = new BufferGeometry();
  33. geometry.setAttribute( "position", new BufferAttribute( new Float32Array( vertices ), 3 ) );
  34. geometry.computeBoundingBox();
  35. return geometry.boundingBox;
  36. }
  37. function getBSForVertices( vertices ) {
  38. var geometry = new BufferGeometry();
  39. geometry.setAttribute( "position", new BufferAttribute( new Float32Array( vertices ), 3 ) );
  40. geometry.computeBoundingSphere();
  41. return geometry.boundingSphere;
  42. }
  43. function getNormalsForVertices( vertices, assert ) {
  44. var geometry = new BufferGeometry();
  45. geometry.setAttribute( "position", new BufferAttribute( new Float32Array( vertices ), 3 ) );
  46. geometry.computeVertexNormals();
  47. assert.ok( geometry.attributes.normal !== undefined, "normal attribute was created" );
  48. return geometry.attributes.normal.array;
  49. }
  50. export default QUnit.module( 'Core', () => {
  51. QUnit.module( 'BufferGeometry', () => {
  52. // INHERITANCE
  53. QUnit.todo( "Extending", ( assert ) => {
  54. assert.ok( false, "everything's gonna be alright" );
  55. } );
  56. // INSTANCING
  57. QUnit.todo( "Instancing", ( assert ) => {
  58. assert.ok( false, "everything's gonna be alright" );
  59. } );
  60. // PUBLIC STUFF
  61. QUnit.todo( "isBufferGeometry", ( assert ) => {
  62. assert.ok( false, "everything's gonna be alright" );
  63. } );
  64. QUnit.test( "setIndex/getIndex", ( assert ) => {
  65. var a = new BufferGeometry();
  66. var uint16 = [ 1, 2, 3 ];
  67. var uint32 = [ 65535, 65536, 65537 ];
  68. var str = "foo";
  69. a.setIndex( uint16 );
  70. assert.ok( a.getIndex() instanceof Uint16BufferAttribute, "Index has the right type" );
  71. assert.deepEqual( a.getIndex().array, new Uint16Array( uint16 ), "Small index gets stored correctly" );
  72. a.setIndex( uint32 );
  73. assert.ok( a.getIndex() instanceof Uint32BufferAttribute, "Index has the right type" );
  74. assert.deepEqual( a.getIndex().array, new Uint32Array( uint32 ), "Large index gets stored correctly" );
  75. a.setIndex( str );
  76. assert.strictEqual( a.getIndex(), str, "Weird index gets stored correctly" );
  77. } );
  78. QUnit.todo( "getAttribute", ( assert ) => {
  79. assert.ok( false, "everything's gonna be alright" );
  80. } );
  81. QUnit.test( "set / delete Attribute", ( assert ) => {
  82. var geometry = new BufferGeometry();
  83. var attributeName = "position";
  84. assert.ok( geometry.attributes[ attributeName ] === undefined, 'no attribute defined' );
  85. geometry.setAttribute( attributeName, new BufferAttribute( new Float32Array( [ 1, 2, 3 ], 1 ) ) );
  86. assert.ok( geometry.attributes[ attributeName ] !== undefined, 'attribute is defined' );
  87. geometry.deleteAttribute( attributeName );
  88. assert.ok( geometry.attributes[ attributeName ] === undefined, 'no attribute defined' );
  89. } );
  90. QUnit.test( "addGroup", ( assert ) => {
  91. var a = new BufferGeometry();
  92. var expected = [
  93. {
  94. start: 0,
  95. count: 1,
  96. materialIndex: 0
  97. },
  98. {
  99. start: 1,
  100. count: 2,
  101. materialIndex: 2
  102. }
  103. ];
  104. a.addGroup( 0, 1, 0 );
  105. a.addGroup( 1, 2, 2 );
  106. assert.deepEqual( a.groups, expected, "Check groups were stored correctly and in order" );
  107. a.clearGroups();
  108. assert.strictEqual( a.groups.length, 0, "Check groups were deleted correctly" );
  109. } );
  110. QUnit.todo( "clearGroups", ( assert ) => {
  111. assert.ok( false, "everything's gonna be alright" );
  112. } );
  113. QUnit.test( "setDrawRange", ( assert ) => {
  114. var a = new BufferGeometry();
  115. a.setDrawRange( 1.0, 7 );
  116. assert.deepEqual( a.drawRange, {
  117. start: 1,
  118. count: 7
  119. }, "Check draw range was stored correctly" );
  120. } );
  121. QUnit.test( "applyMatrix4", ( assert ) => {
  122. var geometry = new BufferGeometry();
  123. geometry.setAttribute( "position", new BufferAttribute( new Float32Array( 6 ), 3 ) );
  124. var matrix = new Matrix4().set(
  125. 1, 0, 0, 1.5,
  126. 0, 1, 0, - 2,
  127. 0, 0, 1, 3,
  128. 0, 0, 0, 1
  129. );
  130. geometry.applyMatrix4( matrix );
  131. var position = geometry.attributes.position.array;
  132. var m = matrix.elements;
  133. assert.ok( position[ 0 ] === m[ 12 ] && position[ 1 ] === m[ 13 ] && position[ 2 ] === m[ 14 ], "position was extracted from matrix" );
  134. assert.ok( position[ 3 ] === m[ 12 ] && position[ 4 ] === m[ 13 ] && position[ 5 ] === m[ 14 ], "position was extracted from matrix twice" );
  135. assert.ok( geometry.attributes.position.version === 1, "version was increased during update" );
  136. } );
  137. QUnit.test( "rotateX/Y/Z", ( assert ) => {
  138. var geometry = new BufferGeometry();
  139. geometry.setAttribute( "position", new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ) );
  140. var pos = geometry.attributes.position.array;
  141. geometry.rotateX( 180 * DegToRad );
  142. // object was rotated around x so all items should be flipped but the x ones
  143. assert.ok( pos[ 0 ] === 1 && pos[ 1 ] === - 2 && pos[ 2 ] === - 3 &&
  144. pos[ 3 ] === 4 && pos[ 4 ] === - 5 && pos[ 5 ] === - 6, "vertices were rotated around x by 180 degrees" );
  145. geometry.rotateY( 180 * DegToRad );
  146. // vertices were rotated around y so all items should be flipped again but the y ones
  147. assert.ok( pos[ 0 ] === - 1 && pos[ 1 ] === - 2 && pos[ 2 ] === 3 &&
  148. pos[ 3 ] === - 4 && pos[ 4 ] === - 5 && pos[ 5 ] === 6, "vertices were rotated around y by 180 degrees" );
  149. geometry.rotateZ( 180 * DegToRad );
  150. // vertices were rotated around z so all items should be flipped again but the z ones
  151. assert.ok( pos[ 0 ] === 1 && pos[ 1 ] === 2 && pos[ 2 ] === 3 &&
  152. pos[ 3 ] === 4 && pos[ 4 ] === 5 && pos[ 5 ] === 6, "vertices were rotated around z by 180 degrees" );
  153. } );
  154. QUnit.test( "translate", ( assert ) => {
  155. var geometry = new BufferGeometry();
  156. geometry.setAttribute( "position", new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ) );
  157. var pos = geometry.attributes.position.array;
  158. geometry.translate( 10, 20, 30 );
  159. assert.ok( pos[ 0 ] === 11 && pos[ 1 ] === 22 && pos[ 2 ] === 33 &&
  160. pos[ 3 ] === 14 && pos[ 4 ] === 25 && pos[ 5 ] === 36, "vertices were translated" );
  161. } );
  162. QUnit.test( "scale", ( assert ) => {
  163. var geometry = new BufferGeometry();
  164. geometry.setAttribute( "position", new BufferAttribute( new Float32Array( [ - 1, - 1, - 1, 2, 2, 2 ] ), 3 ) );
  165. var pos = geometry.attributes.position.array;
  166. geometry.scale( 1, 2, 3 );
  167. assert.ok( pos[ 0 ] === - 1 && pos[ 1 ] === - 2 && pos[ 2 ] === - 3 &&
  168. pos[ 3 ] === 2 && pos[ 4 ] === 4 && pos[ 5 ] === 6, "vertices were scaled" );
  169. } );
  170. QUnit.test( "lookAt", ( assert ) => {
  171. var a = new BufferGeometry();
  172. var vertices = new Float32Array( [
  173. - 1.0, - 1.0, 1.0,
  174. 1.0, - 1.0, 1.0,
  175. 1.0, 1.0, 1.0,
  176. 1.0, 1.0, 1.0,
  177. - 1.0, 1.0, 1.0,
  178. - 1.0, - 1.0, 1.0
  179. ] );
  180. a.setAttribute( 'position', new BufferAttribute( vertices, 3 ) );
  181. var sqrt = Math.sqrt( 2 );
  182. var expected = new Float32Array( [
  183. 1, 0, - sqrt,
  184. - 1, 0, - sqrt,
  185. - 1, sqrt, 0,
  186. - 1, sqrt, 0,
  187. 1, sqrt, 0,
  188. 1, 0, - sqrt
  189. ] );
  190. a.lookAt( new Vector3( 0, 1, - 1 ) );
  191. assert.ok( bufferAttributeEquals( a.attributes.position.array, expected ), "Rotation is correct" );
  192. } );
  193. QUnit.test( "center", ( assert ) => {
  194. var geometry = new BufferGeometry();
  195. geometry.setAttribute( "position", new BufferAttribute( new Float32Array( [
  196. - 1, - 1, - 1,
  197. 1, 1, 1,
  198. 4, 4, 4
  199. ] ), 3 ) );
  200. geometry.center();
  201. var pos = geometry.attributes.position.array;
  202. // the boundingBox should go from (-1, -1, -1) to (4, 4, 4) so it has a size of (5, 5, 5)
  203. // after centering it the vertices should be placed between (-2.5, -2.5, -2.5) and (2.5, 2.5, 2.5)
  204. assert.ok( pos[ 0 ] === - 2.5 && pos[ 1 ] === - 2.5 && pos[ 2 ] === - 2.5 &&
  205. pos[ 3 ] === - 0.5 && pos[ 4 ] === - 0.5 && pos[ 5 ] === - 0.5 &&
  206. pos[ 6 ] === 2.5 && pos[ 7 ] === 2.5 && pos[ 8 ] === 2.5, "vertices were replaced by boundingBox dimensions" );
  207. } );
  208. QUnit.test( "computeBoundingBox", ( assert ) => {
  209. var bb = getBBForVertices( [ - 1, - 2, - 3, 13, - 2, - 3.5, - 1, - 20, 0, - 4, 5, 6 ] );
  210. assert.ok( bb.min.x === - 4 && bb.min.y === - 20 && bb.min.z === - 3.5, "min values are set correctly" );
  211. assert.ok( bb.max.x === 13 && bb.max.y === 5 && bb.max.z === 6, "max values are set correctly" );
  212. var bb = getBBForVertices( [ - 1, - 1, - 1 ] );
  213. assert.ok( bb.min.x === bb.max.x && bb.min.y === bb.max.y && bb.min.z === bb.max.z, "since there is only one vertex, max and min are equal" );
  214. assert.ok( bb.min.x === - 1 && bb.min.y === - 1 && bb.min.z === - 1, "since there is only one vertex, min and max are this vertex" );
  215. } );
  216. QUnit.test( "computeBoundingSphere", ( assert ) => {
  217. var bs = getBSForVertices( [ - 10, 0, 0, 10, 0, 0 ] );
  218. assert.ok( bs.radius === ( 10 + 10 ) / 2, "radius is equal to deltaMinMax / 2" );
  219. assert.ok( bs.center.x === 0 && bs.center.y === 0 && bs.center.y === 0, "bounding sphere is at ( 0, 0, 0 )" );
  220. var bs = getBSForVertices( [ - 5, 11, - 3, 5, - 11, 3 ] );
  221. var radius = new Vector3( 5, 11, 3 ).length();
  222. assert.ok( bs.radius === radius, "radius is equal to directionLength" );
  223. assert.ok( bs.center.x === 0 && bs.center.y === 0 && bs.center.y === 0, "bounding sphere is at ( 0, 0, 0 )" );
  224. } );
  225. QUnit.todo( "computeFaceNormals", ( assert ) => {
  226. assert.ok( false, "everything's gonna be alright" );
  227. } );
  228. QUnit.test( "computeVertexNormals", ( assert ) => {
  229. // get normals for a counter clockwise created triangle
  230. var normals = getNormalsForVertices( [ - 1, 0, 0, 1, 0, 0, 0, 1, 0 ], assert );
  231. assert.ok( normals[ 0 ] === 0 && normals[ 1 ] === 0 && normals[ 2 ] === 1,
  232. "first normal is pointing to screen since the the triangle was created counter clockwise" );
  233. assert.ok( normals[ 3 ] === 0 && normals[ 4 ] === 0 && normals[ 5 ] === 1,
  234. "second normal is pointing to screen since the the triangle was created counter clockwise" );
  235. assert.ok( normals[ 6 ] === 0 && normals[ 7 ] === 0 && normals[ 8 ] === 1,
  236. "third normal is pointing to screen since the the triangle was created counter clockwise" );
  237. // get normals for a clockwise created triangle
  238. var normals = getNormalsForVertices( [ 1, 0, 0, - 1, 0, 0, 0, 1, 0 ], assert );
  239. assert.ok( normals[ 0 ] === 0 && normals[ 1 ] === 0 && normals[ 2 ] === - 1,
  240. "first normal is pointing to screen since the the triangle was created clockwise" );
  241. assert.ok( normals[ 3 ] === 0 && normals[ 4 ] === 0 && normals[ 5 ] === - 1,
  242. "second normal is pointing to screen since the the triangle was created clockwise" );
  243. assert.ok( normals[ 6 ] === 0 && normals[ 7 ] === 0 && normals[ 8 ] === - 1,
  244. "third normal is pointing to screen since the the triangle was created clockwise" );
  245. var normals = getNormalsForVertices( [ 0, 0, 1, 0, 0, - 1, 1, 1, 0 ], assert );
  246. // the triangle is rotated by 45 degrees to the right so the normals of the three vertices
  247. // should point to (1, -1, 0).normalized(). The simplest solution is to check against a normalized
  248. // vector (1, -1, 0) but you will get calculation errors because of floating calculations so another
  249. // valid technique is to create a vector which stands in 90 degrees to the normals and calculate the
  250. // dot product which is the cos of the angle between them. This should be < floating calculation error
  251. // which can be taken from Number.EPSILON
  252. var direction = new Vector3( 1, 1, 0 ).normalize(); // a vector which should have 90 degrees difference to normals
  253. var difference = direction.dot( new Vector3( normals[ 0 ], normals[ 1 ], normals[ 2 ] ) );
  254. assert.ok( difference < Number.EPSILON, "normal is equal to reference vector" );
  255. // get normals for a line should be NAN because you need min a triangle to calculate normals
  256. var normals = getNormalsForVertices( [ 1, 0, 0, - 1, 0, 0 ], assert );
  257. for ( var i = 0; i < normals.length; i ++ ) {
  258. assert.ok( ! normals[ i ], "normals can't be calculated which is good" );
  259. }
  260. } );
  261. QUnit.test( "computeVertexNormals (indexed)", ( assert ) => {
  262. var sqrt = 0.5 * Math.sqrt( 2 );
  263. var normal = new BufferAttribute( new Float32Array( [
  264. - 1, 0, 0, - 1, 0, 0, - 1, 0, 0,
  265. sqrt, sqrt, 0, sqrt, sqrt, 0, sqrt, sqrt, 0,
  266. - 1, 0, 0
  267. ] ), 3 );
  268. var position = new BufferAttribute( new Float32Array( [
  269. 0.5, 0.5, 0.5, 0.5, 0.5, - 0.5, 0.5, - 0.5, 0.5,
  270. 0.5, - 0.5, - 0.5, - 0.5, 0.5, - 0.5, - 0.5, 0.5, 0.5,
  271. - 0.5, - 0.5, - 0.5
  272. ] ), 3 );
  273. var index = new BufferAttribute( new Uint16Array( [
  274. 0, 2, 1, 2, 3, 1, 4, 6, 5, 6, 7, 5
  275. ] ), 1 );
  276. var a = new BufferGeometry();
  277. a.setAttribute( "position", position );
  278. a.computeVertexNormals();
  279. assert.ok(
  280. bufferAttributeEquals( normal, a.getAttribute( "normal" ) ),
  281. "Regular geometry: first computed normals are correct"
  282. );
  283. // a second time to see if the existing normals get properly deleted
  284. a.computeVertexNormals();
  285. assert.ok(
  286. bufferAttributeEquals( normal, a.getAttribute( "normal" ) ),
  287. "Regular geometry: second computed normals are correct"
  288. );
  289. // indexed geometry
  290. var a = new BufferGeometry();
  291. a.setAttribute( "position", position );
  292. a.setIndex( index );
  293. a.computeVertexNormals();
  294. assert.ok( bufferAttributeEquals( normal, a.getAttribute( "normal" ) ), "Indexed geometry: computed normals are correct" );
  295. } );
  296. QUnit.test( "merge", ( assert ) => {
  297. var geometry1 = new BufferGeometry();
  298. geometry1.setAttribute( "attrName", new BufferAttribute( new Float32Array( [ 1, 2, 3, 0, 0, 0 ] ), 3 ) );
  299. var geometry2 = new BufferGeometry();
  300. geometry2.setAttribute( "attrName", new BufferAttribute( new Float32Array( [ 4, 5, 6 ] ), 3 ) );
  301. var attr = geometry1.attributes.attrName.array;
  302. geometry1.merge( geometry2, 1 );
  303. // merged array should be 1, 2, 3, 4, 5, 6
  304. for ( var i = 0; i < attr.length; i ++ ) {
  305. assert.ok( attr[ i ] === i + 1, "" );
  306. }
  307. console.level = CONSOLE_LEVEL.ERROR;
  308. geometry1.merge( geometry2 );
  309. console.level = CONSOLE_LEVEL.DEFAULT;
  310. assert.ok( attr[ 0 ] === 4 && attr[ 1 ] === 5 && attr[ 2 ] === 6, "copied the 3 attributes without offset" );
  311. } );
  312. QUnit.todo( "normalizeNormals", ( assert ) => {
  313. assert.ok( false, "everything's gonna be alright" );
  314. } );
  315. QUnit.test( "toNonIndexed", ( assert ) => {
  316. var geometry = new BufferGeometry();
  317. var vertices = new Float32Array( [
  318. 0.5, 0.5, 0.5, 0.5, 0.5, - 0.5, 0.5, - 0.5, 0.5, 0.5, - 0.5, - 0.5
  319. ] );
  320. var index = new BufferAttribute( new Uint16Array( [ 0, 2, 1, 2, 3, 1 ] ) );
  321. var expected = new Float32Array( [
  322. 0.5, 0.5, 0.5, 0.5, - 0.5, 0.5, 0.5, 0.5, - 0.5,
  323. 0.5, - 0.5, 0.5, 0.5, - 0.5, - 0.5, 0.5, 0.5, - 0.5
  324. ] );
  325. geometry.setAttribute( 'position', new BufferAttribute( vertices, 3 ) );
  326. geometry.setIndex( index );
  327. var nonIndexed = geometry.toNonIndexed();
  328. assert.deepEqual( nonIndexed.getAttribute( "position" ).array, expected, "Expected vertices" );
  329. } );
  330. QUnit.test( "toJSON", ( assert ) => {
  331. var index = new BufferAttribute( new Uint16Array( [ 0, 1, 2, 3 ] ), 1 );
  332. var attribute1 = new BufferAttribute( new Uint16Array( [ 1, 3, 5, 7 ] ), 1 );
  333. attribute1.name = "attribute1";
  334. var a = new BufferGeometry();
  335. a.name = "JSONQUnit.test";
  336. // a.parameters = { "placeholder": 0 };
  337. a.setAttribute( "attribute1", attribute1 );
  338. a.setIndex( index );
  339. a.addGroup( 0, 1, 2 );
  340. a.boundingSphere = new Sphere( new Vector3( x, y, z ), 0.5 );
  341. var j = a.toJSON();
  342. var gold = {
  343. "metadata": {
  344. "version": 4.5,
  345. "type": "BufferGeometry",
  346. "generator": "BufferGeometry.toJSON"
  347. },
  348. "uuid": a.uuid,
  349. "type": "BufferGeometry",
  350. "name": "JSONQUnit.test",
  351. "data": {
  352. "attributes": {
  353. "attribute1": {
  354. "itemSize": 1,
  355. "type": "Uint16Array",
  356. "array": [ 1, 3, 5, 7 ],
  357. "normalized": false,
  358. "name": "attribute1"
  359. }
  360. },
  361. "index": {
  362. "type": "Uint16Array",
  363. "array": [ 0, 1, 2, 3 ]
  364. },
  365. "groups": [
  366. {
  367. "start": 0,
  368. "count": 1,
  369. "materialIndex": 2
  370. }
  371. ],
  372. "boundingSphere": {
  373. "center": [ 2, 3, 4 ],
  374. "radius": 0.5
  375. }
  376. }
  377. };
  378. assert.deepEqual( j, gold, "Generated JSON is as expected" );
  379. // add morphAttributes
  380. a.morphAttributes.attribute1 = [];
  381. a.morphAttributes.attribute1.push( attribute1.clone() );
  382. j = a.toJSON();
  383. gold.data.morphAttributes = {
  384. "attribute1": [ {
  385. "itemSize": 1,
  386. "type": "Uint16Array",
  387. "array": [ 1, 3, 5, 7 ],
  388. "normalized": false,
  389. "name": "attribute1"
  390. } ]
  391. };
  392. gold.data.morphTargetsRelative = false;
  393. assert.deepEqual( j, gold, "Generated JSON with morphAttributes is as expected" );
  394. } );
  395. QUnit.test( "clone", ( assert ) => {
  396. var a = new BufferGeometry();
  397. a.setAttribute( "attribute1", new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ) );
  398. a.setAttribute( "attribute2", new BufferAttribute( new Float32Array( [ 0, 1, 3, 5, 6 ] ), 1 ) );
  399. a.addGroup( 0, 1, 2 );
  400. a.computeBoundingBox();
  401. a.computeBoundingSphere();
  402. a.setDrawRange( 0, 1 );
  403. var b = a.clone();
  404. assert.notEqual( a, b, "A new object was created" );
  405. assert.notEqual( a.id, b.id, "New object has a different GUID" );
  406. assert.strictEqual(
  407. Object.keys( a.attributes ).count, Object.keys( b.attributes ).count,
  408. "Both objects have the same amount of attributes"
  409. );
  410. assert.ok(
  411. bufferAttributeEquals( a.getAttribute( "attribute1" ), b.getAttribute( "attribute1" ) ),
  412. "First attributes buffer is identical"
  413. );
  414. assert.ok(
  415. bufferAttributeEquals( a.getAttribute( "attribute2" ), b.getAttribute( "attribute2" ) ),
  416. "Second attributes buffer is identical"
  417. );
  418. assert.deepEqual( a.groups, b.groups, "Groups are identical" );
  419. assert.ok( a.boundingBox.equals( b.boundingBox ), "BoundingBoxes are equal" );
  420. assert.ok( a.boundingSphere.equals( b.boundingSphere ), "BoundingSpheres are equal" );
  421. assert.strictEqual( a.drawRange.start, b.drawRange.start, "DrawRange start is identical" );
  422. assert.strictEqual( a.drawRange.count, b.drawRange.count, "DrawRange count is identical" );
  423. } );
  424. QUnit.test( "copy", ( assert ) => {
  425. var geometry = new BufferGeometry();
  426. geometry.setAttribute( "attrName", new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ) );
  427. geometry.setAttribute( "attrName2", new BufferAttribute( new Float32Array( [ 0, 1, 3, 5, 6 ] ), 1 ) );
  428. var copy = new BufferGeometry().copy( geometry );
  429. assert.ok( copy !== geometry && geometry.id !== copy.id, "new object was created" );
  430. Object.keys( geometry.attributes ).forEach( function ( key ) {
  431. var attribute = geometry.attributes[ key ];
  432. assert.ok( attribute !== undefined, "all attributes where copied" );
  433. for ( var i = 0; i < attribute.array.length; i ++ ) {
  434. assert.ok( attribute.array[ i ] === copy.attributes[ key ].array[ i ], "values of the attribute are equal" );
  435. }
  436. } );
  437. } );
  438. QUnit.todo( "dispose", ( assert ) => {
  439. assert.ok( false, "everything's gonna be alright" );
  440. } );
  441. } );
  442. } );