From 816c0d3618a8a2d5c94b471736ba539355979434 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Sun, 1 Sep 2019 13:36:46 +0200 Subject: [PATCH] Fix placements --- src/ifcgeom/schema/mapping.cpp | 10 ++++++++++ src/ifcgeom/schema/mapping.i | 2 +- src/ifcgeom/schema_agnostic/Converter.cpp | 3 +++ src/ifcgeom/taxonomy.h | 4 ++-- src/serializers/ColladaSerializer.cpp | 10 +++++----- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/ifcgeom/schema/mapping.cpp b/src/ifcgeom/schema/mapping.cpp index caedda2c6f..dd7a605dae 100644 --- a/src/ifcgeom/schema/mapping.cpp +++ b/src/ifcgeom/schema/mapping.cpp @@ -223,6 +223,15 @@ taxonomy::item* mapping::map_impl(const IfcSchema::IfcPolyLoop* inst) { taxonomy::item* mapping::map_impl(const IfcSchema::IfcCartesianPoint* inst) { auto coords = inst->Coordinates(); return new taxonomy::point3( + coords.size() >= 1 ? coords[0] * length_unit_ : 0., + coords.size() >= 2 ? coords[1] * length_unit_ : 0., + coords.size() >= 3 ? coords[2] * length_unit_ : 0. + ); +} + +taxonomy::item* mapping::map_impl(const IfcSchema::IfcDirection* inst) { + auto coords = inst->DirectionRatios(); + return new taxonomy::direction3( coords.size() >= 1 ? coords[0] : 0., coords.size() >= 2 ? coords[1] : 0., coords.size() >= 3 ? coords[2] : 0. @@ -320,6 +329,7 @@ taxonomy::item* mapping::map_impl(const IfcSchema::IfcLocalPlacement* inst) { break; } } + return m4; } IfcSchema::IfcProduct::list::ptr mapping::products_represented_by(const IfcSchema::IfcRepresentation* representation) { diff --git a/src/ifcgeom/schema/mapping.i b/src/ifcgeom/schema/mapping.i index c794c6f447..bc94010fd7 100644 --- a/src/ifcgeom/schema/mapping.i +++ b/src/ifcgeom/schema/mapping.i @@ -118,7 +118,7 @@ BIND(IfcPolyLoop); #endif BIND(IfcCartesianPoint); -// BIND(IfcDirection); +BIND(IfcDirection); // BIND(IfcAxis2Placement2D); BIND(IfcAxis2Placement3D); // BIND(IfcAxis1Placement); diff --git a/src/ifcgeom/schema_agnostic/Converter.cpp b/src/ifcgeom/schema_agnostic/Converter.cpp index 19843b11a8..97a6f41d78 100644 --- a/src/ifcgeom/schema_agnostic/Converter.cpp +++ b/src/ifcgeom/schema_agnostic/Converter.cpp @@ -42,6 +42,9 @@ ifcopenshell::geometry::NativeElement* ifcopenshell::geometry::Converter::create // @todo decide how to get placement from product auto placement = (taxonomy::geom_item*) mapping_->map(product); + if (placement == nullptr) { + return nullptr; + } kernel_->convert(rep_item, shapes); shape = new ifcopenshell::geometry::Representation::BRep(s, representation_id_builder.str(), shapes); diff --git a/src/ifcgeom/taxonomy.h b/src/ifcgeom/taxonomy.h index 8ed21d8dd2..35a79e176c 100644 --- a/src/ifcgeom/taxonomy.h +++ b/src/ifcgeom/taxonomy.h @@ -53,8 +53,8 @@ struct matrix4 : public item { auto Z = z.normalized(); components << X(0), Y(0), Z(0), o(0), - X(1), Y(1), Z(1), o(0), - X(2), Y(2), Z(2), o(0), + X(1), Y(1), Z(1), o(1), + X(2), Y(2), Z(2), o(2), 0, 0, 0, 1.; } diff --git a/src/serializers/ColladaSerializer.cpp b/src/serializers/ColladaSerializer.cpp index b9ca3a6786..4267ed7f3b 100644 --- a/src/serializers/ColladaSerializer.cpp +++ b/src/serializers/ColladaSerializer.cpp @@ -204,13 +204,13 @@ void ColladaSerializer::ColladaExporter::ColladaScene::add( // @todo verify - const double* posmatrix = transformation_towrite->data().components.data(); + const double* m = transformation_towrite->data().components.data(); double matrix_array[4][4] = { - { (double)posmatrix[0], (double)posmatrix[3], (double)posmatrix[6], (double)posmatrix[9] }, - { (double)posmatrix[1], (double)posmatrix[4], (double)posmatrix[7], (double)posmatrix[10] }, - { (double)posmatrix[2], (double)posmatrix[5], (double)posmatrix[8], (double)posmatrix[11] }, - { 0, 0, 0, 1 } + { m[0], m[4], m[8], m[12] }, + { m[1], m[5], m[9], m[13] }, + { m[2], m[6], m[10], m[14] }, + { m[3], m[7], m[11], m[15] } }; /// @todo: TFK: Rather than applying this offset to all leafs (which might be undesirable) should this offset be applied to a node higher up in the hierarchy?