LOD.tests.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* global QUnit */
  2. import { Object3D } from '../../../../src/core/Object3D.js';
  3. import { Raycaster } from '../../../../src/core/Raycaster.js';
  4. import { LOD } from '../../../../src/objects/LOD.js';
  5. export default QUnit.module( 'Objects', () => {
  6. QUnit.module( 'LOD', () => {
  7. // INHERITANCE
  8. QUnit.test( 'Extending', ( assert ) => {
  9. const lod = new LOD();
  10. assert.strictEqual( ( lod instanceof Object3D ), true, 'LOD extends from Object3D' );
  11. } );
  12. // PROPERTIES
  13. QUnit.test( 'type', ( assert ) => {
  14. const object = new LOD();
  15. assert.ok(
  16. object.type === 'LOD',
  17. 'LOD.type should be LOD'
  18. );
  19. } );
  20. QUnit.test( 'levels', ( assert ) => {
  21. const lod = new LOD();
  22. const levels = lod.levels;
  23. assert.strictEqual( Array.isArray( levels ), true, 'LOD.levels is of type array.' );
  24. assert.strictEqual( levels.length, 0, 'LOD.levels is empty by default.' );
  25. } );
  26. QUnit.test( 'autoUpdate', ( assert ) => {
  27. const lod = new LOD();
  28. assert.strictEqual( lod.autoUpdate, true, 'LOD.autoUpdate is of type boolean and true by default.' );
  29. } );
  30. // PUBLIC
  31. QUnit.test( 'isLOD', ( assert ) => {
  32. const lod = new LOD();
  33. assert.strictEqual( lod.isLOD, true, '.isLOD property is defined.' );
  34. } );
  35. QUnit.test( 'copy', ( assert ) => {
  36. const lod1 = new LOD();
  37. const lod2 = new LOD();
  38. const high = new Object3D();
  39. const mid = new Object3D();
  40. const low = new Object3D();
  41. lod1.addLevel( high, 5 );
  42. lod1.addLevel( mid, 25 );
  43. lod1.addLevel( low, 50 );
  44. lod1.autoUpdate = false;
  45. lod2.copy( lod1 );
  46. assert.strictEqual( lod2.autoUpdate, false, 'LOD.autoUpdate is correctly copied.' );
  47. assert.strictEqual( lod2.levels.length, 3, 'LOD.levels has the correct length after the copy.' );
  48. } );
  49. QUnit.test( 'addLevel', ( assert ) => {
  50. const lod = new LOD();
  51. const high = new Object3D();
  52. const mid = new Object3D();
  53. const low = new Object3D();
  54. lod.addLevel( high, 5, 0.00 );
  55. lod.addLevel( mid, 25, 0.05 );
  56. lod.addLevel( low, 50, 0.10 );
  57. assert.strictEqual( lod.levels.length, 3, 'LOD.levels has the correct length.' );
  58. assert.deepEqual( lod.levels[ 0 ], { distance: 5, object: high, hysteresis: 0.00 }, 'First entry correct.' );
  59. assert.deepEqual( lod.levels[ 1 ], { distance: 25, object: mid, hysteresis: 0.05 }, 'Second entry correct.' );
  60. assert.deepEqual( lod.levels[ 2 ], { distance: 50, object: low, hysteresis: 0.10 }, 'Third entry correct.' );
  61. } );
  62. QUnit.todo( 'getCurrentLevel', ( assert ) => {
  63. assert.ok( false, 'everything\'s gonna be alright' );
  64. } );
  65. QUnit.test( 'getObjectForDistance', ( assert ) => {
  66. const lod = new LOD();
  67. const high = new Object3D();
  68. const mid = new Object3D();
  69. const low = new Object3D();
  70. assert.strictEqual( lod.getObjectForDistance( 5 ), null, 'Returns null if no LOD levels are defined.' );
  71. lod.addLevel( high, 5 );
  72. assert.strictEqual( lod.getObjectForDistance( 0 ), high, 'Returns always the same object if only one LOD level is defined.' );
  73. assert.strictEqual( lod.getObjectForDistance( 10 ), high, 'Returns always the same object if only one LOD level is defined.' );
  74. lod.addLevel( mid, 25 );
  75. lod.addLevel( low, 50 );
  76. assert.strictEqual( lod.getObjectForDistance( 0 ), high, 'Returns the high resolution object.' );
  77. assert.strictEqual( lod.getObjectForDistance( 10 ), high, 'Returns the high resolution object.' );
  78. assert.strictEqual( lod.getObjectForDistance( 25 ), mid, 'Returns the mid resolution object.' );
  79. assert.strictEqual( lod.getObjectForDistance( 50 ), low, 'Returns the low resolution object.' );
  80. assert.strictEqual( lod.getObjectForDistance( 60 ), low, 'Returns the low resolution object.' );
  81. } );
  82. QUnit.test( 'raycast', ( assert ) => {
  83. const lod = new LOD();
  84. const raycaster = new Raycaster();
  85. const intersections = [];
  86. lod.raycast( raycaster, intersections );
  87. assert.strictEqual( intersections.length, 0, 'Does not fail if raycasting is used with a LOD object without levels.' );
  88. } );
  89. QUnit.todo( 'update', ( assert ) => {
  90. assert.ok( false, 'everything\'s gonna be alright' );
  91. } );
  92. QUnit.todo( 'toJSON', ( assert ) => {
  93. assert.ok( false, 'everything\'s gonna be alright' );
  94. } );
  95. } );
  96. } );
粤ICP备19079148号