experimenting around with scene and rendering components

This commit is contained in:
Hartmut Seichter 2020-12-01 23:22:19 +01:00
parent 8915080b64
commit 0cd3c99119
10 changed files with 117 additions and 117 deletions

View file

@ -103,17 +103,16 @@ void register_core_function(sol::state& lua,sol::table& ns)
"reset",&time::reset
);
auto mesh_type = ns.new_usertype<mesh>("mesh"
, sol::constructors<mesh()>()
, "topology", sol::property(&mesh::topology,&mesh::set_topology)
, "vertices", sol::property(&mesh::vertices,&mesh::set_vertices)
, "indices", sol::property(&mesh::indices,&mesh::set_indices)
auto geoom_type = ns.new_usertype<geometry>("geometry"
, sol::constructors<geometry()>()
, "topology", sol::property(&geometry::topology,&geometry::set_topology)
, "vertices", sol::property(&geometry::vertices,&geometry::set_vertices)
, "indices", sol::property(&geometry::indices,&geometry::set_indices)
);
mesh_type.new_enum("topology"
, "points", mesh::topology_type::points
, "lines", mesh::topology_type::lines
, "line_strip", mesh::topology_type::line_strip
geoom_type.new_enum("topology"
, "points", geometry::topology_type::points
, "lines", geometry::topology_type::lines
, "line_strip", geometry::topology_type::line_strip
);
ns.new_usertype<image>("image"

View file

@ -30,18 +30,10 @@
namespace pw {
class mesh {
class geometry {
public:
using index_t = unsigned int ;
using valuearray_t = std::vector<real_t> ;
using indexarray_t = std::vector<index_t> ;
using vertex2array_t = std::vector<vector2> ;
using vertex3array_t = std::vector<vector3> ;
enum topology_type {
enum class topology_type {
triangles,
triangle_strip,
triangle_fan,
@ -51,7 +43,15 @@ public:
points
};
mesh();
using index_t = size_t;
using valuearray_t = std::vector<real_t> ;
using indexarray_t = std::vector<index_t> ;
using vertex2array_t = std::vector<vector2> ;
using vertex3array_t = std::vector<vector3> ;
geometry() = default;
void set_indices(const indexarray_t& v) { _indices = v; }
const indexarray_t& indices() const { return _indices; }
@ -59,8 +59,8 @@ public:
void set_vertices(const vertex3array_t& v);
const vertex3array_t& vertices() const { return _vertices; }
void set_normals(const mesh::vertex3array_t &v);
const mesh::vertex3array_t& normals() const;
void set_normals(const geometry::vertex3array_t &v);
const geometry::vertex3array_t& normals() const;
void set_topology(topology_type t) { _topology = t; }
topology_type topology() { return _topology; }
@ -77,10 +77,9 @@ public:
protected:
topology_type _topology;
topology_type _topology = topology_type::triangles;
indexarray_t _indices; //!< indices according to topology type
vertex3array_t _vertices; //!< geometry data
vertex3array_t _normals; //!< normal data
vertex3array_t _colors; //!< color data

View file

@ -4,13 +4,9 @@
namespace pw {
mesh::mesh()
{
}
void mesh::compute_normals()
void geometry::compute_normals()
{
// assumption is that we have some array as the vertices
vertex3array_t normals; normals.resize(_vertices.size());
@ -59,26 +55,29 @@ void mesh::compute_normals()
// now set back
}
void mesh::set_vertices(const mesh::vertex3array_t &v)
void geometry::set_vertices(const geometry::vertex3array_t &v)
{
// first set vertices
_vertices = v;
//
compute_normals();
// update bounds
compute_bounds();
}
void mesh::set_normals(const mesh::vertex3array_t &v)
void geometry::set_normals(const geometry::vertex3array_t &v)
{
_normals = v;
}
const mesh::vertex3array_t &mesh::normals() const
const geometry::vertex3array_t &geometry::normals() const
{
return _normals;
}
void mesh::apply(const matrix4x4 &m)
void geometry::apply(const matrix4x4 &m)
{
// apply transformation to all vertices
for (auto &v : _vertices)
@ -92,7 +91,7 @@ void mesh::apply(const matrix4x4 &m)
compute_bounds();
}
void mesh::compute_bounds()
void geometry::compute_bounds()
{
// only do if there are vertices
if (_vertices.size()) {

View file

@ -8,9 +8,9 @@
int main(int argc,char **argv) {
pw::mesh amesh;
pw::geometry amesh;
pw::mesh::vertex3array_t vs = { {-1,-1,0},{1,-1,0},{0,1,0} };
pw::geometry::vertex3array_t vs = { {-1,-1,0},{1,-1,0},{0,1,0} };
amesh.set_vertices(vs);
for (auto v : amesh.vertices()) {

View file

@ -7,13 +7,13 @@ namespace pw {
struct primitives {
static mesh box(real_t size_x, real_t size_y, real_t size_z);
static geometry box(real_t size_x, real_t size_y, real_t size_z);
static mesh sphere(real_t radius,int divisions_latitude,int divisions_longitude);
static geometry sphere(real_t radius,int divisions_latitude,int divisions_longitude);
static mesh cone();
static geometry cone();
static mesh pyramid();
static geometry pyramid();
};
};

View file

@ -2,11 +2,11 @@
namespace pw {
mesh primitives::box(real_t size_x,real_t size_y, real_t size_z)
geometry primitives::box(real_t size_x,real_t size_y, real_t size_z)
{
mesh m;
geometry m;
mesh::vertex3array_t vertices;
geometry::vertex3array_t vertices;
// vertices.push_back( { -size_x / 2,-size_y / 2, size_z / 2 } ); // 0
// vertices.push_back( { size_x / 2,-size_y / 2, size_z / 2 } ); // 1
@ -38,7 +38,7 @@ mesh primitives::box(real_t size_x,real_t size_y, real_t size_z)
return m;
}
mesh primitives::sphere(real_t radius,int divisions_latitude,int divisions_longitude)
geometry primitives::sphere(real_t radius,int divisions_latitude,int divisions_longitude)
{
using std::cos;
using std::sin;
@ -46,9 +46,9 @@ mesh primitives::sphere(real_t radius,int divisions_latitude,int divisions_longi
const real_t _division_lat = real_t(360.0) / divisions_latitude;
const real_t _division_lon = real_t(360.0) / divisions_longitude;
mesh geom;
geometry geom;
geom.set_topology(mesh::topology_type::triangle_strip);
geom.set_topology(geometry::topology_type::triangle_strip);
real_t x, y, z;

View file

@ -8,14 +8,17 @@
namespace pw {
/**
* @brief Connects mesh data with the render backend
*/
class vertex_array {
public:
vertex_array();
vertex_array(const mesh& m);
vertex_array(const geometry& m);
~vertex_array();
void create(const mesh &m);
void create(const geometry &m);
void release();
void draw();

View file

@ -39,7 +39,7 @@ struct triangle_renderer
// GLuint shader_programme = 0;
shader shader_p;
mesh amesh;
geometry amesh;
vertex_array amesh_renderer;
time::tick_t tick;
@ -73,7 +73,7 @@ struct triangle_renderer
// 2 -- 3
// geometry
mesh::vertex3array_t vertices = {
geometry::vertex3array_t vertices = {
{-s, s, z_val} // 0
,{ s, s, z_val} // 1
,{-s, -s, z_val} // 2
@ -81,7 +81,7 @@ struct triangle_renderer
};
// topology / indices
mesh::indexarray_t indices = { 2, 1, 0,
geometry::indexarray_t indices = { 2, 1, 0,
2, 3, 1};

View file

@ -32,7 +32,7 @@ struct vertex_array::impl {
return GL_TRUE == glIsVertexArray(_vao);
}
void create(const mesh& m)
void create(const geometry& m)
{
// not sure ...
if (ready()) {
@ -110,7 +110,7 @@ vertex_array::vertex_array()
{
}
vertex_array::vertex_array(const mesh &m)
vertex_array::vertex_array(const geometry &m)
{
vertex_array();
_impl->create(m);
@ -125,7 +125,7 @@ bool vertex_array::ready() const
return _impl->ready();
}
void vertex_array::create(const mesh &m)
void vertex_array::create(const geometry &m)
{
_impl->create(m);
}