mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-29 03:37:21 +00:00
Rename --use-guids and --use-names to --use-element-guids and --use-element-names. Add explicit --use-material-names for controlling material naming.
This commit is contained in:
@@ -124,7 +124,8 @@ void ColladaSerializer::ColladaExporter::ColladaGeometries::write(
|
|||||||
const size_t num_triangles = std::distance(index_range_start, it) / 3;
|
const size_t num_triangles = std::distance(index_range_start, it) / 3;
|
||||||
if ((previous_material_id != current_material_id && num_triangles > 0) || (it == faces.end())) {
|
if ((previous_material_id != current_material_id && num_triangles > 0) || (it == faces.end())) {
|
||||||
COLLADASW::Triangles triangles(mSW);
|
COLLADASW::Triangles triangles(mSW);
|
||||||
std::string material_name = (serializer->settings().get(IfcGeom::IteratorSettings::USE_NAMES) ? materials[previous_material_id].original_name() : materials[previous_material_id].name());
|
std::string material_name = (serializer->settings().get(IfcGeom::IteratorSettings::USE_MATERIAL_NAMES)
|
||||||
|
? materials[previous_material_id].original_name() : materials[previous_material_id].name());
|
||||||
collada_id(material_name);
|
collada_id(material_name);
|
||||||
triangles.setMaterial(material_name);
|
triangles.setMaterial(material_name);
|
||||||
triangles.setCount((unsigned long)num_triangles);
|
triangles.setCount((unsigned long)num_triangles);
|
||||||
@@ -182,7 +183,8 @@ void ColladaSerializer::ColladaExporter::ColladaGeometries::write(
|
|||||||
|
|
||||||
for (linelist_t::const_iterator it = linelist.begin(); it != linelist.end(); ++it) {
|
for (linelist_t::const_iterator it = linelist.begin(); it != linelist.end(); ++it) {
|
||||||
COLLADASW::Lines lines(mSW);
|
COLLADASW::Lines lines(mSW);
|
||||||
std::string material_name = (serializer->settings().get(IfcGeom::IteratorSettings::USE_NAMES) ? materials[it->first].original_name() : materials[it->first].name());
|
std::string material_name = (serializer->settings().get(IfcGeom::IteratorSettings::USE_MATERIAL_NAMES)
|
||||||
|
? materials[it->first].original_name() : materials[it->first].name());
|
||||||
collada_id(material_name);
|
collada_id(material_name);
|
||||||
lines.setMaterial(material_name);
|
lines.setMaterial(material_name);
|
||||||
lines.setCount((unsigned long)it->second.size());
|
lines.setCount((unsigned long)it->second.size());
|
||||||
@@ -256,7 +258,8 @@ void ColladaSerializer::ColladaExporter::ColladaScene::write() {
|
|||||||
|
|
||||||
void ColladaSerializer::ColladaExporter::ColladaMaterials::ColladaEffects::write(const IfcGeom::Material& material)
|
void ColladaSerializer::ColladaExporter::ColladaMaterials::ColladaEffects::write(const IfcGeom::Material& material)
|
||||||
{
|
{
|
||||||
std::string material_name = (serializer->settings().get(IfcGeom::IteratorSettings::USE_NAMES) ? material.original_name() : material.name());
|
std::string material_name = (serializer->settings().get(IfcGeom::IteratorSettings::USE_MATERIAL_NAMES)
|
||||||
|
? material.original_name() : material.name());
|
||||||
collada_id(material_name);
|
collada_id(material_name);
|
||||||
openEffect(material_name + "-fx");
|
openEffect(material_name + "-fx");
|
||||||
COLLADASW::EffectProfile effect(mSW);
|
COLLADASW::EffectProfile effect(mSW);
|
||||||
@@ -302,7 +305,8 @@ bool ColladaSerializer::ColladaExporter::ColladaMaterials::contains(const IfcGeo
|
|||||||
void ColladaSerializer::ColladaExporter::ColladaMaterials::write() {
|
void ColladaSerializer::ColladaExporter::ColladaMaterials::write() {
|
||||||
effects.close();
|
effects.close();
|
||||||
foreach(const IfcGeom::Material& material, materials) {
|
foreach(const IfcGeom::Material& material, materials) {
|
||||||
std::string material_name = (serializer->settings().get(IfcGeom::IteratorSettings::USE_NAMES) ? material.original_name() : material.name());
|
std::string material_name = (serializer->settings().get(IfcGeom::IteratorSettings::USE_MATERIAL_NAMES)
|
||||||
|
? material.original_name() : material.name());
|
||||||
std::string material_name_unescaped = material_name; // workaround double-escaping that would occur in addInstanceEffect()
|
std::string material_name_unescaped = material_name; // workaround double-escaping that would occur in addInstanceEffect()
|
||||||
IfcUtil::sanitate_material_name(material_name_unescaped);
|
IfcUtil::sanitate_material_name(material_name_unescaped);
|
||||||
collada_id(material_name);
|
collada_id(material_name);
|
||||||
@@ -333,7 +337,8 @@ void ColladaSerializer::ColladaExporter::write(const std::string& unique_id, con
|
|||||||
if (!materials.contains(material)) {
|
if (!materials.contains(material)) {
|
||||||
materials.add(material);
|
materials.add(material);
|
||||||
}
|
}
|
||||||
std::string material_name = (serializer->settings().get(IfcGeom::IteratorSettings::USE_NAMES) ? material.original_name() : material.name());
|
std::string material_name = (serializer->settings().get(IfcGeom::IteratorSettings::USE_MATERIAL_NAMES)
|
||||||
|
? material.original_name() : material.name());
|
||||||
collada_id(material_name);
|
collada_id(material_name);
|
||||||
material_references.push_back(material_name);
|
material_references.push_back(material_name);
|
||||||
}
|
}
|
||||||
@@ -367,8 +372,8 @@ void ColladaSerializer::writeHeader() {
|
|||||||
|
|
||||||
void ColladaSerializer::write(const IfcGeom::TriangulationElement<real_t>* o) {
|
void ColladaSerializer::write(const IfcGeom::TriangulationElement<real_t>* o) {
|
||||||
const IfcGeom::Representation::Triangulation<real_t>& mesh = o->geometry();
|
const IfcGeom::Representation::Triangulation<real_t>& mesh = o->geometry();
|
||||||
const std::string name = settings().get(IfcGeom::IteratorSettings::USE_GUIDS) ?
|
const std::string name = settings().get(IfcGeom::IteratorSettings::USE_ELEMENT_GUIDS) ?
|
||||||
o->guid() : (settings().get(IfcGeom::IteratorSettings::USE_NAMES) ? o->name() : o->unique_id());
|
o->guid() : (settings().get(IfcGeom::IteratorSettings::USE_ELEMENT_NAMES) ? o->name() : o->unique_id());
|
||||||
exporter.write(name, o->type(), o->transformation().matrix().data(), mesh.verts(),
|
exporter.write(name, o->type(), o->transformation().matrix().data(), mesh.verts(),
|
||||||
mesh.normals(), mesh.faces(), mesh.edges(), mesh.material_ids(), mesh.materials());
|
mesh.normals(), mesh.faces(), mesh.edges(), mesh.material_ids(), mesh.materials());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -190,13 +190,15 @@ int main(int argc, char** argv) {
|
|||||||
("bounds", boost::program_options::value<std::string>(&bounds),
|
("bounds", boost::program_options::value<std::string>(&bounds),
|
||||||
"Specifies the bounding rectangle, for example 512x512, to which the "
|
"Specifies the bounding rectangle, for example 512x512, to which the "
|
||||||
"output will be scaled. Only used when converting to SVG.")
|
"output will be scaled. Only used when converting to SVG.")
|
||||||
("use-names",
|
("use-element-names",
|
||||||
"Use entity names instead of unique IDs for naming objects and materials "
|
"Use entity names instead of unique IDs for naming elements upon serialization. "
|
||||||
"upon serialization. Applicable for .obj and .dae output.")
|
"Applicable for OBJ, DAE, and SVG output.")
|
||||||
("use-guids",
|
("use-element-guids",
|
||||||
"Use entity GUIDs instead of unique IDs for naming objects upon serialization. "
|
"Use entity GUIDs instead of unique IDs for naming elements upon serialization. "
|
||||||
"Overrides possible usage of --use-names for objects but not for materials."
|
"Applicable for OBJ, DAE, and SVG output.")
|
||||||
"Applicable for .obj and .dae output.")
|
("use-material-names",
|
||||||
|
"Use material names instead of unique IDs for naming materials upon serialization. "
|
||||||
|
"Applicable for OBJ and DAE output.")
|
||||||
/*("center-model",
|
/*("center-model",
|
||||||
"Centers the models upon serialization by applying the center point of "
|
"Centers the models upon serialization by applying the center point of "
|
||||||
"the scene bounds as an offset. Applicable only for .dae output currently.")
|
"the scene bounds as an offset. Applicable only for .dae output currently.")
|
||||||
@@ -256,8 +258,9 @@ int main(int argc, char** argv) {
|
|||||||
bool include_entities = vmap.count("include") != 0;
|
bool include_entities = vmap.count("include") != 0;
|
||||||
const bool include_plan = vmap.count("plan") != 0;
|
const bool include_plan = vmap.count("plan") != 0;
|
||||||
const bool include_model = vmap.count("model") != 0 || (!include_plan);
|
const bool include_model = vmap.count("model") != 0 || (!include_plan);
|
||||||
const bool use_names = vmap.count("use-names") != 0;
|
const bool use_element_names = vmap.count("use-element-names") != 0;
|
||||||
const bool use_guids = vmap.count("use-guids") != 0 ;
|
const bool use_element_guids = vmap.count("use-element-guids") != 0 ;
|
||||||
|
const bool use_material_names = vmap.count("use-material-names") != 0;
|
||||||
//const bool no_normals = vmap.count("no-normals") != 0 ;
|
//const bool no_normals = vmap.count("no-normals") != 0 ;
|
||||||
//const bool center_model = vmap.count("center-model") != 0 ;
|
//const bool center_model = vmap.count("center-model") != 0 ;
|
||||||
//const bool generate_uvs = vmap.count("generate-uvs") != 0 ;
|
//const bool generate_uvs = vmap.count("generate-uvs") != 0 ;
|
||||||
@@ -338,8 +341,9 @@ int main(int argc, char** argv) {
|
|||||||
settings.set(IfcGeom::IteratorSettings::DISABLE_OPENING_SUBTRACTIONS, disable_opening_subtractions);
|
settings.set(IfcGeom::IteratorSettings::DISABLE_OPENING_SUBTRACTIONS, disable_opening_subtractions);
|
||||||
settings.set(IfcGeom::IteratorSettings::INCLUDE_CURVES, include_plan);
|
settings.set(IfcGeom::IteratorSettings::INCLUDE_CURVES, include_plan);
|
||||||
settings.set(IfcGeom::IteratorSettings::EXCLUDE_SOLIDS_AND_SURFACES, !include_model);
|
settings.set(IfcGeom::IteratorSettings::EXCLUDE_SOLIDS_AND_SURFACES, !include_model);
|
||||||
settings.set(IfcGeom::IteratorSettings::USE_NAMES, use_names);
|
settings.set(IfcGeom::IteratorSettings::USE_ELEMENT_NAMES, use_element_names);
|
||||||
settings.set(IfcGeom::IteratorSettings::USE_GUIDS, use_guids);
|
settings.set(IfcGeom::IteratorSettings::USE_ELEMENT_GUIDS, use_element_guids);
|
||||||
|
settings.set(IfcGeom::IteratorSettings::USE_MATERIAL_NAMES, use_material_names);
|
||||||
//settings.set(IfcGeom::IteratorSettings::NO_NORMALS, no_normals);
|
//settings.set(IfcGeom::IteratorSettings::NO_NORMALS, no_normals);
|
||||||
//settings.set(IfcGeom::IteratorSettings::CENTER_MODEL, center_model);
|
//settings.set(IfcGeom::IteratorSettings::CENTER_MODEL, center_model);
|
||||||
//settings.set(IfcGeom::IteratorSettings::GENERATE_UVS, generate_uvs);
|
//settings.set(IfcGeom::IteratorSettings::GENERATE_UVS, generate_uvs);
|
||||||
|
|||||||
@@ -345,8 +345,8 @@ std::string SvgSerializer::nameElement(const IfcGeom::Element<real_t>* elem)
|
|||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
const std::string type = "product";
|
const std::string type = "product";
|
||||||
const std::string name = (settings().get(IfcGeom::IteratorSettings::USE_GUIDS)
|
const std::string name = (settings().get(IfcGeom::IteratorSettings::USE_ELEMENT_GUIDS)
|
||||||
? elem->guid() : (settings().get(IfcGeom::IteratorSettings::USE_NAMES)
|
? elem->guid() : (settings().get(IfcGeom::IteratorSettings::USE_ELEMENT_NAMES)
|
||||||
? elem->name() : elem->unique_id()));
|
? elem->name() : elem->unique_id()));
|
||||||
oss << "id=\"" << type << "-" << name<< "\"";
|
oss << "id=\"" << type << "-" << name<< "\"";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ void WaveFrontOBJSerializer::writeHeader() {
|
|||||||
|
|
||||||
void WaveFrontOBJSerializer::writeMaterial(const IfcGeom::Material& style)
|
void WaveFrontOBJSerializer::writeMaterial(const IfcGeom::Material& style)
|
||||||
{
|
{
|
||||||
std::string material_name = (settings().get(IfcGeom::IteratorSettings::USE_NAMES) ? style.original_name() : style.name());
|
std::string material_name = (settings().get(IfcGeom::IteratorSettings::USE_MATERIAL_NAMES)
|
||||||
|
? style.original_name() : style.name());
|
||||||
IfcUtil::sanitate_material_name(material_name);
|
IfcUtil::sanitate_material_name(material_name);
|
||||||
mtl_stream << "newmtl " << material_name << "\n";
|
mtl_stream << "newmtl " << material_name << "\n";
|
||||||
if (style.hasDiffuse()) {
|
if (style.hasDiffuse()) {
|
||||||
@@ -72,7 +73,7 @@ void WaveFrontOBJSerializer::writeMaterial(const IfcGeom::Material& style)
|
|||||||
|
|
||||||
void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement<real_t>* o)
|
void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement<real_t>* o)
|
||||||
{
|
{
|
||||||
obj_stream << "g " << (settings().get(IfcGeom::IteratorSettings::USE_GUIDS) ? o->guid() : (settings().get(IfcGeom::IteratorSettings::USE_NAMES) ? o->name() : o->unique_id())) << "\n";
|
obj_stream << "g " << (settings().get(IfcGeom::IteratorSettings::USE_ELEMENT_GUIDS) ? o->guid() : (settings().get(IfcGeom::IteratorSettings::USE_ELEMENT_NAMES) ? o->name() : o->unique_id())) << "\n";
|
||||||
obj_stream << "s 1" << "\n";
|
obj_stream << "s 1" << "\n";
|
||||||
|
|
||||||
const IfcGeom::Representation::Triangulation<real_t>& mesh = o->geometry();
|
const IfcGeom::Representation::Triangulation<real_t>& mesh = o->geometry();
|
||||||
@@ -100,7 +101,8 @@ void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement<real_t>*
|
|||||||
const int material_id = *(material_it++);
|
const int material_id = *(material_it++);
|
||||||
if (material_id != previous_material_id) {
|
if (material_id != previous_material_id) {
|
||||||
const IfcGeom::Material& material = mesh.materials()[material_id];
|
const IfcGeom::Material& material = mesh.materials()[material_id];
|
||||||
std::string material_name = (settings().get(IfcGeom::IteratorSettings::USE_NAMES) ? material.original_name() : material.name());
|
std::string material_name = (settings().get(IfcGeom::IteratorSettings::USE_MATERIAL_NAMES)
|
||||||
|
? material.original_name() : material.name());
|
||||||
IfcUtil::sanitate_material_name(material_name);
|
IfcUtil::sanitate_material_name(material_name);
|
||||||
obj_stream << "usemtl " << material_name << "\n";
|
obj_stream << "usemtl " << material_name << "\n";
|
||||||
if (materials.find(material_name) == materials.end()) {
|
if (materials.find(material_name) == materials.end()) {
|
||||||
@@ -132,7 +134,8 @@ void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement<real_t>*
|
|||||||
|
|
||||||
if (material_id != previous_material_id) {
|
if (material_id != previous_material_id) {
|
||||||
const IfcGeom::Material& material = mesh.materials()[material_id];
|
const IfcGeom::Material& material = mesh.materials()[material_id];
|
||||||
std::string material_name = (settings().get(IfcGeom::IteratorSettings::USE_NAMES) ? material.original_name() : material.name());
|
std::string material_name = (settings().get(IfcGeom::IteratorSettings::USE_MATERIAL_NAMES)
|
||||||
|
? material.original_name() : material.name());
|
||||||
IfcUtil::sanitate_material_name(material_name);
|
IfcUtil::sanitate_material_name(material_name);
|
||||||
obj_stream << "usemtl " << material_name << "\n";
|
obj_stream << "usemtl " << material_name << "\n";
|
||||||
if (materials.find(material_name) == materials.end()) {
|
if (materials.find(material_name) == materials.end()) {
|
||||||
|
|||||||
@@ -71,20 +71,22 @@ namespace IfcGeom
|
|||||||
/// in instances where you're going to recompute normals for the exported
|
/// in instances where you're going to recompute normals for the exported
|
||||||
/// model in other modelling application in any case.
|
/// model in other modelling application in any case.
|
||||||
//NO_NORMALS = 1 << 11,
|
//NO_NORMALS = 1 << 11,
|
||||||
/// Use entity names instead of unique IDs for naming objects and materials.
|
/// Use entity names instead of unique IDs for naming elements.
|
||||||
/// Applicable for OBJ, DAE, and SVG output.
|
/// Applicable for OBJ, DAE, and SVG output.
|
||||||
USE_NAMES = 1 << 12,
|
USE_ELEMENT_NAMES = 1 << 12,
|
||||||
/// Use entity GUIDs instead of unique IDs for naming objects.
|
/// Use entity GUIDs instead of unique IDs for naming elements.
|
||||||
/// Overrides possible usage of --use-names for objects but not for materials.
|
|
||||||
/// Applicable for OBJ, DAE, and SVG output.
|
/// Applicable for OBJ, DAE, and SVG output.
|
||||||
USE_GUIDS = 1 << 13,
|
USE_ELEMENT_GUIDS = 1 << 13,
|
||||||
|
/// Use material names instead of unique IDs for naming materials.
|
||||||
|
/// Applicable for OBJ and DAE output.
|
||||||
|
USE_MATERIAL_NAMES = 1 << 14,
|
||||||
/// Centers the models upon serialization by the applying the center point of
|
/// Centers the models upon serialization by the applying the center point of
|
||||||
/// the scene bounds as an offset. Applicable only for .dae output currently.
|
/// the scene bounds as an offset. Applicable only for .dae output currently.
|
||||||
//CENTER_MODEL = 1 << 14,
|
//CENTER_MODEL = 1 << 15,
|
||||||
/// Generates UVs by using simple box projection. Requires normals.
|
/// Generates UVs by using simple box projection. Requires normals.
|
||||||
/// Applicable only for DAE output currently.
|
/// Applicable only for DAE output currently.
|
||||||
//GENERATE_UVS = 1 << 15,
|
//GENERATE_UVS = 1 << 16,
|
||||||
//NUM_SETTINGS = 15
|
//NUM_SETTINGS = 16
|
||||||
};
|
};
|
||||||
/// Used to store logical OR combination of setting flags.
|
/// Used to store logical OR combination of setting flags.
|
||||||
typedef unsigned SettingField;
|
typedef unsigned SettingField;
|
||||||
@@ -104,12 +106,14 @@ namespace IfcGeom
|
|||||||
/// @todo Sanity check for the value
|
/// @todo Sanity check for the value
|
||||||
void set_deflection_tolerance(double value) { deflection_tolerance_ = value; }
|
void set_deflection_tolerance(double value) { deflection_tolerance_ = value; }
|
||||||
|
|
||||||
|
/// Get boolean value for a single settings or for a combination of settings.
|
||||||
bool get(SettingField setting) const
|
bool get(SettingField setting) const
|
||||||
{
|
{
|
||||||
/// @todo If unknown setting value/combination: throw IfcParse::IfcException("Invalid IteratorSetting")?
|
/// @todo If unknown setting value/combination: throw IfcParse::IfcException("Invalid IteratorSetting")?
|
||||||
return (settings_ & setting) != 0;
|
return (settings_ & setting) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set boolean value for a single settings or for a combination of settings.
|
||||||
void set(SettingField setting, bool value)
|
void set(SettingField setting, bool value)
|
||||||
{
|
{
|
||||||
/// @todo If unknown setting value/combination: throw IfcParse::IfcException("Invalid IteratorSetting")?
|
/// @todo If unknown setting value/combination: throw IfcParse::IfcException("Invalid IteratorSetting")?
|
||||||
|
|||||||
Reference in New Issue
Block a user