36 TC_LOG_INFO(
"maps.mmapgen.debug",
"[Map {:04}] [{:02},{:02}]: Writing debug output intermediate values...", mapID, tileX, tileY);
38 auto debugWrite = [=, outputDirectory = outputDirectory.generic_string()](
char const* extension,
auto const* data)
40 std::string fileName =
Trinity::StringFormat(
"{}/meshes/{:04}_{:02}_{:02}{}.{}", outputDirectory, mapID, tileX, tileY, fileNameSuffix, extension);
41 if (
auto file = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(fileName.c_str(),
"wb")))
46 TC_LOG_ERROR(
"maps.mmapgen.debug",
"{}: [{:04}-{:02},{:02}] Failed to open {} for writing!", strerror(errno), mapID, tileX, tileY, fileName);
66 fwrite(&(mesh->cs),
sizeof(
float), 1, file);
67 fwrite(&(mesh->ch),
sizeof(
float), 1, file);
68 fwrite(&(mesh->width),
sizeof(
int), 1, file);
69 fwrite(&(mesh->height),
sizeof(
int), 1, file);
70 fwrite(mesh->bmin,
sizeof(
float), 3, file);
71 fwrite(mesh->bmax,
sizeof(
float), 3, file);
73 for (
int y = 0; y < mesh->height; ++y)
74 for (
int x = 0; x < mesh->width; ++x)
76 rcSpan* span = mesh->spans[x+y*mesh->width];
87 fwrite(&spanCount,
sizeof(
int), 1, file);
90 span = mesh->spans[x+y*mesh->width];
93 fwrite(span,
sizeof(rcSpan), 1, file);
104 fwrite(&(chf->width),
sizeof(chf->width), 1, file);
105 fwrite(&(chf->height),
sizeof(chf->height), 1, file);
106 fwrite(&(chf->spanCount),
sizeof(chf->spanCount), 1, file);
108 fwrite(&(chf->walkableHeight),
sizeof(chf->walkableHeight), 1, file);
109 fwrite(&(chf->walkableClimb),
sizeof(chf->walkableClimb), 1, file);
111 fwrite(&(chf->maxDistance),
sizeof(chf->maxDistance), 1, file);
112 fwrite(&(chf->maxRegions),
sizeof(chf->maxRegions), 1, file);
114 fwrite(chf->bmin,
sizeof(chf->bmin), 1, file);
115 fwrite(chf->bmax,
sizeof(chf->bmax), 1, file);
117 fwrite(&(chf->cs),
sizeof(chf->cs), 1, file);
118 fwrite(&(chf->ch),
sizeof(chf->ch), 1, file);
121 if (chf->cells) tmp |= 1;
122 if (chf->spans) tmp |= 2;
123 if (chf->dist) tmp |= 4;
124 if (chf->areas) tmp |= 8;
126 fwrite(&tmp,
sizeof(tmp), 1, file);
129 fwrite(chf->cells,
sizeof(rcCompactCell), chf->width*chf->height, file);
131 fwrite(chf->spans,
sizeof(rcCompactSpan), chf->spanCount, file);
133 fwrite(chf->dist,
sizeof(
unsigned short), chf->spanCount, file);
135 fwrite(chf->areas,
sizeof(
unsigned char), chf->spanCount, file);
143 fwrite(&(cs->cs),
sizeof(
float), 1, file);
144 fwrite(&(cs->ch),
sizeof(
float), 1, file);
145 fwrite(cs->bmin,
sizeof(
float), 3, file);
146 fwrite(cs->bmax,
sizeof(
float), 3, file);
147 fwrite(&(cs->nconts),
sizeof(
int), 1, file);
148 for (
int i = 0; i < cs->nconts; ++i)
150 fwrite(&cs->conts[i].area,
sizeof(
unsigned char), 1, file);
151 fwrite(&cs->conts[i].reg,
sizeof(
unsigned short), 1, file);
152 fwrite(&cs->conts[i].nverts,
sizeof(
int), 1, file);
153 fwrite(cs->conts[i].verts,
sizeof(
int), cs->conts[i].nverts*4, file);
154 fwrite(&cs->conts[i].nrverts,
sizeof(
int), 1, file);
155 fwrite(cs->conts[i].rverts,
sizeof(
int), cs->conts[i].nrverts*4, file);
183 fwrite(&(mesh->nverts),
sizeof(
int), 1, file);
184 fwrite(mesh->verts,
sizeof(
float), mesh->nverts*3, file);
185 fwrite(&(mesh->ntris),
sizeof(
int), 1, file);
186 fwrite(mesh->tris,
sizeof(
char), mesh->ntris*4, file);
187 fwrite(&(mesh->nmeshes),
sizeof(
int), 1, file);
188 fwrite(mesh->meshes,
sizeof(
int), mesh->nmeshes*4, file);
193 std::string objFileName;
194 objFileName =
Trinity::StringFormat(
"{}/meshes/map{:04}_{:02}_{:02}{}.obj", outputDirectory.generic_string(), mapID, tileX, tileY, fileNameSuffix);
196 auto objFile = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(objFileName.c_str(),
"wb"));
199 TC_LOG_ERROR(
"maps.mmapgen.debug",
"{}: Failed to open {} for writing!", strerror(errno), objFileName);
203 std::vector<float> allVerts;
204 std::vector<int> allTris;
211 float* verts = allVerts.data();
212 int vertCount = allVerts.size() / 3;
213 int* tris = allTris.data();
214 int triCount = allTris.size() / 3;
216 for (std::size_t i = 0; i < allVerts.size() / 3; i++)
217 fprintf(objFile.get(),
"v %f %f %f\n", verts[i * 3], verts[i * 3 + 1], verts[i * 3 + 2]);
219 for (std::size_t i = 0; i < allTris.size() / 3; i++)
220 fprintf(objFile.get(),
"f %i %i %i\n", tris[i * 3] + 1, tris[i * 3 + 1] + 1, tris[i * 3 + 2] + 1);
222 TC_LOG_INFO(
"maps.mmapgen.debug",
"[Map {:04}] [{:02},{:02}]: Writing debug output object file...", mapID, tileX, tileY);
224 objFileName =
Trinity::StringFormat(
"{}/meshes/map{:04}.map", outputDirectory.generic_string(), mapID);
226 objFile.reset(fopen(objFileName.c_str(),
"wb"));
229 TC_LOG_ERROR(
"maps.mmapgen.debug",
"{}: Failed to open {} for writing!", strerror(errno), objFileName);
234 fwrite(&b,
sizeof(
char), 1, objFile.get());
236 objFileName =
Trinity::StringFormat(
"{}/meshes/map{:04}_{:02}_{:02}{}.mesh", outputDirectory.generic_string(), mapID, tileX, tileY, fileNameSuffix);
237 objFile.reset(fopen(objFileName.c_str(),
"wb"));
240 TC_LOG_ERROR(
"maps.mmapgen.debug",
"{}: Failed to open {} for writing!", strerror(errno), objFileName);
244 fwrite(&vertCount,
sizeof(
int), 1, objFile.get());
245 fwrite(verts,
sizeof(
float), vertCount*3, objFile.get());
246 fflush(objFile.get());
248 fwrite(&triCount,
sizeof(
int), 1, objFile.get());
249 fwrite(tris,
sizeof(
int), triCount*3, objFile.get());
250 fflush(objFile.get());