|
1 | 1 | import * as THREE from 'three'; |
2 | 2 |
|
3 | | -import { UICheckbox, UINumber, UIRow, UIText } from './libs/ui.js'; |
| 3 | +import { UICheckbox, UIDiv, UINumber, UIRow, UIText } from './libs/ui.js'; |
4 | 4 | import { UITexture } from './libs/ui.three.js'; |
5 | 5 | import { SetMaterialMapCommand } from './commands/SetMaterialMapCommand.js'; |
6 | 6 | import { SetMaterialValueCommand } from './commands/SetMaterialValueCommand.js'; |
| 7 | +import { SetMaterialRangeCommand } from './commands/SetMaterialRangeCommand.js'; |
7 | 8 | import { SetMaterialVectorCommand } from './commands/SetMaterialVectorCommand.js'; |
8 | 9 |
|
9 | 10 | function SidebarMaterialMapProperty( editor, property, name ) { |
@@ -51,6 +52,36 @@ function SidebarMaterialMapProperty( editor, property, name ) { |
51 | 52 |
|
52 | 53 | } |
53 | 54 |
|
| 55 | + let rangeMin, rangeMax; |
| 56 | + |
| 57 | + if ( property === 'iridescenceThicknessMap' ) { |
| 58 | + |
| 59 | + const range = new UIDiv().setMarginLeft( '3px' ); |
| 60 | + container.add( range ); |
| 61 | + |
| 62 | + const rangeMinRow = new UIRow().setMarginBottom( '0px' ).setStyle( 'min-height', '0px' ); |
| 63 | + range.add( rangeMinRow ); |
| 64 | + |
| 65 | + rangeMinRow.add( new UIText( 'min:' ).setWidth( '35px' ) ); |
| 66 | + |
| 67 | + rangeMin = new UINumber().setWidth( '40px' ).onChange( onRangeChange ); |
| 68 | + rangeMinRow.add( rangeMin ); |
| 69 | + |
| 70 | + const rangeMaxRow = new UIRow().setMarginBottom( '6px' ).setStyle( 'min-height', '0px' ); |
| 71 | + range.add( rangeMaxRow ); |
| 72 | + |
| 73 | + rangeMaxRow.add( new UIText( 'max:' ).setWidth( '35px' ) ); |
| 74 | + |
| 75 | + rangeMax = new UINumber().setWidth( '40px' ).onChange( onRangeChange ); |
| 76 | + rangeMaxRow.add( rangeMax ); |
| 77 | + |
| 78 | + // Additional settings for iridescenceThicknessMap |
| 79 | + // Please add conditional if more maps are having a range property |
| 80 | + rangeMin.setPrecision( 0 ).setRange( 0, Infinity ).setNudge( 1 ).setStep( 10 ).setUnit( 'nm' ); |
| 81 | + rangeMax.setPrecision( 0 ).setRange( 0, Infinity ).setNudge( 1 ).setStep( 10 ).setUnit( 'nm' ); |
| 82 | + |
| 83 | + } |
| 84 | + |
54 | 85 | let object = null; |
55 | 86 | let material = null; |
56 | 87 |
|
@@ -127,6 +158,18 @@ function SidebarMaterialMapProperty( editor, property, name ) { |
127 | 158 |
|
128 | 159 | } |
129 | 160 |
|
| 161 | + function onRangeChange() { |
| 162 | + |
| 163 | + const value = [ rangeMin.getValue(), rangeMax.getValue() ]; |
| 164 | + |
| 165 | + if ( material[ `${ mapType }Range` ][ 0 ] !== value[ 0 ] || material[ `${ mapType }Range` ][ 1 ] !== value[ 1 ] ) { |
| 166 | + |
| 167 | + editor.execute( new SetMaterialRangeCommand( editor, object, `${ mapType }Range`, value[ 0 ], value[ 1 ], 0 /* TODOL currentMaterialSlot */ ) ); |
| 168 | + |
| 169 | + } |
| 170 | + |
| 171 | + } |
| 172 | + |
130 | 173 | function update() { |
131 | 174 |
|
132 | 175 | if ( object === null ) return; |
@@ -164,6 +207,13 @@ function SidebarMaterialMapProperty( editor, property, name ) { |
164 | 207 |
|
165 | 208 | } |
166 | 209 |
|
| 210 | + if ( rangeMin !== undefined ) { |
| 211 | + |
| 212 | + rangeMin.setValue( material[ `${ mapType }Range` ][ 0 ] ); |
| 213 | + rangeMax.setValue( material[ `${ mapType }Range` ][ 1 ] ); |
| 214 | + |
| 215 | + } |
| 216 | + |
167 | 217 | container.setDisplay( '' ); |
168 | 218 |
|
169 | 219 | } else { |
|
0 commit comments