@@ -26,27 +26,15 @@ namespace Shabby
26
26
27
27
public static class MaterialDefLibrary
28
28
{
29
- public static readonly Dictionary < string , string > normalMapProperties = new Dictionary < string , string > ( ) ;
30
29
public static readonly Dictionary < string , MaterialDef > items = new Dictionary < string , MaterialDef > ( ) ;
31
30
32
31
public static void Load ( )
33
32
{
34
- foreach ( var node in GameDatabase . Instance . GetConfigNodes ( "SHABBY_SHADER_NORMAL_MAP_PROPERTY" ) ) {
35
- var shader = node . GetValue ( "shader" ) ;
36
- var property = node . GetValue ( "property" ) ;
37
- if ( string . IsNullOrEmpty ( shader ) || string . IsNullOrEmpty ( property ) ) {
38
- Debug . Log ( $ "[Shabby] invalid shader normal map property specification { shader } = { property } ") ;
39
- } else {
40
- normalMapProperties [ shader ] = property ;
41
- }
42
- }
43
-
44
33
foreach ( var node in GameDatabase . Instance . GetConfigNodes ( "SHABBY_MATERIAL_DEF" ) ) {
45
34
var def = new MaterialDef ( node ) ;
46
35
if ( string . IsNullOrEmpty ( def . name ) || ! def . isValid ) {
47
36
Debug . LogError ( $ "[Shabby][MaterialDef { def . name } ] removing invalid definition") ;
48
- }
49
- else {
37
+ } else {
50
38
items [ def . name ] = def ;
51
39
}
52
40
}
@@ -70,9 +58,7 @@ public class MaterialDef
70
58
public readonly Dictionary < string , float > floats ;
71
59
public readonly Dictionary < string , Color > colors ;
72
60
public readonly Dictionary < string , Vector4 > vectors ;
73
- public readonly Dictionary < string , string > textureNames ;
74
-
75
- readonly Dictionary < string , Texture > textures = new Dictionary < string , Texture > ( ) ;
61
+ public readonly Dictionary < string , Texture > textures ;
76
62
77
63
public readonly bool isValid = true ;
78
64
@@ -95,9 +81,13 @@ public MaterialDef(ConfigNode node)
95
81
96
82
keywords = LoadDictionary < bool > ( node . GetNode ( "Keyword" ) ) ;
97
83
floats = LoadDictionary < float > ( node . GetNode ( "Float" ) ) ;
98
- colors = LoadDictionary < Color > ( node . GetNode ( "Color" ) , ParseColor ) ;
84
+ colors = LoadDictionary < Color > (
85
+ node . GetNode ( "Color" ) ,
86
+ value => ParseColor ( value , out var color ) ? ( object ) color : null ) ;
99
87
vectors = LoadDictionary < Vector4 > ( node . GetNode ( "Vector" ) ) ;
100
- textureNames = LoadDictionary < string > ( node . GetNode ( "Texture" ) ) ;
88
+ textures = LoadDictionary < Texture > (
89
+ node . GetNode ( "Texture" ) ,
90
+ value => GameDatabase . Instance . GetTexture ( value , asNormalMap : false ) ) ;
101
91
}
102
92
103
93
static readonly Func < Type , string , object > ReadValue =
@@ -114,7 +104,7 @@ Dictionary<string, T> LoadDictionary<T>(ConfigNode node, Func<string, object> pa
114
104
if ( value is T parsed ) {
115
105
items [ item . name ] = parsed ;
116
106
} else {
117
- Debug . LogError ( $ "[Shabby][MaterialDef { name } ] failed to parse property { item . name } = { item . value } as a { typeof ( T ) . Name } ") ;
107
+ Debug . LogError ( $ "[Shabby][MaterialDef { name } ] failed to load { typeof ( T ) . Name } property { item . name } = { item . value } ") ;
118
108
}
119
109
}
120
110
@@ -128,8 +118,6 @@ public static bool ParseColor(string value, out Color color)
128
118
return false ;
129
119
}
130
120
131
- static object ParseColor ( string value ) => ParseColor ( value , out var color ) ? ( object ) color : null ;
132
-
133
121
/// <summary>
134
122
/// Create a new material based on this definition. The material name is copied from the
135
123
/// passed reference material. In update-existing mode, all properties are also copied from
@@ -161,25 +149,7 @@ public Material Instantiate(Material referenceMaterial)
161
149
162
150
foreach ( var kvp in vectors ) material . SetVector ( kvp . Key , kvp . Value ) ;
163
151
164
- foreach ( var kvp in textureNames ) {
165
- var ( propName , texName ) = ( kvp . Key , kvp . Value ) ;
166
- if ( ! textures . TryGetValue ( texName , out var texture ) ) {
167
- var texInfo = GameDatabase . Instance . GetTextureInfo ( texName ) ;
168
- if ( texInfo == null )
169
- {
170
- Debug . LogError ( $ "[Shabby] failed to find texture { texName } ") ;
171
- continue ;
172
- }
173
-
174
- MaterialDefLibrary . normalMapProperties . TryGetValue ( material . shader . name , out var nrmPropName ) ;
175
- var isNormalMap = propName == ( nrmPropName ?? "_BumpMap" ) ;
176
-
177
- texture = isNormalMap ? texInfo . normalMap : texInfo . texture ;
178
- textures [ texName ] = texture ;
179
- }
180
-
181
- material . SetTexture ( propName , texture ) ;
182
- }
152
+ foreach ( var kvp in textures ) material . SetTexture ( kvp . Key , kvp . Value ) ;
183
153
184
154
return material ;
185
155
}
0 commit comments