1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "light_ig_loader.h"
27 #include <nel/misc/vector_2f.h>
28 #include <nel/misc/object_vector.h>
29 #include <nel/misc/rgba.h>
30 #include <nel/misc/plane.h>
31 #include <nel/misc/aabbox.h>
35 using namespace NLMISC
;
41 #define SERIAL_DUMMY(type) { type dummy; _File.serial(dummy); }
45 enum { NumLightPerCorner
= 2 };
47 uint8 SunContribution
;
48 uint8 Light
[NumLightPerCorner
];
51 void serial(NLMISC::IStream
&f
)
53 uint ver
= f
.serialVersion(1);
54 nlassert(NumLightPerCorner
==2);
57 f
.serial(LocalAmbientId
);
58 f
.serial(SunContribution
);
64 class CSurfaceLightGrid
67 NLMISC::CVector2f Origin
;
70 NLMISC::CObjectVector
<CCellCorner
> Cells
;
74 void serial(NLMISC::IStream
&f
)
76 (void)f
.serialVersion(0);
84 class CRetrieverLightGrid
87 //NLMISC::CObjectVector<CSurfaceLightGrid> Grids;
91 void serial(NLMISC::IStream
&_File
)
93 (void)_File
.serialVersion(0);
94 SERIAL_DUMMY(NLMISC::CObjectVector
<CSurfaceLightGrid
>);
105 CLightIGLoader::CLightIGLoader()
111 void CLightIGLoader::loadIG(const string
&filename
)
113 _File
.open(CPath::lookup(filename
));
117 _File
.serialCheck (NELID("TPRG"));
119 // Serial a version number
120 sint version
= _File
.serialVersion (5);
123 // _RealTimeSunContribution
126 SERIAL_DUMMY(bool); // _RealTimeSunContribution
130 // Serial the IGSurfaceLight
133 sint ver
= _File
.serialVersion(1);
135 SERIAL_DUMMY(float); // _CellSize
136 SERIAL_DUMMY(float); // _OOCellSize
140 std::map
<std::string
, CRetrieverLightGrid
> _RetrieverGridMap
;
141 _File
.serialCont(_RetrieverGridMap
);
145 std::map
<uint32
, CRetrieverLightGrid
> _RetrieverGridMap
;
146 _File
.serialCont(_RetrieverGridMap
);
151 // Serial the PointLights info
154 sint ver
= _File
.serialVersion(1);
161 sint ver
= _File
.serialVersion(1);
164 sint verp
= _File
.serialVersion(2);
173 SERIAL_DUMMY(sint32
); // enum _Type
174 SERIAL_DUMMY(CVector
); // _SpotDirection
175 SERIAL_DUMMY(float); // _SpotAngleBegin
176 SERIAL_DUMMY(float); // _SpotAngleEnd
179 SERIAL_DUMMY(CVector
); // _Position
180 SERIAL_DUMMY(CRGBA
); // _Ambient
181 SERIAL_DUMMY(CRGBA
); // _Diffuse
182 SERIAL_DUMMY(CRGBA
); // _Specular
183 SERIAL_DUMMY(float); // _AttenuationBegin
184 SERIAL_DUMMY(float); // _AttenuationEnd
187 SERIAL_DUMMY(string
); // AnimatedLight
188 SERIAL_DUMMY(CRGBA
); // _DefaultAmbient
189 SERIAL_DUMMY(CRGBA
); // _DefaultDiffuse
190 SERIAL_DUMMY(CRGBA
); // _DefaultSpecular
193 SERIAL_DUMMY(uint32
); // LightGroup
202 SERIAL_DUMMY(uint32
); // StartId
203 SERIAL_DUMMY(uint32
); // EndId
208 // _PointLightGroupMap
213 _File
.serialVersion (0);
214 SERIAL_DUMMY(string
); // AnimationLight
215 SERIAL_DUMMY(uint32
); // LightGroup
216 SERIAL_DUMMY(uint32
); // StartId
217 SERIAL_DUMMY(uint32
); // EndId
224 SERIAL_DUMMY(CVector
); // _GlobalPos
237 // f.serialCont (_ClusterInfos);
238 _File
.serial(numClusters
);
239 for (num
=numClusters
; num
>0; --num
)
241 sint version
= _File
.serialVersion (3);
244 SERIAL_DUMMY(string
); // Name
248 // f.serialCont (_LocalVolume);
251 SERIAL_DUMMY(CPlane
); // _LocalVolume
253 SERIAL_DUMMY(CAABBox
); // _LocalBBox
254 SERIAL_DUMMY(bool) ; // FatherVisible
255 SERIAL_DUMMY(bool); // VisibleFromFather
259 SERIAL_DUMMY(string
); // soundGroup
260 SERIAL_DUMMY(string
); // envFxName
265 SERIAL_DUMMY(bool); // AudibleFromFather
266 SERIAL_DUMMY(bool); // FatherAudible
270 // f.serialCont (_Portals);
274 int version
= _File
.serialVersion (1);
278 //f.serialCont (_LocalPoly);
281 SERIAL_DUMMY(CVector
);
283 SERIAL_DUMMY(string
); // _Name
287 SERIAL_DUMMY(string
); // occName;
288 SERIAL_DUMMY(string
); // occName;
294 for (i
= 0; i
< numClusters
; ++i
)
297 _File
.serial (nNbPortals
);
299 for (j
= 0; j
< nNbPortals
; ++j
)
300 SERIAL_DUMMY(sint32
); // nPortalNb
305 // f.serialCont (_InstancesInfos);
314 - DontCastShadowForExterior
316 - DontCastShadowForInterior
326 // Serial a version number
327 sint version
= _File
.serialVersion (7);
333 // DontCastShadowForExterior
337 // DontCastShadowForInterior
342 // Serial the LocalAmbientId.
344 SERIAL_DUMMY(uint8
); // LocalAmbientId)
346 // Serial the StaticLight
350 SERIAL_DUMMY(bool); // AvoidStaticLightPreCompute
351 SERIAL_DUMMY(bool); // DontCastShadow
352 SERIAL_DUMMY(bool); // StaticLightEnabled
353 SERIAL_DUMMY(uint8
); // SunContribution
355 SERIAL_DUMMY(uint8
); // Light[0]
356 SERIAL_DUMMY(uint8
); // Light[1]
359 // Serial the gamedev data
360 _InstanceNames
.resize(_InstanceNames
.size()+1);
363 _File
.serial(_InstanceNames
.back());
364 SERIAL_DUMMY(bool); // DontAddToScene
367 // Serial the clusters
370 // f.serialCont (Clusters);
374 SERIAL_DUMMY(uint32
);
378 _ShapeNames
.resize(_ShapeNames
.size()+1);
379 _File
.serial(_ShapeNames
.back());
380 //serialDummy<string>(); // Name
382 // Serial the position vector
383 _ShapePos
.resize(_ShapePos
.size()+1);
384 _File
.serial(_ShapePos
.back());
385 //serialDummy<CVector>(); // Pos
387 // Serial the rotation vector
388 _ShapeRots
.resize(_ShapeRots
.size()+1);
389 _File
.serial(_ShapeRots
.back());
390 //serialDummy<CQuat>(); // Rot
392 // Serial the scale vector
393 _ShapeScales
.resize(_ShapeScales
.size()+1);
394 _File
.serial(_ShapeScales
.back());
395 //serialDummy<CVector>(); // Scale
397 // Serial the parent location in the vector (-1 if no parent)
398 SERIAL_DUMMY(sint32
); // nParent