first ideation about a better geometry / topo handling

This commit is contained in:
Hartmut Seichter 2024-07-13 23:58:46 +02:00
parent 6b4eb83e64
commit c70c18e41c
3 changed files with 84 additions and 64 deletions

View file

@ -8,8 +8,8 @@
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in all * The above copyright notice and this permission notice shall be included in
* copies or substantial portions of the Software. * all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
@ -23,23 +23,24 @@
#ifndef PW_CORE_GEOMETRY_HPP #ifndef PW_CORE_GEOMETRY_HPP
#define PW_CORE_GEOMETRY_HPP #define PW_CORE_GEOMETRY_HPP
#include <pw/core/globals.hpp> #include <cstddef>
#include <pw/core/vector.hpp>
#include <pw/core/aabb.hpp> #include <pw/core/aabb.hpp>
#include <pw/core/globals.hpp>
#include <pw/core/resource.hpp> #include <pw/core/resource.hpp>
#include <pw/core/vector.hpp>
#include <vector>
namespace pw { namespace pw {
/* /*
* NOTE this needs to be rewritten to take into account for *any* kind of geometry * NOTE this needs to be rewritten to take into account for *any* kind of
* Some ideas are drafted down there to separate out the attribute buffers. Things to * geometry Some ideas are drafted down there to separate out the attribute
* consider: multiple UVs, triangle soup, per-vertex-color, texture transforms, weights, * buffers. Things to consider: multiple UVs, triangle soup, per-vertex-color,
* etc. pp. * texture transforms, weights, etc. pp.
*/ */
class geometry { class geometry {
public: public:
/** /**
* @brief describes the topology for the primitives based on Vulkan * @brief describes the topology for the primitives based on Vulkan
*/ */
@ -59,7 +60,9 @@ public:
geometry(primitive_topology_type t, vector3_array v, indices_t i); geometry(primitive_topology_type t, vector3_array v, indices_t i);
~geometry() = default; ~geometry() = default;
void set_primitive_topology(primitive_topology_type t) { _primitive_topology = t; } void set_primitive_topology(primitive_topology_type t) {
_primitive_topology = t;
}
primitive_topology_type primitive_topology() { return _primitive_topology; } primitive_topology_type primitive_topology() { return _primitive_topology; }
void set_vertices(vector3_array v); void set_vertices(vector3_array v);
@ -72,7 +75,9 @@ public:
const vector3_array& normals() const; const vector3_array& normals() const;
void set_texture_coordinates(std::vector<vector2_array> v); void set_texture_coordinates(std::vector<vector2_array> v);
const std::vector<vector2_array>& texture_coordinates() const { return _texture_coords;} const std::vector<vector2_array>& texture_coordinates() const {
return _texture_coords;
}
void transform(const matrix4x4& m); void transform(const matrix4x4& m);
@ -85,10 +90,9 @@ public:
uint64_t change_count() const { return _change_count; } uint64_t change_count() const { return _change_count; }
void set_change_count(uint64_t n) { _change_count = n; } void set_change_count(uint64_t n) { _change_count = n; }
protected: protected:
primitive_topology_type _primitive_topology =
primitive_topology_type _primitive_topology = primitive_topology_type::point_list; primitive_topology_type::point_list;
vector3_array _vertices; //!< vertex data vector3_array _vertices; //!< vertex data
indices_t _indices; //!< indices indices_t _indices; //!< indices
@ -102,7 +106,11 @@ protected:
uint64_t _change_count{0}; uint64_t _change_count{0};
}; };
} struct attribute final {
};
} // namespace pw
#endif #endif

View file

@ -9,5 +9,4 @@ make_test(pwcore_test_axisangle)
make_test(pwcore_test_quaternion) make_test(pwcore_test_quaternion)
make_test(pwcore_test_color) make_test(pwcore_test_color)
make_test(pwcore_test_transform_tools) make_test(pwcore_test_transform_tools)
make_test(pwcore_test_mesh)
# make_test(pwcore_test_mesh)

View file

@ -1,34 +1,50 @@
#include <pw/core/vector.hpp>
#include <pw/core/serialize.hpp>
#include <pw/core/matrix_transform.hpp> #include <pw/core/matrix_transform.hpp>
#include <pw/core/geometry.hpp> #include <pw/core/serialize.hpp>
#include <pw/core/vector.hpp>
// #include <pw/core/geometry.hpp>
#include <pw/core/axisangle.hpp> #include <pw/core/axisangle.hpp>
#include <iostream> #include <variant>
#include <vector>
#include <print>
int main(int argc,char **argv) { namespace pw {
struct geometry_n {
pw::geometry geo; std::vector<vector<float, 3>> vertices{};
std::vector<std::size_t> indices{};
pw::vector3_array vs = {
{ -1, 1, 0 },
{ -1,-1, 0 },
{ 1,-1, 0 },
{ 1, 1, 0 }
}; };
pw::geometry::indices_t idx = { } // namespace pw
0, 1, 2,
0, 2, 3
};
auto main() -> int {
geo.set_vertices(vs); auto geom = pw::geometry_n{.vertices = {{1.2f, 2.4f, 4.8f},
geo.set_indices(idx); {2.4f, 1.2f, 4.8f},
{1.2f, 4.8f, 2.4f}},
.indices = {0, 1, 2}};
geo.compute_normals(); for (auto i : geom.indices) {
std::print("({}) ",pw::serialize::to_string(geom.vertices[i]));
}
// pw::geometry geo;
// pw::vector3_array vs = {
// { -1, 1, 0 },
// { -1,-1, 0 },
// { 1,-1, 0 },
// { 1, 1, 0 }
// };
// pw::geometry::indices_t idx = {
// 0, 1, 2,
// 0, 2, 3
// };
// geo.set_vertices(vs);
// geo.set_indices(idx);
// geo.compute_normals();
// amesh.set_vertices(vs); // amesh.set_vertices(vs);
@ -60,7 +76,4 @@ int main(int argc,char **argv) {
// for (auto v : amesh.vertices()) { // for (auto v : amesh.vertices()) {
// std::cout << pw::serialize::matrix(v.transposed()) << std::endl; // std::cout << pw::serialize::matrix(v.transposed()) << std::endl;
// } // }
} }