|
| 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 | + |
| 5 | +export default QUnit.module( 'Addons', () => { |
| 6 | + |
| 7 | + QUnit.module( 'Utils', () => { |
| 8 | + |
| 9 | + QUnit.module( 'ColorUtils', () => { |
| 10 | + |
| 11 | + const colorManagementEnabled = ColorManagement.enabled; |
| 12 | + |
| 13 | + QUnit.testDone( () => { |
| 14 | + |
| 15 | + ColorManagement.enabled = colorManagementEnabled; |
| 16 | + |
| 17 | + } ); |
| 18 | + |
| 19 | + QUnit.test( 'setKelvin', ( assert ) => { |
| 20 | + |
| 21 | + ColorManagement.enabled = false; // TODO: Update and enable. |
| 22 | + |
| 23 | + const c = new Color(); |
| 24 | + |
| 25 | + // ~1900K candle flame — warm reddish-orange, no blue |
| 26 | + ColorUtils.setKelvin( c, 1900 ); |
| 27 | + assert.ok( c.r > c.g && c.g > c.b && c.b === 0, 'Candle (~1900K): r > g > b, b = 0' ); |
| 28 | + |
| 29 | + // ~6500K daylight — roughly white, all channels near 1 |
| 30 | + ColorUtils.setKelvin( c, 6500 ); |
| 31 | + assert.ok( c.r > 0.9 && c.g > 0.9 && c.b > 0.9, 'Daylight (~6500K): all channels near 1' ); |
| 32 | + |
| 33 | + // clamping: below 1000K should equal 1000K |
| 34 | + const atMin = ColorUtils.setKelvin( new Color(), 1000 ); |
| 35 | + ColorUtils.setKelvin( c, 500 ); |
| 36 | + assert.ok( c.equals( atMin ), 'Values below 1000K are clamped to 1000K' ); |
| 37 | + |
| 38 | + // clamping: above 40000K should equal 40000K |
| 39 | + const atMax = ColorUtils.setKelvin( new Color(), 40000 ); |
| 40 | + ColorUtils.setKelvin( c, 50000 ); |
| 41 | + assert.ok( c.equals( atMax ), 'Values above 40000K are clamped to 40000K' ); |
| 42 | + |
| 43 | + // ~10000K cool blue sky — blue channel above red |
| 44 | + ColorUtils.setKelvin( c, 10000 ); |
| 45 | + assert.ok( c.b > c.r, 'Blue sky (~10000K): b > r' ); |
| 46 | + |
| 47 | + } ); |
| 48 | + |
| 49 | + } ); |
| 50 | + |
| 51 | + } ); |
| 52 | + |
| 53 | +} ); |
0 commit comments