1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org/ |
---|
6 | |
---|
7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | |
---|
24 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | #include "OldMaterialReader.h" |
---|
30 | |
---|
31 | |
---|
32 | //----------------------------------------------------------------------- |
---|
33 | // Internal parser methods |
---|
34 | // Material Attributes |
---|
35 | ColourValue _parseColourValue(StringVector::iterator& params, int numParams) |
---|
36 | { |
---|
37 | ColourValue colour( |
---|
38 | StringConverter::parseReal(params[1].c_str()) , |
---|
39 | StringConverter::parseReal(params[2].c_str()) , |
---|
40 | StringConverter::parseReal(params[3].c_str()) , |
---|
41 | (numParams==5) ? StringConverter::parseReal(params[4].c_str()) : 1.0f ) ; |
---|
42 | return colour ; |
---|
43 | } |
---|
44 | void parseAmbient(StringVector::iterator& params, int numParams, MaterialPtr& pMat) |
---|
45 | { |
---|
46 | // Must be 3 or 4parameters (+ command = 4 or 5) |
---|
47 | if (numParams != 4 && numParams != 5) |
---|
48 | { |
---|
49 | LogManager::getSingleton().logMessage("Bad ambient attribute line in " |
---|
50 | + pMat->getName() + ", wrong number of parameters (expected 3 or 4)"); |
---|
51 | } |
---|
52 | else |
---|
53 | { |
---|
54 | pMat->setAmbient( _parseColourValue(params, numParams) ); |
---|
55 | } |
---|
56 | } |
---|
57 | //----------------------------------------------------------------------- |
---|
58 | void parseDiffuse(StringVector::iterator& params, int numParams, MaterialPtr& pMat) |
---|
59 | { |
---|
60 | // Must be 3 or 4 parameters (+ command = 4 or 5) |
---|
61 | if (numParams != 4 && numParams != 5) |
---|
62 | { |
---|
63 | LogManager::getSingleton().logMessage("Bad diffuse attribute line in " |
---|
64 | + pMat->getName() + ", wrong number of parameters (expected 3 or 4)"); |
---|
65 | } |
---|
66 | else |
---|
67 | { |
---|
68 | pMat->setDiffuse( _parseColourValue(params, numParams) ); |
---|
69 | } |
---|
70 | } |
---|
71 | //----------------------------------------------------------------------- |
---|
72 | void parseSpecular(StringVector::iterator& params, int numParams, MaterialPtr& pMat) |
---|
73 | { |
---|
74 | // Must be 4 or 5 parameters (+ command = 5 or 6) |
---|
75 | if (numParams != 5 && numParams != 6) |
---|
76 | { |
---|
77 | LogManager::getSingleton().logMessage("Bad specular attribute line in " |
---|
78 | + pMat->getName() + ", wrong number of parameters (expected 4 or 5)"); |
---|
79 | } |
---|
80 | else |
---|
81 | { |
---|
82 | pMat->setSpecular( _parseColourValue(params, numParams-1) ); |
---|
83 | pMat->setShininess(StringConverter::parseReal(params[numParams-1].c_str())); |
---|
84 | } |
---|
85 | } |
---|
86 | //----------------------------------------------------------------------- |
---|
87 | void parseEmissive(StringVector::iterator& params, int numParams, MaterialPtr& pMat) |
---|
88 | { |
---|
89 | // Must be 3 or 4 parameters (+ command = 4 or 5) |
---|
90 | if (numParams != 4 && numParams != 5) |
---|
91 | { |
---|
92 | LogManager::getSingleton().logMessage("Bad emissive attribute line in " |
---|
93 | + pMat->getName() + ", wrong number of parameters (expected 3 or 4)"); |
---|
94 | } |
---|
95 | else |
---|
96 | { |
---|
97 | pMat->setSelfIllumination( _parseColourValue(params, numParams) ); |
---|
98 | } |
---|
99 | } |
---|
100 | //----------------------------------------------------------------------- |
---|
101 | SceneBlendFactor convertBlendFactor(const String& param) |
---|
102 | { |
---|
103 | if (param == "one") |
---|
104 | return SBF_ONE; |
---|
105 | else if (param == "zero") |
---|
106 | return SBF_ZERO; |
---|
107 | else if (param == "dest_colour") |
---|
108 | return SBF_DEST_COLOUR; |
---|
109 | else if (param == "src_colour") |
---|
110 | return SBF_SOURCE_COLOUR; |
---|
111 | else if (param == "one_minus_dest_colour") |
---|
112 | return SBF_ONE_MINUS_DEST_COLOUR; |
---|
113 | else if (param == "one_minus_src_colour") |
---|
114 | return SBF_ONE_MINUS_SOURCE_COLOUR; |
---|
115 | else if (param == "dest_alpha") |
---|
116 | return SBF_DEST_ALPHA; |
---|
117 | else if (param == "src_alpha") |
---|
118 | return SBF_SOURCE_ALPHA; |
---|
119 | else if (param == "one_minus_dest_alpha") |
---|
120 | return SBF_ONE_MINUS_DEST_ALPHA; |
---|
121 | else if (param == "one_minus_src_alpha") |
---|
122 | return SBF_ONE_MINUS_SOURCE_ALPHA; |
---|
123 | else |
---|
124 | { |
---|
125 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Invalid blend factor.", "convertBlendFactor"); |
---|
126 | } |
---|
127 | |
---|
128 | |
---|
129 | } |
---|
130 | //----------------------------------------------------------------------- |
---|
131 | void parseSceneBlend(StringVector::iterator& params, int numParams, MaterialPtr& pMat) |
---|
132 | { |
---|
133 | // Should be 1 or 2 params (+ command) |
---|
134 | if (numParams == 2) |
---|
135 | { |
---|
136 | //simple |
---|
137 | SceneBlendType stype; |
---|
138 | if (params[1] == "add") |
---|
139 | stype = SBT_ADD; |
---|
140 | else if (params[1] == "modulate") |
---|
141 | stype = SBT_TRANSPARENT_COLOUR; |
---|
142 | else if (params[1] == "alpha_blend") |
---|
143 | stype = SBT_TRANSPARENT_ALPHA; |
---|
144 | else |
---|
145 | { |
---|
146 | LogManager::getSingleton().logMessage("Bad scene_blend attribute line in " |
---|
147 | + pMat->getName() + ", unrecognised parameter '" + params[1] + "'"); |
---|
148 | return ; |
---|
149 | } |
---|
150 | pMat->setSceneBlending(stype); |
---|
151 | |
---|
152 | } |
---|
153 | else if (numParams == 3) |
---|
154 | { |
---|
155 | //src/dest |
---|
156 | SceneBlendFactor src, dest; |
---|
157 | |
---|
158 | try { |
---|
159 | src = convertBlendFactor(params[1]); |
---|
160 | dest = convertBlendFactor(params[2]); |
---|
161 | pMat->setSceneBlending(src,dest); |
---|
162 | } |
---|
163 | catch (Exception& e) |
---|
164 | { |
---|
165 | LogManager::getSingleton().logMessage("Bad scene_blend attribute line in " |
---|
166 | + pMat->getName() + ", " + e.getFullDescription()); |
---|
167 | } |
---|
168 | |
---|
169 | } |
---|
170 | else |
---|
171 | { |
---|
172 | LogManager::getSingleton().logMessage("Bad scene_blend attribute line in " |
---|
173 | + pMat->getName() + ", wrong number of parameters (expected 1 or 2)"); |
---|
174 | } |
---|
175 | |
---|
176 | |
---|
177 | } |
---|
178 | //----------------------------------------------------------------------- |
---|
179 | CompareFunction convertCompareFunction(const String& param) |
---|
180 | { |
---|
181 | if (param == "always_fail") |
---|
182 | return CMPF_ALWAYS_FAIL; |
---|
183 | else if (param == "always_pass") |
---|
184 | return CMPF_ALWAYS_PASS; |
---|
185 | else if (param == "less") |
---|
186 | return CMPF_LESS; |
---|
187 | else if (param == "less_equal") |
---|
188 | return CMPF_LESS_EQUAL; |
---|
189 | else if (param == "equal") |
---|
190 | return CMPF_EQUAL; |
---|
191 | else if (param == "not_equal") |
---|
192 | return CMPF_NOT_EQUAL; |
---|
193 | else if (param == "greater_equal") |
---|
194 | return CMPF_GREATER_EQUAL; |
---|
195 | else if (param == "greater") |
---|
196 | return CMPF_GREATER; |
---|
197 | else |
---|
198 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Invalid compare function", "convertCompareFunction"); |
---|
199 | |
---|
200 | } |
---|
201 | //----------------------------------------------------------------------- |
---|
202 | void parseDepthParams(StringVector::iterator& params, int numParams, MaterialPtr& pMat) |
---|
203 | { |
---|
204 | if (numParams != 2) |
---|
205 | { |
---|
206 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
207 | + pMat->getName() + ", wrong number of parameters (expected 1)"); |
---|
208 | return; |
---|
209 | } |
---|
210 | |
---|
211 | if (params[0] == "depth_check") |
---|
212 | { |
---|
213 | if (params[1] == "on") |
---|
214 | pMat->setDepthCheckEnabled(true); |
---|
215 | else if (params[1] == "off") |
---|
216 | pMat->setDepthCheckEnabled(false); |
---|
217 | else |
---|
218 | LogManager::getSingleton().logMessage("Bad depth_check attribute line in " |
---|
219 | + pMat->getName() + ", valid parameters are 'on' or 'off'."); |
---|
220 | } |
---|
221 | else if (params[0] == "depth_write") |
---|
222 | { |
---|
223 | if (params[1] == "on") |
---|
224 | pMat->setDepthWriteEnabled(true); |
---|
225 | else if (params[1] == "off") |
---|
226 | pMat->setDepthWriteEnabled(false); |
---|
227 | else |
---|
228 | LogManager::getSingleton().logMessage("Bad depth_write attribute line in " |
---|
229 | + pMat->getName() + ", valid parameters are 'on' or 'off'."); |
---|
230 | } |
---|
231 | else if (params[0] == "depth_func") |
---|
232 | { |
---|
233 | try { |
---|
234 | CompareFunction func = convertCompareFunction(params[1]); |
---|
235 | pMat->setDepthFunction(func); |
---|
236 | } |
---|
237 | catch (...) |
---|
238 | { |
---|
239 | LogManager::getSingleton().logMessage("Bad depth_func attribute line in " |
---|
240 | + pMat->getName() + ", invalid function parameter."); |
---|
241 | } |
---|
242 | } |
---|
243 | |
---|
244 | } |
---|
245 | //----------------------------------------------------------------------- |
---|
246 | void parseCullMode(StringVector::iterator& params, int numParams, MaterialPtr& pMat) |
---|
247 | { |
---|
248 | |
---|
249 | if (numParams != 2) |
---|
250 | { |
---|
251 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
252 | + pMat->getName() + ", wrong number of parameters (expected 1)"); |
---|
253 | return; |
---|
254 | } |
---|
255 | |
---|
256 | if (params[0] == "cull_hardware") |
---|
257 | { |
---|
258 | if (params[1]=="none") |
---|
259 | pMat->setCullingMode(CULL_NONE); |
---|
260 | else if (params[1]=="anticlockwise") |
---|
261 | pMat->setCullingMode(CULL_ANTICLOCKWISE); |
---|
262 | else if (params[1]=="clockwise") |
---|
263 | pMat->setCullingMode(CULL_CLOCKWISE); |
---|
264 | else |
---|
265 | LogManager::getSingleton().logMessage("Bad cull_hardware attribute line in " |
---|
266 | + pMat->getName() + ", valid parameters are 'none', 'clockwise' or 'anticlockwise'."); |
---|
267 | |
---|
268 | } |
---|
269 | else // cull_software |
---|
270 | { |
---|
271 | if (params[1]=="none") |
---|
272 | pMat->setManualCullingMode(MANUAL_CULL_NONE); |
---|
273 | else if (params[1]=="back") |
---|
274 | pMat->setManualCullingMode(MANUAL_CULL_BACK); |
---|
275 | else if (params[1]=="front") |
---|
276 | pMat->setManualCullingMode(MANUAL_CULL_FRONT); |
---|
277 | else |
---|
278 | LogManager::getSingleton().logMessage("Bad cull_software attribute line in " |
---|
279 | + pMat->getName() + ", valid parameters are 'none', 'front' or 'back'."); |
---|
280 | |
---|
281 | |
---|
282 | } |
---|
283 | } |
---|
284 | //----------------------------------------------------------------------- |
---|
285 | void parseLighting(StringVector::iterator& params, int numParams, MaterialPtr& pMat) |
---|
286 | { |
---|
287 | if (numParams != 2) |
---|
288 | { |
---|
289 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
290 | + pMat->getName() + ", wrong number of parameters (expected 1)"); |
---|
291 | return; |
---|
292 | } |
---|
293 | if (params[1]=="on") |
---|
294 | pMat->setLightingEnabled(true); |
---|
295 | else if (params[1]=="off") |
---|
296 | pMat->setLightingEnabled(false); |
---|
297 | else |
---|
298 | LogManager::getSingleton().logMessage("Bad lighting attribute line in " |
---|
299 | + pMat->getName() + ", valid parameters are 'on' or 'off'."); |
---|
300 | } |
---|
301 | //----------------------------------------------------------------------- |
---|
302 | void parseFogging(StringVector::iterator& params, int numParams, MaterialPtr& pMat) |
---|
303 | { |
---|
304 | if (numParams < 2) |
---|
305 | { |
---|
306 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
307 | + pMat->getName() + ", wrong number of parameters (expected 1)"); |
---|
308 | return; |
---|
309 | } |
---|
310 | if (params[1]=="true") |
---|
311 | { |
---|
312 | // if true, we need to see if they supplied all arguments, or just the 1... if just the one, |
---|
313 | // Assume they want to disable the default fog from effecting this material. |
---|
314 | if( numParams == 9 ) |
---|
315 | { |
---|
316 | FogMode mFogtype; |
---|
317 | if( params[2] == "none" ) |
---|
318 | mFogtype = FOG_NONE; |
---|
319 | else if( params[2] == "linear" ) |
---|
320 | mFogtype = FOG_LINEAR; |
---|
321 | else if( params[2] == "exp" ) |
---|
322 | mFogtype = FOG_EXP; |
---|
323 | else if( params[2] == "exp2" ) |
---|
324 | mFogtype = FOG_EXP2; |
---|
325 | else |
---|
326 | LogManager::getSingleton().logMessage("Bad fogging attribute line in " |
---|
327 | + pMat->getName() + ", valid parameters are 'none', 'linear', 'exp', or 'exp2'."); |
---|
328 | |
---|
329 | pMat->setFog(true,mFogtype,ColourValue(StringConverter::parseReal(params[3].c_str()),StringConverter::parseReal(params[4].c_str()),StringConverter::parseReal(params[5].c_str())),StringConverter::parseReal(params[6].c_str()),StringConverter::parseReal(params[7].c_str()),StringConverter::parseReal(params[8].c_str())); |
---|
330 | } |
---|
331 | else |
---|
332 | { |
---|
333 | pMat->setFog(true); |
---|
334 | } |
---|
335 | } |
---|
336 | else if (params[1]=="false") |
---|
337 | pMat->setFog(false); |
---|
338 | else |
---|
339 | LogManager::getSingleton().logMessage("Bad fog_override attribute line in " |
---|
340 | + pMat->getName() + ", valid parameters are 'true' or 'false'."); |
---|
341 | } |
---|
342 | //----------------------------------------------------------------------- |
---|
343 | void parseShading(StringVector::iterator& params, int numParams, MaterialPtr& pMat) |
---|
344 | { |
---|
345 | if (numParams != 2) |
---|
346 | { |
---|
347 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
348 | + pMat->getName() + ", wrong number of parameters (expected 1)"); |
---|
349 | return; |
---|
350 | } |
---|
351 | if (params[1]=="flat") |
---|
352 | pMat->setShadingMode(SO_FLAT); |
---|
353 | else if (params[1]=="gouraud") |
---|
354 | pMat->setShadingMode(SO_GOURAUD); |
---|
355 | else if (params[1]=="phong") |
---|
356 | pMat->setShadingMode(SO_PHONG); |
---|
357 | else |
---|
358 | LogManager::getSingleton().logMessage("Bad shading attribute line in " |
---|
359 | + pMat->getName() + ", valid parameters are 'flat', 'gouraud' or 'phong'."); |
---|
360 | |
---|
361 | } |
---|
362 | //----------------------------------------------------------------------- |
---|
363 | void parseFiltering(StringVector::iterator& params, int numParams, MaterialPtr& pMat) |
---|
364 | { |
---|
365 | if (numParams != 2) |
---|
366 | { |
---|
367 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
368 | + pMat->getName() + ", wrong number of parameters (expected 1)"); |
---|
369 | return; |
---|
370 | } |
---|
371 | if (params[1]=="none") |
---|
372 | pMat->setTextureFiltering(TFO_NONE); |
---|
373 | else if (params[1]=="bilinear") |
---|
374 | pMat->setTextureFiltering(TFO_BILINEAR); |
---|
375 | else if (params[1]=="trilinear") |
---|
376 | pMat->setTextureFiltering(TFO_TRILINEAR); |
---|
377 | else if (params[1]=="anisotropic") |
---|
378 | pMat->setTextureFiltering(TFO_ANISOTROPIC); |
---|
379 | else |
---|
380 | LogManager::getSingleton().logMessage("Bad filtering attribute line in " |
---|
381 | + pMat->getName() + ", valid parameters are 'none', 'bilinear', 'trilinear' or 'anisotropic'."); |
---|
382 | } |
---|
383 | //----------------------------------------------------------------------- |
---|
384 | // Texture layer attributes |
---|
385 | void parseTexture(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex) |
---|
386 | { |
---|
387 | if (numParams != 2) |
---|
388 | { |
---|
389 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
390 | + pMat->getName() + ", wrong number of parameters (expected 1)"); |
---|
391 | return; |
---|
392 | } |
---|
393 | pTex->setTextureName(params[1]); |
---|
394 | } |
---|
395 | //----------------------------------------------------------------------- |
---|
396 | void parseAnimTexture(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex) |
---|
397 | { |
---|
398 | // Determine which form it is |
---|
399 | // Must have at least 3 params though |
---|
400 | if (numParams < 4) |
---|
401 | { |
---|
402 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
403 | + pMat->getName() + ", wrong number of parameters (expected at least 3)"); |
---|
404 | return; |
---|
405 | } |
---|
406 | if (numParams == 4 && atoi(params[2].c_str()) != 0 ) |
---|
407 | { |
---|
408 | // First form using base name & number of frames |
---|
409 | pTex->setAnimatedTextureName(params[1], atoi(params[2].c_str()), StringConverter::parseReal(params[3].c_str())); |
---|
410 | } |
---|
411 | else |
---|
412 | { |
---|
413 | // Second form using individual names |
---|
414 | // Can use params[1] as array start point |
---|
415 | pTex->setAnimatedTextureName((String*)¶ms[1], numParams-2, StringConverter::parseReal(params[numParams-1].c_str())); |
---|
416 | } |
---|
417 | |
---|
418 | } |
---|
419 | //----------------------------------------------------------------------- |
---|
420 | void parseCubicTexture(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex) |
---|
421 | { |
---|
422 | |
---|
423 | // Get final param |
---|
424 | bool useUVW; |
---|
425 | String uvOpt = params[numParams-1]; |
---|
426 | StringUtil::toLowerCase(uvOpt); |
---|
427 | if (uvOpt == "combineduvw") |
---|
428 | useUVW = true; |
---|
429 | else if (uvOpt == "separateuv") |
---|
430 | useUVW = false; |
---|
431 | else |
---|
432 | { |
---|
433 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
434 | + pMat->getName() + ", final parameter must be 'combinedUVW' or 'separateUV'."); |
---|
435 | return; |
---|
436 | } |
---|
437 | // Determine which form it is |
---|
438 | if (numParams == 3) |
---|
439 | { |
---|
440 | // First form using base name |
---|
441 | pTex->setCubicTextureName(params[1], useUVW); |
---|
442 | } |
---|
443 | else if (numParams == 8) |
---|
444 | { |
---|
445 | // Second form using individual names |
---|
446 | // Can use params[1] as array start point |
---|
447 | pTex->setCubicTextureName((String*)¶ms[1], useUVW); |
---|
448 | } |
---|
449 | else |
---|
450 | { |
---|
451 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
452 | + pMat->getName() + ", wrong number of parameters (expected 2 or 7)"); |
---|
453 | return; |
---|
454 | } |
---|
455 | |
---|
456 | } |
---|
457 | //----------------------------------------------------------------------- |
---|
458 | void parseTexCoord(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex) |
---|
459 | { |
---|
460 | if (numParams != 2) |
---|
461 | { |
---|
462 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
463 | + pMat->getName() + ", wrong number of parameters (expected 1)"); |
---|
464 | return; |
---|
465 | } |
---|
466 | pTex->setTextureCoordSet(atoi(params[1].c_str())); |
---|
467 | |
---|
468 | } |
---|
469 | //----------------------------------------------------------------------- |
---|
470 | void parseTexAddressMode(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex) |
---|
471 | { |
---|
472 | if (numParams != 2) |
---|
473 | { |
---|
474 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
475 | + pMat->getName() + ", wrong number of parameters (expected 1)"); |
---|
476 | return; |
---|
477 | } |
---|
478 | if (params[1]=="wrap") |
---|
479 | pTex->setTextureAddressingMode(TextureUnitState::TAM_WRAP); |
---|
480 | else if (params[1]=="mirror") |
---|
481 | pTex->setTextureAddressingMode(TextureUnitState::TAM_MIRROR); |
---|
482 | else if (params[1]=="clamp") |
---|
483 | pTex->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); |
---|
484 | else |
---|
485 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
486 | + pMat->getName() + ", valid parameters are 'wrap', 'clamp' or 'mirror'."); |
---|
487 | |
---|
488 | } |
---|
489 | //----------------------------------------------------------------------- |
---|
490 | void parseColourOp(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex) |
---|
491 | { |
---|
492 | if (numParams != 2) |
---|
493 | { |
---|
494 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
495 | + pMat->getName() + ", wrong number of parameters (expected 1)"); |
---|
496 | return; |
---|
497 | } |
---|
498 | if (params[1]=="replace") |
---|
499 | pTex->setColourOperation(LBO_REPLACE); |
---|
500 | else if (params[1]=="add") |
---|
501 | pTex->setColourOperation(LBO_ADD); |
---|
502 | else if (params[1]=="modulate") |
---|
503 | pTex->setColourOperation(LBO_MODULATE); |
---|
504 | else if (params[1]=="alpha_blend") |
---|
505 | pTex->setColourOperation(LBO_ALPHA_BLEND); |
---|
506 | else |
---|
507 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
508 | + pMat->getName() + ", valid parameters are 'replace', 'add', 'modulate' or 'alpha_blend'."); |
---|
509 | } |
---|
510 | //----------------------------------------------------------------------- |
---|
511 | void parseAlphaRejection(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex) |
---|
512 | { |
---|
513 | if (numParams != 3) |
---|
514 | { |
---|
515 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
516 | + pMat->getName() + ", wrong number of parameters (expected 2)"); |
---|
517 | return; |
---|
518 | } |
---|
519 | |
---|
520 | CompareFunction cmp; |
---|
521 | try { |
---|
522 | cmp = convertCompareFunction(params[1]); |
---|
523 | } |
---|
524 | catch (...) |
---|
525 | { |
---|
526 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
527 | + pMat->getName() + ", invalid compare function."); |
---|
528 | return; |
---|
529 | } |
---|
530 | |
---|
531 | // set on parent |
---|
532 | pTex->getParent()->setAlphaRejectSettings(cmp, atoi(params[2].c_str())); |
---|
533 | |
---|
534 | } |
---|
535 | //----------------------------------------------------------------------- |
---|
536 | LayerBlendOperationEx convertBlendOpEx(const String& param) |
---|
537 | { |
---|
538 | if (param == "source1") |
---|
539 | return LBX_SOURCE1; |
---|
540 | else if (param == "source2") |
---|
541 | return LBX_SOURCE2; |
---|
542 | else if (param == "modulate") |
---|
543 | return LBX_MODULATE; |
---|
544 | else if (param == "modulate_x2") |
---|
545 | return LBX_MODULATE_X2; |
---|
546 | else if (param == "modulate_x4") |
---|
547 | return LBX_MODULATE_X4; |
---|
548 | else if (param == "add") |
---|
549 | return LBX_ADD; |
---|
550 | else if (param == "add_signed") |
---|
551 | return LBX_ADD_SIGNED; |
---|
552 | else if (param == "add_smooth") |
---|
553 | return LBX_ADD_SMOOTH; |
---|
554 | else if (param == "subtract") |
---|
555 | return LBX_SUBTRACT; |
---|
556 | else if (param == "blend_diffuse_alpha") |
---|
557 | return LBX_BLEND_DIFFUSE_ALPHA; |
---|
558 | else if (param == "blend_texture_alpha") |
---|
559 | return LBX_BLEND_TEXTURE_ALPHA; |
---|
560 | else if (param == "blend_current_alpha") |
---|
561 | return LBX_BLEND_CURRENT_ALPHA; |
---|
562 | else if (param == "blend_manual") |
---|
563 | return LBX_BLEND_MANUAL; |
---|
564 | else if (param == "dotproduct") |
---|
565 | return LBX_DOTPRODUCT; |
---|
566 | else |
---|
567 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Invalid blend function", "convertBlendOpEx"); |
---|
568 | } |
---|
569 | //----------------------------------------------------------------------- |
---|
570 | LayerBlendSource convertBlendSource(const String& param) |
---|
571 | { |
---|
572 | if (param == "src_current") |
---|
573 | return LBS_CURRENT; |
---|
574 | else if (param == "src_texture") |
---|
575 | return LBS_TEXTURE; |
---|
576 | else if (param == "src_diffuse") |
---|
577 | return LBS_DIFFUSE; |
---|
578 | else if (param == "src_specular") |
---|
579 | return LBS_SPECULAR; |
---|
580 | else if (param == "src_manual") |
---|
581 | return LBS_MANUAL; |
---|
582 | else |
---|
583 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Invalid blend source", "convertBlendSource"); |
---|
584 | } |
---|
585 | //----------------------------------------------------------------------- |
---|
586 | void parseLayerFiltering(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex) |
---|
587 | { |
---|
588 | if (numParams != 2) |
---|
589 | { |
---|
590 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
591 | + pMat->getName() + ", wrong number of parameters (expected 1)"); |
---|
592 | return; |
---|
593 | } |
---|
594 | if (params[1]=="none") |
---|
595 | pTex->setTextureFiltering(TFO_NONE); |
---|
596 | else if (params[1]=="bilinear") |
---|
597 | pTex->setTextureFiltering(TFO_BILINEAR); |
---|
598 | else if (params[1]=="trilinear") |
---|
599 | pTex->setTextureFiltering(TFO_TRILINEAR); |
---|
600 | else if (params[1]=="anisotropic") |
---|
601 | pTex->setTextureFiltering(TFO_ANISOTROPIC); |
---|
602 | else |
---|
603 | LogManager::getSingleton().logMessage("Bad texture layer filtering attribute line in " |
---|
604 | + pMat->getName() + ", valid parameters are 'none', 'bilinear', 'trilinear' or 'anisotropic'."); |
---|
605 | } |
---|
606 | //----------------------------------------------------------------------- |
---|
607 | void parseColourOpEx(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex) |
---|
608 | { |
---|
609 | if (numParams < 4 || numParams > 13) |
---|
610 | { |
---|
611 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
612 | + pMat->getName() + ", wrong number of parameters (expected 3 to 10)"); |
---|
613 | return; |
---|
614 | } |
---|
615 | LayerBlendOperationEx op; |
---|
616 | LayerBlendSource src1, src2; |
---|
617 | Real manual = 0.0; |
---|
618 | ColourValue colSrc1 = ColourValue::White; |
---|
619 | ColourValue colSrc2 = ColourValue::White; |
---|
620 | |
---|
621 | try { |
---|
622 | op = convertBlendOpEx(params[1]); |
---|
623 | src1 = convertBlendSource(params[2]); |
---|
624 | src2 = convertBlendSource(params[3]); |
---|
625 | |
---|
626 | if (op == LBX_BLEND_MANUAL) |
---|
627 | { |
---|
628 | if (numParams < 5) |
---|
629 | { |
---|
630 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
631 | + pMat->getName() + ", wrong number of parameters (expected 4 for manual blend)"); |
---|
632 | return; |
---|
633 | } |
---|
634 | manual = StringConverter::parseReal(*(params+4)); |
---|
635 | } |
---|
636 | |
---|
637 | if (src1 == LBS_MANUAL) |
---|
638 | { |
---|
639 | int parIndex = 4; |
---|
640 | if (op == LBX_BLEND_MANUAL) |
---|
641 | parIndex++; |
---|
642 | |
---|
643 | if (numParams < parIndex + 3) |
---|
644 | { |
---|
645 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
646 | + pMat->getName() + ", wrong number of parameters (expected " + StringConverter::toString(parIndex + 2) + ")"); |
---|
647 | return; |
---|
648 | } |
---|
649 | |
---|
650 | colSrc1.r = StringConverter::parseReal(*(params+(parIndex++))); |
---|
651 | colSrc1.g = StringConverter::parseReal(*(params+(parIndex++))); |
---|
652 | colSrc1.b = StringConverter::parseReal(*(params+(parIndex))); |
---|
653 | } |
---|
654 | |
---|
655 | if (src2 == LBS_MANUAL) |
---|
656 | { |
---|
657 | int parIndex = 4; |
---|
658 | if (op == LBX_BLEND_MANUAL) |
---|
659 | parIndex++; |
---|
660 | if (src1 == LBS_MANUAL) |
---|
661 | parIndex += 3; |
---|
662 | |
---|
663 | if (numParams < parIndex + 3) |
---|
664 | { |
---|
665 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
666 | + pMat->getName() + ", wrong number of parameters (expected " + StringConverter::toString(parIndex + 2) + ")"); |
---|
667 | return; |
---|
668 | } |
---|
669 | |
---|
670 | colSrc2.r = StringConverter::parseReal(*(params + (parIndex++))); |
---|
671 | colSrc2.g = StringConverter::parseReal(*(params + (parIndex++))); |
---|
672 | colSrc2.b = StringConverter::parseReal(*(params + (parIndex))); |
---|
673 | } |
---|
674 | } |
---|
675 | catch (Exception& e) |
---|
676 | { |
---|
677 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
678 | + pMat->getName() + ", " + e.getFullDescription()); |
---|
679 | return; |
---|
680 | } |
---|
681 | |
---|
682 | pTex->setColourOperationEx(op, src1, src2, colSrc1, colSrc2, manual); |
---|
683 | } |
---|
684 | //----------------------------------------------------------------------- |
---|
685 | void parseColourOpFallback(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex) |
---|
686 | { |
---|
687 | if (numParams != 3) |
---|
688 | { |
---|
689 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
690 | + pMat->getName() + ", wrong number of parameters (expected 2)"); |
---|
691 | return; |
---|
692 | } |
---|
693 | |
---|
694 | //src/dest |
---|
695 | SceneBlendFactor src, dest; |
---|
696 | |
---|
697 | try { |
---|
698 | src = convertBlendFactor(params[1]); |
---|
699 | dest = convertBlendFactor(params[2]); |
---|
700 | pTex->setColourOpMultipassFallback(src,dest); |
---|
701 | } |
---|
702 | catch (Exception& e) |
---|
703 | { |
---|
704 | LogManager::getSingleton().logMessage("Bad "+ params[0] +" attribute line in " |
---|
705 | + pMat->getName() + ", " + e.getFullDescription()); |
---|
706 | } |
---|
707 | } |
---|
708 | //----------------------------------------------------------------------- |
---|
709 | void parseAlphaOpEx(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex) |
---|
710 | { |
---|
711 | if (numParams < 4 || numParams > 7) |
---|
712 | { |
---|
713 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
714 | + pMat->getName() + ", wrong number of parameters (expected 3 or 4)"); |
---|
715 | return; |
---|
716 | } |
---|
717 | LayerBlendOperationEx op; |
---|
718 | LayerBlendSource src1, src2; |
---|
719 | Real manual = 0.0; |
---|
720 | Real arg1 = 1.0, arg2 = 1.0; |
---|
721 | |
---|
722 | try { |
---|
723 | op = convertBlendOpEx(params[1]); |
---|
724 | src1 = convertBlendSource(params[2]); |
---|
725 | src2 = convertBlendSource(params[3]); |
---|
726 | if (op == LBX_BLEND_MANUAL) |
---|
727 | { |
---|
728 | if (numParams != 5) |
---|
729 | { |
---|
730 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
731 | + pMat->getName() + ", wrong number of parameters (expected 4 for manual blend)"); |
---|
732 | return; |
---|
733 | } |
---|
734 | manual = StringConverter::parseReal(*(params + 4)); |
---|
735 | } |
---|
736 | if (src1 == LBS_MANUAL) |
---|
737 | { |
---|
738 | int parIndex = 4; |
---|
739 | if (op == LBX_BLEND_MANUAL) |
---|
740 | parIndex++; |
---|
741 | |
---|
742 | if (numParams < parIndex) |
---|
743 | { |
---|
744 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
745 | + pMat->getName() + ", wrong number of parameters (expected " + StringConverter::toString(parIndex - 1) + ")"); |
---|
746 | return; |
---|
747 | } |
---|
748 | |
---|
749 | arg1 = StringConverter::parseReal(*(params + parIndex)); |
---|
750 | } |
---|
751 | |
---|
752 | if (src2 == LBS_MANUAL) |
---|
753 | { |
---|
754 | int parIndex = 4; |
---|
755 | if (op == LBX_BLEND_MANUAL) |
---|
756 | parIndex++; |
---|
757 | if (src1 == LBS_MANUAL) |
---|
758 | parIndex++; |
---|
759 | |
---|
760 | if (numParams < parIndex) |
---|
761 | { |
---|
762 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
763 | + pMat->getName() + ", wrong number of parameters (expected " + StringConverter::toString(parIndex - 1) + ")"); |
---|
764 | return; |
---|
765 | } |
---|
766 | |
---|
767 | arg2 = StringConverter::parseReal(*(params + parIndex)); |
---|
768 | } |
---|
769 | } |
---|
770 | catch (Exception& e) |
---|
771 | { |
---|
772 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
773 | + pMat->getName() + ", " + e.getFullDescription()); |
---|
774 | return; |
---|
775 | } |
---|
776 | |
---|
777 | pTex->setAlphaOperation(op, src1, src2, arg1, arg2, manual); |
---|
778 | } |
---|
779 | //----------------------------------------------------------------------- |
---|
780 | void parseEnvMap(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex) |
---|
781 | { |
---|
782 | if (numParams != 2) |
---|
783 | { |
---|
784 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
785 | + pMat->getName() + ", wrong number of parameters (expected 2)"); |
---|
786 | return; |
---|
787 | } |
---|
788 | if (params[1]=="off") |
---|
789 | pTex->setEnvironmentMap(false); |
---|
790 | else if (params[1]=="spherical") |
---|
791 | pTex->setEnvironmentMap(true, TextureUnitState::ENV_CURVED); |
---|
792 | else if (params[1]=="planar") |
---|
793 | pTex->setEnvironmentMap(true, TextureUnitState::ENV_PLANAR); |
---|
794 | else if (params[1]=="cubic_reflection") |
---|
795 | pTex->setEnvironmentMap(true, TextureUnitState::ENV_REFLECTION); |
---|
796 | else if (params[1]=="cubic_normal") |
---|
797 | pTex->setEnvironmentMap(true, TextureUnitState::ENV_NORMAL); |
---|
798 | else |
---|
799 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
800 | + pMat->getName() + ", valid parameters are 'off', 'spherical', 'planar', 'cubic_reflection' and 'cubic_normal'."); |
---|
801 | |
---|
802 | } |
---|
803 | //----------------------------------------------------------------------- |
---|
804 | void parseScroll(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex) |
---|
805 | { |
---|
806 | if (numParams != 3) |
---|
807 | { |
---|
808 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
809 | + pMat->getName() + ", wrong number of parameters (expected 3)"); |
---|
810 | return; |
---|
811 | } |
---|
812 | if (params[0]=="scroll") |
---|
813 | { |
---|
814 | pTex->setTextureScroll(StringConverter::parseReal(params[1].c_str()), StringConverter::parseReal(params[2].c_str())); |
---|
815 | } |
---|
816 | else // scroll_anim |
---|
817 | { |
---|
818 | pTex->setScrollAnimation(StringConverter::parseReal(params[1].c_str()), StringConverter::parseReal(params[2].c_str())); |
---|
819 | } |
---|
820 | } |
---|
821 | //----------------------------------------------------------------------- |
---|
822 | void parseRotate(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex) |
---|
823 | { |
---|
824 | if (numParams != 2) |
---|
825 | { |
---|
826 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
827 | + pMat->getName() + ", wrong number of parameters (expected 2)"); |
---|
828 | return; |
---|
829 | } |
---|
830 | if (params[0]=="rotate") |
---|
831 | { |
---|
832 | pTex->setTextureRotate(Degree(StringConverter::parseReal(params[1].c_str()))); |
---|
833 | } |
---|
834 | else // rotate_anim |
---|
835 | { |
---|
836 | pTex->setRotateAnimation(StringConverter::parseReal(params[1].c_str())); |
---|
837 | } |
---|
838 | } |
---|
839 | //----------------------------------------------------------------------- |
---|
840 | void parseScale(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex) |
---|
841 | { |
---|
842 | if (numParams != 3) |
---|
843 | { |
---|
844 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
845 | + pMat->getName() + ", wrong number of parameters (expected 3)"); |
---|
846 | return; |
---|
847 | } |
---|
848 | pTex->setTextureScale(StringConverter::parseReal(params[1].c_str()), StringConverter::parseReal(params[2].c_str()) ); |
---|
849 | } |
---|
850 | //----------------------------------------------------------------------- |
---|
851 | void parseWaveXform(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex) |
---|
852 | { |
---|
853 | if (numParams != 7) |
---|
854 | { |
---|
855 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
856 | + pMat->getName() + ", wrong number of parameters (expected 6)"); |
---|
857 | return; |
---|
858 | } |
---|
859 | TextureUnitState::TextureTransformType ttype; |
---|
860 | WaveformType waveType; |
---|
861 | // Check transform type |
---|
862 | if (params[1]=="scroll_x") |
---|
863 | ttype = TextureUnitState::TT_TRANSLATE_U; |
---|
864 | else if (params[1]=="scroll_y") |
---|
865 | ttype = TextureUnitState::TT_TRANSLATE_V; |
---|
866 | else if (params[1]=="rotate") |
---|
867 | ttype = TextureUnitState::TT_ROTATE; |
---|
868 | else if (params[1]=="scale_x") |
---|
869 | ttype = TextureUnitState::TT_SCALE_U; |
---|
870 | else if (params[1]=="scale_y") |
---|
871 | ttype = TextureUnitState::TT_SCALE_V; |
---|
872 | else |
---|
873 | { |
---|
874 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
875 | + pMat->getName() + ", parameter 1 must be 'scroll_x', 'scroll_y', 'rotate', 'scale_x' or 'scale_y'"); |
---|
876 | return; |
---|
877 | } |
---|
878 | // Check wave type |
---|
879 | if (params[2]=="sine") |
---|
880 | waveType = WFT_SINE; |
---|
881 | else if (params[2]=="triangle") |
---|
882 | waveType = WFT_TRIANGLE; |
---|
883 | else if (params[2]=="square") |
---|
884 | waveType = WFT_SQUARE; |
---|
885 | else if (params[2]=="sawtooth") |
---|
886 | waveType = WFT_SAWTOOTH; |
---|
887 | else if (params[2]=="inverse_sawtooth") |
---|
888 | waveType = WFT_INVERSE_SAWTOOTH; |
---|
889 | else |
---|
890 | { |
---|
891 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
892 | + pMat->getName() + ", parameter 2 must be 'sine', 'triangle', 'square', 'sawtooth' or 'inverse_sawtooth'"); |
---|
893 | return; |
---|
894 | } |
---|
895 | |
---|
896 | pTex->setTransformAnimation(ttype, waveType, StringConverter::parseReal(params[3].c_str()), StringConverter::parseReal(params[4].c_str()), |
---|
897 | StringConverter::parseReal(params[5].c_str()), StringConverter::parseReal(params[6].c_str()) ); |
---|
898 | |
---|
899 | } |
---|
900 | //----------------------------------------------------------------------- |
---|
901 | void parseDepthBias(StringVector::iterator& params, int numParams, MaterialPtr& pMat) |
---|
902 | { |
---|
903 | if (numParams != 2) |
---|
904 | { |
---|
905 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
906 | + pMat->getName() + ", wrong number of parameters (expected 2)"); |
---|
907 | return; |
---|
908 | } |
---|
909 | pMat->setDepthBias(atoi(params[1].c_str()), 0); |
---|
910 | } |
---|
911 | //----------------------------------------------------------------------- |
---|
912 | void parseAnisotropy(StringVector::iterator& params, int numParams, MaterialPtr& pMat) |
---|
913 | { |
---|
914 | if (numParams != 2) |
---|
915 | { |
---|
916 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
917 | + pMat->getName() + ", wrong number of parameters (expected 2)"); |
---|
918 | return; |
---|
919 | } |
---|
920 | pMat->setTextureAnisotropy(atoi(params[1].c_str())); |
---|
921 | } |
---|
922 | //----------------------------------------------------------------------- |
---|
923 | void parseLayerAnisotropy(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex) |
---|
924 | { |
---|
925 | if (numParams != 2) |
---|
926 | { |
---|
927 | LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in " |
---|
928 | + pMat->getName() + ", wrong number of parameters (expected 2)"); |
---|
929 | return; |
---|
930 | } |
---|
931 | pTex->setTextureAnisotropy(atoi(params[1].c_str())); |
---|
932 | } |
---|
933 | //----------------------------------------------------------------------- |
---|
934 | OldMaterialReader::OldMaterialReader() |
---|
935 | { |
---|
936 | |
---|
937 | // Set up material attribute parsers |
---|
938 | mMatAttribParsers.insert(MatAttribParserList::value_type("ambient", (MATERIAL_ATTRIB_PARSER)parseAmbient)); |
---|
939 | mMatAttribParsers.insert(MatAttribParserList::value_type("diffuse", (MATERIAL_ATTRIB_PARSER)parseDiffuse)); |
---|
940 | mMatAttribParsers.insert(MatAttribParserList::value_type("specular", (MATERIAL_ATTRIB_PARSER)parseSpecular)); |
---|
941 | mMatAttribParsers.insert(MatAttribParserList::value_type("emissive", (MATERIAL_ATTRIB_PARSER)parseEmissive)); |
---|
942 | mMatAttribParsers.insert(MatAttribParserList::value_type("scene_blend", (MATERIAL_ATTRIB_PARSER)parseSceneBlend)); |
---|
943 | mMatAttribParsers.insert(MatAttribParserList::value_type("depth_check", (MATERIAL_ATTRIB_PARSER)parseDepthParams)); |
---|
944 | mMatAttribParsers.insert(MatAttribParserList::value_type("depth_write", (MATERIAL_ATTRIB_PARSER)parseDepthParams)); |
---|
945 | mMatAttribParsers.insert(MatAttribParserList::value_type("depth_func", (MATERIAL_ATTRIB_PARSER)parseDepthParams)); |
---|
946 | mMatAttribParsers.insert(MatAttribParserList::value_type("cull_hardware", (MATERIAL_ATTRIB_PARSER)parseCullMode)); |
---|
947 | mMatAttribParsers.insert(MatAttribParserList::value_type("cull_software", (MATERIAL_ATTRIB_PARSER)parseCullMode)); |
---|
948 | mMatAttribParsers.insert(MatAttribParserList::value_type("lighting", (MATERIAL_ATTRIB_PARSER)parseLighting)); |
---|
949 | mMatAttribParsers.insert(MatAttribParserList::value_type("fog_override", (MATERIAL_ATTRIB_PARSER)parseFogging)); |
---|
950 | mMatAttribParsers.insert(MatAttribParserList::value_type("shading", (MATERIAL_ATTRIB_PARSER)parseShading)); |
---|
951 | mMatAttribParsers.insert(MatAttribParserList::value_type("filtering", (MATERIAL_ATTRIB_PARSER)parseFiltering)); |
---|
952 | mMatAttribParsers.insert(MatAttribParserList::value_type("depth_bias", (MATERIAL_ATTRIB_PARSER)parseDepthBias)); |
---|
953 | mMatAttribParsers.insert(MatAttribParserList::value_type("anisotropy", (MATERIAL_ATTRIB_PARSER)parseAnisotropy)); |
---|
954 | |
---|
955 | // Set up layer attribute parsers |
---|
956 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("texture", (TEXLAYER_ATTRIB_PARSER)parseTexture)); |
---|
957 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("anim_texture", (TEXLAYER_ATTRIB_PARSER)parseAnimTexture)); |
---|
958 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("cubic_texture", (TEXLAYER_ATTRIB_PARSER)parseCubicTexture)); |
---|
959 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("tex_coord_set", (TEXLAYER_ATTRIB_PARSER)parseTexCoord)); |
---|
960 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("tex_address_mode", (TEXLAYER_ATTRIB_PARSER)parseTexAddressMode)); |
---|
961 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("colour_op", (TEXLAYER_ATTRIB_PARSER)parseColourOp)); |
---|
962 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("alpha_rejection", (TEXLAYER_ATTRIB_PARSER)parseAlphaRejection)); |
---|
963 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("colour_op_ex", (TEXLAYER_ATTRIB_PARSER)parseColourOpEx)); |
---|
964 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("colour_op_multipass_fallback", (TEXLAYER_ATTRIB_PARSER)parseColourOpFallback)); |
---|
965 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("alpha_op_ex", (TEXLAYER_ATTRIB_PARSER)parseAlphaOpEx)); |
---|
966 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("env_map", (TEXLAYER_ATTRIB_PARSER)parseEnvMap)); |
---|
967 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("scroll", (TEXLAYER_ATTRIB_PARSER)parseScroll)); |
---|
968 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("scroll_anim", (TEXLAYER_ATTRIB_PARSER)parseScroll)); |
---|
969 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("rotate", (TEXLAYER_ATTRIB_PARSER)parseRotate)); |
---|
970 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("rotate_anim", (TEXLAYER_ATTRIB_PARSER)parseRotate)); |
---|
971 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("scale", (TEXLAYER_ATTRIB_PARSER)parseScale)); |
---|
972 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("wave_xform", (TEXLAYER_ATTRIB_PARSER)parseWaveXform)); |
---|
973 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("tex_filtering", (TEXLAYER_ATTRIB_PARSER)parseLayerFiltering)); |
---|
974 | mLayerAttribParsers.insert(LayerAttribParserList::value_type("tex_anisotropy", (TEXLAYER_ATTRIB_PARSER)parseLayerAnisotropy)); |
---|
975 | } |
---|
976 | //----------------------------------------------------------------------- |
---|
977 | OldMaterialReader::~OldMaterialReader() |
---|
978 | { |
---|
979 | } |
---|
980 | //----------------------------------------------------------------------- |
---|
981 | void OldMaterialReader::parseScript(DataStreamPtr& stream) |
---|
982 | { |
---|
983 | String line; |
---|
984 | MaterialPtr pMat; |
---|
985 | char tempBuf[512]; |
---|
986 | |
---|
987 | while(!stream->eof()) |
---|
988 | { |
---|
989 | line = stream->getLine(); |
---|
990 | // Ignore comments & blanks |
---|
991 | if (!(line.length() == 0 || line.substr(0,2) == "//")) |
---|
992 | { |
---|
993 | if (pMat.isNull()) |
---|
994 | { |
---|
995 | // No current material |
---|
996 | // So first valid data should be a material name |
---|
997 | pMat = MaterialManager::getSingleton().create(line, |
---|
998 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
999 | // Skip to and over next { |
---|
1000 | stream->readLine(tempBuf, 511, "{"); |
---|
1001 | } |
---|
1002 | else |
---|
1003 | { |
---|
1004 | // Already in a material |
---|
1005 | if (line == "}") |
---|
1006 | { |
---|
1007 | // Finished material |
---|
1008 | pMat.setNull(); |
---|
1009 | } |
---|
1010 | else if (line == "{") |
---|
1011 | { |
---|
1012 | // new pass |
---|
1013 | parseNewTextureLayer(stream, pMat); |
---|
1014 | |
---|
1015 | } |
---|
1016 | else |
---|
1017 | { |
---|
1018 | // Attribute |
---|
1019 | StringUtil::toLowerCase(line); |
---|
1020 | parseAttrib(line, pMat); |
---|
1021 | } |
---|
1022 | |
---|
1023 | } |
---|
1024 | |
---|
1025 | } |
---|
1026 | |
---|
1027 | |
---|
1028 | } |
---|
1029 | |
---|
1030 | } |
---|
1031 | //----------------------------------------------------------------------- |
---|
1032 | void OldMaterialReader::parseNewTextureLayer(DataStreamPtr& stream, MaterialPtr& pMat) |
---|
1033 | { |
---|
1034 | String line; |
---|
1035 | TextureUnitState* pLayer; |
---|
1036 | |
---|
1037 | pLayer = pMat->getTechnique(0)->getPass(0)->createTextureUnitState(""); |
---|
1038 | |
---|
1039 | |
---|
1040 | while (!stream->eof()) |
---|
1041 | { |
---|
1042 | line = stream->getLine(); |
---|
1043 | // Ignore comments & blanks |
---|
1044 | if (line.length() != 0 && !(line.substr(0,2) == "//")) |
---|
1045 | { |
---|
1046 | if (line == "}") |
---|
1047 | { |
---|
1048 | // end of layer |
---|
1049 | return; |
---|
1050 | } |
---|
1051 | else |
---|
1052 | { |
---|
1053 | parseLayerAttrib(line, pMat, pLayer); |
---|
1054 | } |
---|
1055 | } |
---|
1056 | |
---|
1057 | |
---|
1058 | } |
---|
1059 | } |
---|
1060 | //----------------------------------------------------------------------- |
---|
1061 | void OldMaterialReader::parseAttrib( const String& line, MaterialPtr& pMat) |
---|
1062 | { |
---|
1063 | StringVector vecparams; |
---|
1064 | |
---|
1065 | // Split params on space |
---|
1066 | vecparams = StringUtil::split(line, " \t"); |
---|
1067 | StringVector::iterator params = vecparams.begin(); |
---|
1068 | |
---|
1069 | // Look up first param (command setting) |
---|
1070 | MatAttribParserList::iterator iparsers = mMatAttribParsers.find(params[0]); |
---|
1071 | if (iparsers == mMatAttribParsers.end()) |
---|
1072 | { |
---|
1073 | // BAD command. BAD! |
---|
1074 | LogManager::getSingleton().logMessage( |
---|
1075 | "Bad material attribute line: '" |
---|
1076 | + line + "' in " + pMat->getName() + |
---|
1077 | ", unknown command '" + params[0] + "'"); |
---|
1078 | } |
---|
1079 | else |
---|
1080 | { |
---|
1081 | // Use parser |
---|
1082 | iparsers->second( |
---|
1083 | params, static_cast< int >( vecparams.size() ), pMat ); |
---|
1084 | } |
---|
1085 | |
---|
1086 | |
---|
1087 | } |
---|
1088 | //----------------------------------------------------------------------- |
---|
1089 | void OldMaterialReader::parseLayerAttrib( const String& line, MaterialPtr& pMat, TextureUnitState* pLayer) |
---|
1090 | { |
---|
1091 | StringVector vecparams; |
---|
1092 | |
---|
1093 | // Split params on space |
---|
1094 | vecparams = StringUtil::split(line, " \t"); |
---|
1095 | StringVector::iterator params = vecparams.begin(); |
---|
1096 | |
---|
1097 | // Look up first param (command setting) |
---|
1098 | StringUtil::toLowerCase(params[0]); |
---|
1099 | LayerAttribParserList::iterator iparsers = mLayerAttribParsers.find(params[0]); |
---|
1100 | if (iparsers == mLayerAttribParsers.end()) |
---|
1101 | { |
---|
1102 | // BAD command. BAD! |
---|
1103 | LogManager::getSingleton().logMessage("Bad texture layer attribute line: '" |
---|
1104 | + line + "' in " + pMat->getName() + ", unknown command '" + params[0] + "'"); |
---|
1105 | } |
---|
1106 | else |
---|
1107 | { |
---|
1108 | // Use parser |
---|
1109 | if (params[0] != "texture" && params[0] != "cubic_texture" && params[0] != "anim_texture") |
---|
1110 | { |
---|
1111 | // Lower case all params if not texture |
---|
1112 | for( size_t p = 1; p < vecparams.size(); ++p ) |
---|
1113 | StringUtil::toLowerCase(params[p]); |
---|
1114 | |
---|
1115 | } |
---|
1116 | iparsers->second(params, (unsigned int)vecparams.size(), pMat, pLayer); |
---|
1117 | } |
---|
1118 | |
---|
1119 | |
---|
1120 | |
---|
1121 | } |
---|