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