diff --git a/src/core/include/pw/core/geometry.hpp b/src/core/include/pw/core/geometry.hpp index e3edf50..c460c76 100644 --- a/src/core/include/pw/core/geometry.hpp +++ b/src/core/include/pw/core/geometry.hpp @@ -8,8 +8,8 @@ * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, @@ -23,23 +23,24 @@ #ifndef PW_CORE_GEOMETRY_HPP #define PW_CORE_GEOMETRY_HPP -#include -#include +#include #include +#include #include +#include +#include namespace pw { /* - * NOTE this needs to be rewritten to take into account for *any* kind of geometry - * Some ideas are drafted down there to separate out the attribute buffers. Things to - * consider: multiple UVs, triangle soup, per-vertex-color, texture transforms, weights, - * etc. pp. + * NOTE this needs to be rewritten to take into account for *any* kind of + * geometry Some ideas are drafted down there to separate out the attribute + * buffers. Things to consider: multiple UVs, triangle soup, per-vertex-color, + * texture transforms, weights, etc. pp. */ class geometry { -public: - + public: /** * @brief describes the topology for the primitives based on Vulkan */ @@ -52,14 +53,16 @@ public: triangle_fan }; - using index_t = uint32_t; //< needs to be compatible with GL_UNSIGNED_INT + using index_t = uint32_t; //< needs to be compatible with GL_UNSIGNED_INT using indices_t = std::vector; geometry() = default; geometry(primitive_topology_type t, vector3_array v, indices_t i); ~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; } void set_vertices(vector3_array v); @@ -72,7 +75,9 @@ public: const vector3_array& normals() const; void set_texture_coordinates(std::vector v); - const std::vector& texture_coordinates() const { return _texture_coords;} + const std::vector& texture_coordinates() const { + return _texture_coords; + } void transform(const matrix4x4& m); @@ -85,13 +90,12 @@ public: uint64_t change_count() const { return _change_count; } void set_change_count(uint64_t n) { _change_count = n; } + protected: + primitive_topology_type _primitive_topology = + primitive_topology_type::point_list; -protected: - - primitive_topology_type _primitive_topology = primitive_topology_type::point_list; - - vector3_array _vertices; //!< vertex data - indices_t _indices; //!< indices + vector3_array _vertices; //!< vertex data + indices_t _indices; //!< indices vector3_array _normals; //!< normal data vector3_array _tangents; //!< tangent data @@ -99,10 +103,14 @@ protected: std::vector _texture_coords; //! texture coordinates - uint64_t _change_count { 0 }; + uint64_t _change_count{0}; }; -} +struct attribute final { + +}; + + +} // namespace pw #endif - diff --git a/src/core/tests/CMakeLists.txt b/src/core/tests/CMakeLists.txt index c4f33f0..0140b6d 100644 --- a/src/core/tests/CMakeLists.txt +++ b/src/core/tests/CMakeLists.txt @@ -9,5 +9,4 @@ make_test(pwcore_test_axisangle) make_test(pwcore_test_quaternion) make_test(pwcore_test_color) make_test(pwcore_test_transform_tools) - -# make_test(pwcore_test_mesh) +make_test(pwcore_test_mesh) diff --git a/src/core/tests/pwcore_test_mesh.cpp b/src/core/tests/pwcore_test_mesh.cpp index e45ec0f..d28f4a7 100644 --- a/src/core/tests/pwcore_test_mesh.cpp +++ b/src/core/tests/pwcore_test_mesh.cpp @@ -1,66 +1,79 @@ -#include -#include #include -#include +#include +#include +// #include #include -#include +#include +#include +#include -int main(int argc,char **argv) { +namespace pw { +struct geometry_n { + std::vector> vertices{}; + std::vector indices{}; +}; - pw::geometry geo; +} // namespace pw - pw::vector3_array vs = { - { -1, 1, 0 }, - { -1,-1, 0 }, - { 1,-1, 0 }, - { 1, 1, 0 } - }; +auto main() -> int { - pw::geometry::indices_t idx = { - 0, 1, 2, - 0, 2, 3 - }; + auto geom = pw::geometry_n{.vertices = {{1.2f, 2.4f, 4.8f}, + {2.4f, 1.2f, 4.8f}, + {1.2f, 4.8f, 2.4f}}, + .indices = {0, 1, 2}}; + for (auto i : geom.indices) { + std::print("({}) ",pw::serialize::to_string(geom.vertices[i])); + } - geo.set_vertices(vs); - geo.set_indices(idx); + // pw::geometry geo; - geo.compute_normals(); + // 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); -// amesh.set_vertices(vs); + // geo.compute_normals(); -// for (auto v : amesh.vertices()) { -// std::cout << pw::serialize::matrix(v.transposed()) << std::endl; -// } + // amesh.set_vertices(vs); -// auto scale = pw::matrix_transform::scale_matrix({2,2,2}); + // for (auto v : amesh.vertices()) { + // std::cout << pw::serialize::matrix(v.transposed()) << std::endl; + // } -// amesh.transform(scale); + // auto scale = pw::matrix_transform::scale_matrix({2,2,2}); -// std::cout << "after scale" << std::endl; + // amesh.transform(scale); -// for (auto v : amesh.vertices()) { -// std::cout << pw::serialize::matrix(v.transposed()) << std::endl; -// } + // std::cout << "after scale" << std::endl; -// pw::axisangle aa; + // for (auto v : amesh.vertices()) { + // std::cout << pw::serialize::matrix(v.transposed()) << std::endl; + // } -// aa.axis = pw::vector3({ 0, 0, 1 }); -// aa.angle = pw::deg_to_rad(90.0f); + // pw::axisangle aa; -// auto rot_mat = aa.to_matrix(); + // aa.axis = pw::vector3({ 0, 0, 1 }); + // aa.angle = pw::deg_to_rad(90.0f); -// amesh.transform(rot_mat); - -// std::cout << "after rotate" << std::endl; - -// for (auto v : amesh.vertices()) { -// std::cout << pw::serialize::matrix(v.transposed()) << std::endl; -// } + // auto rot_mat = aa.to_matrix(); + // amesh.transform(rot_mat); + // std::cout << "after rotate" << std::endl; + // for (auto v : amesh.vertices()) { + // std::cout << pw::serialize::matrix(v.transposed()) << std::endl; + // } }