Skip to content

Commit

Permalink
Editor: Fix multi-material support. (mrdoob#27265)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 authored and AdaRoseCannon committed Jan 15, 2024
1 parent 865e9ab commit 5a0a788
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 90 deletions.
2 changes: 1 addition & 1 deletion editor/js/Script.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function Script( editor ) {

currentObject.material[ currentScript ] = string;
currentObject.material.needsUpdate = true;
signals.materialChanged.dispatch( currentObject.material );
signals.materialChanged.dispatch( currentObject, 0 ); // TODO: Add multi-material support

const programs = renderer.info.programs;

Expand Down
19 changes: 8 additions & 11 deletions editor/js/Sidebar.Material.BooleanProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,28 @@ function SidebarMaterialBooleanProperty( editor, property, name ) {
container.add( boolean );

let object = null;
let materialSlot = null;
let material = null;

function onChange() {

if ( material[ property ] !== boolean.getValue() ) {

editor.execute( new SetMaterialValueCommand( editor, object, property, boolean.getValue(), 0 /* TODO: currentMaterialSlot */ ) );
editor.execute( new SetMaterialValueCommand( editor, object, property, boolean.getValue(), materialSlot ) );

}

}

function update() {
function update( currentObject, currentMaterialSlot = 0 ) {

object = currentObject;
materialSlot = currentMaterialSlot;

if ( object === null ) return;
if ( object.material === undefined ) return;

material = object.material;
material = editor.getObjectMaterial( object, materialSlot );

if ( property in material ) {

Expand All @@ -46,14 +50,7 @@ function SidebarMaterialBooleanProperty( editor, property, name ) {

//

signals.objectSelected.add( function ( selected ) {

object = selected;

update();

} );

signals.objectSelected.add( update );
signals.materialChanged.add( update );

return container;
Expand Down
21 changes: 9 additions & 12 deletions editor/js/Sidebar.Material.ColorProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,38 @@ function SidebarMaterialColorProperty( editor, property, name ) {
}

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(), 0 /* TODO: currentMaterialSlot */ ) );
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(), /* TODO: currentMaterialSlot*/ 0 ) );
editor.execute( new SetMaterialValueCommand( editor, object, `${ property }Intensity`, intensity.getValue(), materialSlot ) );

}

}

}

