6#ifndef MATERIALX_MESH_H
7#define MATERIALX_MESH_H
34 static const string POSITION_ATTRIBUTE;
35 static const string NORMAL_ATTRIBUTE;
36 static const string TEXCOORD_ATTRIBUTE;
37 static const string TANGENT_ATTRIBUTE;
38 static const string BITANGENT_ATTRIBUTE;
39 static const string COLOR_ATTRIBUTE;
40 static const string GEOMETRY_PROPERTY_ATTRIBUTE;
42 static const unsigned int STRIDE_3D = 3;
43 static const unsigned int STRIDE_2D = 2;
44 static const unsigned int DEFAULT_STRIDE = STRIDE_3D;
47 MeshStream(
const string& name,
const string& type,
unsigned int index) :
51 _stride(DEFAULT_STRIDE)
59 return std::make_shared<MeshStream>(name, type, index);
65 _data.resize(elementCount * (
size_t) _stride);
99 template <
class T> T& getElement(
size_t index)
101 return reinterpret_cast<T*
>(getData().data())[index];
105 template <
class T>
const T& getElement(
size_t index)
const
107 return reinterpret_cast<const T*
>(getData().data())[index];
122 size_t getSize()
const
127 void transform(
const Matrix44 &matrix);
133 MeshFloatBuffer _data;
134 unsigned int _stride;
155 return std::make_shared<MeshPartition>();
161 _indices.resize(indexCount);
213using MeshMap = std::unordered_map<string, MeshPtr>;
220 Mesh(
const string& identifier);
226 return std::make_shared<Mesh>(identifier);
238 _sourceUri = sourceUri;
244 return !_sourceUri.empty();
258 for (
const auto& stream : _streams)
260 if (stream->getName() == name)
274 for (
const auto& stream : _streams)
276 if (stream->getType() == type &&
277 stream->getIndex() == index)
288 _streams.push_back(stream);
294 auto it = std::find(_streams.begin(), _streams.end(), stream);
295 if (it != _streams.end())
316 _minimumBounds = val;
322 return _minimumBounds;
334 return _maximumBounds;
346 return _sphereCenter;
358 return _sphereRadius;
364 return _partitions.size();
370 _partitions.push_back(partition);
376 return _partitions[partIndex];
392 void mergePartitions();
409 vector<MeshPartitionPtr> _partitions;
Macros for declaring imported and exported symbols.
vector< MeshStreamPtr > MeshStreamList
List of mesh streams.
Definition: Mesh.h:27
shared_ptr< class MeshStream > MeshStreamPtr
Shared pointer to a mesh stream.
Definition: Mesh.h:24
vector< float > MeshFloatBuffer
Float geometry buffer.
Definition: Mesh.h:21
vector< MeshPtr > MeshList
List of meshes.
Definition: Mesh.h:210
std::unordered_map< string, MeshPtr > MeshMap
Map from names to meshes.
Definition: Mesh.h:213
shared_ptr< class MeshPartition > MeshPartitionPtr
Shared pointer to a mesh partition.
Definition: Mesh.h:138
vector< uint32_t > MeshIndexBuffer
Geometry index buffer.
Definition: Mesh.h:19
shared_ptr< class Mesh > MeshPtr
Shared pointer to a mesh.
Definition: Mesh.h:207
Container for mesh data.
Definition: Mesh.h:218
void setMinimumBounds(const Vector3 &val)
Set the minimum bounds for the geometry.
Definition: Mesh.h:314
size_t getVertexCount() const
Get vertex count.
Definition: Mesh.h:308
void setSphereCenter(const Vector3 &val)
Set center of the bounding sphere.
Definition: Mesh.h:338
bool hasSourceUri() const
Return true if this mesh has a source URI.
Definition: Mesh.h:242
const Vector3 & getSphereCenter() const
Return center of the bounding sphere.
Definition: Mesh.h:344
void addPartition(MeshPartitionPtr partition)
Add a partition.
Definition: Mesh.h:368
MeshStreamPtr getStream(const string &name) const
Get a mesh stream by name.
Definition: Mesh.h:256
void setSphereRadius(float val)
Set radius of the bounding sphere.
Definition: Mesh.h:350
const string & getSourceUri() const
Return the mesh's source URI.
Definition: Mesh.h:248
const Vector3 & getMaximumBounds() const
Return the minimum bounds for the geometry.
Definition: Mesh.h:332
MeshPartitionPtr getPartition(size_t partIndex) const
Return a reference to a mesh partition.
Definition: Mesh.h:374
const string & getIdentifier() const
Get mesh identifier.
Definition: Mesh.h:230
float getSphereRadius() const
Return radius of the bounding sphere.
Definition: Mesh.h:356
void setMaximumBounds(const Vector3 &v)
Set the minimum bounds for the geometry.
Definition: Mesh.h:326
static MeshPtr create(const string &identifier)
Create a new mesh.
Definition: Mesh.h:224
void addStream(MeshStreamPtr stream)
Add a mesh stream.
Definition: Mesh.h:286
const Vector3 & getMinimumBounds() const
Return the minimum bounds for the geometry.
Definition: Mesh.h:320
MeshStreamPtr getStream(const string &type, unsigned int index) const
Get a mesh stream by type and index.
Definition: Mesh.h:272
void removeStream(MeshStreamPtr stream)
Remove a mesh stream.
Definition: Mesh.h:292
void setVertexCount(size_t val)
Set vertex count.
Definition: Mesh.h:302
void setSourceUri(const string &sourceUri)
Set the mesh's source URI.
Definition: Mesh.h:236
size_t getPartitionCount() const
Return the number of mesh partitions.
Definition: Mesh.h:362
Class that describes a sub-region of a mesh using vertex indexing.
Definition: Mesh.h:144
const string & getIdentifier() const
Get geometry identifier.
Definition: Mesh.h:165
void resize(size_t indexCount)
Resize data to the given number of indices.
Definition: Mesh.h:159
MeshIndexBuffer & getIndices()
Return indexing.
Definition: Mesh.h:177
void setFaceCount(size_t val)
Set face count.
Definition: Mesh.h:195
void setIdentifier(const string &val)
Set geometry identifier.
Definition: Mesh.h:171
size_t getFaceCount() const
Return number of faces.
Definition: Mesh.h:189
static MeshPartitionPtr create()
Create a new mesh partition.
Definition: Mesh.h:153
const MeshIndexBuffer & getIndices() const
Return indexing.
Definition: Mesh.h:183
Class to represent a mesh data stream.
Definition: Mesh.h:32
const string & getName() const
Get stream name.
Definition: Mesh.h:69
unsigned int getIndex() const
Get stream index.
Definition: Mesh.h:81
const string & getType() const
Get stream attribute name.
Definition: Mesh.h:75
unsigned int getStride() const
Get stride between elements.
Definition: Mesh.h:111
MeshFloatBuffer & getData()
Return the raw float vector.
Definition: Mesh.h:87
void setStride(unsigned int stride)
Set stride between elements.
Definition: Mesh.h:117
const MeshFloatBuffer & getData() const
Return the raw float vector.
Definition: Mesh.h:93
static MeshStreamPtr create(const string &name, const string &type, unsigned int index=0)
Create a new mesh stream.
Definition: Mesh.h:57
void resize(size_t elementCount)
Resize data to an given number of elements.
Definition: Mesh.h:63
A vector of three floating-point values.
Definition: Types.h:303