Skip to content

Commit d33bab2

Browse files
authored
Editor: Fix multi-material support. (#27265)
1 parent 5d75579 commit d33bab2

15 files changed

+90
-90
lines changed

editor/js/Script.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function Script( editor ) {
223223

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

228228
const programs = renderer.info.programs;
229229

editor/js/Sidebar.Material.BooleanProperty.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,28 @@ function SidebarMaterialBooleanProperty( editor, property, name ) {
1212
container.add( boolean );
1313

1414
let object = null;
15+
let materialSlot = null;
1516
let material = null;
1617

1718
function onChange() {
1819

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

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

2324
}
2425

2526
}
2627

27-
function update() {
28+
function update( currentObject, currentMaterialSlot = 0 ) {
29+
30+
object = currentObject;
31+
materialSlot = currentMaterialSlot;
2832

2933
if ( object === null ) return;
3034
if ( object.material === undefined ) return;
3135

32-
material = object.material;
36+
material = editor.getObjectMaterial( object, materialSlot );
3337

3438
if ( property in material ) {
3539

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

4751
//
4852

49-
signals.objectSelected.add( function ( selected ) {
50-
51-
object = selected;
52-
53-
update();
54-
55-
} );
56-
53+
signals.objectSelected.add( update );
5754
signals.materialChanged.add( update );
5855

5956
return container;

editor/js/Sidebar.Material.ColorProperty.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,38 @@ function SidebarMaterialColorProperty( editor, property, name ) {
2222
}
2323

2424
let object = null;
25+
let materialSlot = null;
2526
let material = null;
2627

2728
function onChange() {
2829

2930
if ( material[ property ].getHex() !== color.getHexValue() ) {
3031

31-
editor.execute( new SetMaterialColorCommand( editor, object, property, color.getHexValue(), 0 /* TODO: currentMaterialSlot */ ) );
32+
editor.execute( new SetMaterialColorCommand( editor, object, property, color.getHexValue(), materialSlot ) );
3233

3334
}
3435

3536
if ( intensity !== undefined ) {
3637

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

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

4142
}
4243

4344
}
4445

4546
}
4647

47-
function update() {
48+
function update( currentObject, currentMaterialSlot = 0 ) {
49+
50+
object = currentObject;
51+
materialSlot = currentMaterialSlot;
4852

4953
if ( object === null ) return;
5054
if ( object.material === undefined ) return;
5155

52-
material = object.material;
56+
material = editor.getObjectMaterial( object, materialSlot );
5357

5458
if ( property in material ) {
5559

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

7478
//
7579

76-
signals.objectSelected.add( function ( selected ) {
77-
78-
object = selected;
79-
80-
update();
81-
82-
} );
83-
80+
signals.objectSelected.add( update );
8481
signals.materialChanged.add( update );
8582

8683
return container;

editor/js/Sidebar.Material.ConstantProperty.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function SidebarMaterialConstantProperty( editor, property, name, options ) {
1212
container.add( constant );
1313

1414
let object = null;
15+
let materialSlot = null;
1516
let material = null;
1617

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

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

23-
editor.execute( new SetMaterialValueCommand( editor, object, property, value, 0 /* TODO: currentMaterialSlot */ ) );
24+
editor.execute( new SetMaterialValueCommand( editor, object, property, value, materialSlot ) );
2425

2526
}
2627

2728
}
2829

29-
function update() {
30+
function update( currentObject, currentMaterialSlot = 0 ) {
31+
32+
object = currentObject;
33+
materialSlot = currentMaterialSlot;
3034

3135
if ( object === null ) return;
3236
if ( object.material === undefined ) return;
3337

34-
material = object.material;
38+
material = editor.getObjectMaterial( object, materialSlot );
3539

3640
if ( property in material ) {
3741

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

4953
//
5054

51-
signals.objectSelected.add( function ( selected ) {
52-
53-
object = selected;
54-
55-
update();
56-
57-
} );
58-
55+
signals.objectSelected.add( update );
5956
signals.materialChanged.add( update );
6057

6158
return container;

editor/js/Sidebar.Material.MapProperty.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ function SidebarMaterialMapProperty( editor, property, name ) {
8585
}
8686

8787
let object = null;
88+
let materialSlot = null;
8889
let material = null;
8990

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

104105
}
105106

106-
editor.execute( new SetMaterialMapCommand( editor, object, property, newMap, 0 /* TODO: currentMaterialSlot */ ) );
107+
editor.execute( new SetMaterialMapCommand( editor, object, property, newMap, materialSlot ) );
107108

108109
}
109110

@@ -132,7 +133,7 @@ function SidebarMaterialMapProperty( editor, property, name ) {
132133

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

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

137138
}
138139

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

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

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

147148
}
148149

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

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

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

159160
}
160161

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

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

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

171172
}
172173

173174
}
174175

175-
function update() {
176+
function update( currentObject, currentMaterialSlot = 0 ) {
177+
178+
object = currentObject;
179+
materialSlot = currentMaterialSlot;
176180

177181
if ( object === null ) return;
178182
if ( object.material === undefined ) return;
179183

180-
material = object.material;
184+
material = editor.getObjectMaterial( object, materialSlot );
181185

182186
if ( property in material ) {
183187

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

231235
signals.objectSelected.add( function ( selected ) {
232236

233-
object = selected;
234-
235237
map.setValue( null );
236238

237-
update();
239+
update( selected );
238240

239241
} );
240242

editor/js/Sidebar.Material.NumberProperty.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,28 @@ function SidebarMaterialNumberProperty( editor, property, name, range = [ - Infi
1212
container.add( number );
1313

1414
let object = null;
15+
let materialSlot = null;
1516
let material = null;
1617

1718
function onChange() {
1819

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

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

2324
}
2425

2526
}
2627

27-
function update() {
28+
function update( currentObject, currentMaterialSlot = 0 ) {
29+
30+
object = currentObject;
31+
materialSlot = currentMaterialSlot;
2832

2933
if ( object === null ) return;
3034
if ( object.material === undefined ) return;
3135

32-
material = object.material;
36+
material = editor.getObjectMaterial( object, materialSlot );
3337

3438
if ( property in material ) {
3539

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

4751
//
4852

49-
signals.objectSelected.add( function ( selected ) {
50-
51-
object = selected;
52-
53-
update();
54-
55-
} );
56-
53+
signals.objectSelected.add( update );
5754
signals.materialChanged.add( update );
5855

5956
return container;

editor/js/Sidebar.Material.Program.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function SidebarMaterialProgram( editor, property ) {
66
const strings = editor.strings;
77

88
let object = null;
9+
let materialSlot = null;
910
let material = null;
1011

1112
const container = new UIRow();
@@ -38,12 +39,15 @@ function SidebarMaterialProgram( editor, property ) {
3839
} );
3940
container.add( programFragment );
4041

41-
function update() {
42+
function update( currentObject, currentMaterialSlot = 0 ) {
43+
44+
object = currentObject;
45+
materialSlot = currentMaterialSlot;
4246

4347
if ( object === null ) return;
4448
if ( object.material === undefined ) return;
4549

46-
material = object.material;
50+
material = editor.getObjectMaterial( object, materialSlot );
4751

4852
if ( property in material ) {
4953

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

6064
//
6165

62-
signals.objectSelected.add( function ( selected ) {
63-
64-
object = selected;
65-
66-
update();
67-
68-
} );
69-
66+
signals.objectSelected.add( update );
7067
signals.materialChanged.add( update );
7168

7269
return container;

editor/js/Sidebar.Material.RangeValueProperty.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function SidebarMaterialRangeValueProperty( editor, property, name, isMin, range
1212
container.add( number );
1313

1414
let object = null;
15+
let materialSlot = null;
1516
let material = null;
1617

1718
function onChange() {
@@ -21,18 +22,21 @@ function SidebarMaterialRangeValueProperty( editor, property, name, isMin, range
2122
const minValue = isMin ? number.getValue() : material[ property ][ 0 ];
2223
const maxValue = isMin ? material[ property ][ 1 ] : number.getValue();
2324

24-
editor.execute( new SetMaterialRangeCommand( editor, object, property, minValue, maxValue, 0 /* TODO: currentMaterialSlot */ ) );
25+
editor.execute( new SetMaterialRangeCommand( editor, object, property, minValue, maxValue, materialSlot ) );
2526

2627
}
2728

2829
}
2930

30-
function update() {
31+
function update( currentObject, currentMaterialSlot = 0 ) {
32+
33+
object = currentObject;
34+
materialSlot = currentMaterialSlot;
3135

3236
if ( object === null ) return;
3337
if ( object.material === undefined ) return;
3438

35-
material = object.material;
39+
material = editor.getObjectMaterial( object, materialSlot );
3640

3741
if ( property in material ) {
3842

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

5054
//
5155

52-
signals.objectSelected.add( function ( selected ) {
53-
54-
object = selected;
55-
56-
update();
57-
58-
} );
59-
56+
signals.objectSelected.add( update );
6057
signals.materialChanged.add( update );
6158

6259
return container;

editor/js/Sidebar.Material.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,11 @@ function SidebarMaterial( editor ) {
421421

422422
currentMaterialSlot = parseInt( materialSlotSelect.getValue() );
423423

424-
if ( currentMaterialSlot !== previousSelectedSlot ) refreshUI();
424+
if ( currentMaterialSlot !== previousSelectedSlot ) {
425+
426+
editor.signals.materialChanged.dispatch( currentObject, currentMaterialSlot );
427+
428+
}
425429

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

0 commit comments

Comments
 (0)