Skip to content

Commit

Permalink
Fixed adding faces to existing groups
Browse files Browse the repository at this point in the history
  • Loading branch information
JaCzekanski committed Sep 14, 2020
1 parent df280f3 commit 74bbb3d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/device/gpu/primitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ struct Line {
struct Triangle {
struct Vertex {
ivec2 pos;
RGB color; // Valid if bits == 0 or !isRawTexture
ivec2 uv; // Valid if bits != 0
RGB color; // Valid if bits == 0 or !isRawTexture
ivec2 uv{}; // Valid if bits != 0
};
Vertex v[3];

Expand Down
45 changes: 20 additions & 25 deletions src/utils/screenshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,18 +612,14 @@ struct Screenshot {
cleanUp();
}

void groupFace(std::map<uint32_t, std::vector<ScreenshotFace *>> *groups, ScreenshotVertex *screenshotVertex,
ScreenshotFace *screenshotFace) {
std::vector<ScreenshotFace *> f;
uint32_t group = groupObjects ? screenshotVertex->group : 0;
auto it = groups->find(group);
if (it == groups->end()) {
f = std::vector<ScreenshotFace *>();
f.push_back(screenshotFace);
groups->emplace(std::pair<uint32_t, std::vector<ScreenshotFace *>>(group, f));
void groupFace(std::map<uint32_t, std::vector<ScreenshotFace>> &groups, ScreenshotVertex &screenshotVertex,
ScreenshotFace &screenshotFace) {
uint32_t groupNumber = groupObjects ? screenshotVertex.group : 0;
auto group = groups.find(groupNumber);
if (group == groups.end()) {
groups.emplace(groupNumber, std::vector<ScreenshotFace>{screenshotFace});
} else {
f = it->second;
f.push_back(screenshotFace);
group->second.push_back(screenshotFace);
}
}

Expand Down Expand Up @@ -704,23 +700,22 @@ struct Screenshot {
it->g[2] / 255.0f, it->b[2] / 255.0f, it->s[2] / 255.0f, it->t[2] / 255.0f,
v2.originalX, v2.originalY, v2.originalZ, v2.group, v2.depth, normal, it->comp);
}
std::map<uint32_t, std::vector<ScreenshotFace *>> groups;
for (auto it = faceBuffer.begin(); it != faceBuffer.end(); it++) {
ScreenshotVertex v0 = vertexBuffer[it->v[0]];
ScreenshotVertex v1 = vertexBuffer[it->v[1]];
ScreenshotVertex v2 = vertexBuffer[it->v[2]];
groupFace(&groups, &v0, &*it);
groupFace(&groups, &v1, &*it);
groupFace(&groups, &v2, &*it);
std::map<uint32_t, std::vector<ScreenshotFace>> groups;
for (auto it : faceBuffer) {
ScreenshotVertex v0 = vertexBuffer[it.v[0]];
ScreenshotVertex v1 = vertexBuffer[it.v[1]];
ScreenshotVertex v2 = vertexBuffer[it.v[2]];
groupFace(groups, v0, it);
groupFace(groups, v1, it);
groupFace(groups, v2, it);
}
for (auto it = groups.begin(); it != groups.end(); it++) {
stream << "g geometry_" << it->first << "\n";
for (auto it2 = it->second.begin(); it2 != it->second.end(); it2++) {
ScreenshotFace *screenshotFace = (*it2);
uint32_t vremap0 = screenshotFace->vremap[0];
uint32_t vremap1 = screenshotFace->vremap[1];
uint32_t vremap2 = screenshotFace->vremap[2];
uint32_t textureIndex = getTextureIndex(screenshotFace->tpageX, screenshotFace->tpageY);
for (ScreenshotFace screenshotFace : it->second) {
uint32_t vremap0 = screenshotFace.vremap[0];
uint32_t vremap1 = screenshotFace.vremap[1];
uint32_t vremap2 = screenshotFace.vremap[2];
uint32_t textureIndex = getTextureIndex(screenshotFace.tpageX, screenshotFace.tpageY);
// uint32_t pageId = GETTPAGE(screenshotFace->tpageX, screenshotFace->tpageY);
stream << "usemtl output_" + std::to_string(frameIndex) << "_" << textureIndex << "\n";
stream << "f " << vremap0 << "/" << vremap0 << "/" << vremap0 << " " << vremap1 << "/" << vremap1 << "/"
Expand Down
8 changes: 4 additions & 4 deletions src/utils/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct vec2;
struct vec3;

struct ivec2 {
int x, y;
int x = 0, y = 0;
ivec2() = default;
ivec2(int x, int y) : x(x), y(y) {}

Expand All @@ -18,7 +18,7 @@ struct ivec2 {
};

struct ivec3 {
int x, y, z;
int x = 0, y = 0, z = 0;
ivec3(int x, int y, int z) : x(x), y(y), z(z) {}
ivec3(const vec3& v);

Expand All @@ -29,7 +29,7 @@ struct ivec3 {
};

struct vec2 {
float x, y;
float x = 0.f, y = 0.f;
vec2() = default;
vec2(float x, float y) : x(x), y(y) {}
vec2(const ivec2& v);
Expand All @@ -46,7 +46,7 @@ struct vec2 {
};

struct vec3 {
float x, y, z;
float x = 0.f, y = 0.f, z = 0.f;
vec3() = default;
vec3(float x, float y, float z) : x(x), y(y), z(z) {}
vec3(const ivec3& v);
Expand Down

0 comments on commit 74bbb3d

Please sign in to comment.