6
6
#include " RNFCullingModeEnum.h"
7
7
#include " RNFTransparencyModeEnum.h"
8
8
#include < filament/Material.h>
9
+ #include < math/mat3.h>
9
10
10
11
namespace margelo {
11
12
void MaterialInstanceWrapper::loadHybridMethods () {
12
13
registerHybridMethod (" setCullingMode" , &MaterialInstanceWrapper::setCullingMode, this );
13
14
registerHybridMethod (" setTransparencyMode" , &MaterialInstanceWrapper::setTransparencyMode, this );
14
15
registerHybridMethod (" changeAlpha" , &MaterialInstanceWrapper::changeAlpha, this );
15
- registerHybridMethod (" setParameter" , &MaterialInstanceWrapper::setParameter, this );
16
- registerHybridMethod (" setDefaultFloat4Parameter" , &MaterialInstanceWrapper::setBaseColorSRGB, this );
16
+ registerHybridMethod (" setFloat4Parameter" , &MaterialInstanceWrapper::setFloatParameter, this );
17
+ registerHybridMethod (" setIntParameter" , &MaterialInstanceWrapper::setIntParameter, this );
18
+ registerHybridMethod (" setFloat3Parameter" , &MaterialInstanceWrapper::setFloat3Parameter, this );
19
+ registerHybridMethod (" setFloat4Parameter" , &MaterialInstanceWrapper::setFloat4Parameter, this );
20
+ registerHybridMethod (" setMat3fParameter" , &MaterialInstanceWrapper::setMat3fParameter, this );
21
+ registerHybridMethod (" getFloatParameter" , &MaterialInstanceWrapper::getFloatParameter, this );
22
+ registerHybridMethod (" getIntParameter" , &MaterialInstanceWrapper::getIntParameter, this );
23
+ registerHybridMethod (" getFloat3Parameter" , &MaterialInstanceWrapper::getFloat3Parameter, this );
24
+ registerHybridMethod (" getFloat4Parameter" , &MaterialInstanceWrapper::getFloat4Parameter, this );
25
+ registerHybridMethod (" getMat3fParameter" , &MaterialInstanceWrapper::getMat3fParameter, this );
17
26
registerHybridGetter (" getName" , &MaterialInstanceWrapper::getName, this );
18
27
}
19
28
@@ -50,31 +59,80 @@ void MaterialInstanceWrapper::changeAlpha(double alpha) {
50
59
changeAlpha (_materialInstance, alpha);
51
60
}
52
61
53
- void MaterialInstanceWrapper::setParameter (std::string name, double value) {
62
+ void MaterialInstanceWrapper::setFloatParameter (std::string name, double value) {
54
63
std::unique_lock lock (_mutex);
55
64
56
65
const Material* material = _materialInstance->getMaterial ();
57
-
58
66
if (!material->hasParameter (name.c_str ())) {
59
- throw std::runtime_error (" MaterialInstanceWrapper::setParameter : Material does not have parameter \" " + name + " \" !" );
67
+ throw std::runtime_error (" MaterialInstanceWrapper::setFloatParameter : Material does not have parameter \" " + name + " \" !" );
60
68
}
61
69
62
70
_materialInstance->setParameter (name.c_str (), (float )value);
63
71
}
64
72
65
- void MaterialInstanceWrapper::setBaseColorSRGB (std::vector<double > rgba) {
73
+ void MaterialInstanceWrapper::setIntParameter (std::string name, int value) {
74
+ std::unique_lock lock (_mutex);
75
+
76
+ const Material* material = _materialInstance->getMaterial ();
77
+ if (!material->hasParameter (name.c_str ())) {
78
+ throw std::runtime_error (" MaterialInstanceWrapper::setIntParameter: Material does not have parameter \" " + name + " \" !" );
79
+ }
80
+
81
+ _materialInstance->setParameter (name.c_str (), value);
82
+ }
83
+
84
+ void MaterialInstanceWrapper::setFloat3Parameter (std::string name, std::vector<double > vector) {
66
85
std::unique_lock lock (_mutex);
86
+ if (vector.size () != 3 ) {
87
+ throw std::runtime_error (" MaterialInstanceWrapper::setFloat3Parameter: RGB vector must have 3 elements!" );
88
+ }
89
+
90
+ const Material* material = _materialInstance->getMaterial ();
91
+ if (!material->hasParameter (name.c_str ())) {
92
+ throw std::runtime_error (" MaterialInstanceWrapper::setFloat3Parameter: Material does not have parameter \" " + name + " \" !" );
93
+ }
67
94
68
- if (rgba.size () != 4 ) {
69
- throw std::runtime_error (" MaterialInstanceWrapper::setDefaultFloat4Parameter: RGBA vector must have 4 elements!" );
95
+ float x = vector[0 ];
96
+ float y = vector[1 ];
97
+ float z = vector[2 ];
98
+
99
+ _materialInstance->setParameter (name.c_str (), math::float3 ({x, y, z}));
100
+ }
101
+
102
+ void MaterialInstanceWrapper::setFloat4Parameter (std::string name, std::vector<double > vector) {
103
+ std::unique_lock lock (_mutex);
104
+ if (vector.size () != 4 ) {
105
+ throw std::runtime_error (" MaterialInstanceWrapper::setFloat4Parameter: RGBA vector must have 4 elements!" );
106
+ }
107
+
108
+ const Material* material = _materialInstance->getMaterial ();
109
+ if (!material->hasParameter (name.c_str ())) {
110
+ throw std::runtime_error (" MaterialInstanceWrapper::setFloat4Parameter: Material does not have parameter \" " + name + " \" !" );
111
+ }
112
+
113
+ double r = vector[0 ];
114
+ double g = vector[1 ];
115
+ double b = vector[2 ];
116
+ double a = vector[3 ];
117
+
118
+ _materialInstance->setParameter (name.c_str (), math::float4 ({r, g, b, a}));
119
+ }
120
+
121
+ void MaterialInstanceWrapper::setMat3fParameter (std::string name, std::vector<double > value) {
122
+ std::unique_lock lock (_mutex);
123
+
124
+ const Material* material = _materialInstance->getMaterial ();
125
+ if (!material->hasParameter (name.c_str ())) {
126
+ throw std::runtime_error (" MaterialInstanceWrapper::setMat3fParameter: Material does not have parameter \" " + name + " \" !" );
70
127
}
71
128
72
- double r = rgba[0 ];
73
- double g = rgba[1 ];
74
- double b = rgba[2 ];
75
- double a = rgba[3 ];
129
+ if (value.size () != 9 ) {
130
+ throw std::runtime_error (" MaterialInstanceWrapper::setMat3fParameter: Value vector must have 9 elements!" );
131
+ }
76
132
77
- _materialInstance->setParameter (" baseColorFactor" , math::float4 ({r, g, b, a}));
133
+ math::mat3f matrix = math::mat3f ((float )value[0 ], (float )value[1 ], (float )value[2 ], (float )value[3 ], (float )value[4 ], (float )value[5 ],
134
+ (float )value[6 ], (float )value[7 ], (float )value[8 ]);
135
+ _materialInstance->setParameter (name.c_str (), matrix);
78
136
}
79
137
80
138
std::string MaterialInstanceWrapper::getName () {
@@ -83,4 +141,54 @@ std::string MaterialInstanceWrapper::getName() {
83
141
return _materialInstance->getName ();
84
142
}
85
143
144
+ double MaterialInstanceWrapper::getFloatParameter (std::string name) {
145
+ const Material* material = _materialInstance->getMaterial ();
146
+ if (!material->hasParameter (name.c_str ())) {
147
+ throw std::runtime_error (" MaterialInstanceWrapper::getFloatParameter: Material does not have parameter \" " + name + " \" !" );
148
+ }
149
+
150
+ return _materialInstance->getParameter <float >(name.c_str ());
151
+ }
152
+
153
+ int MaterialInstanceWrapper::getIntParameter (std::string name) {
154
+ const Material* material = _materialInstance->getMaterial ();
155
+ if (!material->hasParameter (name.c_str ())) {
156
+ throw std::runtime_error (" MaterialInstanceWrapper::getIntParameter: Material does not have parameter \" " + name + " \" !" );
157
+ }
158
+
159
+ return _materialInstance->getParameter <int >(name.c_str ());
160
+ }
161
+
162
+ std::vector<double > MaterialInstanceWrapper::getFloat3Parameter (std::string name) {
163
+ const Material* material = _materialInstance->getMaterial ();
164
+ if (!material->hasParameter (name.c_str ())) {
165
+ throw std::runtime_error (" MaterialInstanceWrapper::getFloat3Parameter: Material does not have parameter \" " + name + " \" !" );
166
+ }
167
+
168
+ math::float3 vector = _materialInstance->getParameter <math::float3>(name.c_str ());
169
+ return {vector.x , vector.y , vector.z };
170
+ }
171
+
172
+ std::vector<double > MaterialInstanceWrapper::getFloat4Parameter (std::string name) {
173
+ const Material* material = _materialInstance->getMaterial ();
174
+ if (!material->hasParameter (name.c_str ())) {
175
+ throw std::runtime_error (" MaterialInstanceWrapper::getFloat4Parameter: Material does not have parameter \" " + name + " \" !" );
176
+ }
177
+
178
+ math::float4 vector = _materialInstance->getParameter <math::float4>(name.c_str ());
179
+ return {vector.r , vector.g , vector.b , vector.a };
180
+ }
181
+
182
+ std::vector<double > MaterialInstanceWrapper::getMat3fParameter (std::string name) {
183
+ const Material* material = _materialInstance->getMaterial ();
184
+ if (!material->hasParameter (name.c_str ())) {
185
+ throw std::runtime_error (" MaterialInstanceWrapper::getMat3fParameter: Material does not have parameter \" " + name + " \" !" );
186
+ }
187
+
188
+ math::mat3f matrix = _materialInstance->getParameter <math::mat3f>(name.c_str ());
189
+ const float * matrixArray = matrix.asArray ();
190
+ return {matrixArray[0 ], matrixArray[1 ], matrixArray[2 ], matrixArray[3 ], matrixArray[4 ],
191
+ matrixArray[5 ], matrixArray[6 ], matrixArray[7 ], matrixArray[8 ]};
192
+ }
193
+
86
194
} // namespace margelo
0 commit comments