@@ -26,6 +26,7 @@ void Material::SetDefaultProperties() {
2626 SetTransmission (1 .f );
2727 SetAbsorptionColor (Eigen::Vector4f (1 .f , 1 .f , 1 .f , 1 .f ));
2828 SetAbsorptionDistance (1 .f );
29+ SetEmissiveColor (Eigen::Vector4f (1 .f , 1 .f , 1 .f , 1 .f ));
2930 SetPointSize (3 .f );
3031 SetLineWidth (1 .f );
3132}
@@ -39,6 +40,24 @@ void Material::SetTextureMap(const std::string &key,
3940 texture_maps_[key] = image.To (core::Device (" CPU:0" ), true );
4041}
4142
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+
4261void Material::ToMaterialRecord (MaterialRecord &record) const {
4362 record.shader = GetMaterialName ();
4463 // Convert base material properties
@@ -63,6 +82,9 @@ void Material::ToMaterialRecord(MaterialRecord &record) const {
6382 if (HasAnisotropy ()) {
6483 record.base_anisotropy = GetAnisotropy ();
6584 }
85+ if (HasEmissiveColor ()) {
86+ record.emissive_color = GetEmissiveColor ();
87+ }
6688 if (HasThickness ()) {
6789 record.thickness = GetThickness ();
6890 }
@@ -124,6 +146,62 @@ void Material::ToMaterialRecord(MaterialRecord &record) const {
124146 }
125147}
126148
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+
127205} // namespace rendering
128206} // namespace visualization
129207} // namespace open3d
0 commit comments