Skip to content

Commit

Permalink
Remove geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
xelatihy committed Jan 30, 2024
1 parent 0f712e0 commit 0af4e82
Show file tree
Hide file tree
Showing 16 changed files with 1,038 additions and 1,151 deletions.
96 changes: 95 additions & 1 deletion apps/yconverts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
//

#include <yocto/yocto_cli.h>
#include <yocto/yocto_geometry.h>
#include <yocto/yocto_gui.h>
#include <yocto/yocto_image.h>
#include <yocto/yocto_math.h>
Expand All @@ -38,6 +37,101 @@
using namespace yocto;
using namespace std::string_literals;

vector<string> shape_stats(const shape_data& shape, bool verbose) {
auto format = [](auto num) {
auto str = std::to_string(num);
while (str.size() < 13) str = " " + str;
return str;
};
auto format3 = [](auto num) {
auto str = std::to_string(num.x) + " " + std::to_string(num.y) + " " +
std::to_string(num.z);
while (str.size() < 13) str = " " + str;
return str;
};

auto bbox = invalidb3f;
for (auto& pos : shape.positions) bbox = merge(bbox, pos);

auto stats = vector<string>{};
stats.push_back("points: " + format(shape.points.size()));
stats.push_back("lines: " + format(shape.lines.size()));
stats.push_back("triangles: " + format(shape.triangles.size()));
stats.push_back("quads: " + format(shape.quads.size()));
stats.push_back("positions: " + format(shape.positions.size()));
stats.push_back("normals: " + format(shape.normals.size()));
stats.push_back("texcoords: " + format(shape.texcoords.size()));
stats.push_back("colors: " + format(shape.colors.size()));
stats.push_back("radius: " + format(shape.radius.size()));
stats.push_back("center: " + format3(center(bbox)));
stats.push_back("size: " + format3(size(bbox)));
stats.push_back("min: " + format3(bbox.min));
stats.push_back("max: " + format3(bbox.max));

return stats;
}

vector<string> fvshape_stats(const fvshape_data& shape, bool verbose) {
auto format = [](auto num) {
auto str = std::to_string(num);
while (str.size() < 13) str = " " + str;
return str;
};
auto format3 = [](auto num) {
auto str = std::to_string(num.x) + " " + std::to_string(num.y) + " " +
std::to_string(num.z);
while (str.size() < 13) str = " " + str;
return str;
};

auto bbox = invalidb3f;
for (auto& pos : shape.positions) bbox = merge(bbox, pos);

auto stats = vector<string>{};
stats.push_back("fvquads: " + format(shape.quadspos.size()));
stats.push_back("positions: " + format(shape.positions.size()));
stats.push_back("normals: " + format(shape.normals.size()));
stats.push_back("texcoords: " + format(shape.texcoords.size()));
stats.push_back("center: " + format3(center(bbox)));
stats.push_back("size: " + format3(size(bbox)));
stats.push_back("min: " + format3(bbox.min));
stats.push_back("max: " + format3(bbox.max));

return stats;
}

// Align vertex positions. Alignment is 0: none, 1: min, 2: max, 3: center.
inline vector<vec3f> align_vertices(
const vector<vec3f>& positions, vec3i alignment) {
auto bounds = invalidb3f;
for (auto& p : positions) bounds = merge(bounds, p);
auto offset = vec3f{0, 0, 0};
switch (alignment.x) {
case 0: break;
case 1: offset.x = bounds.min.x; break;
case 2: offset.x = (bounds.min.x + bounds.max.x) / 2; break;
case 3: offset.x = bounds.max.x; break;
default: throw std::invalid_argument{"invalid alignment"};
}
switch (alignment.y) {
case 0: break;
case 1: offset.y = bounds.min.y; break;
case 2: offset.y = (bounds.min.y + bounds.max.y) / 2; break;
case 3: offset.y = bounds.max.y; break;
default: throw std::invalid_argument{"invalid alignment"};
}
switch (alignment.z) {
case 0: break;
case 1: offset.z = bounds.min.z; break;
case 2: offset.z = (bounds.min.z + bounds.max.z) / 2; break;
case 3: offset.z = bounds.max.z; break;
default: throw std::invalid_argument{"invalid alignment"};
}
auto aligned = positions;
for (auto& p : aligned) p -= offset;
return aligned;
}

// main function
void run(const vector<string>& args) {
// parameters
Expand Down
1 change: 0 additions & 1 deletion apps/ysamples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
//

#include <yocto/yocto_cli.h>
#include <yocto/yocto_geometry.h>
#include <yocto/yocto_image.h>
#include <yocto/yocto_math.h>
#include <yocto/yocto_scene.h>
Expand Down
2 changes: 1 addition & 1 deletion libs/yocto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_library(yocto STATIC
yocto_math.h yocto_geometry.h
yocto_math.h
yocto_sampling.h yocto_shading.h
yocto_modeling.h yocto_animation.h
yocto_bvh.h yocto_bvh.cpp
Expand Down
24 changes: 22 additions & 2 deletions libs/yocto/yocto_bvh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
#include <string>
#include <utility>

#include "yocto_geometry.h"

// -----------------------------------------------------------------------------
// USING DIRECTIVES
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -777,6 +775,28 @@ void update_scene_bvh(scene_bvh& sbvh, const scene_data& scene,
refit_bvh(sbvh.bvh, bboxes);
}

// Compute scene bounding box
bbox3f scene_bounds(const scene_data& scene) {
auto shape_bbox = vector<bbox3f>{};
auto bbox = invalidb3f;
for (auto& shape : scene.shapes) {
auto& sbbox = shape_bbox.emplace_back();
for (auto p : shape.positions) sbbox = merge(sbbox, p);
}
for (auto& instance : scene.instances) {
auto& sbbox = shape_bbox[instance.shape];
bbox = merge(bbox, transform_bbox(instance.frame, sbbox));
}
return bbox;
}

// Compute shape bounding box
bbox3f shape_bounds(const shape_data& shape) {
auto bbox = invalidb3f;
for (auto p : shape.positions) bbox = merge(bbox, p);
return bbox;
}

} // namespace yocto

// -----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 0af4e82

Please sign in to comment.