@@ -26,6 +26,7 @@ void Material::SetDefaultProperties() {
26
26
SetTransmission (1 .f );
27
27
SetAbsorptionColor (Eigen::Vector4f (1 .f , 1 .f , 1 .f , 1 .f ));
28
28
SetAbsorptionDistance (1 .f );
29
+ SetEmissiveColor (Eigen::Vector4f (1 .f , 1 .f , 1 .f , 1 .f ));
29
30
SetPointSize (3 .f );
30
31
SetLineWidth (1 .f );
31
32
}
@@ -39,6 +40,24 @@ void Material::SetTextureMap(const std::string &key,
39
40
texture_maps_[key] = image.To (core::Device (" CPU:0" ), true );
40
41
}
41
42
43
+ std::string Material::ToString () const {
44
+ if (!IsValid ()) {
45
+ return " Invalid Material\n " ;
46
+ }
47
+ std::ostringstream os;
48
+ os << " Material " << material_name_ << ' \n ' ;
49
+ for (const auto &kv : scalar_properties_) {
50
+ os << ' \t ' << kv.first << " : " << kv.second << ' \n ' ;
51
+ }
52
+ for (const auto &kv : vector_properties_) {
53
+ os << ' \t ' << kv.first << " : " << kv.second .transpose () << ' \n ' ;
54
+ }
55
+ for (const auto &kv : texture_maps_) {
56
+ os << ' \t ' << kv.first << " : " << kv.second .ToString () << ' \n ' ;
57
+ }
58
+ return os.str ();
59
+ }
60
+
42
61
void Material::ToMaterialRecord (MaterialRecord &record) const {
43
62
record.shader = GetMaterialName ();
44
63
// Convert base material properties
@@ -63,6 +82,9 @@ void Material::ToMaterialRecord(MaterialRecord &record) const {
63
82
if (HasAnisotropy ()) {
64
83
record.base_anisotropy = GetAnisotropy ();
65
84
}
85
+ if (HasEmissiveColor ()) {
86
+ record.emissive_color = GetEmissiveColor ();
87
+ }
66
88
if (HasThickness ()) {
67
89
record.thickness = GetThickness ();
68
90
}
@@ -124,6 +146,62 @@ void Material::ToMaterialRecord(MaterialRecord &record) const {
124
146
}
125
147
}
126
148
149
+ Material Material::FromMaterialRecord (const MaterialRecord &record) {
150
+ using t::geometry::Image;
151
+ Material tmat (record.shader );
152
+ // scalar and vector properties
153
+ tmat.SetBaseColor (record.base_color );
154
+ tmat.SetBaseMetallic (record.base_metallic );
155
+ tmat.SetBaseRoughness (record.base_roughness );
156
+ tmat.SetBaseReflectance (record.base_reflectance );
157
+ tmat.SetBaseClearcoat (record.base_clearcoat );
158
+ tmat.SetBaseClearcoatRoughness (record.base_clearcoat_roughness );
159
+ tmat.SetAnisotropy (record.base_anisotropy );
160
+ tmat.SetEmissiveColor (record.emissive_color );
161
+ // refractive materials
162
+ tmat.SetThickness (record.thickness );
163
+ tmat.SetTransmission (record.transmission );
164
+ tmat.SetAbsorptionDistance (record.absorption_distance );
165
+ // points and lines
166
+ tmat.SetPointSize (record.point_size );
167
+ tmat.SetLineWidth (record.line_width );
168
+ // maps
169
+ if (record.albedo_img ) {
170
+ tmat.SetAlbedoMap (Image::FromLegacy (*record.albedo_img ));
171
+ }
172
+ if (record.normal_img ) {
173
+ tmat.SetNormalMap (Image::FromLegacy (*record.normal_img ));
174
+ }
175
+ if (record.ao_img ) {
176
+ tmat.SetAOMap (Image::FromLegacy (*record.ao_img ));
177
+ }
178
+ if (record.metallic_img ) {
179
+ tmat.SetMetallicMap (Image::FromLegacy (*record.metallic_img ));
180
+ }
181
+ if (record.roughness_img ) {
182
+ tmat.SetRoughnessMap (Image::FromLegacy (*record.roughness_img ));
183
+ }
184
+ if (record.reflectance_img ) {
185
+ tmat.SetReflectanceMap (Image::FromLegacy (*record.reflectance_img ));
186
+ }
187
+ if (record.clearcoat_img ) {
188
+ tmat.SetClearcoatMap (Image::FromLegacy (*record.clearcoat_img ));
189
+ }
190
+ if (record.clearcoat_roughness_img ) {
191
+ tmat.SetClearcoatRoughnessMap (
192
+ Image::FromLegacy (*record.clearcoat_roughness_img ));
193
+ }
194
+ if (record.anisotropy_img ) {
195
+ tmat.SetAnisotropyMap (Image::FromLegacy (*record.anisotropy_img ));
196
+ }
197
+ if (record.ao_rough_metal_img ) {
198
+ tmat.SetAORoughnessMetalMap (
199
+ Image::FromLegacy (*record.ao_rough_metal_img ));
200
+ }
201
+
202
+ return tmat;
203
+ }
204
+
127
205
} // namespace rendering
128
206
} // namespace visualization
129
207
} // namespace open3d
0 commit comments