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/>.
17 #include "nel/misc/stream.h"
18 #include "nel/misc/file.h"
19 #include "nel/misc/vector.h"
20 #include "nel/misc/time_nl.h"
21 #include "nel/3d/zone.h"
22 #include "nel/3d/landscape.h"
23 #include "nel/misc/triangle.h"
24 #include "../zone_lib/zone_utility.h" // load a header file from zone_welder project
30 using namespace NLMISC
;
33 void buildFaces(CLandscape
& landscape
, sint zoneId
, sint patch
, std::vector
<CTriangle
> &faces
)
37 CZone
* pZone
=landscape
.getZone (zoneId
);
39 // Then trace all patch.
40 sint N
= pZone
->getNumPatchs();
43 const CPatch
*pa
= const_cast<const CZone
*>(pZone
)->getPatch(patch
);
47 sint ordS
= 4*pa
->getOrderS();
48 sint ordT
= 4*pa
->getOrderT();
57 f
.V0
= pa
->computeVertex(x
*OOS
, y
*OOT
);
58 f
.V1
= pa
->computeVertex(x
*OOS
, (y
+1)*OOT
);
59 f
.V2
= pa
->computeVertex((x
+1)*OOS
, (y
+1)*OOT
);
61 f
.V0
= pa
->computeVertex(x
*OOS
, y
*OOT
);
62 f
.V1
= pa
->computeVertex((x
+1)*OOS
, (y
+1)*OOT
);
63 f
.V2
= pa
->computeVertex((x
+1)*OOS
, y
*OOT
);
69 int main(int argc
, char* argv
[])
73 // Good number of args ?
77 printf ("zone_dump [first_zone.zone] [last_zone.zone] [output.dump]\n");
78 printf ("Dump file format:\n");
79 printf ("\t4 bytes: number of triangles\n");
80 printf ("\tfor each triangles:\n");
81 printf ("\t\t3 floats, X, Y, Z for Vertex 0\n");
82 printf ("\t\t3 floats, X, Y, Z for Vertex 1\n");
83 printf ("\t\t3 floats, X, Y, Z for Vertex 2\n");
84 printf ("\t\tVertices are CCW, in a right hand basis with Z axis to the top\n");
88 // Get zones coordinates
91 if (!getZoneCoordByName(getName (argv
[1]).c_str(), xMin
, yMin
))
92 fprintf (stderr
, "Invalid zone name: %s\n", argv
[1]);
95 // Get zones coordinates
98 if (!getZoneCoordByName(getName (argv
[2]).c_str(), xMax
, yMax
))
99 fprintf (stderr
, "Invalid zone name: %s\n", argv
[2]);
102 // Reorder coordinates
117 // Open the output file
119 if (output
.open (argv
[3]))
123 output
.serial (zero
);
128 // Get zones path name
129 string path
=getDir (argv
[1]);
130 string ext
=getExt (argv
[1]);
133 for (int y
=yMin
; y
<=yMax
; y
++)
134 for (int x
=xMin
; x
<=xMax
; x
++)
139 // Generate the zone name
140 getZoneNameByCoord(x
, y
, name
);
144 if (input
.open(path
+name
+ext
))
147 printf ("Dump %s\n", name
.c_str());
150 CLandscape landscape
;
159 landscape
.addZone (zone
);
161 // Add triangle of this zone in the quadtree
162 for (uint patch
=0; patch
<(uint
)zone
.getNumPatchs(); patch
++)
164 // vector of triangle
165 std::vector
<CTriangle
> faces
;
167 // Build a list of triangles at 50 cm
168 buildFaces (landscape
, zone
.getZoneId(), patch
, faces
);
171 for (uint tri
=0; tri
<faces
.size(); tri
++)
173 // Serial the triangle
174 faces
[tri
].V0
.serial (output
);
175 faces
[tri
].V1
.serial (output
);
176 faces
[tri
].V2
.serial (output
);
180 triangles
+=(uint32
)faces
.size();
185 printf ("Dump %s (missing)\n", name
.c_str());
188 // Get the current pos
189 sint32 curPos
=output
.getPos ();
191 // File at the beginning
192 output
.seek (0, NLMISC::IStream::begin
);
194 // Write the triangle count
195 output
.serial (triangles
);
197 // Go to the end of the file
198 output
.seek (curPos
, NLMISC::IStream::begin
);
205 fprintf (stderr
, "Can't open %s for writing.", argv
[3]);
214 catch (const Exception
& e
)
216 fprintf (stderr
, "FATAL: %s", e
.what());