1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
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/>.
20 #include "nel/misc/file.h"
22 #include "nel/3d/scene_group.h"
24 using namespace NLMISC
;
28 // ***************************************************************************
29 CInstanceGroup
* LoadInstanceGroup (const char* sFilename
)
32 CInstanceGroup
*newIG
= new CInstanceGroup
;
34 if( file
.open( sFilename
) )
40 catch (const Exception
&)
54 // ***************************************************************************
55 bool SaveInstanceGroup (const char* sFilename
, CInstanceGroup
*pIG
)
59 if( file
.open( sFilename
) )
65 catch (const Exception
&)
77 // ***************************************************************************
78 int main(int nNbArg
, char**ppArgs
)
83 // Display help information
84 cout
<< "USAGE : ig_add out in1 in2" << endl
;
85 cout
<< "Make out = in1 + in2 (out, in1 and in2 are *.IG files" << endl
;
91 CInstanceGroup
*pIG1
= LoadInstanceGroup (ppArgs
[2]);
94 cerr
<< "File " << ppArgs
[2] << " not found" << endl
;
97 CInstanceGroup
*pIG2
= LoadInstanceGroup (ppArgs
[3]);
100 cerr
<< "File " << ppArgs
[3] << " not found" << endl
;
107 CInstanceGroup
*pIGout
= new CInstanceGroup
;
109 CVector vGP1
, vGP2
, vGPout
;
110 CInstanceGroup::TInstanceArray IA1
, IA2
, IAout
;
111 vector
<CCluster
> Clusters1
, Clusters2
, Clustersout
;
112 vector
<CPortal
> Portals1
, Portals2
, Portalsout
;
113 vector
<CPointLightNamed
> PLN1
, PLN2
, PLNout
;
115 pIG1
->retrieve (vGP1
, IA1
, Clusters1
, Portals1
, PLN1
);
116 pIG2
->retrieve (vGP2
, IA2
, Clusters2
, Portals2
, PLN2
);
120 // -----------------------------------------------------------------------
121 vGPout
= (vGP1
+vGP2
) / 2.0f
;
123 // -----------------------------------------------------------------------
124 for (i
= 0; i
< IA1
.size(); ++i
)
126 CInstanceGroup::CInstance iTmp
= IA1
[i
];
127 iTmp
.Pos
+= (vGP1
- vGPout
);
128 IAout
.push_back(iTmp
);
130 for (i
= 0; i
< IA2
.size(); ++i
)
132 CInstanceGroup::CInstance iTmp
= IA2
[i
];
133 iTmp
.Pos
+= (vGP2
- vGPout
);
134 IAout
.push_back(iTmp
);
137 // -----------------------------------------------------------------------
138 Clustersout
= Clusters1
;
139 for (i
= 0; i
< Clusters2
.size(); ++i
)
140 Clustersout
.push_back(Clusters2
[i
]);
142 // -----------------------------------------------------------------------
143 Portalsout
= Portals1
;
144 for (i
= 0; i
< Portals2
.size(); ++i
)
145 Portalsout
.push_back(Portals2
[i
]);
147 // -----------------------------------------------------------------------
149 for (i
= 0; i
< PLN2
.size(); ++i
)
150 PLNout
.push_back(PLN2
[i
]);
153 pIGout
->build (vGPout
, IAout
, Clustersout
, Portalsout
, PLNout
);
157 if (!SaveInstanceGroup (ppArgs
[1], pIGout
))
159 cerr
<< "Cannot save to file " << ppArgs
[1] << endl
;
177 // NOTES : For the moment the behaviour of the build with cluster system is
178 // strange because the instance of the instance group are not relinked to
179 // all the clusters... But this is not a big deal because we just want to
180 // add group of instances without any cluster system