Skip to content

Commit

Permalink
improve part palette
Browse files Browse the repository at this point in the history
log time
t=179.25h
  • Loading branch information
bb1950328 committed Jan 5, 2024
1 parent 3465338 commit e2c81e2
Show file tree
Hide file tree
Showing 16 changed files with 379 additions and 150 deletions.
14 changes: 0 additions & 14 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 39 additions & 2 deletions src/config/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,40 @@ namespace bricksim::config {
friend bool operator!=(const ElementTree& lhs, const ElementTree& rhs) { return !(lhs == rhs); }
};

struct PartCategoryTreeNode {
uint64_t id;
std::string name;
std::string ldrawCategory;
std::string nameFilter;
std::vector<PartCategoryTreeNode> children;

explicit PartCategoryTreeNode() {
json_helper::defaultInit(this);
}

template<typename JsonIo>
void json_io(JsonIo& io) {
io
& json_dto::optional("id", id, 0)
& json_dto::optional("name", name, "")
& json_dto::optional("ldrawCategory", ldrawCategory, "")
& json_dto::optional("nameFilter", nameFilter, "")
& json_dto::optional("children", children, decltype(children)());
}

friend bool operator==(const PartCategoryTreeNode& lhs, const PartCategoryTreeNode& rhs) {
return lhs.id == rhs.id
&& lhs.name == rhs.name
&& lhs.ldrawCategory == rhs.ldrawCategory
&& lhs.nameFilter == rhs.nameFilter;
}

friend bool operator!=(const PartCategoryTreeNode& lhs, const PartCategoryTreeNode& rhs) { return !(lhs == rhs); }
};

