202 {
203 char objFileName[255];
204 sprintf(objFileName, "meshes/map%03u%02u%02u.obj", mapID, tileY, tileX);
205
206 FILE* objFile = fopen(objFileName, "wb");
207 if (!objFile)
208 {
209 char message[1024];
210 sprintf(message, "Failed to open %s for writing!\n", objFileName);
211 perror(message);
212 return;
213 }
214
215 G3D::Array<float> allVerts;
216 G3D::Array<int> allTris;
217
218 allTris.append(meshData.liquidTris);
219 allVerts.append(meshData.liquidVerts);
221 allVerts.append(meshData.solidVerts);
222
223 float* verts = allVerts.getCArray();
224 int vertCount = allVerts.size() / 3;
225 int* tris = allTris.getCArray();
226 int triCount = allTris.size() / 3;
227
228 for (int i = 0; i < allVerts.size() / 3; i++)
229 fprintf(objFile, "v %f %f %f\n", verts[i * 3], verts[i * 3 + 1], verts[i * 3 + 2]);
230
231 for (int i = 0; i < allTris.size() / 3; i++)
232 fprintf(objFile, "f %i %i %i\n", tris[i * 3] + 1, tris[i * 3 + 1] + 1, tris[i * 3 + 2] + 1);
233
234 fclose(objFile);
235
236 char tileString[25];
237 sprintf(tileString, "[%02u,%02u]: ", tileY, tileX);
238 printf("%sWriting debug output... \r", tileString);
239
240 sprintf(objFileName, "meshes/%03u.map", mapID);
241
242 objFile = fopen(objFileName, "wb");
243 if (!objFile)
244 {
245 char message[1024];
246 sprintf(message, "Failed to open %s for writing!\n", objFileName);
247 perror(message);
248 return;
249 }
250
251 char b = '\0';
252 fwrite(&b, sizeof(char), 1, objFile);
253 fclose(objFile);
254
255 sprintf(objFileName, "meshes/%03u%02u%02u.mesh", mapID, tileY, tileX);
256 objFile = fopen(objFileName, "wb");
257 if (!objFile)
258 {
259 char message[1024];
260 sprintf(message, "Failed to open %s for writing!\n", objFileName);
261 perror(message);
262 return;
263 }
264
265 fwrite(&vertCount, sizeof(int), 1, objFile);
266 fwrite(verts, sizeof(float), vertCount * 3, objFile);
267 fflush(objFile);
268
269 fwrite(&triCount, sizeof(int), 1, objFile);
270 fwrite(tris, sizeof(int), triCount * 3, objFile);
271 fflush(objFile);
272
273 fclose(objFile);
274 }
static void copyIndices(std::vector< VMAP::MeshTriangle > &source, G3D::Array< int > &dest, int offest, bool flip)
Definition: TerrainBuilder.cpp:850