Rumba C++ SDK
maquina::Mesh Class Reference

A mesh value. More...

#include <Mesh.h>

Inheritance diagram for maquina::Mesh:
maquina::Points maquina::Shape maquina::Value

Public Member Functions

 Mesh ()
 Create an empty Mesh. More...
 
 Mesh (const BufferConstV3f &points, const BufferConstUInt32 &indices, const BufferConstUInt32 &offsets)
 Create a mesh. More...
 
 Mesh (const Value &v)
 Cast a Value in Mesh. More...
 
SpanSpan< const uint32_t, const uint32_t > position_topology () const
 Get the polygons to position lists. More...
 
SpanSpan< const uint32_t, const uint32_t > vertex_to_faces () const
 
SpanSpan< const uint32_t, const uint32_t > vertex_to_edges () const
 
SpanSpan< const uint32_t, const uint32_t > edges_to_faces () const
 
SpanSpan< const uint32_t, const uint32_t > adjacent_vertices () const
 
Mesh triangulate () const
 Build a triangle version of the Mesh. More...
 
void compute_triangle_indices (BufferV3i &result) const
 Compute and return the triangle vertex indices. More...
 
void compute_triangle_face_varying_indices (BufferV3i &result) const
 Compute and return the triangle face varying indices. More...
 
int closest_face (const Imath::V3f &p, float &max_distance, Imath::V3f *closest_pos=nullptr) const
 Get the closest polygon to a point. More...
 
Imath::V3f normal (int face, int corner) const
 Returns the normal at a face corner. More...
 
Imath::V3f smooth_normal (int vertex) const
 Compute a smooth normal for a vertex. More...
 
- Public Member Functions inherited from maquina::Points
 Points ()
 Create an empty. More...
 
 Points (const Value &v)
 Cast a Value in Points. More...
 
BufferV3f write_points ()
 Return the points buffer. More...
 
const BufferConstV3f read_points () const
 Return the points buffer. More...
 
size_t point_count () const
 Return the number of points. More...
 
Imath::Box3f bounding_box () const
 Compute the object points bounding box. More...
 
void compute_vertex_normals (BufferV3f &result) const
 Compute and return the vertex normals. More...
 
- Public Member Functions inherited from maquina::Shape
 Shape ()
 
 Shape (const Value &v)
 Cast a Value object in Shape. More...
 
bool has_attribute (const char *attribute_name, Topology topology) const
 Test if the shape has this attribute. More...
 
template<typename T >
write_attribute (const char *attribute_name, Topology topology)
 Get a write access to an attribute. More...
 
const Value read_attribute (const char *attribute_name, Topology topology) const
 Get a read access to an attribute. More...
 
bool set_attribute (const char *name, Topology topology, const Value &value)
 Set an attribute. More...
 
bool remove_attribute (const char *name, Topology topology)
 Remove an attribute. More...
 
void finalize ()
 Finalize the shape after deformation. More...
 
size_t topology_size (Topology topology) const
 Get the number of faces, edges or vertices. More...
 
Attributes read_attributes () const
 Return a read-only attribute iteration. More...
 
- Public Member Functions inherited from maquina::Value
 Value ()
 
 Value (Value &&other)=default
 
 Value (const Value &other)=default
 
Valueoperator= (Value &&other)=default
 
Valueoperator= (const Value &other)=default
 
virtual ~Value ()=default
 
Value duplicate () const
 Duplicate the value. More...
 
bool as_bool () const
 Returns the value as a bool. More...
 
int as_int () const
 Returns the value as an integer. More...
 
float as_float () const
 Returns the value as a float. More...
 
double as_double () const
 Returns the value as a double. More...
 
const std::string & as_string () const
 Returns the value as a string. More...
 
std::wstring as_wstring () const
 Returns the value as a wstring. More...
 
Imath::V2f as_V2f () const
 Returns the value as a V2f. More...
 
Imath::V3f as_V3f () const
 Returns the value as a V3f. More...
 
Imath::V4f as_V4f () const
 Returns the value as a V4f. More...
 
const Imath::V2das_V2d () const
 Returns the value as a V2d. More...
 
const Imath::V3das_V3d () const
 Returns the value as a V3d. More...
 
