Skip to content

Commit f48edd4

Browse files
committed
Add a function to create point geometry
1 parent 2c346d9 commit f48edd4

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

render_pipeline/rpcore/util/primitives.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace rpcore {
88

9+
RENDER_PIPELINE_DECL NodePath create_points(const std::string& name, int count);
910
RENDER_PIPELINE_DECL NodePath create_cube(const std::string& name);
1011
RENDER_PIPELINE_DECL NodePath create_sphere(const std::string& name, unsigned int latitude, unsigned int longitude);
1112

src/rpcore/util/primitives.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <geomVertexWriter.h>
44
#include <geomTriangles.h>
5+
#include <geomPoints.h>
56
#include <geomNode.h>
67
#include <materialAttrib.h>
78

@@ -21,6 +22,30 @@ static NodePath create_geom_node(const std::string& name, Geom* geom)
2122
return NodePath(geom_node);
2223
}
2324

25+
NodePath create_points(const std::string& name, int count)
26+
{
27+
// create vertices
28+
PT(GeomVertexData) vdata = new GeomVertexData(name, GeomVertexFormat::get_v3(), Geom::UsageHint::UH_static);
29+
vdata->unclean_set_num_rows(count);
30+
31+
GeomVertexWriter vertex(vdata, InternalName::get_vertex());
32+
33+
for (int k = 0; k < count; ++k)
34+
vertex.add_data3f(0.0f);
35+
36+
// create indices
37+
PT(GeomPoints) prim = new GeomPoints(Geom::UsageHint::UH_static);
38+
prim->reserve_num_vertices(count);
39+
for (int k = 0; k < count; ++k)
40+
prim->add_vertex(k);
41+
prim->close_primitive();
42+
43+
PT(Geom) geom = new Geom(vdata);
44+
geom->add_primitive(prim);
45+
46+
return create_geom_node(name, geom);
47+
}
48+
2449
NodePath create_cube(const std::string& name)
2550
{
2651
// create vertices

0 commit comments

Comments
 (0)