BufferAttribute.tests.js 9.9 KB

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