const Imath::V4das_V4d () const
 Returns the value as a V4d. More...
 
const Imath::V2ias_V2i () const
 Returns the value as a V2i. More...
 
const Imath::V3ias_V3i () const
 Returns the value as a V3i. More...
 
const Imath::V4ias_V4i () const
 Returns the value as a V4i. More...
 
Imath::M44f as_M44f () const
 Returns the value as a M44f. More...
 
const Imath::M44das_M44d () const
 Returns the value as a M44d. More...
 
const Imath::Box3fas_Box3f () const
 Returns the value as a Box3f. More...
 
const Imath::Color4fas_Color4f () const
 Returns the value as a Color4f. More...
 
Imath::Quatf as_Quatf () const
 Returns the value as a Quatf. More...
 
const Imath::Quatdas_Quatd () const
 Returns the value as a Quatd. More...
 
std::shared_ptr< const UserDataas_user_data () const
 Returns the value as a user data. More...
 
StringView type_name () const
 Return the type name of the Value. More...
 
virtual bool has_node_delegate () const
 Check if this value can produces a NodeDelegate. More...
 
virtual std::shared_ptr< NodeDelegatenode_delegate (const std::shared_ptr< NodeDelegate > &parent, const StringView &name) const
 
bool operator== (const Value &o) const
 Compare the two values. More...
 
bool operator!= (const Value &o) const
 
bool is_instance (const char *value_type_name) const
 Check if this type derives from another value type. More...
 
 operator bool () const
 
 Value (bool)
 Create a boolean value. More...
 
 Value (int)
 Create an integer value. More...
 
 Value (float)
 Create a float value. More...
 
 Value (double)
 Create a double value (stored in a float right now) More...
 
 Value (const char *string)
 Create a string value. More...
 
 Value (const wchar_t *string)
 Create a string value. More...
 
 Value (const std::string &string)
 Create a string value. More...
 
 Value (const std::wstring &string)
 Create a wide string value. More...
 
 Value (const Imath::V2f &)
 Create a Imath::V2f value. More...
 
 Value (const Imath::V3f &)
 Create a Imath::V3f value. More...
 
 Value (const Imath::V4f &)
 Create a Imath::V4f value. More...
 
 Value (const Imath::V2d &)
 Create a Imath::V2d value. More...
 
 Value (const Imath::V3d &)
 Create a Imath::V3d value. More...
 
 Value (const Imath::V4d &)
 Create a Imath::V4d value. More...
 
 Value (const Imath::V2i &)
 Create a Imath::V2i value. More...
 
 Value (const Imath::V3i &)
 Create a Imath::V3i value. More...
 
 Value (const Imath::V4i &)
 Create a Imath::V4i value. More...
 
 Value (const Imath::Color4f &)
 Create a Imath::Color4f value. More...
 
 Value (const Imath::M44f &)
 Create a Imath::M44f value. More...
 
 Value (const Imath::M44d &)
 Create a Imath::M44d value. More...
 
 Value (const Imath::Box3f &)
 Create a Imath::Box3f value. More...
 
 Value (const Imath::Quatf &)
 Create a Imath::Quatf value. More...
 
 Value (const Imath::Quatd &)
 Create a Imath::Quatd value. More...
 
 Value (const std::shared_ptr< const UserData > &user_data)
 Create a user data value. More...
 

Additional Inherited Members

- Public Types inherited from maquina::Shape
enum  Topology { constant =0, vertex, face, face_varying }
 The different attribute topologies. More...
 
- Static Public Member Functions inherited from maquina::Value
static bool validate_type_name (const char *type_name)
 Return true if the name is a valid type name. More...
 
static Value get_default_value (const char *type_name)
 Return a default value for a given type. More...
 
- Static Public Attributes inherited from maquina::Points
static const Points default_value
 The default value. More...
 
- Static Public Attributes inherited from maquina::Value
static const Value default_value
 The default value. More...
 

Detailed Description

A mesh value.

This mesh class supports n-gones, per vertex and per face user channel with arbitrary types.

attributes

