6#ifndef MATERIALX_TYPES_H
7#define MATERIALX_TYPES_H
22extern MX_CORE_API
const string DEFAULT_TYPE_STRING;
23extern MX_CORE_API
const string FILENAME_TYPE_STRING;
24extern MX_CORE_API
const string GEOMNAME_TYPE_STRING;
25extern MX_CORE_API
const string STRING_TYPE_STRING;
26extern MX_CORE_API
const string SURFACE_SHADER_TYPE_STRING;
27extern MX_CORE_API
const string DISPLACEMENT_SHADER_TYPE_STRING;
28extern MX_CORE_API
const string VOLUME_SHADER_TYPE_STRING;
29extern MX_CORE_API
const string LIGHT_SHADER_TYPE_STRING;
30extern MX_CORE_API
const string MATERIAL_TYPE_STRING;
31extern MX_CORE_API
const string SURFACE_MATERIAL_NODE_STRING;
32extern MX_CORE_API
const string VOLUME_MATERIAL_NODE_STRING;
33extern MX_CORE_API
const string MULTI_OUTPUT_TYPE_STRING;
34extern MX_CORE_API
const string NONE_TYPE_STRING;
35extern MX_CORE_API
const string VALUE_STRING_TRUE;
36extern MX_CORE_API
const string VALUE_STRING_FALSE;
37extern MX_CORE_API
const string NAME_PREFIX_SEPARATOR;
38extern MX_CORE_API
const string NAME_PATH_SEPARATOR;
39extern MX_CORE_API
const string ARRAY_VALID_SEPARATORS;
40extern MX_CORE_API
const string ARRAY_PREFERRED_SEPARATOR;
56 using Iterator =
typename std::array<S, N>::iterator;
57 using ConstIterator =
typename std::array<S, N>::const_iterator;
62 explicit VectorN(S s) { _arr.fill(s); }
63 explicit VectorN(
const std::array<S, N>& arr) : _arr(arr) { }
64 explicit VectorN(
const vector<S>& vec) { std::copy(vec.begin(), vec.end(), _arr.begin()); }
65 explicit VectorN(
const S* begin,
const S* end) { std::copy(begin, end, _arr.begin()); }
71 bool operator==(
const V& rhs)
const {
return _arr == rhs._arr; }
74 bool operator!=(
const V& rhs)
const {
return _arr != rhs._arr; }
79 return _arr < rhs._arr;
90 const S&
operator[](
size_t i)
const {
return _arr.at(i); }
100 for (
size_t i = 0; i < N; i++)
101 res[i] = _arr[i] + rhs[i];
108 for (
size_t i = 0; i < N; i++)
117 for (
size_t i = 0; i < N; i++)
118 res[i] = _arr[i] - rhs[i];
125 for (
size_t i = 0; i < N; i++)
134 for (
size_t i = 0; i < N; i++)
135 res[i] = _arr[i] * rhs[i];
142 for (
size_t i = 0; i < N; i++)
151 for (
size_t i = 0; i < N; i++)
152 res[i] = _arr[i] / rhs[i];
159 for (
size_t i = 0; i < N; i++)
168 for (
size_t i = 0; i < N; i++)
169 res[i] = _arr[i] * s;
176 for (
size_t i = 0; i < N; i++)
185 for (
size_t i = 0; i < N; i++)
186 res[i] = _arr[i] / s;
193 for (
size_t i = 0; i < N; i++)
202 for (
size_t i = 0; i < N; i++)
215 for (
size_t i = 0; i < N; i++)
216 res += _arr[i] * _arr[i];
217 return std::sqrt(res);
230 for (
size_t i = 0; i < N; i++)
231 res += _arr[i] * rhs[i];
239 Iterator begin() {
return _arr.begin(); }
240 ConstIterator begin()
const {
return _arr.begin(); }
242 Iterator end() {
return _arr.end(); }
243 ConstIterator end()
const {
return _arr.end(); }
250 S*
data() {
return _arr.data(); }
253 const S*
data()
const {
return _arr.data(); }
259 size_t operator()(
const V& v)
const noexcept
262 for (
size_t i = 0; i < N; i++)
278 std::array<S, N> _arr;
296 return _arr[0] * rhs[1] - _arr[1] * rhs[0];
315 return Vector3(_arr[1] * rhs[2] - _arr[2] * rhs[1],
316 _arr[2] * rhs[0] - _arr[0] * rhs[2],
317 _arr[0] * rhs[1] - _arr[1] * rhs[0]);
350 _arr[0] * q._arr[3] + _arr[3] * q._arr[0] + _arr[1] * q._arr[2] - _arr[2] * q._arr[1],
351 _arr[1] * q._arr[3] + _arr[3] * q._arr[1] + _arr[2] * q._arr[0] - _arr[0] * q._arr[2],
352 _arr[2] * q._arr[3] + _arr[3] * q._arr[2] + _arr[0] * q._arr[1] - _arr[1] * q._arr[0],
353 _arr[3] * q._arr[3] - _arr[0] * q._arr[0] - _arr[1] * q._arr[1] - _arr[2] * q._arr[2]
359 float l = 1.f / getMagnitude() * (_arr[3] < 0 ? -1.f : 1.f);
360 return { _arr[0] * l, _arr[1] * l, _arr[2] * l, _arr[3] * l };
365 float s = std::sin(a * 0.5f);
366 return Quaternion(v[0] * s, v[1] * s, v[2] * s, std::cos(a * 0.5f));
413 using RowArray =
typename std::array<S, N>;
414 using Iterator =
typename std::array<RowArray, N>::iterator;
415 using ConstIterator =
typename std::array<RowArray, N>::const_iterator;
420 explicit MatrixN(S s) { std::fill_n(&_arr[0][0], N * N, s); }
421 explicit MatrixN(
const S* begin,
const S* end) { std::copy(begin, end, &_arr[0][0]); }
427 bool operator==(
const M& rhs)
const {
return _arr == rhs._arr; }
430 bool operator!=(
const M& rhs)
const {
return _arr != rhs._arr; }
436 for (
size_t i = 0; i < N; i++)
438 for (
size_t j = 0; j < N; j++)
440 if (std::abs(_arr[i][j] - rhs[i][j]) > tolerance)
457 const RowArray&
operator[](
size_t i)
const {
return _arr.at(i); }
467 for (
size_t i = 0; i < N; i++)
468 for (
size_t j = 0; j < N; j++)
469 res[i][j] = _arr[i][j] + rhs[i][j];
484 for (
size_t i = 0; i < N; i++)
485 for (
size_t j = 0; j < N; j++)
486 res[i][j] = _arr[i][j] - rhs[i][j];
501 for (
size_t i = 0; i < N; i++)
502 for (
size_t j = 0; j < N; j++)
503 res[i][j] = _arr[i][j] * s;
518 for (
size_t i = 0; i < N; i++)
519 for (
size_t j = 0; j < N; j++)
520 res[i][j] = _arr[i][j] / s;
539 for (
size_t i = 0; i < N; i++)
540 for (
size_t j = 0; j < N; j++)
541 for (
size_t k = 0; k < N; k++)
542 res[i][j] += _arr[i][k] * rhs[k][j];
557 return *
this * rhs.getInverse();
587 Iterator begin() {
return _arr.begin(); }
588 ConstIterator begin()
const {
return _arr.begin(); }
590 Iterator end() {
return _arr.end(); }
591 ConstIterator end()
const {
return _arr.end(); }
598 S*
data() {
return _arr.front().data(); }
601 const S*
data()
const {
return _arr.front().data(); }
608 static constexpr size_t numRows() {
return N; }
616 std::array<RowArray, N> _arr;
629 Matrix33(
float m00,
float m01,
float m02,
630 float m10,
float m11,
float m12,
631 float m20,
float m21,
float m22) :
634 _arr = {m00, m01, m02,
662 static Matrix33 createRotation(
float angle);
680 Matrix44(
float m00,
float m01,
float m02,
float m03,
681 float m10,
float m11,
float m12,
float m13,
682 float m20,
float m21,
float m22,
float m23,
683 float m30,
float m31,
float m32,
float m33) :
686 _arr = {m00, m01, m02, m03,
715 static Matrix44 createRotationX(
float angle);
719 static Matrix44 createRotationY(
float angle);
723 static Matrix44 createRotationZ(
float angle);
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:52
A three-component color value.
Definition: Types.h:376
A four-component color value.
Definition: Types.h:389
A 3x3 matrix of floating-point values.
Definition: Types.h:625
A 4x4 matrix of floating-point values.
Definition: Types.h:676
The base class for square matrices of scalar values.
Definition: Types.h:400
The class template for square matrices of scalar values.
Definition: Types.h:411
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:555
MatrixN & operator/=(S s)
Component-wise division of a matrix by a scalar.
Definition: Types.h:525
MatrixN & operator*=(const M &rhs)
Compute the matrix product.
Definition: Types.h:547
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:562
M getAdjugate() const
Return the adjugate of the matrix.
static constexpr size_t numRows()
Return the number of rows in this matrix.
Definition: Types.h:608
MatrixN & operator*=(S s)
Component-wise multiplication of a matrix and a scalar.
Definition: Types.h:508
const S * data() const
Return a const pointer to the underlying data array.
Definition: Types.h:601
RowArray & operator[](size_t i)
Return the row array at the given index.
Definition: Types.h:454
const RowArray & operator[](size_t i) const
Return the const row array at the given index.
Definition: Types.h:457
M getTranspose() const
Return the transpose of the matrix.
M operator-(const M &rhs) const
Component-wise subtraction of two matrices.
Definition: Types.h:481
static constexpr size_t numColumns()
Return the number of columns in this matrix.
Definition: Types.h:611
M getInverse() const
Return the inverse of the matrix.
Definition: Types.h:578
MatrixN & operator+=(const M &rhs)
Component-wise addition of two matrices.
Definition: Types.h:474
M operator+(const M &rhs) const
Component-wise addition of two matrices.
Definition: Types.h:464
M operator/(S s) const
Component-wise division of a matrix by a scalar.
Definition: Types.h:515
bool operator==(const M &rhs) const
Return true if the given matrix is identical to this one.
Definition: Types.h:427
MatrixN & operator-=(const M &rhs)
Component-wise subtraction of two matrices.
Definition: Types.h:491
M operator*(S s) const
Component-wise multiplication of a matrix and a scalar.
Definition: Types.h:498
S getDeterminant() const
Return the determinant of the matrix.
M operator*(const M &rhs) const
Compute the matrix product.
Definition: Types.h:536
bool operator!=(const M &rhs) const
Return true if the given matrix differs from this one.
Definition: Types.h:430
S * data()
Return a pointer to the underlying data array.
Definition: Types.h:598
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:434
A quaternion vector.
Definition: Types.h:337
A tag class for constructing vectors and matrices without initialization.
Definition: Types.h:46
A vector of two floating-point values.
Definition: Types.h:284
float cross(const Vector2 &rhs) const
Return the cross product of two vectors.
Definition: Types.h:294
A vector of three floating-point values.
Definition: Types.h:303
Vector3 cross(const Vector3 &rhs) const
Return the cross product of two vectors.
Definition: Types.h:313
A vector of four floating-point values.
Definition: Types.h:324
The base class for vectors of scalar values.
Definition: Types.h:43
Function object for hashing vectors.
Definition: Types.h:257
The class template for vectors of scalar values.
Definition: Types.h:54
VectorN & operator+=(const V &rhs)
Component-wise addition of two vectors.
Definition: Types.h:106
bool operator!=(const V &rhs) const
Return true if the given vector differs from this one.
Definition: Types.h:74
V operator*(S s) const
Component-wise multiplication of a vector by a scalar.
Definition: Types.h:165
V operator+(const V &rhs) const
Component-wise addition of two vectors.
Definition: Types.h:97
V operator-() const
Unary negation of a vector.
Definition: Types.h:199
const S * data() const
Return a const pointer to the underlying data array.
Definition: Types.h:253
VectorN & operator*=(S s)
Component-wise multiplication of a vector by a scalar.
Definition: Types.h:174
V operator*(const V &rhs) const
Component-wise multiplication of two vectors.
Definition: Types.h:131
V operator/(const V &rhs) const
Component-wise division of two vectors.
Definition: Types.h:148
const S & operator[](size_t i) const
Return the const scalar value at the given index.
Definition: Types.h:90
VectorN & operator*=(const V &rhs)
Component-wise multiplication of two vectors.
Definition: Types.h:140
V operator/(S s) const
Component-wise division of a vector by a scalar.
Definition: Types.h:182
bool operator<(const V &rhs) const
Compare two vectors lexicographically.
Definition: Types.h:77
bool operator==(const V &rhs) const
Return true if the given vector is identical to this one.
Definition: Types.h:71
VectorN & operator-=(const V &rhs)
Component-wise subtraction of two vectors.
Definition: Types.h:123
V getNormalized() const
Return a normalized vector.
Definition: Types.h:221
S dot(const V &rhs) const
Return the dot product of two vectors.
Definition: Types.h:227
V operator-(const V &rhs) const
Component-wise subtraction of two vectors.
Definition: Types.h:114
S & operator[](size_t i)
Return the scalar value at the given index.
Definition: Types.h:87
static constexpr size_t numElements()
Return the number of scalar elements for the vector.
Definition: Types.h:273
S getMagnitude() const
Return the magnitude of the vector.
Definition: Types.h:212
VectorN & operator/=(const V &rhs)
Component-wise division of two vectors.
Definition: Types.h:157
VectorN & operator/=(S s)
Component-wise division of a vector by a scalar.
Definition: Types.h:191
S * data()
Return a pointer to the underlying data array.
Definition: Types.h:250