Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOMaterialSpecifier.m
Go to the documentation of this file.
1/*
2
3OOMaterialSpecifier.m
4
5
6Copyright (C) 2010-2013 Jens Ayton
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in all
16copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24SOFTWARE.
25
26*/
27
29#import "OOColor.h"
31#import "OOTexture.h"
32#import "Universe.h"
34
35
36NSString * const kOOMaterialDiffuseColorName = @"diffuse_color";
37NSString * const kOOMaterialDiffuseColorLegacyName = @"diffuse";
38NSString * const kOOMaterialAmbientColorName = @"ambient_color";
39NSString * const kOOMaterialAmbientColorLegacyName = @"ambient";
40NSString * const kOOMaterialSpecularColorName = @"specular_color";
41NSString * const kOOMaterialSpecularColorLegacyName = @"specular";
42NSString * const kOOMaterialSpecularModulateColorName = @"specular_modulate_color";
43NSString * const kOOMaterialEmissionColorName = @"emission_color";
44NSString * const kOOMaterialEmissionColorLegacyName = @"emission";
45NSString * const kOOMaterialEmissionModulateColorName = @"emission_modulate_color";
46NSString * const kOOMaterialIlluminationModulateColorName = @"illumination_modulate_color";
47
48NSString * const kOOMaterialDiffuseMapName = @"diffuse_map";
49NSString * const kOOMaterialSpecularColorMapName = @"specular_color_map";
50NSString * const kOOMaterialSpecularExponentMapName = @"specular_exponent_map";
51NSString * const kOOMaterialCombinedSpecularMapName = @"specular_map"; // Combined specular_color_map and specular_exponent_map (unfortunate name required for backwards-compatibility).
52NSString * const kOOMaterialNormalMapName = @"normal_map";
53NSString * const kOOMaterialParallaxMapName = @"parallax_map";
54NSString * const kOOMaterialNormalAndParallaxMapName = @"normal_and_parallax_map";
55NSString * const kOOMaterialEmissionMapName = @"emission_map";
56NSString * const kOOMaterialIlluminationMapName = @"illumination_map";
57NSString * const kOOMaterialEmissionAndIlluminationMapName = @"emission_and_illumination_map";
58
59NSString * const kOOMaterialParallaxScaleName = @"parallax_scale";
60NSString * const kOOMaterialParallaxBiasName = @"parallax_bias";
61
62NSString * const kOOMaterialGammaCorrectName = @"gamma_correct";
63
64NSString * const kOOMaterialGlossName = @"gloss";
65
66NSString * const kOOMaterialSpecularExponentName = @"specular_exponent";
67NSString * const kOOMaterialSpecularExponentLegacyName = @"shininess";
68
69NSString * const kOOMaterialLightMapsName = @"light_map";
70
71
72@implementation NSDictionary (OOMateralProperties)
73
74// Internal. Used to avoid mutual recusion between -oo_specularExponentMapSpecifier and -oo_specularExponent.
76{
77 NSObject *value = [self objectForKey:kOOMaterialSpecularExponentName];
78 if (value == nil) value = [self objectForKey:kOOMaterialSpecularExponentLegacyName];
79 return OOIntFromObject(value, -1);
80}
81
82
84{
85 OOColor *result = [OOColor colorWithDescription:[self objectForKey:kOOMaterialDiffuseColorName]];
86 if (result == nil) result = [OOColor colorWithDescription:[self objectForKey:kOOMaterialDiffuseColorLegacyName]];
87
88 if ([result isWhite]) result = nil;
89 return result;
90}
91
92
94{
95 OOColor *result = [OOColor colorWithDescription:[self objectForKey:kOOMaterialAmbientColorName]];
96 if (result == nil) result = [OOColor colorWithDescription:[self objectForKey:kOOMaterialAmbientColorLegacyName]];
97 return result;
98}
99
100
102{
103 OOColor *result = [OOColor colorWithDescription:[self objectForKey:kOOMaterialSpecularColorName]];
104 if (result == nil) result = [OOColor colorWithDescription:[self objectForKey:kOOMaterialSpecularColorLegacyName]];
105 if (result == nil)
106 {
107 result = [OOColor colorWithWhite:0.2f alpha:1.0f];
108 }
109 return result;
110}
111
112
114{
115 OOColor *result = [OOColor colorWithDescription:[self objectForKey:kOOMaterialSpecularModulateColorName]];
116 if (result == nil) result = [OOColor whiteColor];
117
118 return result;
119}
120
121
123{
124 OOColor *result = [OOColor colorWithDescription:[self objectForKey:kOOMaterialEmissionColorName]];
125 if (result == nil) result = [OOColor colorWithDescription:[self objectForKey:kOOMaterialEmissionColorLegacyName]];
126
127 if ([result isBlack]) result = nil;
128 return result;
129}
130
131
133{
134 OOColor *result = [OOColor colorWithDescription:[self objectForKey:kOOMaterialEmissionModulateColorName]];
135
136 if ([result isWhite]) result = nil;
137 return result;
138}
139
140
142{
143 OOColor *result = [OOColor colorWithDescription:[self objectForKey:kOOMaterialIlluminationModulateColorName]];
144
145 if ([result isWhite]) result = nil;
146 return result;
147}
148
149
150- (NSDictionary *) oo_diffuseMapSpecifierWithDefaultName:(NSString *)name
151{
152 return [self oo_textureSpecifierForKey:kOOMaterialDiffuseMapName defaultName:name];
153}
154
155
156- (NSDictionary *) oo_combinedSpecularMapSpecifier
157{
158 if ([self oo_rawSpecularExponentValue] == 0) return nil;
159 return [self oo_textureSpecifierForKey:kOOMaterialCombinedSpecularMapName defaultName:nil];
160}
161
162
163- (NSDictionary *) oo_specularColorMapSpecifier
164{
165 if ([self oo_rawSpecularExponentValue] == 0) return nil;
166 NSDictionary *result = [self oo_textureSpecifierForKey:kOOMaterialSpecularColorMapName defaultName:nil];
167 if (result == nil) result = [self oo_combinedSpecularMapSpecifier];
168 return result;
169}
170
171
172- (NSDictionary *) oo_specularExponentMapSpecifier
173{
174 if ([self oo_rawSpecularExponentValue] == 0) return nil;
175 NSDictionary *result = [self oo_textureSpecifierForKey:kOOMaterialSpecularExponentMapName defaultName:nil];
176 if (result == nil) result = [[self oo_combinedSpecularMapSpecifier] dictionaryByAddingObject:@"a" forKey:@"extract_channel"];
177 return result;
178}
179
180
181- (NSDictionary *) oo_normalMapSpecifier
182{
183 if ([self oo_normalAndParallaxMapSpecifier] != nil) return nil;
184 return [self oo_textureSpecifierForKey:kOOMaterialNormalMapName defaultName:nil];
185}
186
187
188- (NSDictionary *) oo_parallaxMapSpecifier
189{
190 id spec = [self oo_textureSpecifierForKey:kOOMaterialParallaxMapName defaultName:nil];
191 if (spec == nil)
192 {
193 // Default is alpha channel of normal_and_parallax_map.
194 spec = [[self oo_normalAndParallaxMapSpecifier] dictionaryByAddingObject:@"a"
195 forKey:@"extract_channel"];
196 }
197
198 return spec;
199}
200
201
202- (NSDictionary *) oo_normalAndParallaxMapSpecifier
203{
204 return [self oo_textureSpecifierForKey:kOOMaterialNormalAndParallaxMapName defaultName:nil];
205}
206
207
208- (NSDictionary *) oo_emissionMapSpecifier
209{
210 return [self oo_textureSpecifierForKey:kOOMaterialEmissionMapName defaultName:nil];
211}
212
213
214- (NSDictionary *) oo_illuminationMapSpecifier
215{
216 return [self oo_textureSpecifierForKey:kOOMaterialIlluminationMapName defaultName:nil];
217}
218
219
221{
222 if ([self oo_emissionMapSpecifier] != nil || [self oo_illuminationMapSpecifier] != nil) return nil;
223 return [self oo_textureSpecifierForKey:kOOMaterialEmissionAndIlluminationMapName defaultName:nil];
224}
225
226
227- (float) oo_parallaxScale
228{
229 return [self oo_floatForKey:kOOMaterialParallaxScaleName defaultValue:kOOMaterialDefaultParallaxScale];
230}
231
232
233- (float) oo_parallaxBias
234{
235 return [self oo_floatForKey:kOOMaterialParallaxBiasName];
236}
237
238
239- (BOOL) oo_gammaCorrect
240{
241 return [self oo_boolForKey:kOOMaterialGammaCorrectName defaultValue:![[NSUserDefaults standardUserDefaults] boolForKey:@"no-gamma-correct"]];
242}
243
244
245- (float) oo_gloss
246{
247 return OOClamp_0_1_f([self oo_floatForKey:kOOMaterialGlossName defaultValue:0.375f]);
248}
249
250
252{
253 int result = [self oo_rawSpecularExponentValue];
254 if (result < 0)
255 {
256 if ([UNIVERSE useShaders] && [self oo_specularExponentMapSpecifier] != nil)
257 {
258 result = 128;
259 }
260 else
261 {
262 result = 10;
263 }
264 }
265
266 return result;
267}
268
269@end
NSString *const kOOMaterialGlossName
NSString *const kOOMaterialNormalAndParallaxMapName
NSString *const kOOMaterialSpecularColorLegacyName
NSString *const kOOMaterialDiffuseColorName
NSString *const kOOMaterialEmissionMapName
NSString *const kOOMaterialEmissionAndIlluminationMapName
NSString *const kOOMaterialEmissionColorName
NSString *const kOOMaterialNormalMapName
NSString *const kOOMaterialParallaxScaleName
NSString *const kOOMaterialDiffuseMapName
NSString *const kOOMaterialEmissionModulateColorName
NSString *const kOOMaterialIlluminationModulateColorName
NSString *const kOOMaterialDiffuseColorLegacyName
NSString *const kOOMaterialGammaCorrectName
NSString *const kOOMaterialSpecularColorName
NSString *const kOOMaterialAmbientColorName
NSString *const kOOMaterialParallaxBiasName
NSString *const kOOMaterialLightMapsName
NSString *const kOOMaterialGlossName
NSString *const kOOMaterialEmissionColorLegacyName
NSString *const kOOMaterialIlluminationMapName
NSString *const kOOMaterialAmbientColorLegacyName
NSString *const kOOMaterialSpecularColorMapName
NSString *const kOOMaterialParallaxMapName
NSString *const kOOMaterialSpecularExponentLegacyName
NSString *const kOOMaterialSpecularModulateColorName
NSString *const kOOMaterialSpecularExponentName
NSString *const kOOMaterialCombinedSpecularMapName
NSString *const kOOMaterialSpecularExponentMapName
return nil
#define UNIVERSE
Definition Universe.h:840
OOColor * colorWithWhite:alpha:(float white,[alpha] float alpha)
Definition OOColor.m:103
OOColor * colorWithDescription:(id description)
Definition OOColor.m:127
OOColor * whiteColor()
Definition OOColor.m:256
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque