ColorUtils.tests.js 1.5 KB

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