A mesh can have any attributes but some of them have a specific meaning:

  • "UV" : the mesh's UVs. Must be a Shape::face_varying IndexedBufferV2f.
  • "N" : the mesh's normals. Must be a Shape::face_varying IndexedBufferV3f.
  • "Color" : the mesh's vertex color. Must be a Shape::face_varying IndexedBufferV3f. If this attribute exists, this vertex color overrides the shader's diffuse color.

Constructor & Destructor Documentation

◆ Mesh() [1/3]

maquina::Mesh::Mesh ( )

Create an empty Mesh.

◆ Mesh() [2/3]

maquina::Mesh::Mesh ( const BufferConstV3f points,
const BufferConstUInt32 indices,
const BufferConstUInt32 offsets 
)

Create a mesh.

Note the buffers may be shared, so you should not modify them after calling this constructor.

Exceptions
std::runtime_errorin case of invalid data.
Parameters
points< The vertex buffer.
indices< The polygon indices, this buffer size must be the number of polygon corners in the mesh.
offsets< The offset in the indices buffer of the start of the i-th polygon. This buffer size must by the polygon count + 1. The last entry must be indices.size().

◆ Mesh() [3/3]

maquina::Mesh::Mesh ( const Value v)

Cast a Value in Mesh.

If v is not a Mesh object, this object will be an empty mesh.

Member Function Documentation

◆ adjacent_vertices()

SpanSpan< const uint32_t, const uint32_t > maquina::Mesh::adjacent_vertices ( ) const

◆ closest_face()

int maquina::Mesh::closest_face ( const Imath::V3f p,
float &  max_distance,
Imath::V3f closest_pos = nullptr 
) const

Get the closest polygon to a point.

Return the index of the face closest to p and closer than max_distance, if it exists; returns -1 otherwise. max_distance must be initialized with the maximum search distance, and is returned with the closest hit distance. This function is quite slow and should be used only for few queries. If a lot of queries have to be done, consider to use BVHTriangle.

Note
The returned integer is a polygon index.
Parameters
max_distanceThe maximum search distance. In return, d is filled with the closest triangle distance
closest_posIf not null and if a closest triangle has been found, closest_pos is filled with the closest triangle position.

◆ compute_triangle_face_varying_indices()

void maquina::Mesh::compute_triangle_face_varying_indices ( BufferV3i result) const

Compute and return the triangle face varying indices.

The mesh internal structure stores polygones of n-vertices. This function computes and returns a buffer of triangle indices. The triangulation is performed trivialy and is stable with deformations. Each integer triplet forms a triangle. Each element is an index per face corner.

◆ compute_triangle_indices()

void maquina::Mesh::compute_triangle_indices ( BufferV3i result) const

Compute and return the triangle vertex indices.

The mesh internal structure stores polygones of n-vertices. This function computes and returns a buffer of triangle indices. The triangulation is performed trivialy and is stable with deformations. Each integer triplet forms a triangle. Each element is a vertex index.

◆ edges_to_faces()

SpanSpan< const uint32_t, const uint32_t > maquina::Mesh::edges_to_faces ( ) const

◆ normal()

Imath::V3f maquina::Mesh::normal ( int  face,
int  corner 
) const

Returns the normal at a face corner.

If the mesh normals are dirty, the normal is computed. Return (0,0,0) if face or corner are invalid.

Parameters
faceThe face where to compute the normal
cornerThe corner of the face where to compute the normal

◆ position_topology()

SpanSpan<const uint32_t, const uint32_t> maquina::Mesh::position_topology ( ) const

Get the polygons to position lists.

◆ smooth_normal()

Imath::V3f maquina::Mesh::smooth_normal ( int  vertex) const

Compute a smooth normal for a vertex.

◆ triangulate()

Mesh maquina::Mesh::triangulate ( ) const

Build a triangle version of the Mesh.

The mesh internal structure stores polygones of n-vertices. This function builds a mesh, with the same vertices, whose internal structures stores triangles. The triangulation is performed as for compute_triangle_indices().

Warning
The returned mesh does not handle attributes.

◆ vertex_to_edges()

SpanSpan< const uint32_t, const uint32_t > maquina::Mesh::vertex_to_edges ( ) const

◆ vertex_to_faces()

SpanSpan< const uint32_t, const uint32_t > maquina::Mesh::vertex_to_faces ( ) const

The documentation for this class was generated from the following file: