6#ifndef MATERIALX_TYPES_H
7#define MATERIALX_TYPES_H
19MATERIALX_NAMESPACE_BEGIN
21extern MX_CORE_API
const string DEFAULT_TYPE_STRING;
22extern MX_CORE_API
const string FILENAME_TYPE_STRING;
23extern MX_CORE_API
const string GEOMNAME_TYPE_STRING;
24extern MX_CORE_API
const string STRING_TYPE_STRING;
25extern MX_CORE_API
const string BSDF_TYPE_STRING;
26extern MX_CORE_API
const string EDF_TYPE_STRING;
27extern MX_CORE_API
const string VDF_TYPE_STRING;
28extern MX_CORE_API
const string SURFACE_SHADER_TYPE_STRING;
29extern MX_CORE_API
const string DISPLACEMENT_SHADER_TYPE_STRING;
30extern MX_CORE_API
const string VOLUME_SHADER_TYPE_STRING;
31extern MX_CORE_API
const string LIGHT_SHADER_TYPE_STRING;
32extern MX_CORE_API
const string MATERIAL_TYPE_STRING;
33extern MX_CORE_API
const string SURFACE_MATERIAL_NODE_STRING;
34extern MX_CORE_API
const string VOLUME_MATERIAL_NODE_STRING;
35extern MX_CORE_API
const string MULTI_OUTPUT_TYPE_STRING;
36extern MX_CORE_API
const string NONE_TYPE_STRING;
37extern MX_CORE_API
const string VALUE_STRING_TRUE;
38extern MX_CORE_API
const string VALUE_STRING_FALSE;
39extern MX_CORE_API
const string NAME_PREFIX_SEPARATOR;
40extern MX_CORE_API
const string NAME_PATH_SEPARATOR;
41extern MX_CORE_API
const string ARRAY_VALID_SEPARATORS;
42extern MX_CORE_API
const string ARRAY_PREFERRED_SEPARATOR;
55template <
class V,
class S,
size_t N>
class VectorN :
public VectorBase
58 using Iterator =
typename std::array<S, N>::iterator;
59 using ConstIterator =
typename std::array<S, N>::const_iterator;
62 VectorN() : _arr{} { }
63 explicit VectorN(
Uninit) { }
64 explicit VectorN(S s) { _arr.fill(s); }
65 explicit VectorN(
const std::array<S, N>& arr) : _arr(arr) { }
66 explicit VectorN(
const vector<S>& vec) { std::copy(vec.begin(), vec.end(), _arr.begin()); }
67 explicit VectorN(
const S* begin,
const S* end) { std::copy(begin, end, _arr.begin()); }
73 bool operator==(
const V& rhs)
const {
return _arr == rhs._arr; }
76 bool operator!=(
const V& rhs)
const {
return _arr != rhs._arr; }
81 return _arr < rhs._arr;
92 const S&
operator[](
size_t i)
const {
return _arr.at(i); }
102 for (
size_t i = 0; i < N; i++)
103 res[i] = _arr[i] + rhs[i];
110 for (
size_t i = 0; i < N; i++)
119 for (
size_t i = 0; i < N; i++)
120 res[i] = _arr[i] - rhs[i];
127 for (
size_t i = 0; i < N; i++)
136 for (
size_t i = 0; i < N; i++)
137 res[i] = _arr[i] * rhs[i];
144 for (
size_t i = 0; i < N; i++)
153 for (
size_t i = 0; i < N; i++)
154 res[i] = _arr[i] / rhs[i];
161 for (
size_t i = 0; i < N; i++)
170 for (
size_t i = 0; i < N; i++)
171 res[i] = _arr[i] * s;
178 for (
size_t i = 0; i < N; i++)
187 for (
size_t i = 0; i < N; i++)
188 res[i] = _arr[i] / s;
195 for (
size_t i = 0; i < N; i++)
204 for (
size_t i = 0; i < N; i++)
217 for (
size_t i = 0; i < N; i++)
218 res += _arr[i] * _arr[i];
219 return std::sqrt(res);
232 for (
size_t i = 0; i < N; i++)
233 res += _arr[i] * rhs[i];
241 Iterator begin() {
return _arr.begin(); }
242 ConstIterator begin()
const {
return _arr.begin(); }
244 Iterator end() {
return _arr.end(); }
245 ConstIterator end()
const {
return _arr.end(); }
252 S*
data() {
return _arr.data(); }
255 const S*
data()
const {
return _arr.data(); }
261 size_t operator()(
const V& v)
const noexcept
264 for (
size_t i = 0; i < N; i++)
280 std::array<S, N> _arr;
285class MX_CORE_API Vector2 :
public VectorN<Vector2, float, 2>
288 using VectorN<Vector2, float, 2>::VectorN;
290 Vector2(
float x,
float y) :
297 float cross(
const Vector2& rhs)
const
299 return _arr[0] * rhs[1] - _arr[1] * rhs[0];
305class MX_CORE_API Vector3 :
public VectorN<Vector3, float, 3>
308 using VectorN<Vector3, float, 3>::VectorN;
310 Vector3(
float x,
float y,
float z) :
317 Vector3
cross(
const Vector3& rhs)
const
319 return Vector3(_arr[1] * rhs[2] - _arr[2] * rhs[1],
320 _arr[2] * rhs[0] - _arr[0] * rhs[2],
321 _arr[0] * rhs[1] - _arr[1] * rhs[0]);
327class MX_CORE_API Vector4 :
public VectorN<Vector4, float, 4>
330 using VectorN<Vector4, float, 4>::VectorN;
332 Vector4(
float x,
float y,
float z,
float w) :
335 _arr = { x, y, z, w };
341class MX_CORE_API Color3 :
public VectorN<Color3, float, 3>
344 using VectorN<Color3, float, 3>::VectorN;
346 Color3(
float r,
float g,
float b) :
363class MX_CORE_API Color4 :
public VectorN<Color4, float, 4>
366 using VectorN<Color4, float, 4>::VectorN;
368 Color4(
float r,
float g,
float b,
float a) :
371 _arr = { r, g, b, a };
386template <
class M,
class S,
size_t N>
class MatrixN :
public MatrixBase
389 using RowArray =
typename std::array<S, N>;
390 using Iterator =
typename std::array<RowArray, N>::iterator;
391 using ConstIterator =
typename std::array<RowArray, N>::const_iterator;
394 MatrixN() : _arr{} { }
395 explicit MatrixN(
Uninit) { }
396 explicit MatrixN(S s) { std::fill_n(&_arr[0][0], N * N, s); }
397 explicit MatrixN(
const S* begin,
const S* end) { std::copy(begin, end, &_arr[0][0]); }
403 bool operator==(
const M& rhs)
const {
return _arr == rhs._arr; }
406 bool operator!=(
const M& rhs)
const {
return _arr != rhs._arr; }
412 for (
size_t i = 0; i < N; i++)
414 for (
size_t j = 0; j < N; j++)
416 if (std::abs(_arr[i][j] - rhs[i][j]) > tolerance)
433 const RowArray&
operator[](
size_t i)
const {
return _arr.at(i); }
443 for (
size_t i = 0; i < N; i++)
444 for (
size_t j = 0; j < N; j++)
445 res[i][j] = _arr[i][j] + rhs[i][j];
460 for (
size_t i = 0; i < N; i++)
461 for (
size_t j = 0; j < N; j++)
462 res[i][j] = _arr[i][j] - rhs[i][j];
477 for (
size_t i = 0; i < N; i++)
478 for (
size_t j = 0; j < N; j++)
479 res[i][j] = _arr[i][j] * s;
494 for (
size_t i = 0; i < N; i++)
495 for (
size_t j = 0; j < N; j++)
496 res[i][j] = _arr[i][j] / s;
515 for (
size_t i = 0; i < N; i++)
516 for (
size_t j = 0; j < N; j++)
517 for (
size_t k = 0; k < N; k++)
518 res[i][j] += _arr[i][k] * rhs[k][j];
533 return *
this * rhs.getInverse();
540 *
this *= rhs.getInverse();
548 Iterator begin() {
return _arr.begin(); }
549 ConstIterator begin()
const {
return _arr.begin(); }
551 Iterator end() {
return _arr.end(); }
552 ConstIterator end()
const {
return _arr.end(); }
559 S*
data() {
return _arr.front().data(); }
562 const S*
data()
const {
return _arr.front().data(); }
569 static constexpr size_t numRows() {
return N; }
577 std::array<RowArray, N> _arr;
585class MX_CORE_API Matrix33 :
public MatrixN<Matrix33, float, 3>
588 using MatrixN<Matrix33, float, 3>::MatrixN;
589 Matrix33() =
default;
590 Matrix33(
float m00,
float m01,
float m02,
591 float m10,
float m11,
float m12,
592 float m20,
float m21,
float m22) :
595 _arr = { RowArray{ m00, m01, m02 },
596 RowArray{ m10, m11, m12 },
597 RowArray{ m20, m21, m22 } };
647 static const Matrix33 IDENTITY;
655class MX_CORE_API Matrix44 :
public MatrixN<Matrix44, float, 4>
658 using MatrixN<Matrix44, float, 4>::MatrixN;
659 Matrix44() =
default;
660 Matrix44(
float m00,
float m01,
float m02,
float m03,
661 float m10,
float m11,
float m12,
float m13,
662 float m20,
float m21,
float m22,
float m23,
663 float m30,
float m31,
float m32,
float m33) :
666 _arr = { RowArray{ m00, m01, m02, m03 },
667 RowArray{ m10, m11, m12, m13 },
668 RowArray{ m20, m21, m22, m23 },
669 RowArray{ m30, m31, m32, m33 } };
727 static const Matrix44 IDENTITY;
730MATERIALX_NAMESPACE_END
Import and export declarations for the Core library.
void hashCombine(size_t &seed, const T &value)
Combine the hash of a value with an existing seed.
Definition Util.h:58
Color3 srgbToLinear() const
Transform the given color from the sRGB encoding to linear RGB, returning the result as a new value.
Color3 linearToSrgb() const
Transform the given color from linear RGB to the sRGB encoding, returning the result as a new value.
Matrix33 getAdjugate() const
Return the adjugate of the matrix.
static Matrix33 createTranslation(const Vector2 &v)
Create a translation matrix.
static Matrix33 createRotation(float angle)
Create a rotation matrix.
Matrix33 getInverse() const
Return the inverse of the matrix.
Definition Types.h:613
Vector3 transformNormal(const Vector3 &v) const
Transform the given 3D normal vector.
float getDeterminant() const
Return the determinant of the matrix.
Vector2 transformVector(const Vector2 &v) const
Transform the given 2D direction vector.
Vector3 multiply(const Vector3 &v) const
Return the product of this matrix and a 3D vector.
Matrix33 getTranspose() const
Return the transpose of the matrix.
static Matrix33 createScale(const Vector2 &v)
Create a scale matrix.
Vector2 transformPoint(const Vector2 &v) const
Transform the given 2D point.
Vector4 multiply(const Vector4 &v) const
Return the product of this matrix and a 4D vector.
static Matrix44 createScale(const Vector3 &v)
Create a scale matrix.
Vector3 transformPoint(const Vector3 &v) const
Transform the given 3D point.
static Matrix44 createRotationX(float angle)
Create a rotation matrix about the X-axis.
static Matrix44 createTranslation(const Vector3 &v)
Create a translation matrix.
static Matrix44 createRotationY(float angle)
Create a rotation matrix about the Y-axis.
Vector3 transformVector(const Vector3 &v) const
Transform the given 3D direction vector.
Matrix44 getAdjugate() const
Return the adjugate of the matrix.
static Matrix44 createRotationZ(float angle)
Create a rotation matrix about the Z-axis.
Vector3 transformNormal(const Vector3 &v) const
Transform the given 3D normal vector.
float getDeterminant() const
Return the determinant of the matrix.
Matrix44 getInverse() const
Return the inverse of the matrix.
Definition Types.h:685
Matrix44 getTranspose() const
Return the transpose of the matrix.
The base class for square matrices of scalar values.
Definition Types.h:376
M operator/(const M &rhs) const
Divide the first matrix by the second (computed as the product of the first matrix and the inverse of...
Definition Types.h:531
MatrixN & operator/=(S s)
Component-wise division of a matrix by a scalar.
Definition Types.h:501
MatrixN & operator*=(const M &rhs)
Compute the matrix product.
Definition Types.h:523
MatrixN & operator/=(const M &rhs)
Divide the first matrix by the second (computed as the product of the first matrix and the inverse of...
Definition Types.h:538
static constexpr size_t numRows()
Return the number of rows in this matrix.
Definition Types.h:569
MatrixN & operator*=(S s)
Component-wise multiplication of a matrix and a scalar.
Definition Types.h:484
const S * data() const
Return a const pointer to the underlying data array.
Definition Types.h:562
RowArray & operator[](size_t i)
Return the row array at the given index.
Definition Types.h:430
const RowArray & operator[](size_t i) const
Return the const row array at the given index.
Definition Types.h:433
M operator-(const M &rhs) const
Component-wise subtraction of two matrices.
Definition Types.h:457
static constexpr size_t numColumns()
Return the number of columns in this matrix.
Definition Types.h:572
MatrixN & operator+=(const M &rhs)
Component-wise addition of two matrices.
Definition Types.h:450
M operator+(const M &rhs) const
Component-wise addition of two matrices.
Definition Types.h:440
M operator/(S s) const
Component-wise division of a matrix by a scalar.
Definition Types.h:491
bool operator==(const M &rhs) const
Return true if the given matrix is identical to this one.
Definition Types.h:403
MatrixN & operator-=(const M &rhs)
Component-wise subtraction of two matrices.
Definition Types.h:467
M operator*(S s) const
Component-wise multiplication of a matrix and a scalar.
Definition Types.h:474
M operator*(const M &rhs) const
Compute the matrix product.
Definition Types.h:512
bool operator!=(const M &rhs) const
Return true if the given matrix differs from this one.
Definition Types.h:406
S * data()
Return a pointer to the underlying data array.
Definition Types.h:559
bool isEquivalent(const M &rhs, S tolerance) const
Return true if the given matrix is equivalent to this one within a given floating-point tolerance.
Definition Types.h:410
A tag class for constructing vectors and matrices without initialization.
Definition Types.h:48
A vector of two floating-point values.
Definition Types.h:286
float cross(const Vector2 &rhs) const
Return the cross product of two vectors.
Definition Types.h:297
A vector of three floating-point values.
Definition Types.h:306
Vector3 cross(const Vector3 &rhs) const
Return the cross product of two vectors.
Definition Types.h:317
A vector of four floating-point values.
Definition Types.h:328
The base class for vectors of scalar values.
Definition Types.h:45
Function object for hashing vectors.
Definition Types.h:259
VectorN & operator+=(const V &rhs)
Component-wise addition of two vectors.
Definition Types.h:108
bool operator!=(const V &rhs) const
Return true if the given vector differs from this one.
Definition Types.h:76
V operator*(S s) const
Component-wise multiplication of a vector by a scalar.
Definition Types.h:167
V operator+(const V &rhs) const
Component-wise addition of two vectors.
Definition Types.h:99
V operator-() const
Unary negation of a vector.
Definition Types.h:201
const S * data() const
Return a const pointer to the underlying data array.
Definition Types.h:255
VectorN & operator*=(S s)
Component-wise multiplication of a vector by a scalar.
Definition Types.h:176
V operator*(const V &rhs) const
Component-wise multiplication of two vectors.
Definition Types.h:133
V operator/(const V &rhs) const
Component-wise division of two vectors.
Definition Types.h:150
const S & operator[](size_t i) const
Return the const scalar value at the given index.
Definition Types.h:92
VectorN & operator*=(const V &rhs)
Component-wise multiplication of two vectors.
Definition Types.h:142
V operator/(S s) const
Component-wise division of a vector by a scalar.
Definition Types.h:184
bool operator<(const V &rhs) const
Compare two vectors lexicographically.
Definition Types.h:79
bool operator==(const V &rhs) const
Return true if the given vector is identical to this one.
Definition Types.h:73
VectorN & operator-=(const V &rhs)
Component-wise subtraction of two vectors.
Definition Types.h:125
V getNormalized() const
Return a normalized vector.
Definition Types.h:223
S dot(const V &rhs) const
Return the dot product of two vectors.
Definition Types.h:229
V operator-(const V &rhs) const
Component-wise subtraction of two vectors.
Definition Types.h:116
S & operator[](size_t i)
Return the scalar value at the given index.
Definition Types.h:89
static constexpr size_t numElements()
Return the number of scalar elements for the vector.
Definition Types.h:275
S getMagnitude() const
Return the magnitude of the vector.
Definition Types.h:214
VectorN & operator/=(const V &rhs)
Component-wise division of two vectors.
Definition Types.h:159
VectorN & operator/=(S s)
Component-wise division of a vector by a scalar.
Definition Types.h:193
S * data()
Return a pointer to the underlying data array.
Definition Types.h:252