first ideation about a better geometry / topo handling
This commit is contained in:
parent
6b4eb83e64
commit
c70c18e41c
3 changed files with 84 additions and 64 deletions
|
@ -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 <pw/core/globals.hpp>
|
||||
#include <pw/core/vector.hpp>
|
||||
#include <cstddef>
|
||||
#include <pw/core/aabb.hpp>
|
||||
#include <pw/core/globals.hpp>
|
||||
#include <pw/core/resource.hpp>
|
||||
#include <pw/core/vector.hpp>
|
||||
#include <vector>
|
||||
|
||||
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<index_t>;
|
||||
|
||||
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<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);
|
||||
|
||||
|
@ -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<vector2_array> _texture_coords; //! texture coordinates
|
||||
|
||||
uint64_t _change_count { 0 };
|
||||
uint64_t _change_count{0};
|
||||
};
|
||||
|
||||
}
|
||||
struct attribute final {
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace pw
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,66 +1,79 @@
|
|||
#include <pw/core/vector.hpp>
|
||||
#include <pw/core/serialize.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 <iostream>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
#include <print>
|
||||
|
||||
int main(int argc,char **argv) {
|
||||
namespace pw {
|
||||
struct geometry_n {
|
||||
std::vector<vector<float, 3>> vertices{};
|
||||
std::vector<std::size_t> 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<float>::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<float>::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;
|
||||
// }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue