|
| TypedMesh (DrawType dt=DrawType::Points, ConnectivityType ct=ConnectivityType::None) |
|
| TypedMesh (DrawType dt, ConnectivityType ct, const std::vector< Vertex > &vertices, std::vector< std::uint32_t > &&indices) |
|
| TypedMesh (const TypedMesh &rhs) |
|
TypedMesh & | operator= (const TypedMesh &that) |
|
virtual TypedMesh * | clone () const override |
|
void | append (const TypedMesh *mesh) |
| Append another TypedMesh to the current TypedMesh. More...
|
|
void | addVertices (const std::vector< Vertex > &vertices) |
| Adds a vector of vertices to the mesh. More...
|
|
uint32_t | addVertex (const Vertex &vertex) |
|
void | setVertex (size_t index, const Vertex &vertex) |
|
template<typename... Args> |
uint32_t | addVertex (Args &&... args) |
| Adds a vertex. More...
|
|
template<typename... Args> |
void | setVertex (size_t index, Args &&... args) |
| Sets a specific vertex. More...
|
|
template<typename BT > |
void | setVertex (size_t index, const typename BT::type &v) |
| Updates the a specific value in specific buffer. More...
|
|
template<typename BT > |
auto | getTypedBuffer () |
| Returns a specific buffer. The following example shows how to get the color buffer: More...
|
|
template<typename BT > |
auto | getTypedBuffer () const |
|
template<typename BT > |
auto | getTypedRAMRepresentation () const |
|
template<typename BT > |
auto | getTypedEditableRAMRepresentation () |
|
template<typename BT > |
auto & | getTypedDataContainer () const |
|
template<typename BT > |
auto & | getTypedDataContainer () |
|
| Mesh (DrawType dt, ConnectivityType ct) |
|
| Mesh (const Mesh &rhs) |
|
Mesh & | operator= (const Mesh &that) |
|
virtual Document | getInfo () const |
|
void | addBuffer (BufferInfo info, std::shared_ptr< BufferBase > att) |
|
void | addBuffer (BufferType type, std::shared_ptr< BufferBase > att) |
|
void | removeBuffer (size_t idx) |
|
void | replaceBuffer (size_t idx, BufferInfo info, std::shared_ptr< BufferBase > att) |
|
void | setBuffer (size_t idx, BufferInfo info, std::shared_ptr< BufferBase > att) |
|
void | addIndicies (MeshInfo info, std::shared_ptr< IndexBuffer > ind) |
|
std::shared_ptr< IndexBufferRAM > | addIndexBuffer (DrawType dt, ConnectivityType ct) |
|
void | removeIndexBuffer (size_t idx) |
|
void | reserveSizeInVertexBuffer (size_t size) |
|
void | reserveIndexBuffers (size_t size) |
|
const BufferVector & | getBuffers () const |
|
const IndexVector & | getIndexBuffers () const |
|
const BufferBase * | getBuffer (size_t idx) const |
|
BufferInfo | getBufferInfo (size_t idx) const |
|
const IndexBuffer * | getIndices (size_t idx) const |
|
std::pair< const BufferBase *, int > | findBuffer (BufferType type) const |
|
bool | hasBuffer (BufferType type) const |
|
BufferBase * | getBuffer (size_t idx) |
|
IndexBuffer * | getIndices (size_t idx) |
|
MeshInfo | getDefaultMeshInfo () const |
|
MeshInfo | getIndexMeshInfo (size_t idx) const |
|
size_t | getNumberOfBuffers () const |
|
size_t | getNumberOfIndicies () const |
|
void | append (const Mesh &mesh) |
| Append another mesh to this mesh. More...
|
|
virtual const SpatialCameraCoordinateTransformer< 3 > & | getCoordinateTransformer (const Camera &camera) const |
|
const T * | getRepresentation () const |
|
T * | getEditableRepresentation () |
|
bool | hasRepresentation () const |
|
bool | hasRepresentations () const |
|
void | clearRepresentations () |
|
| SpatialEntity (const SpatialEntity< N > &rhs) |
|
| SpatialEntity (const Matrix< N+1, float > &modelMatrix) |
|
| SpatialEntity (const Matrix< N+1, float > &modelMatrix, const Matrix< N+1, float > &worldMatrix) |
|
SpatialEntity< N > & | operator= (const SpatialEntity< N > &that) |
|
Vector< N, float > | getOffset () const |
|
void | setOffset (const Vector< N, float > &offset) |
|
Matrix< N, float > | getBasis () const |
|
void | setBasis (const Matrix< N, float > &basis) |
|
Matrix< N+1, float > | getModelMatrix () const |
|
void | setModelMatrix (const Matrix< N+1, float > &modelMatrix) |
|
Matrix< N+1, float > | getWorldMatrix () const |
|
void | setWorldMatrix (const Matrix< N+1, float > &worldMatrix) |
|
virtual const SpatialCoordinateTransformer< N > & | getCoordinateTransformer () const |
|
virtual const SpatialCameraCoordinateTransformer< N > & | getCoordinateTransformer (const CameraND< N > &camera) const |
|
| MetaDataOwner (const MetaDataOwner &rhs)=default |
|
MetaDataOwner & | operator= (const MetaDataOwner &rhs)=default |
|
void | copyMetaDataFrom (const MetaDataOwner &src) |
|
void | copyMetaDataTo (MetaDataOwner &dst) |
|
template<typename T > |
T * | createMetaData (const std::string &key) |
|
template<typename T , typename U > |
void | setMetaData (const std::string &key, U value) |
|
template<typename T > |
bool | unsetMetaData (const std::string &key) |
| unset, i.e. remove the metadata entry matching the given key and type More...
|
|
template<typename T , typename U > |
U | getMetaData (const std::string &key, U val) const |
|
template<typename T > |
T * | getMetaData (const std::string &key) |
|
template<typename T > |
const T * | getMetaData (const std::string &key) const |
|
MetaDataMap * | getMetaDataMap () |
|
const MetaDataMap * | getMetaDataMap () const |
|
template<typename T > |
bool | hasMetaData (const std::string &key) const |
|
virtual void | serialize (Serializer &s) const |
|
virtual void | deserialize (Deserializer &d) |
|
template<typename... BufferTraits>
class inviwo::TypedMesh< BufferTraits >
TypedMesh is a templated data structure for creating meshes with a custom amount of vertex buffers. It uses a variadic set of BufferTraits to define its interface. For example, a Mesh with a position and color per vertex would be defined as TypedMesh<PositionsBufferTrait,ColorsBufferTrait>
. Depending on the Traits specified in the declaration the interface towards the class is updated.
Simple Usage
using MyMesh = TypedMesh<buffertraits::PositionsBuffer,buffertraits::ColorsBuffer>;
MyMesh mesh;
mesh.addVertex(vec3(0.0f), vec4(1,0,0,1) );
mesh.addVertex(vec3(1.0f), vec4(0,1,0,1) );
If texture coordinates are also needed for each vertex in the mesh then one could instead use:
using MyMesh = TypedMesh<buffertraits::PositionsBuffer, buffertraits::TexcoordBuffer,
buffertraits::ColorsBuffer>;
MyMesh mesh;
mesh.addVertex(vec3(0.0f), vec3(0.0f), vec4(1,0,0,1) );
mesh.addVertex(vec3(1.0f), vec3(1.0f), vec4(0,1,0,1) );
For meshes with more than a couple of vertices, it is more efficient to add all vertices to the mesh at the same time. This can be done by using a std::vector containing TypedMesh::Vertex instead, as described by the following example:
using MyMesh = TypedMesh<PositionsBufferTrait,ColorsBufferTrait>;
std::vector<MyMesh::Vertex> vertices;
vertices.emplace_back(vec3(0.0f), vec4(1,0,0,1));
vertices.emplace_back(vec3(1.0f), vec4(0,1,0,1));
MyMesh mesh;
mesh.addVertices(vertices);
When creating meshes it is very common to also have Index buffers, in addition to the vertex buffers. To add a index buffer to the mesh you can use the function addIndexBuffer as demonstrated by the following example.
using MyMesh = TypedMesh<buffertraits::PositionsBuffer, buffertraits::ColorsBuffer>;
MyMesh mesh;
auto ib = mesh.addIndexBuffer(DrawType::Lines, ConnectivityType::None);
ib->add({0,1});
ib->add({1,2});
Examples
Creating a bounding box with Adjacency information
The following code snippet uses a SimpleMesh2 to create bounding box for a given basisandoffset matrix. It is the code used in meshutil::boundingBoxAdjacency
const vec4& color) {
auto mesh = std::make_shared<PosTexColorMesh>();
mesh->setModelMatrix(basisandoffset);
mesh->addVertices({{vec3(0.0, 0.0, 0.0), vec3(0.0, 0.0, 0.0), color},
{vec3(1.0, 0.0, 0.0), vec3(1.0, 0.0, 0.0), color},
{vec3(1.0, 1.0, 0.0), vec3(1.0, 1.0, 0.0), color},
{vec3(0.0, 1.0, 0.0), vec3(0.0, 1.0, 0.0), color},
{vec3(0.0, 0.0, 1.0), vec3(0.0, 0.0, 1.0), color},
{vec3(1.0, 0.0, 1.0), vec3(1.0, 0.0, 1.0), color},
{vec3(1.0, 1.0, 1.0), vec3(1.0, 1.0, 1.0), color},
{vec3(0.0, 1.0, 1.0), vec3(0.0, 1.0, 1.0), color}});
auto inds1 = mesh->addIndexBuffer(DrawType::Lines, ConnectivityType::StripAdjacency);
inds1->add({3, 0, 1, 2, 3, 0, 1});
auto inds2 = mesh->addIndexBuffer(DrawType::Lines, ConnectivityType::StripAdjacency);
inds2->add({7, 4, 5, 6, 7, 4, 5});
auto inds3 = mesh->addIndexBuffer(DrawType::Lines, ConnectivityType::StripAdjacency);
inds3->add({3, 0, 4, 7, 3, 0, 4});
auto inds4 = mesh->addIndexBuffer(DrawType::Lines, ConnectivityType::StripAdjacency);
inds4->add({2, 1, 5, 6, 2, 1, 2});
return mesh;
}
Creating camera frustum
The following code snippet is another example where we create a camera frustum mesh for a given camera. It is the code used in meshutil::cameraFrustum
std::shared_ptr<ColoredMesh>
cameraFrustum(
const Camera& camera, vec4 color,
std::shared_ptr<ColoredMesh> mesh) {
const static std::vector<vec3> vertices{vec3(-1, -1, -1), vec3(-1, 1, -1), vec3(1, -1, -1),
vec3(1, 1, -1), vec3(-1, -1, 1), vec3(-1, 1, 1),
vec3(1, -1, 1), vec3(1, 1, 1)};
auto& vertVector = mesh->getTypedDataContainer<buffertraits::PositionsBuffer>();
auto& colorVector = mesh->getTypedDataContainer<buffertraits::ColorsBuffer>();
auto off = static_cast<unsigned int>(vertVector.size());
vertVector.insert(vertVector.end(), vertices.begin(), vertices.end());
colorVector.insert(colorVector.end(), 8, color);
mesh->setModelMatrix(glm::inverse(camera.getProjectionMatrix() * camera.getViewMatrix()));
auto ib = std::make_shared<IndexBufferRAM>();
auto indices = std::make_shared<IndexBuffer>(ib);
ib->add({off + 0, off + 1, off + 1, off + 3, off + 3, off + 2, off + 2, off + 0});
ib->add({off + 4, off + 5, off + 5, off + 7, off + 7, off + 6, off + 6, off + 4});
ib->add({off + 0, off + 4, off + 1, off + 5, off + 2, off + 6, off + 3, off + 7});
mesh->addIndicies(Mesh::MeshInfo(DrawType::Lines, ConnectivityType::None), indices);
return mesh;
}