-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MeshPhysicalMaterial: Support iridescence / thin-film materials (#23869)
* Add iridescence parameters to Physical Material * Add iridescence fragment shader code * Iridescence shader integration and glTF loading * Update iridescence default values * Add KHR_materials_iridescence to supported extensions in GLTFLoader docu * Enable iridescence in Editor * Update build results * Remove build files from PR * Honor iridescence parameters in program cache * Use range for iridescence thin-film thickness * Fixed linting errors * Fix always-true conditional * Add iridescence to glTF export * Instantiate iridescenceThicknessRange in GLTFLoader if undefined * Make iridescence Fresnel consistent for IBL * Rename iridescenceIOR to iridescenceIor * Rename iridescenceIor back to iridescenceIOR except for glTF extension
- Loading branch information
1 parent
70e0000
commit 12f550e
Showing
27 changed files
with
929 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { UINumber, UIRow, UIText } from './libs/ui.js'; | ||
import { SetMaterialRangeCommand } from './commands/SetMaterialRangeCommand.js'; | ||
|
||
function SidebarMaterialRangeValueProperty( editor, property, name, isMin, range = [ - Infinity, Infinity ], precision = 2, step = 1, nudge = 0.01, unit = '' ) { | ||
|
||
const signals = editor.signals; | ||
|
||
const container = new UIRow(); | ||
container.add( new UIText( name ).setWidth( '90px' ) ); | ||
|
||
const number = new UINumber().setWidth( '60px' ).setRange( range[ 0 ], range[ 1 ] ).setPrecision( precision ).setStep( step ).setNudge( nudge ).setUnit( unit ).onChange( onChange ); | ||
container.add( number ); | ||
|
||
let object = null; | ||
let material = null; | ||
|
||
function onChange() { | ||
|
||
if ( material[ property ][ isMin ? 0 : 1 ] !== number.getValue() ) { | ||
|
||
const minValue = isMin ? number.getValue() : material[ property ][ 0 ]; | ||
const maxValue = isMin ? material[ property ][ 1 ] : number.getValue(); | ||
|
||
editor.execute( new SetMaterialRangeCommand( editor, object, property, minValue, maxValue, 0 /* TODO: currentMaterialSlot */ ) ); | ||
|
||
} | ||
|
||
} | ||
|
||
function update() { | ||
|
||
if ( object === null ) return; | ||
if ( object.material === undefined ) return; | ||
|
||
material = object.material; | ||
|
||
if ( property in material ) { | ||
|
||
number.setValue( material[ property ][ isMin ? 0 : 1 ] ); | ||
container.setDisplay( '' ); | ||
|
||
} else { | ||
|
||
container.setDisplay( 'none' ); | ||
|
||
} | ||
|
||
} | ||
|
||
// | ||
|
||
signals.objectSelected.add( function ( selected ) { | ||
|
||
object = selected; | ||
|
||
update(); | ||
|
||
} ); | ||
|
||
signals.materialChanged.add( update ); | ||
|
||
return container; | ||
|
||
} | ||
|
||
export { SidebarMaterialRangeValueProperty }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { Command } from '../Command.js'; | ||
|
||
/** | ||
* @param editor Editor | ||
* @param object THREE.Object3D | ||
* @param attributeName string | ||
* @param newMinValue number | ||
* @param newMaxValue number | ||
* @constructor | ||
*/ | ||
class SetMaterialRangeCommand extends Command { | ||
|
||
constructor( editor, object, attributeName, newMinValue, newMaxValue, materialSlot ) { | ||
|
||
super( editor ); | ||
|
||
this.type = 'SetMaterialRangeCommand'; | ||
this.name = `Set Material.${attributeName}`; | ||
this.updatable = true; | ||
|
||
this.object = object; | ||
this.material = this.editor.getObjectMaterial( object, materialSlot ); | ||
|
||
this.oldRange = ( this.material !== undefined && this.material[ attributeName ] !== undefined ) ? [ ...this.material[ attributeName ] ] : undefined; | ||
this.newRange = [ newMinValue, newMaxValue ]; | ||
|
||
this.attributeName = attributeName; | ||
|
||
} | ||
|
||
execute() { | ||
|
||
this.material[ this.attributeName ] = [ ...this.newRange ]; | ||
this.material.needsUpdate = true; | ||
|
||
this.editor.signals.objectChanged.dispatch( this.object ); | ||
this.editor.signals.materialChanged.dispatch( this.material ); | ||
|
||
} | ||
|
||
undo() { | ||
|
||
this.material[ this.attributeName ] = [ ...this.oldRange ]; | ||
this.material.needsUpdate = true; | ||
|
||
this.editor.signals.objectChanged.dispatch( this.object ); | ||
this.editor.signals.materialChanged.dispatch( this.material ); | ||
|
||
} | ||
|
||
update( cmd ) { | ||
|
||
this.newRange = [ ...cmd.newRange ]; | ||
|
||
} | ||
|
||
toJSON() { | ||
|
||
const output = super.toJSON( this ); | ||
|
||
output.objectUuid = this.object.uuid; | ||
output.attributeName = this.attributeName; | ||
output.oldRange = [ ...this.oldRange ]; | ||
output.newRange = [ ...this.newRange ]; | ||
|
||
return output; | ||
|
||
} | ||
|
||
fromJSON( json ) { | ||
|
||
super.fromJSON( json ); | ||
|
||
this.attributeName = json.attributeName; | ||
this.oldRange = [ ...json.oldRange ]; | ||
this.newRange = [ ...json.newRange ]; | ||
this.object = this.editor.objectByUuid( json.objectUuid ); | ||
|
||
} | ||
|
||
} | ||
|
||
export { SetMaterialRangeCommand }; |
Oops, something went wrong.