ColorUtils.tests.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { Color } from '../../../../src/math/Color.js';
  2. import { ColorManagement } from '../../../../src/math/ColorManagement.js';
  3. import * as ColorUtils from '../../../../examples/jsm/utils/ColorUtils.js';
  4. export default QUnit.module( 'Addons', () => {
  5. QUnit.module( 'Utils', () => {
  6. QUnit.module( 'ColorUtils', () => {
  7. const colorManagementEnabled = ColorManagement.enabled;
  8. QUnit.testDone( () => {
  9. ColorManagement.enabled = colorManagementEnabled;
  10. } );
  11. QUnit.test( 'setKelvin', ( assert ) => {
  12. ColorManagement.enabled = false; // TODO: Update and enable.
  13. const c = new Color();
  14. // ~1900K candle flame — warm reddish-orange, no blue
  15. ColorUtils.setKelvin( c, 1900 );
  16. assert.ok( c.r > c.g && c.g > c.b && c.b === 0, 'Candle (~1900K): r > g > b, b = 0' );
  17. // ~6500K daylight — roughly white, all channels near 1
  18. ColorUtils.setKelvin( c, 6500 );
  19. assert.ok( c.r > 0.9 && c.g > 0.9 && c.b > 0.9, 'Daylight (~6500K): all channels near 1' );
  20. // clamping: below 1000K should equal 1000K
  21. const atMin = ColorUtils.setKelvin( new Color(), 1000 );
  22. ColorUtils.setKelvin( c, 500 );
  23. assert.ok( c.equals( atMin ), 'Values below 1000K are clamped to 1000K' );
  24. // clamping: above 40000K should equal 40000K
  25. const atMax = ColorUtils.setKelvin( new Color(), 40000 );
  26. ColorUtils.setKelvin( c, 50000 );
  27. assert.ok( c.equals( atMax ), 'Values above 40000K are clamped to 40000K' );
  28. // ~10000K cool blue sky — blue channel above red
  29. ColorUtils.setKelvin( c, 10000 );
  30. assert.ok( c.b > c.r, 'Blue sky (~10000K): b > r' );
  31. } );
  32. } );
  33. } );
  34. } );
粤ICP备19079148号