| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 | import { UIColor, UINumber, UIRow, UIText } from './libs/ui.js';import { SetMaterialColorCommand } from './commands/SetMaterialColorCommand.js';import { SetMaterialValueCommand } from './commands/SetMaterialValueCommand.js';function SidebarMaterialColorProperty( editor, property, name ) {	const signals = editor.signals;	const container = new UIRow();	container.add( new UIText( name ).setClass( 'Label' ) );	const color = new UIColor().onInput( onChange );	container.add( color );	let intensity;	if ( property === 'emissive' ) {		intensity = new UINumber( 1 ).setWidth( '30px' ).setRange( 0, Infinity ).onChange( onChange );		container.add( intensity );	}	let object = null;	let materialSlot = null;	let material = null;	function onChange() {		if ( material[ property ].getHex() !== color.getHexValue() ) {			editor.execute( new SetMaterialColorCommand( editor, object, property, color.getHexValue(), materialSlot ) );		}		if ( intensity !== undefined ) {			if ( material[ `${ property }Intensity` ] !== intensity.getValue() ) {				editor.execute( new SetMaterialValueCommand( editor, object, `${ property }Intensity`, intensity.getValue(), materialSlot ) );			}		}	}	function update( currentObject, currentMaterialSlot = 0 ) {		object = currentObject;		materialSlot = currentMaterialSlot;		if ( object === null ) return;		if ( object.material === undefined ) return;		material = editor.getObjectMaterial( object, materialSlot );		if ( property in material ) {			color.setHexValue( material[ property ].getHexString() );			if ( intensity !== undefined ) {				intensity.setValue( material[ `${ property }Intensity` ] );			}			container.setDisplay( '' );		} else {			container.setDisplay( 'none' );		}	}	//	signals.objectSelected.add( update );	signals.materialChanged.add( update );	return container;}export { SidebarMaterialColorProperty };
 |