Skip to content

Commit 8d7c7ae

Browse files
committed
Editor: Added material.normalScale support.
1 parent d8db14e commit 8d7c7ae

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed

editor/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@
170170
<script src="js/commands/RemoveScriptCommand.js"></script>
171171
<script src="js/commands/SetScriptValueCommand.js"></script>
172172
<script src="js/commands/SetMaterialCommand.js"></script>
173-
<script src="js/commands/SetMaterialValueCommand.js"></script>
174173
<script src="js/commands/SetMaterialColorCommand.js"></script>
175174
<script src="js/commands/SetMaterialMapCommand.js"></script>
175+
<script src="js/commands/SetMaterialValueCommand.js"></script>
176+
<script src="js/commands/SetMaterialVectorCommand.js"></script>
176177
<script src="js/commands/SetSceneCommand.js"></script>
177178

178179
<script>

editor/js/Sidebar.Material.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,14 @@ Sidebar.Material = function ( editor ) {
340340
var materialNormalMapRow = new UI.Row();
341341
var materialNormalMapEnabled = new UI.Checkbox( false ).onChange( update );
342342
var materialNormalMap = new UI.Texture().onChange( update );
343+
var materialNormalScaleX = new UI.Number( 1 ).setWidth( '30px' ).onChange( update );
344+
var materialNormalScaleY = new UI.Number( 1 ).setWidth( '30px' ).onChange( update );
343345

344346
materialNormalMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/normalmap' ) ).setWidth( '90px' ) );
345347
materialNormalMapRow.add( materialNormalMapEnabled );
346348
materialNormalMapRow.add( materialNormalMap );
349+
materialNormalMapRow.add( materialNormalScaleX );
350+
materialNormalMapRow.add( materialNormalScaleY );
347351

348352
container.add( materialNormalMapRow );
349353

@@ -778,6 +782,17 @@ Sidebar.Material = function ( editor ) {
778782

779783
}
780784

785+
if ( material.normalScale.x !== materialNormalScaleX.getValue() ||
786+
material.normalScale.y !== materialNormalScaleY.getValue() ) {
787+
788+
var value = [
789+
materialNormalScaleX.getValue(),
790+
materialNormalScaleY.getValue()
791+
];
792+
editor.execute( new SetMaterialVectorCommand( editor, currentObject, 'normalScale', value, currentMaterialSlot ) );
793+
794+
}
795+
781796
} else {
782797

783798
if ( normalMapEnabled ) textureWarning = true;
@@ -1313,6 +1328,9 @@ Sidebar.Material = function ( editor ) {
13131328

13141329
}
13151330

1331+
materialNormalScaleX.setValue( material.normalScale.x );
1332+
materialNormalScaleY.setValue( material.normalScale.y );
1333+
13161334
}
13171335

13181336
if ( material.displacementMap !== undefined ) {
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @author dforrer / https://github.com/dforrer
3+
* Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
4+
*/
5+
6+
var SetMaterialVectorCommand = function ( editor, object, attributeName, newValue, materialSlot ) {
7+
8+
Command.call( this, editor );
9+
10+
this.type = 'SetMaterialColorCommand';
11+
this.name = 'Set Material.' + attributeName;
12+
this.updatable = true;
13+
14+
this.object = object;
15+
this.material = this.editor.getObjectMaterial( object, materialSlot );
16+
17+
this.oldValue = ( this.material !== undefined ) ? this.material[ attributeName ].toArray() : undefined;
18+
this.newValue = newValue;
19+
20+
this.attributeName = attributeName;
21+
22+
};
23+
24+
SetMaterialVectorCommand.prototype = {
25+
26+
execute: function () {
27+
28+
this.material[ this.attributeName ].fromArray( this.newValue );
29+
30+
this.editor.signals.materialChanged.dispatch( this.material );
31+
32+
},
33+
34+
undo: function () {
35+
36+
this.material[ this.attributeName ].fromArray( this.oldValue );
37+
38+
this.editor.signals.materialChanged.dispatch( this.material );
39+
40+
},
41+
42+
update: function ( cmd ) {
43+
44+
this.newValue = cmd.newValue;
45+
46+
},
47+
48+
toJSON: function () {
49+
50+
var output = Command.prototype.toJSON.call( this );
51+
52+
output.objectUuid = this.object.uuid;
53+
output.attributeName = this.attributeName;
54+
output.oldValue = this.oldValue;
55+
output.newValue = this.newValue;
56+
57+
return output;
58+
59+
},
60+
61+
fromJSON: function ( json ) {
62+
63+
Command.prototype.fromJSON.call( this, json );
64+
65+
this.object = this.editor.objectByUuid( json.objectUuid );
66+
this.attributeName = json.attributeName;
67+
this.oldValue = json.oldValue;
68+
this.newValue = json.newValue;
69+
70+
}
71+
72+
};

editor/sw.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,10 @@ const staticAssets = [
169169
'./js/commands/RemoveScriptCommand.js',
170170
'./js/commands/SetScriptValueCommand.js',
171171
'./js/commands/SetMaterialCommand.js',
172-
'./js/commands/SetMaterialValueCommand.js',
173172
'./js/commands/SetMaterialColorCommand.js',
174173
'./js/commands/SetMaterialMapCommand.js',
174+
'./js/commands/SetMaterialValueCommand.js',
175+
'./js/commands/SetMaterialVectorCommand.js',
175176
'./js/commands/SetSceneCommand.js',
176177

177178
//

0 commit comments

Comments
 (0)