function update() {
function update( currentObject, currentMaterialSlot = 0 ) {

object = currentObject;
materialSlot = currentMaterialSlot;

if ( object === null ) return;
if ( object.material === undefined ) return;

material = object.material;
material = editor.getObjectMaterial( object, materialSlot );

if ( property in material ) {

Expand All @@ -73,14 +77,7 @@ function SidebarMaterialColorProperty( editor, property, name ) {

//

signals.objectSelected.add( function ( selected ) {

object = selected;

update();

} );

signals.objectSelected.add( update );
signals.materialChanged.add( update );

return container;
Expand Down
19 changes: 8 additions & 11 deletions editor/js/Sidebar.Material.ConstantProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function SidebarMaterialConstantProperty( editor, property, name, options ) {
container.add( constant );

let object = null;
let materialSlot = null;
let material = null;

function onChange() {
Expand All @@ -20,18 +21,21 @@ function SidebarMaterialConstantProperty( editor, property, name, options ) {

if ( material[ property ] !== value ) {

editor.execute( new SetMaterialValueCommand( editor, object, property, value, 0 /* TODO: currentMaterialSlot */ ) );
editor.execute( new SetMaterialValueCommand( editor, object, property, value, materialSlot ) );

}

}

function update() {
function update( currentObject, currentMaterialSlot = 0 ) {

object = currentObject;
materialSlot = currentMaterialSlot;

if ( object === null ) return;
if ( object.material === undefined ) return;

material = object.material;
material = editor.getObjectMaterial( object, materialSlot );

if ( property in material ) {

Expand All @@ -48,14 +52,7 @@ function SidebarMaterialConstantProperty( editor, property, name, options ) {

//

signals.objectSelected.add( function ( selected ) {

object = selected;

update();

} );

signals.objectSelected.add( update );
signals.materialChanged.add( update );

return container;
Expand Down
22 changes: 12 additions & 10 deletions editor/js/Sidebar.Material.MapProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function SidebarMaterialMapProperty( editor, property, name ) {
}

let object = null;
let materialSlot = null;
let material = null;

function onChange() {
Expand All @@ -103,7 +104,7 @@ function SidebarMaterialMapProperty( editor, property, name ) {

}

editor.execute( new SetMaterialMapCommand( editor, object, property, newMap, 0 /* TODO: currentMaterialSlot */ ) );
editor.execute( new SetMaterialMapCommand( editor, object, property, newMap, materialSlot ) );

}

Expand Down Expand Up @@ -132,7 +133,7 @@ function SidebarMaterialMapProperty( editor, property, name ) {

if ( material[ `${ property }Intensity` ] !== intensity.getValue() ) {

editor.execute( new SetMaterialValueCommand( editor, object, `${ property }Intensity`, intensity.getValue(), 0 /* TODO: currentMaterialSlot */ ) );
editor.execute( new SetMaterialValueCommand( editor, object, `${ property }Intensity`, intensity.getValue(), materialSlot ) );

}

Expand All @@ -142,7 +143,7 @@ function SidebarMaterialMapProperty( editor, property, name ) {

if ( material[ `${ mapType }Scale` ] !== scale.getValue() ) {

editor.execute( new SetMaterialValueCommand( editor, object, `${ mapType }Scale`, scale.getValue(), 0 /* TODO: currentMaterialSlot */ ) );
editor.execute( new SetMaterialValueCommand( editor, object, `${ mapType }Scale`, scale.getValue(), materialSlot ) );

}

Expand All @@ -154,7 +155,7 @@ function SidebarMaterialMapProperty( editor, property, name ) {

if ( material[ `${ mapType }Scale` ].x !== value[ 0 ] || material[ `${ mapType }Scale` ].y !== value[ 1 ] ) {

editor.execute( new SetMaterialVectorCommand( editor, object, `${ mapType }Scale`, value, 0 /* TODOL currentMaterialSlot */ ) );
editor.execute( new SetMaterialVectorCommand( editor, object, `${ mapType }Scale`, value, materialSlot ) );

}

Expand All @@ -166,18 +167,21 @@ function SidebarMaterialMapProperty( editor, property, name ) {

if ( material[ `${ mapType }Range` ][ 0 ] !== value[ 0 ] || material[ `${ mapType }Range` ][ 1 ] !== value[ 1 ] ) {

editor.execute( new SetMaterialRangeCommand( editor, object, `${ mapType }Range`, value[ 0 ], value[ 1 ], 0 /* TODOL currentMaterialSlot */ ) );
editor.execute( new SetMaterialRangeCommand( editor, object, `${ mapType }Range`, value[ 0 ], value[ 1 ], materialSlot ) );

}

}

function update() {
function update( currentObject, currentMaterialSlot = 0 ) {

object = currentObject;
materialSlot = currentMaterialSlot;

if ( object === null ) return;
if ( object.material === undefined ) return;

material = object.material;
material = editor.getObjectMaterial( object, materialSlot );

if ( property in material ) {

Expand Down Expand Up @@ -230,11 +234,9 @@ function SidebarMaterialMapProperty( editor, property, name ) {

signals.objectSelected.add( function ( selected ) {

object = selected;

map.setValue( null );

update();
update( selected );

} );

Expand Down
19 changes: 8 additions & 11 deletions editor/js/Sidebar.Material.NumberProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,28 @@ function SidebarMaterialNumberProperty( editor, property, name, range = [ - Infi
container.add( number );

let object = null;
let materialSlot = null;
let material = null;

function onChange() {

if ( material[ property ] !== number.getValue() ) {

editor.execute( new SetMaterialValueCommand( editor, object, property, number.getValue(), 0 /* TODO: currentMaterialSlot */ ) );
editor.execute( new SetMaterialValueCommand( editor, object, property, number.getValue(), materialSlot ) );

}

}

function update() {
function update( currentObject, currentMaterialSlot = 0 ) {

object = currentObject;
materialSlot = currentMaterialSlot;

if ( object === null ) return;
if ( object.material === undefined ) return;

material = object.material;
material = editor.getObjectMaterial( object, materialSlot );

if ( property in material ) {

Expand All @@ -46,14 +50,7 @@ function SidebarMaterialNumberProperty( editor, property, name, range = [ - Infi

//

signals.objectSelected.add( function ( selected ) {

object = selected;

update();

} );

signals.objectSelected.add( update );
signals.materialChanged.add( update );

return container;
Expand Down
17 changes: 7 additions & 10 deletions editor/js/Sidebar.Material.Program.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function SidebarMaterialProgram( editor, property ) {
const strings = editor.strings;

let object = null;
let materialSlot = null;
let material = null;

const container = new UIRow();
Expand Down Expand Up @@ -38,12 +39,15 @@ function SidebarMaterialProgram( editor, property ) {
} );
container.add( programFragment );

function update() {
function update( currentObject, currentMaterialSlot = 0 ) {

object = currentObject;
materialSlot = currentMaterialSlot;

if ( object === null ) return;
if ( object.material === undefined ) return;

material = object.material;
material = editor.getObjectMaterial( object, materialSlot );

if ( property in material ) {

Expand All @@ -59,14 +63,7 @@ function SidebarMaterialProgram( editor, property ) {

//

signals.objectSelected.add( function ( selected ) {

object = selected;

update();

} );

signals.objectSelected.add( update );
signals.materialChanged.add( update );

return container;
Expand Down
19 changes: 8 additions & 11 deletions editor/js/Sidebar.Material.RangeValueProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function SidebarMaterialRangeValueProperty( editor, property, name, isMin, range
container.add( number );

let object = null;
let materialSlot = null;
let material = null;

function onChange() {
Expand All @@ -21,18 +22,21 @@ function SidebarMaterialRangeValueProperty( editor, property, name, isMin, range
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 */ ) );
editor.execute( new SetMaterialRangeCommand( editor, object, property, minValue, maxValue, materialSlot ) );

}

}

function update() {
function update( currentObject, currentMaterialSlot = 0 ) {

object = currentObject;
materialSlot = currentMaterialSlot;

if ( object === null ) return;
if ( object.material === undefined ) return;

material = object.material;
material = editor.getObjectMaterial( object, materialSlot );

if ( property in material ) {

Expand All @@ -49,14 +53,7 @@ function SidebarMaterialRangeValueProperty( editor, property, name, isMin, range

//

signals.objectSelected.add( function ( selected ) {

object = selected;

update();

} );

signals.objectSelected.add( update );
signals.materialChanged.add( update );

return container;
Expand Down
6 changes: 5 additions & 1 deletion editor/js/Sidebar.Material.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,11 @@ function SidebarMaterial( editor ) {

currentMaterialSlot = parseInt( materialSlotSelect.getValue() );

if ( currentMaterialSlot !== previousSelectedSlot ) refreshUI();
if ( currentMaterialSlot !== previousSelectedSlot ) {

editor.signals.materialChanged.dispatch( currentObject, currentMaterialSlot );

}

let material = editor.getObjectMaterial( currentObject, currentMaterialSlot );

Expand Down
Loading

0 comments on commit 5a0a788

Please sign in to comment.