mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 10:33:20 +00:00
--generate-uvs, applicable for DAE only currently
This commit is contained in:
@@ -38,10 +38,9 @@ static void collada_id(std::string &s)
|
||||
IfcUtil::escape_xml(s);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static std::vector<real_t> boxProjectUVs(const std::vector<real_t> &vertices, const std::vector<real_t> &normals) {
|
||||
assert(vertices.size() == normals.size());
|
||||
//TODO if (vertices.size() != normals.size()) log error?
|
||||
/// @todo Very simple impl. Assumes that input vertices and normals match 1:1.
|
||||
static std::vector<real_t> box_project_uvs(const std::vector<real_t> &vertices, const std::vector<real_t> &normals)
|
||||
{
|
||||
std::vector<real_t> uvs;
|
||||
uvs.resize(vertices.size() / 3 * 2);
|
||||
for(size_t uv_idx = 0, v_idx = 0;
|
||||
@@ -67,7 +66,6 @@ static std::vector<real_t> boxProjectUVs(const std::vector<real_t> &vertices, co
|
||||
|
||||
return uvs;
|
||||
}
|
||||
#endif
|
||||
|
||||
void ColladaSerializer::ColladaExporter::ColladaGeometries::addFloatSource(const std::string& mesh_id,
|
||||
const std::string& suffix, const std::vector<real_t>& floats, const char* coords /* = "XYZ" */)
|
||||
@@ -98,17 +96,14 @@ void ColladaSerializer::ColladaExporter::ColladaGeometries::write(
|
||||
// The normals vector can be empty for example when the WELD_VERTICES setting is used.
|
||||
// IfcOpenShell does not provide them with multiple face normals collapsed into a single vertex.
|
||||
const bool has_normals = !normals.empty();
|
||||
#if 0
|
||||
const bool generate_uvs = (has_normals && serializer->settings()..get(IfcGeom::IteratorSettings::GENERATE_UVS));
|
||||
#endif
|
||||
const bool generate_uvs = (has_normals && serializer->settings().get(IfcGeom::IteratorSettings::GENERATE_UVS));
|
||||
|
||||
addFloatSource(mesh_id, COLLADASW::LibraryGeometries::POSITIONS_SOURCE_ID_SUFFIX, positions);
|
||||
if (has_normals) {
|
||||
addFloatSource(mesh_id, COLLADASW::LibraryGeometries::NORMALS_SOURCE_ID_SUFFIX, normals);
|
||||
#if 0
|
||||
if (generate_uvs) {
|
||||
addFloatSource(mesh_id, COLLADASW::LibraryGeometries::TEXCOORDS_SOURCE_ID_SUFFIX, boxProjectUVs(positions, normals), "UV");
|
||||
addFloatSource(mesh_id, COLLADASW::LibraryGeometries::TEXCOORDS_SOURCE_ID_SUFFIX, box_project_uvs(positions, normals), "UV");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
COLLADASW::VerticesElement vertices(mSW);
|
||||
@@ -134,17 +129,15 @@ void ColladaSerializer::ColladaExporter::ColladaGeometries::write(
|
||||
if (has_normals) {
|
||||
triangles.getInputList().push_back(COLLADASW::Input(COLLADASW::InputSemantic::NORMAL,"#" + mesh_id + COLLADASW::LibraryGeometries::NORMALS_SOURCE_ID_SUFFIX, offset++));
|
||||
}
|
||||
#if 0
|
||||
if (generate_uvs) {
|
||||
triangles.getInputList().push_back(COLLADASW::Input(COLLADASW::InputSemantic::TEXCOORD,"#" + mesh_id + COLLADASW::LibraryGeometries::TEXCOORDS_SOURCE_ID_SUFFIX, offset++));
|
||||
}
|
||||
#endif
|
||||
triangles.prepareToAppendValues();
|
||||
for (std::vector<int>::const_iterator jt = index_range_start; jt != it; ++jt) {
|
||||
const int idx = *jt;
|
||||
/*if (has_normals && generate_uvs) {
|
||||
if (has_normals && generate_uvs) {
|
||||
triangles.appendValues(idx, idx, idx);
|
||||
} else*/ if(has_normals) {
|
||||
} else if(has_normals) {
|
||||
triangles.appendValues(idx, idx);
|
||||
} else {
|
||||
triangles.appendValues(idx);
|
||||
|
||||
@@ -202,9 +202,9 @@ int main(int argc, char** argv) {
|
||||
("center-model",
|
||||
"Centers the models upon serialization by applying the center point of "
|
||||
"the scene bounds as an offset. Applicable only for DAE output currently.")
|
||||
/*("generate-uvs",
|
||||
("generate-uvs",
|
||||
"Generates UVs (texture coordinates) by using simple box projection. Requires normals. Not guaranteed to work "
|
||||
"properly if used with --weld-vertices. Applicable only for .dae output currently.")*/;
|
||||
"properly if used with --weld-vertices. Applicable only for DAE output currently.");
|
||||
|
||||
boost::program_options::options_description cmdline_options;
|
||||
cmdline_options.add(generic_options).add(fileio_options).add(geom_options).add(serializer_options);
|
||||
@@ -263,7 +263,7 @@ int main(int argc, char** argv) {
|
||||
const bool use_material_names = vmap.count("use-material-names") != 0;
|
||||
const bool no_normals = vmap.count("no-normals") != 0 ;
|
||||
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 ;
|
||||
const bool deflection_tolerance_specified = vmap.count("deflection-tolerance") != 0 ;
|
||||
boost::optional<int> bounding_width, bounding_height;
|
||||
if (vmap.count("bounds") == 1) {
|
||||
@@ -346,7 +346,7 @@ int main(int argc, char** argv) {
|
||||
settings.set(IfcGeom::IteratorSettings::USE_MATERIAL_NAMES, use_material_names);
|
||||
settings.set(IfcGeom::IteratorSettings::NO_NORMALS, no_normals);
|
||||
settings.set(IfcGeom::IteratorSettings::CENTER_MODEL, center_model);
|
||||
//settings.set(IfcGeom::IteratorSettings::GENERATE_UVS, generate_uvs);
|
||||
settings.set(IfcGeom::IteratorSettings::GENERATE_UVS, generate_uvs);
|
||||
if (deflection_tolerance_specified) {
|
||||
settings.set_deflection_tolerance(deflection_tolerance);
|
||||
}
|
||||
@@ -366,9 +366,7 @@ int main(int argc, char** argv) {
|
||||
} else if (output_extension == ".stp") {
|
||||
serializer = new StepSerializer(output_filename, settings);
|
||||
} else if (output_extension == ".igs") {
|
||||
// Not sure why this is needed, but it is.
|
||||
// See: http://tracker.dev.opencascade.org/view.php?id=23679
|
||||
IGESControl_Controller::Init();
|
||||
IGESControl_Controller::Init(); // work around Open Cascade bug
|
||||
serializer = new IgesSerializer(output_filename, settings);
|
||||
} else if (output_extension == ".svg") {
|
||||
settings.set(IfcGeom::IteratorSettings::DISABLE_TRIANGULATION, true);
|
||||
@@ -383,10 +381,16 @@ int main(int argc, char** argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (output_extension != ".dae" && center_model) {
|
||||
Logger::Message(Logger::LOG_NOTICE, "--center-model setting ignored for non-DAE output");
|
||||
settings.set(IfcGeom::IteratorSettings::CENTER_MODEL, false);
|
||||
center_model = false;
|
||||
if (output_extension != ".dae") {
|
||||
if (center_model) {
|
||||
Logger::Message(Logger::LOG_NOTICE, "--center-model setting ignored for non-DAE output");
|
||||
settings.set(IfcGeom::IteratorSettings::CENTER_MODEL, false);
|
||||
center_model = false;
|
||||
}
|
||||
if (generate_uvs) {
|
||||
Logger::Message(Logger::LOG_NOTICE, "--generate-uvs setting ignored for non-DAE output");
|
||||
settings.set(IfcGeom::IteratorSettings::GENERATE_UVS, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!serializer->isTesselated()) {
|
||||
|
||||
@@ -20,18 +20,18 @@
|
||||
#ifndef IGESSERIALIZER_H
|
||||
#define IGESSERIALIZER_H
|
||||
|
||||
#include "OpenCascadeBasedSerializer.h"
|
||||
|
||||
#include <IGESControl_Writer.hxx>
|
||||
#include <Interface_Static.hxx>
|
||||
|
||||
#include "../ifcgeom/IfcGeomIterator.h"
|
||||
|
||||
#include "../ifcconvert/OpenCascadeBasedSerializer.h"
|
||||
|
||||
class IgesSerializer : public OpenCascadeBasedSerializer
|
||||
{
|
||||
private:
|
||||
IGESControl_Writer writer;
|
||||
IGESControl_Writer writer;
|
||||
public:
|
||||
/// @note IGESControl_Controller::Init() must be called prior to instantiating IgesSerializer.
|
||||
/// See http://tracker.dev.opencascade.org/view.php?id=23679 for more information.
|
||||
IgesSerializer(const std::string& out_filename, const IfcGeom::IteratorSettings &settings)
|
||||
: OpenCascadeBasedSerializer(out_filename, settings)
|
||||
{}
|
||||
@@ -51,4 +51,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -86,8 +86,9 @@ namespace IfcGeom
|
||||
CENTER_MODEL = 1 << 15,
|
||||
/// Generates UVs by using simple box projection. Requires normals.
|
||||
/// Applicable only for DAE output currently.
|
||||
//GENERATE_UVS = 1 << 16,
|
||||
//NUM_SETTINGS = 16
|
||||
GENERATE_UVS = 1 << 16,
|
||||
/// Number of different setting flags.
|
||||
NUM_SETTINGS = 16
|
||||
};
|
||||
/// Used to store logical OR combination of setting flags.
|
||||
typedef unsigned SettingField;
|
||||
@@ -111,7 +112,7 @@ namespace IfcGeom
|
||||
/// This bug can be reproduced e.g. with the Duplex model that can be found from http://www.nibs.org/?page=bsa_commonbimfiles#project1
|
||||
deflection_tolerance_ = value;
|
||||
if (deflection_tolerance_ <= 1e-6) {
|
||||
Logger::Message(Logger::LOG_WARNING, "Deflection tolerance cannot be set to <= 1e-6, using default 1e-3");
|
||||
Logger::Message(Logger::LOG_WARNING, "Deflection tolerance cannot be set to <= 1e-6; using the default value 1e-3");
|
||||
deflection_tolerance_ = 1e-3;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,6 +176,7 @@ namespace IfcGeom {
|
||||
std::vector<std::pair<int,int> > edges_temp;
|
||||
|
||||
const TColgp_Array1OfPnt& nodes = tri->Nodes();
|
||||
/// @todo can these UVs be used for texture coordinates as is?
|
||||
const TColgp_Array1OfPnt2d& uvs = tri->UVNodes();
|
||||
std::vector<gp_XYZ> coords;
|
||||
BRepGProp_Face prop(face);
|
||||
|
||||
Reference in New Issue
Block a user