struct PartPalette {
uint16_t thumbnailSize;
std::vector<PartCategoryTreeNode> customTrees;

PartPalette() {
defaultInit(this);
Expand All @@ -199,10 +231,15 @@ namespace bricksim::config {
template<typename JsonIo>
void json_io(JsonIo& io) {
io
& json_dto::optional("thumbnailSize", thumbnailSize, 256, json_dto::min_max_constraint(4, 2048));
& json_dto::optional("thumbnailSize", thumbnailSize, 256, json_dto::min_max_constraint(4, 2048))
& json_dto::optional("customTrees", customTrees, decltype(customTrees)());
}

friend bool operator==(const PartPalette& lhs, const PartPalette& rhs) {
return lhs.thumbnailSize == rhs.thumbnailSize
&& lhs.customTrees == rhs.customTrees;
}

friend bool operator==(const PartPalette& lhs, const PartPalette& rhs) { return lhs.thumbnailSize == rhs.thumbnailSize; }
friend bool operator!=(const PartPalette& lhs, const PartPalette& rhs) { return !(lhs == rhs); }
};

Expand Down
10 changes: 5 additions & 5 deletions src/graphics/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,16 @@ namespace bricksim::graphics {
collectPoints(points, node, glm::mat4(1.f));
Seb::Smallest_enclosing_ball<float, glm::vec3> seb(3, points);

auto center = seb.center_begin();
const auto center = seb.center_begin();
const auto sebCenter = glm::vec3(center[0], center[1], center[2]);

auto meshRadius = seb.radius() * constants::LDU_TO_OPENGL_SCALE;
const auto meshRadius = seb.radius() * constants::LDU_TO_OPENGL_SCALE;
target = glm::vec4(sebCenter, 1.0f) * constants::LDU_TO_OPENGL;

//todo calculate the distance from fov instead of this
auto distance = meshRadius * 2.45f;
auto s = glm::radians(45.0f);//todo make variable
auto t = glm::radians(45.0f);
const auto distance = meshRadius * 2.35f;
const auto s = glm::radians(45.0f);//todo make variable
const auto t = glm::radians(45.0f);
cameraPos = glm::vec3(
distance * std::cos(s) * std::cos(t),
distance * std::sin(s) * std::cos(t),
Expand Down
6 changes: 3 additions & 3 deletions src/graphics/mesh/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ namespace bricksim::mesh {
vertexCount += item.second.getVertexCount();
}
if (vertexCount > 0) {
std::vector<glm::vec3> coords;
std::vector<glm::dvec3> coords;
coords.reserve(vertexCount);

for (const auto& item: triangleData) {
Expand All @@ -529,7 +529,7 @@ namespace bricksim::mesh {
item.second.addVerticesForOuterDimensions(coords);
}

Seb::Smallest_enclosing_ball<float, glm::vec3> seb(3, coords);
Seb::Smallest_enclosing_ball<double, glm::dvec3> seb(3, coords);

aabb::AABB aabb;

Expand All @@ -540,7 +540,7 @@ namespace bricksim::mesh {
outerDimensions = OuterDimensions{
.aabb = aabb,
.minEnclosingBallCenter = {seb.center_begin()[0], seb.center_begin()[1], seb.center_begin()[2]},
.minEnclosingBallRadius = seb.radius(),
.minEnclosingBallRadius = static_cast<float>(seb.radius()),
};
} else {
outerDimensions = OuterDimensions{
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/mesh/mesh_textured_triangle_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ namespace bricksim::mesh {
return verticesAlreadyDeleted ? uploadedVertexCount : vertices.size();
}

void TexturedTriangleData::addVerticesForOuterDimensions(std::vector<glm::vec3>& coords) const {
void TexturedTriangleData::addVerticesForOuterDimensions(std::vector<glm::dvec3>& coords) const {
for (auto& item: vertices) {
coords.push_back(item.position);
}
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/mesh/mesh_textured_triangle_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace bricksim::mesh {
void freeBuffers() const;
void draw(const InstanceRange& sceneLayerInstanceRange) const;
[[nodiscard]] size_t getVertexCount() const;
void addVerticesForOuterDimensions(std::vector<glm::vec3>& coords) const;
void addVerticesForOuterDimensions(std::vector<glm::dvec3>& coords) const;
void addVertex(const TexturedTriangleVertex& vertex);

private:
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/mesh/mesh_triangle_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ namespace bricksim::mesh {
vertices.push_back(vertex);
}

void TriangleData::addVerticesForOuterDimensions(std::vector<glm::vec3>& coords) const {
void TriangleData::addVerticesForOuterDimensions(std::vector<glm::dvec3>& coords) const {
for (auto& item: vertices) {
coords.push_back(item.position);
}
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/mesh/mesh_triangle_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace bricksim::mesh {
void rewriteInstanceBuffer(const std::vector<MeshInstance>& instances);
[[nodiscard]] size_t getVertexCount() const;
[[nodiscard]] size_t getIndexCount() const;
void addVerticesForOuterDimensions(std::vector<glm::vec3>& coords) const;
void addVerticesForOuterDimensions(std::vector<glm::dvec3>& coords) const;

[[nodiscard]] bool isDataAlreadyDeleted() const;
[[nodiscard]] const std::vector<TriangleVertex>& getVertices() const;
Expand Down
10 changes: 7 additions & 3 deletions src/gui/gui_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@

namespace bricksim::gui_internal {
bool drawPartThumbnail(const ImVec2& actualThumbSizeSquared, const std::shared_ptr<ldr::File>& part, const ldr::ColorReference color) {
bool realThumbnailAvailable = false;
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(config::get().graphics.background));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {0, 0});
bool realThumbnailDrawn = false;
const bool visible = ImGui::IsRectVisible(actualThumbSizeSquared);
if (visible) {
auto optTexId = controller::getThumbnailGenerator()->getThumbnailNonBlocking({part, color});
if (optTexId.has_value()) {
auto texId = convertTextureId(optTexId.value()->getID());
ImGui::ImageButton(part->metaInfo.name.c_str(), texId, actualThumbSizeSquared, ImVec2(0, 1), ImVec2(1, 0));
realThumbnailAvailable = true;
realThumbnailDrawn = true;
}
} else {
controller::getThumbnailGenerator()->removeFromRenderQueue({part, color});
}
if (!realThumbnailAvailable) {
if (!realThumbnailDrawn) {
ImGui::Button(part->metaInfo.name.c_str(), actualThumbSizeSquared);
}
ImGui::PopStyleVar();
ImGui::PopStyleColor();
if (ImGui::IsItemHovered()) {
auto availableColors = info_providers::part_color_availability::getAvailableColorsForPart(part);
std::string availText;
Expand Down
Loading

0 comments on commit e2c81e2

Please sign in to comment.