diff --git a/src/librt/attributes.c b/src/librt/attributes.c index 75cc20afd33..c1738e74df9 100644 --- a/src/librt/attributes.c +++ b/src/librt/attributes.c @@ -331,6 +331,27 @@ db5_update_attributes(struct directory *dp, struct bu_attribute_value_set *avsp, } } + const char *material_name = bu_avs_get(avsp, "material_name"); + const char *material_id = bu_avs_get(&old_avs, "material_id"); + if (material_name != NULL && !BU_STR_EQUAL(material_name, "(null)") && !BU_STR_EQUAL(material_name, "del")) { + struct directory *material_dp = db_lookup(dbip, material_name, LOOKUP_QUIET); + if (material_dp != RT_DIR_NULL) { + struct rt_db_internal intern; + struct rt_material_internal *material_ip; + if (rt_db_get_internal(&intern, material_dp, dbip, NULL, NULL) >= 0) { + if (intern.idb_minor_type == DB5_MINORTYPE_BRLCAD_MATERIAL) { + material_ip = (struct rt_material_internal *) intern.idb_ptr; + const char *id_string = bu_avs_get(&material_ip->physicalProperties, "id"); + if (id_string == NULL) { + bu_log("WARNING: [%s] has invalid material_name value [%s]\nmaterial_id remains at %s\n", dp->d_namep, material_name, material_id); + } else { + bu_avs_add(avsp, "material_id", id_string); + } + } + } + } + } + bu_avs_merge(&old_avs, avsp); db5_export_attributes(&attr, &old_avs); diff --git a/src/librt/db5_attr.c b/src/librt/db5_attr.c index e4bd0a550ed..73935d5caff 100644 --- a/src/librt/db5_attr.c +++ b/src/librt/db5_attr.c @@ -371,13 +371,8 @@ db5_sync_attr_to_comb(struct rt_comb_internal *comb, const struct bu_attribute_v bu_vls_sprintf(&newval, "%s", bu_avs_get(avs, db5_standard_attribute(ATTR_MATERIAL_NAME))); bu_vls_trimspace(&newval); if (bu_vls_strlen(&newval) != 0 && !BU_STR_EQUAL(bu_vls_addr(&newval), "(null)") && !BU_STR_EQUAL(bu_vls_addr(&newval), "del")) { - if (endptr == bu_vls_addr(&newval) + strlen(bu_vls_addr(&newval))) { attr_char_val = bu_vls_strdup(&newval); bu_vls_strcpy(&comb->material, attr_char_val); - // set the material_id using this material_name - } else { - bu_log("WARNING: [%s] has invalid material_name value [%s]\nmaterial_name remains at %s\n", name, bu_vls_addr(&newval), bu_vls_strdup(&comb->material)); - } } else { /* empty - set to zero */ bu_vls_trunc(&comb->material, 0); @@ -504,7 +499,6 @@ db5_sync_comb_to_attr(struct bu_attribute_value_set *avs, const struct rt_comb_i if (bu_vls_strlen(&comb->material) != 0) { bu_vls_sprintf(&newval, "%s", bu_vls_strdup(&comb->material)); (void)bu_avs_add_vls(avs, db5_standard_attribute(ATTR_MATERIAL_NAME), &newval); - // add the material_id using this material_name } else { bu_avs_remove(avs, db5_standard_attribute(ATTR_MATERIAL_NAME)); }