6#ifndef MATERIALX_MESH_H
7#define MATERIALX_MESH_H
15MATERIALX_NAMESPACE_BEGIN
33 static const string POSITION_ATTRIBUTE;
34 static const string NORMAL_ATTRIBUTE;
35 static const string TEXCOORD_ATTRIBUTE;
36 static const string TANGENT_ATTRIBUTE;
37 static const string BITANGENT_ATTRIBUTE;
38 static const string COLOR_ATTRIBUTE;
39 static const string GEOMETRY_PROPERTY_ATTRIBUTE;
41 static const unsigned int STRIDE_2D = 2;
42 static const unsigned int STRIDE_3D = 3;
43 static const unsigned int STRIDE_4D = 4;
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.reserve(elementCount * (
size_t) _stride);
71 _data.resize(elementCount * (
size_t) _stride);
105 template <
class T> T& getElement(
size_t index)
107 return reinterpret_cast<T*
>(getData().data())[index];
111 template <
class T>
const T& getElement(
size_t index)
const
113 return reinterpret_cast<const T*
>(getData().data())[index];
131 return _data.size() / _stride;
142 unsigned int _stride;
163 return std::make_shared<MeshPartition>();
169 _indices.resize(indexCount);
188 _sourceNames.insert(val);
236using MeshMap = std::unordered_map<string, MeshPtr>;
243 Mesh(
const string& name);
249 return std::make_shared<Mesh>(name);
261 _sourceUri = sourceUri;
267 return !_sourceUri.empty();
281 for (
const auto& stream : _streams)
283 if (stream->getName() == name)
297 for (
const auto& stream : _streams)
299 if (stream->getType() == type &&
300 stream->getIndex() == index)
311 _streams.push_back(stream);
317 auto it = std::find(_streams.begin(), _streams.end(), stream);
318 if (it != _streams.end())
339 _minimumBounds = val;
345 return _minimumBounds;
357 return _maximumBounds;
369 return _sphereCenter;
381 return _sphereRadius;
387 return _partitions.size();
393 _partitions.push_back(partition);
399 return _partitions[partIndex];
444 vector<MeshPartitionPtr> _partitions;
447MATERIALX_NAMESPACE_END
std::set< string > StringSet
A set of strings.
Definition: Library.h:59
Macros for declaring imported and exported symbols.
vector< MeshStreamPtr > MeshStreamList
List of mesh streams.
Definition: Mesh.h:26
shared_ptr< class MeshStream > MeshStreamPtr
Shared pointer to a mesh stream.
Definition: Mesh.h:23
vector< float > MeshFloatBuffer
Float geometry buffer.
Definition: Mesh.h:20
vector< MeshPtr > MeshList
List of meshes.
Definition: Mesh.h:233
std::unordered_map< string, MeshPtr > MeshMap
Map from names to meshes.
Definition: Mesh.h:236
shared_ptr< class MeshPartition > MeshPartitionPtr
Shared pointer to a mesh partition.
Definition: Mesh.h:146
vector< uint32_t > MeshIndexBuffer
Geometry index buffer.
Definition: Mesh.h:18
shared_ptr< class Mesh > MeshPtr
Shared pointer to a mesh.
Definition: Mesh.h:230
A 4x4 matrix of floating-point values.
Definition: Types.h:656
Container for mesh data.
Definition: Mesh.h:241
static MeshPtr create(const string &name)
Create a new mesh.
Definition: Mesh.h:247
MeshStreamPtr generateTextureCoordinates(MeshStreamPtr positionStream)
Create texture coordinates from the given positions.
MeshStreamPtr generateBitangents(MeshStreamPtr normalStream, MeshStreamPtr tangentStream)
Generate bitangents from the given normals and tangents.
void setMinimumBounds(const Vector3 &val)
Set the minimum bounds for the geometry.
Definition: Mesh.h:337
size_t getVertexCount() const
Get vertex count.
Definition: Mesh.h:331
MeshStreamPtr generateTangents(MeshStreamPtr positionStream, MeshStreamPtr normalStream, MeshStreamPtr texcoordStream)
Generate tangents from the given positions, normals, and texture coordinates.
void setSphereCenter(const Vector3 &val)
Set center of the bounding sphere.
Definition: Mesh.h:361
bool hasSourceUri() const
Return true if this mesh has a source URI.
Definition: Mesh.h:265
void splitByUdims()
Split the mesh into a single partition per UDIM.
const string & getName() const
Return the name of this mesh.
Definition: Mesh.h:253
const Vector3 & getSphereCenter() const
Return center of the bounding sphere.
Definition: Mesh.h:367
void addPartition(MeshPartitionPtr partition)
Add a partition.
Definition: Mesh.h:391
MeshStreamPtr getStream(const string &name) const
Get a mesh stream by name.
Definition: Mesh.h:279
void setSphereRadius(float val)
Set radius of the bounding sphere.
Definition: Mesh.h:373
const string & getSourceUri() const
Return the mesh's source URI.
Definition: Mesh.h:271
const Vector3 & getMaximumBounds() const
Return the minimum bounds for the geometry.
Definition: Mesh.h:355
MeshPartitionPtr getPartition(size_t partIndex) const
Return a reference to a mesh partition.
Definition: Mesh.h:397
float getSphereRadius() const
Return radius of the bounding sphere.
Definition: Mesh.h:379
MeshStreamPtr generateNormals(MeshStreamPtr positionStream)
Generate face normals from the given positions.
void setMaximumBounds(const Vector3 &v)
Set the minimum bounds for the geometry.
Definition: Mesh.h:349
void mergePartitions()
Merge all mesh partitions into one.
void addStream(MeshStreamPtr stream)
Add a mesh stream.
Definition: Mesh.h:309
const Vector3 & getMinimumBounds() const
Return the minimum bounds for the geometry.
Definition: Mesh.h:343
MeshStreamPtr getStream(const string &type, unsigned int index) const
Get a mesh stream by type and index.
Definition: Mesh.h:295
void removeStream(MeshStreamPtr stream)
Remove a mesh stream.
Definition: Mesh.h:315
void setVertexCount(size_t val)
Set vertex count.
Definition: Mesh.h:325
void setSourceUri(const string &sourceUri)
Set the mesh's source URI.
Definition: Mesh.h:259
size_t getPartitionCount() const
Return the number of mesh partitions.
Definition: Mesh.h:385
Class that describes a sub-region of a mesh using vertex indexing.
Definition: Mesh.h:152
const StringSet & getSourceNames() const
Return the vector of source names, representing all partitions that were processed to generate this o...
Definition: Mesh.h:193
const string & getName() const
Return the name of this partition.
Definition: Mesh.h:179
void addSourceName(const string &val)
Add a source name, representing a partition that was processed to generate this one.
Definition: Mesh.h:186
void resize(size_t indexCount)
Resize data to the given number of indices.
Definition: Mesh.h:167
MeshIndexBuffer & getIndices()
Return indexing.
Definition: Mesh.h:199
void setFaceCount(size_t val)
Set face count.
Definition: Mesh.h:217
size_t getFaceCount() const
Return number of faces.
Definition: Mesh.h:211
static MeshPartitionPtr create()
Create a new mesh partition.
Definition: Mesh.h:161
const MeshIndexBuffer & getIndices() const
Return indexing.
Definition: Mesh.h:205
void setName(const string &val)
Set the name of this partition.
Definition: Mesh.h:173
Class to represent a mesh data stream.
Definition: Mesh.h:31
const string & getName() const
Get stream name.
Definition: Mesh.h:75
unsigned int getIndex() const
Get stream index.
Definition: Mesh.h:87
void reserve(size_t elementCount)
Reserve memory for a given number of elements.
Definition: Mesh.h:63
const string & getType() const
Get stream attribute name.
Definition: Mesh.h:81
unsigned int getStride() const
Get stride between elements.
Definition: Mesh.h:117
MeshFloatBuffer & getData()
Return the raw float vector.
Definition: Mesh.h:93
void setStride(unsigned int stride)
Set stride between elements.
Definition: Mesh.h:123
size_t getSize() const
Get the number of elements.
Definition: Mesh.h:129
const MeshFloatBuffer & getData() const
Return the raw float vector.
Definition: Mesh.h:99
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:69
void transform(const Matrix44 &matrix)
Transform elements by a matrix.
A vector of three floating-point values.
Definition: Types.h:306