BufferAttribute.tests.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. /* global QUnit */
  2. import { BufferAttribute } from '../../../../src/core/BufferAttribute';
  3. import { Color } from '../../../../src/math/Color';
  4. import { Vector2 } from '../../../../src/math/Vector2';
  5. import { Vector3 } from '../../../../src/math/Vector3';
  6. import { Vector4 } from '../../../../src/math/Vector4';
  7. import { DynamicDrawUsage } from '../../../../src/constants';
  8. export default QUnit.module( 'Core', () => {
  9. QUnit.module( 'BufferAttribute', () => {
  10. // INSTANCING
  11. QUnit.test( "Instancing", ( assert ) => {
  12. assert.throws(
  13. function () {
  14. var a = new BufferAttribute( [ 1, 2, 3, 4 ], 2, false );
  15. },
  16. /array should be a Typed Array/,
  17. "Calling constructor with a simple array throws Error"
  18. );
  19. } );
  20. // PROPERTIES
  21. QUnit.todo( "needsUpdate", ( assert ) => {
  22. assert.ok( false, "everything's gonna be alright" );
  23. } );
  24. // PUBLIC STUFF
  25. QUnit.todo( "isBufferAttribute", ( assert ) => {
  26. assert.ok( false, "everything's gonna be alright" );
  27. } );
  28. QUnit.test( "setUsage", ( assert ) => {
  29. var attr = new BufferAttribute();
  30. attr.setUsage( DynamicDrawUsage );
  31. assert.strictEqual( attr.usage, DynamicDrawUsage, "Usage was set" );
  32. } );
  33. QUnit.test( "copy", ( assert ) => {
  34. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 );
  35. attr.setUsage( DynamicDrawUsage );
  36. attr.needsUpdate = true;
  37. var attrCopy = new BufferAttribute().copy( attr );
  38. assert.ok( attr.count === attrCopy.count, 'count is equal' );
  39. assert.ok( attr.itemSize === attrCopy.itemSize, 'itemSize is equal' );
  40. assert.ok( attr.usage === attrCopy.usage, 'usage is equal' );
  41. assert.ok( attr.array.length === attrCopy.array.length, 'array length is equal' );
  42. assert.ok( attr.version === 1 && attrCopy.version === 0, 'version is not copied which is good' );
  43. } );
  44. QUnit.test( "copyAt", ( assert ) => {
  45. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ), 3 );
  46. var attr2 = new BufferAttribute( new Float32Array( 9 ), 3 );
  47. attr2.copyAt( 1, attr, 2 );
  48. attr2.copyAt( 0, attr, 1 );
  49. attr2.copyAt( 2, attr, 0 );
  50. var i = attr.array;
  51. var i2 = attr2.array; // should be [4, 5, 6, 7, 8, 9, 1, 2, 3]
  52. assert.ok( i2[ 0 ] === i[ 3 ] && i2[ 1 ] === i[ 4 ] && i2[ 2 ] === i[ 5 ], 'chunck copied to correct place' );
  53. assert.ok( i2[ 3 ] === i[ 6 ] && i2[ 4 ] === i[ 7 ] && i2[ 5 ] === i[ 8 ], 'chunck copied to correct place' );
  54. assert.ok( i2[ 6 ] === i[ 0 ] && i2[ 7 ] === i[ 1 ] && i2[ 8 ] === i[ 2 ], 'chunck copied to correct place' );
  55. } );
  56. QUnit.test( "copyArray", ( assert ) => {
  57. var f32a = new Float32Array( [ 5, 6, 7, 8 ] );
  58. var a = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4 ] ), 2, false );
  59. a.copyArray( f32a );
  60. assert.deepEqual( a.array, f32a, "Check array has new values" );
  61. } );
  62. QUnit.test( "copyColorsArray", ( assert ) => {
  63. var attr = new BufferAttribute( new Float32Array( 6 ), 3 );
  64. attr.copyColorsArray( [
  65. new Color( 0, 0.5, 1 ),
  66. new Color( 0.25, 1, 0 )
  67. ] );
  68. var i = attr.array;
  69. assert.ok( i[ 0 ] === 0 && i[ 1 ] === 0.5 && i[ 2 ] === 1, 'first color was copied correctly' );
  70. assert.ok( i[ 3 ] === 0.25 && i[ 4 ] === 1 && i[ 5 ] === 0, 'second color was copied correctly' );
  71. } );
  72. QUnit.test( "copyVector2sArray", ( assert ) => {
  73. var attr = new BufferAttribute( new Float32Array( 4 ), 2 );
  74. attr.copyVector2sArray( [
  75. new Vector2( 1, 2 ),
  76. new Vector2( 4, 5 )
  77. ] );
  78. var i = attr.array;
  79. assert.ok( i[ 0 ] === 1 && i[ 1 ] === 2, 'first vector was copied correctly' );
  80. assert.ok( i[ 2 ] === 4 && i[ 3 ] === 5, 'second vector was copied correctly' );
  81. } );
  82. QUnit.test( "copyVector3sArray", ( assert ) => {
  83. var attr = new BufferAttribute( new Float32Array( 6 ), 2 );
  84. attr.copyVector3sArray( [
  85. new Vector3( 1, 2, 3 ),
  86. new Vector3( 10, 20, 30 )
  87. ] );
  88. var i = attr.array;
  89. assert.ok( i[ 0 ] === 1 && i[ 1 ] === 2 && i[ 2 ] === 3, 'first vector was copied correctly' );
  90. assert.ok( i[ 3 ] === 10 && i[ 4 ] === 20 && i[ 5 ] === 30, 'second vector was copied correctly' );
  91. } );
  92. QUnit.test( "copyVector4sArray", ( assert ) => {
  93. var attr = new BufferAttribute( new Float32Array( 8 ), 2 );
  94. attr.copyVector4sArray( [
  95. new Vector4( 1, 2, 3, 4 ),
  96. new Vector4( 10, 20, 30, 40 )
  97. ] );
  98. var i = attr.array;
  99. assert.ok( i[ 0 ] === 1 && i[ 1 ] === 2 && i[ 2 ] === 3 && i[ 3 ] === 4, 'first vector was copied correctly' );
  100. assert.ok( i[ 4 ] === 10 && i[ 5 ] === 20 && i[ 6 ] === 30 && i[ 7 ] === 40, 'second vector was copied correctly' );
  101. } );
  102. QUnit.test( "set", ( assert ) => {
  103. var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
  104. var a = new BufferAttribute( f32a, 2, false );
  105. var expected = new Float32Array( [ 9, 2, 8, 4 ] );
  106. a.set( [ 9 ] );
  107. a.set( [ 8 ], 2 );
  108. assert.deepEqual( a.array, expected, "Check array has expected values" );
  109. } );
  110. QUnit.test( "set[X, Y, Z, W, XYZ, XYZW]/get[X, Y, Z, W]", ( assert ) => {
  111. var f32a = new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
  112. var a = new BufferAttribute( f32a, 4, false );
  113. var expected = new Float32Array( [ 1, 2, - 3, - 4, - 5, - 6, 7, 8 ] );
  114. a.setX( 1, a.getX( 1 ) * - 1 );
  115. a.setY( 1, a.getY( 1 ) * - 1 );
  116. a.setZ( 0, a.getZ( 0 ) * - 1 );
  117. a.setW( 0, a.getW( 0 ) * - 1 );
  118. assert.deepEqual( a.array, expected, "Check all set* calls set the correct values" );
  119. } );
  120. QUnit.test( "setXY", ( assert ) => {
  121. var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
  122. var a = new BufferAttribute( f32a, 2, false );
  123. var expected = new Float32Array( [ - 1, - 2, 3, 4 ] );
  124. a.setXY( 0, - 1, - 2 );
  125. assert.deepEqual( a.array, expected, "Check for the correct values" );
  126. } );
  127. QUnit.test( "setXYZ", ( assert ) => {
  128. var f32a = new Float32Array( [ 1, 2, 3, 4, 5, 6 ] );
  129. var a = new BufferAttribute( f32a, 3, false );
  130. var expected = new Float32Array( [ 1, 2, 3, - 4, - 5, - 6 ] );
  131. a.setXYZ( 1, - 4, - 5, - 6 );
  132. assert.deepEqual( a.array, expected, "Check for the correct values" );
  133. } );
  134. QUnit.test( "setXYZW", ( assert ) => {
  135. var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
  136. var a = new BufferAttribute( f32a, 4, false );
  137. var expected = new Float32Array( [ - 1, - 2, - 3, - 4 ] );
  138. a.setXYZW( 0, - 1, - 2, - 3, - 4 );
  139. assert.deepEqual( a.array, expected, "Check for the correct values" );
  140. } );
  141. QUnit.test( "onUpload", ( assert ) => {
  142. var a = new BufferAttribute();
  143. var func = function () { };
  144. a.onUpload( func );
  145. assert.strictEqual( a.onUploadCallback, func, "Check callback was set properly" );
  146. } );
  147. QUnit.test( "clone", ( assert ) => {
  148. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 0.12, - 12 ] ), 2 );
  149. var attrCopy = attr.clone();
  150. assert.ok( attr.array.length === attrCopy.array.length, 'attribute was cloned' );
  151. for ( var i = 0; i < attr.array.length; i ++ ) {
  152. assert.ok( attr.array[ i ] === attrCopy.array[ i ], 'array item is equal' );
  153. }
  154. } );
  155. // OTHERS
  156. QUnit.test( "count", ( assert ) => {
  157. assert.ok(
  158. new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ).count === 2,
  159. 'count is equal to the number of chunks'
  160. );
  161. } );
  162. } );
  163. QUnit.module( 'Int8BufferAttribute', () => {
  164. // INHERITANCE
  165. QUnit.todo( "Extending", ( assert ) => {
  166. assert.ok( false, "everything's gonna be alright" );
  167. } );
  168. // INSTANCING
  169. QUnit.todo( "Instancing", ( assert ) => {
  170. assert.ok( false, "everything's gonna be alright" );
  171. } );
  172. } );
  173. QUnit.module( 'Uint8BufferAttribute', () => {
  174. // INHERITANCE
  175. QUnit.todo( "Extending", ( assert ) => {
  176. assert.ok( false, "everything's gonna be alright" );
  177. } );
  178. // INSTANCING
  179. QUnit.todo( "Instancing", ( assert ) => {
  180. assert.ok( false, "everything's gonna be alright" );
  181. } );
  182. } );
  183. QUnit.module( 'Uint8ClampedBufferAttribute', () => {
  184. // INHERITANCE
  185. QUnit.todo( "Extending", ( assert ) => {
  186. assert.ok( false, "everything's gonna be alright" );
  187. } );
  188. // INSTANCING
  189. QUnit.todo( "Instancing", ( assert ) => {
  190. assert.ok( false, "everything's gonna be alright" );
  191. } );
  192. } );
  193. QUnit.module( 'Int16BufferAttribute', () => {
  194. // INHERITANCE
  195. QUnit.todo( "Extending", ( assert ) => {
  196. assert.ok( false, "everything's gonna be alright" );
  197. } );
  198. // INSTANCING
  199. QUnit.todo( "Instancing", ( assert ) => {
  200. assert.ok( false, "everything's gonna be alright" );
  201. } );
  202. } );
  203. QUnit.module( 'Uint16BufferAttribute', () => {
  204. // INHERITANCE
  205. QUnit.todo( "Extending", ( assert ) => {
  206. assert.ok( false, "everything's gonna be alright" );
  207. } );
  208. // INSTANCING
  209. QUnit.todo( "Instancing", ( assert ) => {
  210. assert.ok( false, "everything's gonna be alright" );
  211. } );
  212. } );
  213. QUnit.module( 'Int32BufferAttribute', () => {
  214. // INHERITANCE
  215. QUnit.todo( "Extending", ( assert ) => {
  216. assert.ok( false, "everything's gonna be alright" );
  217. } );
  218. // INSTANCING
  219. QUnit.todo( "Instancing", ( assert ) => {
  220. assert.ok( false, "everything's gonna be alright" );
  221. } );
  222. } );
  223. QUnit.module( 'Uint32BufferAttribute', () => {
  224. // INHERITANCE
  225. QUnit.todo( "Extending", ( assert ) => {
  226. assert.ok( false, "everything's gonna be alright" );
  227. } );
  228. // INSTANCING
  229. QUnit.todo( "Instancing", ( assert ) => {
  230. assert.ok( false, "everything's gonna be alright" );
  231. } );
  232. } );
  233. QUnit.module( 'Float32BufferAttribute', () => {
  234. // INHERITANCE
  235. QUnit.todo( "Extending", ( assert ) => {
  236. assert.ok( false, "everything's gonna be alright" );
  237. } );
  238. // INSTANCING
  239. QUnit.todo( "Instancing", ( assert ) => {
  240. assert.ok( false, "everything's gonna be alright" );
  241. } );
  242. } );
  243. QUnit.module( 'Float64BufferAttribute', () => {
  244. // INHERITANCE
  245. QUnit.todo( "Extending", ( assert ) => {
  246. assert.ok( false, "everything's gonna be alright" );
  247. } );
  248. // INSTANCING
  249. QUnit.todo( "Instancing", ( assert ) => {
  250. assert.ok( false, "everything's gonna be alright" );
  251. } );
  252. } );
  253. } );
粤ICP备19079148号