2011-06-14 15:58:22 +00:00
|
|
|
/*
|
2012-02-03 03:38:30 +00:00
|
|
|
Open Asset Import Library (assimp)
|
2011-06-14 15:58:22 +00:00
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
Copyright (c) 2006-2010, assimp team
|
2011-06-14 15:58:22 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
|
|
|
following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
* Neither the name of the assimp team, nor the names of its
|
2011-06-14 15:58:22 +00:00
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
2012-02-03 03:38:30 +00:00
|
|
|
written permission of the assimp team.
|
2011-06-14 15:58:22 +00:00
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file IFCGeometry.cpp
|
|
|
|
* @brief Geometry conversion and synthesis for IFC
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "AssimpPCH.h"
|
|
|
|
|
|
|
|
#ifndef ASSIMP_BUILD_NO_IFC_IMPORTER
|
|
|
|
#include "IFCUtil.h"
|
|
|
|
#include "PolyTools.h"
|
|
|
|
#include "ProcessHelper.h"
|
|
|
|
|
2012-01-17 01:49:17 +00:00
|
|
|
#include "../contrib/poly2tri/poly2tri/poly2tri.h"
|
|
|
|
#include "../contrib/clipper/clipper.hpp"
|
|
|
|
|
2011-07-17 01:09:56 +00:00
|
|
|
#include <iterator>
|
|
|
|
|
2011-06-14 15:58:22 +00:00
|
|
|
namespace Assimp {
|
|
|
|
namespace IFC {
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool ProcessPolyloop(const IfcPolyLoop& loop, TempMesh& meshout, ConversionData& /*conv*/)
|
|
|
|
{
|
|
|
|
size_t cnt = 0;
|
|
|
|
BOOST_FOREACH(const IfcCartesianPoint& c, loop.Polygon) {
|
2012-02-02 02:09:49 +00:00
|
|
|
IfcVector3 tmp;
|
2011-06-14 15:58:22 +00:00
|
|
|
ConvertCartesianPoint(tmp,c);
|
|
|
|
|
|
|
|
meshout.verts.push_back(tmp);
|
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
meshout.vertcnt.push_back(cnt);
|
|
|
|
|
|
|
|
// zero- or one- vertex polyloops simply ignored
|
|
|
|
if (meshout.vertcnt.back() > 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (meshout.vertcnt.back()==1) {
|
|
|
|
meshout.vertcnt.pop_back();
|
|
|
|
meshout.verts.pop_back();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2012-10-20 21:26:49 +00:00
|
|
|
void ProcessPolygonBoundaries(TempMesh& result, const TempMesh& inmesh, size_t master_bounds = (size_t)-1)
|
2011-06-14 15:58:22 +00:00
|
|
|
{
|
2012-10-20 21:26:49 +00:00
|
|
|
// handle all trivial cases
|
|
|
|
if(inmesh.vertcnt.empty()) {
|
|
|
|
return;
|
2011-06-14 15:58:22 +00:00
|
|
|
}
|
2012-10-20 21:26:49 +00:00
|
|
|
if(inmesh.vertcnt.size() == 1) {
|
2011-06-14 15:58:22 +00:00
|
|
|
result.Append(inmesh);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-20 21:26:49 +00:00
|
|
|
ai_assert(std::count(inmesh.vertcnt.begin(), inmesh.vertcnt.end(), 0) == 0);
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-10-20 21:26:49 +00:00
|
|
|
typedef std::vector<unsigned int>::const_iterator face_iter;
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-10-20 21:26:49 +00:00
|
|
|
face_iter begin = inmesh.vertcnt.begin(), end = inmesh.vertcnt.end(), iit;
|
|
|
|
std::vector<unsigned int>::const_iterator outer_polygon_it = end;
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-10-20 21:26:49 +00:00
|
|
|
// major task here: given a list of nested polygon boundaries (one of which
|
|
|
|
// is the outer contour), reduce the triangulation task arising here to
|
|
|
|
// one that can be solved using the "quadrulation" algorithm which we use
|
|
|
|
// for pouring windows out of walls. The algorithm does not handle all
|
|
|
|
// cases but at least it is numerically stable and gives "nice" triangles.
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-10-21 18:52:48 +00:00
|
|
|
// first compute normals for all polygons using Newell's algorithm
|
2011-06-14 15:58:22 +00:00
|
|
|
// do not normalize 'normals', we need the original length for computing the polygon area
|
2012-02-02 02:09:49 +00:00
|
|
|
std::vector<IfcVector3> normals;
|
2012-10-21 18:32:25 +00:00
|
|
|
inmesh.ComputePolygonNormals(normals,false);
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-10-20 21:26:49 +00:00
|
|
|
// One of the polygons might be a IfcFaceOuterBound (in which case `master_bounds`
|
|
|
|
// is its index). Sadly we can't rely on it, the docs say 'At most one of the bounds
|
|
|
|
// shall be of the type IfcFaceOuterBound'
|
2012-02-02 02:09:49 +00:00
|
|
|
IfcFloat area_outer_polygon = 1e-10f;
|
2011-06-14 15:58:22 +00:00
|
|
|
if (master_bounds != (size_t)-1) {
|
2012-10-20 21:26:49 +00:00
|
|
|
ai_assert(master_bounds < inmesh.vertcnt.size());
|
|
|
|
outer_polygon_it = begin + master_bounds;
|
2011-06-14 15:58:22 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-10-20 21:26:49 +00:00
|
|
|
for(iit = begin; iit != end; iit++) {
|
|
|
|
// find the polygon with the largest area and take it as the outer bound.
|
2012-02-02 02:09:49 +00:00
|
|
|
IfcVector3& n = normals[std::distance(begin,iit)];
|
|
|
|
const IfcFloat area = n.SquareLength();
|
2011-06-14 15:58:22 +00:00
|
|
|
if (area > area_outer_polygon) {
|
|
|
|
area_outer_polygon = area;
|
2012-10-20 21:26:49 +00:00
|
|
|
outer_polygon_it = iit;
|
2011-06-14 15:58:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-20 21:26:49 +00:00
|
|
|
ai_assert(outer_polygon_it != end);
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-10-20 21:26:49 +00:00
|
|
|
const size_t outer_polygon_size = *outer_polygon_it;
|
|
|
|
const IfcVector3& master_normal = normals[std::distance(begin, outer_polygon_it)];
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-10-21 18:52:48 +00:00
|
|
|
// Generate fake openings to meet the interface for the quadrulate
|
2012-10-20 21:26:49 +00:00
|
|
|
// algorithm. It boils down to generating small boxes given the
|
|
|
|
// inner polygon and the surface normal of the outer contour.
|
|
|
|
// It is important that we use the outer contour's normal because
|
|
|
|
// this is the plane onto which the quadrulate algorithm will
|
|
|
|
// project the entire mesh.
|
|
|
|
std::vector<TempOpening> fake_openings;
|
|
|
|
fake_openings.reserve(inmesh.vertcnt.size()-1);
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-10-20 21:26:49 +00:00
|
|
|
std::vector<IfcVector3>::const_iterator vit = inmesh.verts.begin(), outer_vit;
|
|
|
|
|
|
|
|
for(iit = begin; iit != end; vit += *iit++) {
|
|
|
|
if (iit == outer_polygon_it) {
|
|
|
|
outer_vit = vit;
|
2011-06-14 15:58:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-10-21 18:52:48 +00:00
|
|
|
// Filter degenerate polygons to keep them from causing trouble later on
|
|
|
|
IfcVector3& n = normals[std::distance(begin,iit)];
|
|
|
|
const IfcFloat area = n.SquareLength();
|
|
|
|
if (area < 1e-5f) {
|
|
|
|
IFCImporter::LogWarn("skipping degenerate polygon (ProcessPolygonBoundaries)");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-10-20 21:26:49 +00:00
|
|
|
fake_openings.push_back(TempOpening());
|
|
|
|
TempOpening& opening = fake_openings.back();
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-10-20 21:26:49 +00:00
|
|
|
opening.extrusionDir = master_normal;
|
|
|
|
opening.solid = NULL;
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-10-20 21:26:49 +00:00
|
|
|
opening.profileMesh = boost::make_shared<TempMesh>();
|
|
|
|
opening.profileMesh->verts.reserve(*iit);
|
|
|
|
opening.profileMesh->vertcnt.push_back(*iit);
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-11-01 20:40:45 +00:00
|
|
|
std::copy(vit, vit + *iit, std::back_inserter(opening.profileMesh->verts));
|
2011-06-14 15:58:22 +00:00
|
|
|
}
|
|
|
|
|
2012-10-20 21:26:49 +00:00
|
|
|
// fill a mesh with ONLY the main polygon
|
|
|
|
TempMesh temp;
|
|
|
|
temp.verts.reserve(outer_polygon_size);
|
|
|
|
temp.vertcnt.push_back(outer_polygon_size);
|
|
|
|
std::copy(outer_vit, outer_vit+outer_polygon_size,
|
|
|
|
std::back_inserter(temp.verts));
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-11-02 23:56:38 +00:00
|
|
|
GenerateOpenings(fake_openings, normals, temp, false, false);
|
2012-10-20 21:26:49 +00:00
|
|
|
result.Append(temp);
|
2011-06-14 15:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void ProcessConnectedFaceSet(const IfcConnectedFaceSet& fset, TempMesh& result, ConversionData& conv)
|
|
|
|
{
|
|
|
|
BOOST_FOREACH(const IfcFace& face, fset.CfsFaces) {
|
|
|
|
// size_t ob = -1, cnt = 0;
|
|
|
|
TempMesh meshout;
|
|
|
|
BOOST_FOREACH(const IfcFaceBound& bound, face.Bounds) {
|
|
|
|
|
|
|
|
if(const IfcPolyLoop* const polyloop = bound.Bound->ToPtr<IfcPolyLoop>()) {
|
|
|
|
if(ProcessPolyloop(*polyloop, meshout,conv)) {
|
|
|
|
|
2012-10-21 17:08:12 +00:00
|
|
|
// The outer boundary is better determined by checking which
|
|
|
|
// polygon covers the largest area.
|
|
|
|
|
2011-06-14 15:58:22 +00:00
|
|
|
//if(bound.ToPtr<IfcFaceOuterBound>()) {
|
|
|
|
// ob = cnt;
|
|
|
|
//}
|
|
|
|
//++cnt;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
IFCImporter::LogWarn("skipping unknown IfcFaceBound entity, type is " + bound.Bound->GetClassName());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-10-21 17:08:12 +00:00
|
|
|
// And this, even though it is sometimes TRUE and sometimes FALSE,
|
|
|
|
// does not really improve results.
|
|
|
|
|
2011-06-14 15:58:22 +00:00
|
|
|
/*if(!IsTrue(bound.Orientation)) {
|
|
|
|
size_t c = 0;
|
|
|
|
BOOST_FOREACH(unsigned int& c, meshout.vertcnt) {
|
|
|
|
std::reverse(result.verts.begin() + cnt,result.verts.begin() + cnt + c);
|
|
|
|
cnt += c;
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
}
|
2012-10-20 21:26:49 +00:00
|
|
|
ProcessPolygonBoundaries(result, meshout);
|
2011-06-14 15:58:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void ProcessRevolvedAreaSolid(const IfcRevolvedAreaSolid& solid, TempMesh& result, ConversionData& conv)
|
|
|
|
{
|
|
|
|
TempMesh meshout;
|
|
|
|
|
|
|
|
// first read the profile description
|
|
|
|
if(!ProcessProfile(*solid.SweptArea,meshout,conv) || meshout.verts.size()<=1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-02 02:09:49 +00:00
|
|
|
IfcVector3 axis, pos;
|
2011-06-14 15:58:22 +00:00
|
|
|
ConvertAxisPlacement(axis,pos,solid.Axis);
|
|
|
|
|
2012-02-02 02:09:49 +00:00
|
|
|
IfcMatrix4 tb0,tb1;
|
|
|
|
IfcMatrix4::Translation(pos,tb0);
|
|
|
|
IfcMatrix4::Translation(-pos,tb1);
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-02-02 02:09:49 +00:00
|
|
|
const std::vector<IfcVector3>& in = meshout.verts;
|
2011-06-14 15:58:22 +00:00
|
|
|
const size_t size=in.size();
|
|
|
|
|
|
|
|
bool has_area = solid.SweptArea->ProfileType == "AREA" && size>2;
|
2012-02-02 02:09:49 +00:00
|
|
|
const IfcFloat max_angle = solid.Angle*conv.angle_scale;
|
2014-09-22 22:42:32 +00:00
|
|
|
if(std::fabs(max_angle) < 1e-3) {
|
2011-06-14 15:58:22 +00:00
|
|
|
if(has_area) {
|
|
|
|
result = meshout;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-22 22:42:32 +00:00
|
|
|
const unsigned int cnt_segments = std::max(2u,static_cast<unsigned int>(16 * std::fabs(max_angle)/AI_MATH_HALF_PI_F));
|
2012-02-02 02:09:49 +00:00
|
|
|
const IfcFloat delta = max_angle/cnt_segments;
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2014-09-22 22:42:32 +00:00
|
|
|
has_area = has_area && std::fabs(max_angle) < AI_MATH_TWO_PI_F*0.99;
|
2011-06-14 15:58:22 +00:00
|
|
|
|
|
|
|
result.verts.reserve(size*((cnt_segments+1)*4+(has_area?2:0)));
|
|
|
|
result.vertcnt.reserve(size*cnt_segments+2);
|
|
|
|
|
2012-02-02 02:09:49 +00:00
|
|
|
IfcMatrix4 rot;
|
|
|
|
rot = tb0 * IfcMatrix4::Rotation(delta,axis,rot) * tb1;
|
2011-06-14 15:58:22 +00:00
|
|
|
|
|
|
|
size_t base = 0;
|
2012-02-02 02:09:49 +00:00
|
|
|
std::vector<IfcVector3>& out = result.verts;
|
2011-06-14 15:58:22 +00:00
|
|
|
|
|
|
|
// dummy data to simplify later processing
|
|
|
|
for(size_t i = 0; i < size; ++i) {
|
|
|
|
out.insert(out.end(),4,in[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(unsigned int seg = 0; seg < cnt_segments; ++seg) {
|
|
|
|
for(size_t i = 0; i < size; ++i) {
|
|
|
|
const size_t next = (i+1)%size;
|
|
|
|
|
|
|
|
result.vertcnt.push_back(4);
|
2012-02-02 02:09:49 +00:00
|
|
|
const IfcVector3& base_0 = out[base+i*4+3],base_1 = out[base+next*4+3];
|
2011-06-14 15:58:22 +00:00
|
|
|
|
|
|
|
out.push_back(base_0);
|
|
|
|
out.push_back(base_1);
|
|
|
|
out.push_back(rot*base_1);
|
|
|
|
out.push_back(rot*base_0);
|
|
|
|
}
|
|
|
|
base += size*4;
|
|
|
|
}
|
|
|
|
|
|
|
|
out.erase(out.begin(),out.begin()+size*4);
|
|
|
|
|
|
|
|
if(has_area) {
|
|
|
|
// leave the triangulation of the profile area to the ear cutting
|
|
|
|
// implementation in aiProcess_Triangulate - for now we just
|
|
|
|
// feed in two huge polygons.
|
|
|
|
base -= size*8;
|
|
|
|
for(size_t i = size; i--; ) {
|
|
|
|
out.push_back(out[base+i*4+3]);
|
|
|
|
}
|
|
|
|
for(size_t i = 0; i < size; ++i ) {
|
|
|
|
out.push_back(out[i*4]);
|
|
|
|
}
|
|
|
|
result.vertcnt.push_back(size);
|
|
|
|
result.vertcnt.push_back(size);
|
|
|
|
}
|
|
|
|
|
2012-02-02 02:09:49 +00:00
|
|
|
IfcMatrix4 trafo;
|
2011-06-14 15:58:22 +00:00
|
|
|
ConvertAxisPlacement(trafo, solid.Position);
|
|
|
|
|
|
|
|
result.Transform(trafo);
|
|
|
|
IFCImporter::LogDebug("generate mesh procedurally by radial extrusion (IfcRevolvedAreaSolid)");
|
|
|
|
}
|
|
|
|
|
2012-07-11 22:11:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void ProcessSweptDiskSolid(const IfcSweptDiskSolid solid, TempMesh& result, ConversionData& conv)
|
|
|
|
{
|
|
|
|
const Curve* const curve = Curve::Convert(*solid.Directrix, conv);
|
|
|
|
if(!curve) {
|
|
|
|
IFCImporter::LogError("failed to convert Directrix curve (IfcSweptDiskSolid)");
|
|
|
|
return;
|
|
|
|
}
|
2013-04-08 18:10:25 +00:00
|
|
|
|
2012-07-11 22:11:16 +00:00
|
|
|
const unsigned int cnt_segments = 16;
|
|
|
|
const IfcFloat deltaAngle = AI_MATH_TWO_PI/cnt_segments;
|
|
|
|
|
|
|
|
const size_t samples = curve->EstimateSampleCount(solid.StartParam,solid.EndParam);
|
|
|
|
|
|
|
|
result.verts.reserve(cnt_segments * samples * 4);
|
|
|
|
result.vertcnt.reserve((cnt_segments - 1) * samples);
|
|
|
|
|
2012-07-11 23:08:44 +00:00
|
|
|
std::vector<IfcVector3> points;
|
|
|
|
points.reserve(cnt_segments * samples);
|
2012-07-11 22:11:16 +00:00
|
|
|
|
2012-07-11 23:08:44 +00:00
|
|
|
TempMesh temp;
|
|
|
|
curve->SampleDiscrete(temp,solid.StartParam,solid.EndParam);
|
|
|
|
const std::vector<IfcVector3>& curve_points = temp.verts;
|
|
|
|
|
|
|
|
if(curve_points.empty()) {
|
|
|
|
IFCImporter::LogWarn("curve evaluation yielded no points (IfcSweptDiskSolid)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IfcVector3 current = curve_points[0];
|
2012-07-11 22:11:16 +00:00
|
|
|
IfcVector3 previous = current;
|
|
|
|
IfcVector3 next;
|
|
|
|
|
|
|
|
IfcVector3 startvec;
|
|
|
|
startvec.x = 1.0f;
|
|
|
|
startvec.y = 1.0f;
|
|
|
|
startvec.z = 1.0f;
|
|
|
|
|
2012-09-10 00:40:41 +00:00
|
|
|
unsigned int last_dir = 0;
|
|
|
|
|
2012-07-11 22:11:16 +00:00
|
|
|
// generate circles at the sweep positions
|
2012-07-11 23:08:44 +00:00
|
|
|
for(size_t i = 0; i < samples; ++i) {
|
2012-07-11 22:11:16 +00:00
|
|
|
|
2012-07-11 23:08:44 +00:00
|
|
|
if(i != samples - 1) {
|
|
|
|
next = curve_points[i + 1];
|
|
|
|
}
|
2012-07-11 22:11:16 +00:00
|
|
|
|
|
|
|
// get a direction vector reflecting the approximate curvature (i.e. tangent)
|
|
|
|
IfcVector3 d = (current-previous) + (next-previous);
|
|
|
|
|
|
|
|
d.Normalize();
|
|
|
|
|
|
|
|
// figure out an arbitrary point q so that (p-q) * d = 0,
|
|
|
|
// try to maximize ||(p-q)|| * ||(p_last-q_last)||
|
|
|
|
IfcVector3 q;
|
2012-09-10 00:40:41 +00:00
|
|
|
bool take_any = false;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < 2; ++i, take_any = true) {
|
2015-01-22 20:03:13 +00:00
|
|
|
if ((last_dir == 0 || take_any) && std::abs(d.x) > 1e-6) {
|
2012-09-10 00:40:41 +00:00
|
|
|
q.y = startvec.y;
|
|
|
|
q.z = startvec.z;
|
|
|
|
q.x = -(d.y * q.y + d.z * q.z) / d.x;
|
|
|
|
last_dir = 0;
|
|
|
|
break;
|
|
|
|
}
|
2015-01-22 20:03:13 +00:00
|
|
|
else if ((last_dir == 1 || take_any) && std::abs(d.y) > 1e-6) {
|
2012-09-10 00:40:41 +00:00
|
|
|
q.x = startvec.x;
|
|
|
|
q.z = startvec.z;
|
|
|
|
q.y = -(d.x * q.x + d.z * q.z) / d.y;
|
|
|
|
last_dir = 1;
|
|
|
|
break;
|
|
|
|
}
|
2015-01-22 20:03:13 +00:00
|
|
|
else if ((last_dir == 2 && std::abs(d.z) > 1e-6) || take_any) {
|
2012-09-10 00:40:41 +00:00
|
|
|
q.y = startvec.y;
|
|
|
|
q.x = startvec.x;
|
|
|
|
q.z = -(d.y * q.y + d.x * q.x) / d.z;
|
|
|
|
last_dir = 2;
|
|
|
|
break;
|
|
|
|
}
|
2012-07-11 22:11:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
q *= solid.Radius / q.Length();
|
2012-09-10 00:40:41 +00:00
|
|
|
startvec = q;
|
2012-07-11 22:11:16 +00:00
|
|
|
|
|
|
|
// generate a rotation matrix to rotate q around d
|
|
|
|
IfcMatrix4 rot;
|
|
|
|
IfcMatrix4::Rotation(deltaAngle,d,rot);
|
|
|
|
|
|
|
|
for (unsigned int seg = 0; seg < cnt_segments; ++seg, q *= rot ) {
|
|
|
|
points.push_back(q + current);
|
|
|
|
}
|
|
|
|
|
|
|
|
previous = current;
|
|
|
|
current = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make quads
|
|
|
|
for(size_t i = 0; i < samples - 1; ++i) {
|
|
|
|
|
2012-09-10 00:40:41 +00:00
|
|
|
const aiVector3D& this_start = points[ i * cnt_segments ];
|
|
|
|
|
|
|
|
// locate corresponding point on next sample ring
|
|
|
|
unsigned int best_pair_offset = 0;
|
|
|
|
float best_distance_squared = 1e10f;
|
|
|
|
for (unsigned int seg = 0; seg < cnt_segments; ++seg) {
|
|
|
|
const aiVector3D& p = points[ (i+1) * cnt_segments + seg];
|
|
|
|
const float l = (p-this_start).SquareLength();
|
|
|
|
|
|
|
|
if(l < best_distance_squared) {
|
|
|
|
best_pair_offset = seg;
|
|
|
|
best_distance_squared = l;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned int seg = 0; seg < cnt_segments; ++seg) {
|
2012-07-11 22:11:16 +00:00
|
|
|
|
2012-09-10 00:40:41 +00:00
|
|
|
result.verts.push_back(points[ i * cnt_segments + (seg % cnt_segments)]);
|
|
|
|
result.verts.push_back(points[ i * cnt_segments + (seg + 1) % cnt_segments]);
|
|
|
|
result.verts.push_back(points[ (i+1) * cnt_segments + ((seg + 1 + best_pair_offset) % cnt_segments)]);
|
|
|
|
result.verts.push_back(points[ (i+1) * cnt_segments + ((seg + best_pair_offset) % cnt_segments)]);
|
2012-07-11 22:11:16 +00:00
|
|
|
|
2012-09-10 01:28:19 +00:00
|
|
|
IfcVector3& v1 = *(result.verts.end()-1);
|
|
|
|
IfcVector3& v2 = *(result.verts.end()-2);
|
|
|
|
IfcVector3& v3 = *(result.verts.end()-3);
|
|
|
|
IfcVector3& v4 = *(result.verts.end()-4);
|
|
|
|
|
|
|
|
if (((v4-v3) ^ (v4-v1)) * (v4 - curve_points[i]) < 0.0f) {
|
|
|
|
std::swap(v4, v1);
|
|
|
|
std::swap(v3, v2);
|
|
|
|
}
|
|
|
|
|
2012-07-11 22:11:16 +00:00
|
|
|
result.vertcnt.push_back(4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IFCImporter::LogDebug("generate mesh procedurally by sweeping a disk along a curve (IfcSweptDiskSolid)");
|
|
|
|
}
|
|
|
|
|
2011-06-14 15:58:22 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2013-01-27 20:21:30 +00:00
|
|
|
IfcMatrix3 DerivePlaneCoordinateSpace(const TempMesh& curmesh, bool& ok, IfcVector3& norOut)
|
2012-10-21 18:10:56 +00:00
|
|
|
{
|
2012-02-02 02:09:49 +00:00
|
|
|
const std::vector<IfcVector3>& out = curmesh.verts;
|
|
|
|
IfcMatrix3 m;
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-10-21 18:10:56 +00:00
|
|
|
ok = true;
|
|
|
|
|
2013-01-27 20:21:30 +00:00
|
|
|
// The input "mesh" must be a single polygon
|
2011-06-14 15:58:22 +00:00
|
|
|
const size_t s = out.size();
|
2012-01-17 01:49:17 +00:00
|
|
|
assert(curmesh.vertcnt.size() == 1 && curmesh.vertcnt.back() == s);
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-02-02 02:09:49 +00:00
|
|
|
const IfcVector3 any_point = out[s-1];
|
|
|
|
IfcVector3 nor;
|
2012-01-17 01:49:17 +00:00
|
|
|
|
2012-10-21 18:10:56 +00:00
|
|
|
// The input polygon is arbitrarily shaped, therefore we might need some tries
|
2013-04-08 18:10:25 +00:00
|
|
|
// until we find a suitable normal. Note that Newell's algorithm would give
|
2012-10-21 18:10:56 +00:00
|
|
|
// a more robust result, but this variant also gives us a suitable first
|
|
|
|
// axis for the 2D coordinate space on the polygon plane, exploiting the
|
|
|
|
// fact that the input polygon is nearly always a quad.
|
|
|
|
bool done = false;
|
2013-04-08 18:10:25 +00:00
|
|
|
size_t i, j;
|
2013-01-27 20:21:30 +00:00
|
|
|
for (i = 0; !done && i < s-2; done || ++i) {
|
|
|
|
for (j = i+1; j < s-1; ++j) {
|
2012-02-03 02:28:25 +00:00
|
|
|
nor = -((out[i]-any_point)^(out[j]-any_point));
|
2014-09-22 22:42:32 +00:00
|
|
|
if(std::fabs(nor.Length()) > 1e-8f) {
|
2012-10-21 18:10:56 +00:00
|
|
|
done = true;
|
|
|
|
break;
|
2012-01-17 01:49:17 +00:00
|
|
|
}
|
2011-06-14 15:58:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-21 18:10:56 +00:00
|
|
|
if(!done) {
|
|
|
|
ok = false;
|
|
|
|
return m;
|
|
|
|
}
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-01-17 01:49:17 +00:00
|
|
|
nor.Normalize();
|
2013-01-27 20:21:30 +00:00
|
|
|
norOut = nor;
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-02-02 02:09:49 +00:00
|
|
|
IfcVector3 r = (out[i]-any_point);
|
2012-01-17 01:49:17 +00:00
|
|
|
r.Normalize();
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2013-01-27 20:21:30 +00:00
|
|
|
//if(d) {
|
|
|
|
// *d = -any_point * nor;
|
|
|
|
//}
|
2012-11-01 20:40:45 +00:00
|
|
|
|
2012-10-21 18:10:56 +00:00
|
|
|
// Reconstruct orthonormal basis
|
|
|
|
// XXX use Gram Schmidt for increased robustness
|
2012-02-02 02:09:49 +00:00
|
|
|
IfcVector3 u = r ^ nor;
|
2012-01-17 01:49:17 +00:00
|
|
|
u.Normalize();
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-01-17 01:49:17 +00:00
|
|
|
m.a1 = r.x;
|
|
|
|
m.a2 = r.y;
|
|
|
|
m.a3 = r.z;
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-01-17 01:49:17 +00:00
|
|
|
m.b1 = u.x;
|
|
|
|
m.b2 = u.y;
|
|
|
|
m.b3 = u.z;
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2013-01-25 04:16:02 +00:00
|
|
|
m.c1 = -nor.x;
|
|
|
|
m.c2 = -nor.y;
|
|
|
|
m.c3 = -nor.z;
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-01-17 01:49:17 +00:00
|
|
|
return m;
|
2011-06-14 15:58:22 +00:00
|
|
|
}
|
|
|
|
|
2015-04-13 14:01:33 +00:00
|
|
|
// Extrudes the given polygon along the direction, converts it into an opening or applies all openings as necessary.
|
|
|
|
void ProcessExtrudedArea(const IfcExtrudedAreaSolid& solid, const TempMesh& curve,
|
|
|
|
const IfcVector3& extrusionDir, TempMesh& result, ConversionData &conv, bool collect_openings)
|
2011-06-14 15:58:22 +00:00
|
|
|
{
|
2015-04-13 14:01:33 +00:00
|
|
|
// Outline: 'curve' is now a list of vertex points forming the underlying profile, extrude along the given axis,
|
|
|
|
// forming new triangles.
|
|
|
|
const bool has_area = solid.SweptArea->ProfileType == "AREA" && curve.verts.size() > 2;
|
|
|
|
if( solid.Depth < 1e-6 ) {
|
|
|
|
if( has_area ) {
|
|
|
|
result.Append(curve);
|
2013-02-07 08:51:33 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2015-04-13 14:01:33 +00:00
|
|
|
result.verts.reserve(curve.verts.size()*(has_area ? 4 : 2));
|
|
|
|
result.vertcnt.reserve(curve.verts.size() + 2);
|
|
|
|
std::vector<IfcVector3> in = curve.verts;
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2013-02-07 08:51:33 +00:00
|
|
|
// First step: transform all vertices into the target coordinate space
|
|
|
|
IfcMatrix4 trafo;
|
|
|
|
ConvertAxisPlacement(trafo, solid.Position);
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2013-02-07 08:51:33 +00:00
|
|
|
IfcVector3 vmin, vmax;
|
|
|
|
MinMaxChooser<IfcVector3>()(vmin, vmax);
|
2015-04-13 14:01:33 +00:00
|
|
|
BOOST_FOREACH(IfcVector3& v, in) {
|
2013-02-07 08:51:33 +00:00
|
|
|
v *= trafo;
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2013-02-07 08:51:33 +00:00
|
|
|
vmin = std::min(vmin, v);
|
|
|
|
vmax = std::max(vmax, v);
|
2011-06-14 15:58:22 +00:00
|
|
|
}
|
|
|
|
|
2012-01-17 01:49:17 +00:00
|
|
|
vmax -= vmin;
|
2013-02-07 08:51:33 +00:00
|
|
|
const IfcFloat diag = vmax.Length();
|
2015-04-13 14:01:33 +00:00
|
|
|
IfcVector3 dir = IfcMatrix3(trafo) * extrusionDir;
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2015-02-23 13:23:28 +00:00
|
|
|
// reverse profile polygon if it's winded in the wrong direction in relation to the extrusion direction
|
2015-04-13 14:01:33 +00:00
|
|
|
IfcVector3 profileNormal = TempMesh::ComputePolygonNormal(in.data(), in.size());
|
2015-02-23 13:23:28 +00:00
|
|
|
if( profileNormal * dir < 0.0 )
|
2015-04-13 14:01:33 +00:00
|
|
|
std::reverse(in.begin(), in.end());
|
2015-02-23 13:23:28 +00:00
|
|
|
|
2013-02-07 08:51:33 +00:00
|
|
|
std::vector<IfcVector3> nors;
|
|
|
|
const bool openings = !!conv.apply_openings && conv.apply_openings->size();
|
2015-04-13 14:01:33 +00:00
|
|
|
|
2013-02-07 08:51:33 +00:00
|
|
|
// Compute the normal vectors for all opening polygons as a prerequisite
|
|
|
|
// to TryAddOpenings_Poly2Tri()
|
|
|
|
// XXX this belongs into the aforementioned function
|
2015-04-13 14:01:33 +00:00
|
|
|
if( openings ) {
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2015-04-13 14:01:33 +00:00
|
|
|
if( !conv.settings.useCustomTriangulation ) {
|
2013-02-07 08:51:33 +00:00
|
|
|
// it is essential to apply the openings in the correct spatial order. The direction
|
|
|
|
// doesn't matter, but we would screw up if we started with e.g. a door in between
|
|
|
|
// two windows.
|
2015-04-13 14:01:33 +00:00
|
|
|
std::sort(conv.apply_openings->begin(), conv.apply_openings->end(), TempOpening::DistanceSorter(in[0]));
|
2013-02-07 08:51:33 +00:00
|
|
|
}
|
2015-04-13 14:01:33 +00:00
|
|
|
|
2013-02-07 08:51:33 +00:00
|
|
|
nors.reserve(conv.apply_openings->size());
|
2015-04-13 14:01:33 +00:00
|
|
|
BOOST_FOREACH(TempOpening& t, *conv.apply_openings) {
|
2013-02-07 08:51:33 +00:00
|
|
|
TempMesh& bounds = *t.profileMesh.get();
|
2015-04-13 14:01:33 +00:00
|
|
|
|
|
|
|
if( bounds.verts.size() <= 2 ) {
|
2013-02-07 08:51:33 +00:00
|
|
|
nors.push_back(IfcVector3());
|
|
|
|
continue;
|
2011-06-14 15:58:22 +00:00
|
|
|
}
|
2015-04-13 14:01:33 +00:00
|
|
|
nors.push_back(((bounds.verts[2] - bounds.verts[0]) ^ (bounds.verts[1] - bounds.verts[0])).Normalize());
|
2012-01-17 01:49:17 +00:00
|
|
|
}
|
2013-02-07 08:51:33 +00:00
|
|
|
}
|
2015-04-13 14:01:33 +00:00
|
|
|
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2013-02-07 08:51:33 +00:00
|
|
|
TempMesh temp;
|
|
|
|
TempMesh& curmesh = openings ? temp : result;
|
|
|
|
std::vector<IfcVector3>& out = curmesh.verts;
|
2015-04-13 14:01:33 +00:00
|
|
|
|
2013-02-07 08:51:33 +00:00
|
|
|
size_t sides_with_openings = 0;
|
2015-04-13 14:01:33 +00:00
|
|
|
for( size_t i = 0; i < in.size(); ++i ) {
|
|
|
|
const size_t next = (i + 1) % in.size();
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2013-02-07 08:51:33 +00:00
|
|
|
curmesh.vertcnt.push_back(4);
|
2015-04-13 14:01:33 +00:00
|
|
|
|
2013-02-07 08:51:33 +00:00
|
|
|
out.push_back(in[i]);
|
|
|
|
out.push_back(in[next]);
|
2015-04-13 14:01:33 +00:00
|
|
|
out.push_back(in[next] + dir);
|
|
|
|
out.push_back(in[i] + dir);
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2015-04-13 14:01:33 +00:00
|
|
|
if( openings ) {
|
|
|
|
if( (in[i] - in[next]).Length() > diag * 0.1 && GenerateOpenings(*conv.apply_openings, nors, temp, true, true, dir) ) {
|
2013-02-07 08:51:33 +00:00
|
|
|
++sides_with_openings;
|
2012-01-17 01:49:17 +00:00
|
|
|
}
|
2015-04-13 14:01:33 +00:00
|
|
|
|
2013-02-07 08:51:33 +00:00
|
|
|
result.Append(temp);
|
|
|
|
temp.Clear();
|
2011-06-14 15:58:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-13 14:01:33 +00:00
|
|
|
if( openings ) {
|
2013-02-07 08:51:33 +00:00
|
|
|
BOOST_FOREACH(TempOpening& opening, *conv.apply_openings) {
|
2015-04-13 14:01:33 +00:00
|
|
|
if( !opening.wallPoints.empty() ) {
|
2013-02-07 08:51:33 +00:00
|
|
|
IFCImporter::LogError("failed to generate all window caps");
|
2012-01-17 01:49:17 +00:00
|
|
|
}
|
2013-02-07 08:51:33 +00:00
|
|
|
opening.wallPoints.clear();
|
2012-01-17 01:49:17 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-13 14:01:33 +00:00
|
|
|
|
2013-02-07 08:51:33 +00:00
|
|
|
size_t sides_with_v_openings = 0;
|
2015-04-13 14:01:33 +00:00
|
|
|
if( has_area ) {
|
2012-01-17 01:49:17 +00:00
|
|
|
|
2015-04-13 14:01:33 +00:00
|
|
|
for( size_t n = 0; n < 2; ++n ) {
|
2015-02-23 13:23:28 +00:00
|
|
|
if( n > 0 ) {
|
2015-04-13 14:01:33 +00:00
|
|
|
for( size_t i = 0; i < in.size(); ++i )
|
|
|
|
out.push_back(in[i] + dir);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for( size_t i = in.size(); i--; )
|
2015-02-23 13:23:28 +00:00
|
|
|
out.push_back(in[i]);
|
2012-01-17 01:49:17 +00:00
|
|
|
}
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2015-04-13 14:01:33 +00:00
|
|
|
curmesh.vertcnt.push_back(in.size());
|
|
|
|
if( openings && in.size() > 2 ) {
|
|
|
|
if( GenerateOpenings(*conv.apply_openings, nors, temp, true, true, dir) ) {
|
2013-02-07 08:51:33 +00:00
|
|
|
++sides_with_v_openings;
|
|
|
|
}
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2013-02-07 08:51:33 +00:00
|
|
|
result.Append(temp);
|
|
|
|
temp.Clear();
|
2012-01-17 01:49:17 +00:00
|
|
|
}
|
2012-01-17 17:40:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-13 14:01:33 +00:00
|
|
|
if( openings && ((sides_with_openings == 1 && sides_with_openings) || (sides_with_v_openings == 2 && sides_with_v_openings)) ) {
|
2013-02-07 08:51:33 +00:00
|
|
|
IFCImporter::LogWarn("failed to resolve all openings, presumably their topology is not supported by Assimp");
|
2012-01-17 17:40:15 +00:00
|
|
|
}
|
|
|
|
|
2013-02-07 08:51:33 +00:00
|
|
|
IFCImporter::LogDebug("generate mesh procedurally by extrusion (IfcExtrudedAreaSolid)");
|
2012-01-17 17:40:15 +00:00
|
|
|
|
2013-02-07 08:51:33 +00:00
|
|
|
// If this is an opening element, store both the extruded mesh and the 2D profile mesh
|
|
|
|
// it was created from. Return an empty mesh to the caller.
|
2015-04-13 14:01:33 +00:00
|
|
|
if( collect_openings && !result.IsEmpty() ) {
|
2013-02-07 08:51:33 +00:00
|
|
|
ai_assert(conv.collect_openings);
|
|
|
|
boost::shared_ptr<TempMesh> profile = boost::shared_ptr<TempMesh>(new TempMesh());
|
|
|
|
profile->Swap(result);
|
2012-01-17 17:40:15 +00:00
|
|
|
|
2013-02-07 08:51:33 +00:00
|
|
|
boost::shared_ptr<TempMesh> profile2D = boost::shared_ptr<TempMesh>(new TempMesh());
|
2015-04-13 14:01:33 +00:00
|
|
|
profile2D->verts.insert(profile2D->verts.end(), in.begin(), in.end());
|
|
|
|
profile2D->vertcnt.push_back(in.size());
|
|
|
|
conv.collect_openings->push_back(TempOpening(&solid, dir, profile, profile2D));
|
2012-01-17 17:40:15 +00:00
|
|
|
|
2013-02-07 08:51:33 +00:00
|
|
|
ai_assert(result.IsEmpty());
|
2015-04-13 14:01:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void ProcessExtrudedAreaSolid(const IfcExtrudedAreaSolid& solid, TempMesh& result,
|
|
|
|
ConversionData& conv, bool collect_openings)
|
|
|
|
{
|
|
|
|
TempMesh meshout;
|
|
|
|
|
|
|
|
// First read the profile description.
|
|
|
|
if(!ProcessProfile(*solid.SweptArea,meshout,conv) || meshout.verts.size()<=1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IfcVector3 dir;
|
|
|
|
ConvertDirection(dir,solid.ExtrudedDirection);
|
|
|
|
dir *= solid.Depth;
|
|
|
|
|
|
|
|
// Some profiles bring their own holes, for which we need to provide a container. This all is somewhat backwards,
|
|
|
|
// and there's still so many corner cases uncovered - we really need a generic solution to all of this hole carving.
|
|
|
|
std::vector<TempOpening> fisherPriceMyFirstOpenings;
|
|
|
|
std::vector<TempOpening>* oldApplyOpenings = conv.apply_openings;
|
|
|
|
if( const IfcArbitraryProfileDefWithVoids* const cprofile = solid.SweptArea->ToPtr<IfcArbitraryProfileDefWithVoids>() ) {
|
|
|
|
if( !cprofile->InnerCurves.empty() ) {
|
|
|
|
// read all inner curves and extrude them to form proper openings.
|
|
|
|
std::vector<TempOpening>* oldCollectOpenings = conv.collect_openings;
|
|
|
|
conv.collect_openings = &fisherPriceMyFirstOpenings;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const IfcCurve* curve, cprofile->InnerCurves) {
|
|
|
|
TempMesh curveMesh, tempMesh;
|
|
|
|
ProcessCurve(*curve, curveMesh, conv);
|
|
|
|
ProcessExtrudedArea(solid, curveMesh, dir, tempMesh, conv, true);
|
|
|
|
}
|
|
|
|
// and then apply those to the geometry we're about to generate
|
|
|
|
conv.apply_openings = conv.collect_openings;
|
|
|
|
conv.collect_openings = oldCollectOpenings;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessExtrudedArea(solid, meshout, dir, result, conv, collect_openings);
|
|
|
|
conv.apply_openings = oldApplyOpenings;
|
2012-01-17 17:40:15 +00:00
|
|
|
}
|
|
|
|
|
2013-02-07 08:51:33 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void ProcessSweptAreaSolid(const IfcSweptAreaSolid& swept, TempMesh& meshout,
|
|
|
|
ConversionData& conv)
|
2012-11-18 19:41:26 +00:00
|
|
|
{
|
2013-02-07 08:51:33 +00:00
|
|
|
if(const IfcExtrudedAreaSolid* const solid = swept.ToPtr<IfcExtrudedAreaSolid>()) {
|
|
|
|
ProcessExtrudedAreaSolid(*solid,meshout,conv, !!conv.collect_openings);
|
2012-11-18 19:41:26 +00:00
|
|
|
}
|
2013-02-07 08:51:33 +00:00
|
|
|
else if(const IfcRevolvedAreaSolid* const rev = swept.ToPtr<IfcRevolvedAreaSolid>()) {
|
|
|
|
ProcessRevolvedAreaSolid(*rev,meshout,conv);
|
2011-06-14 15:58:22 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
IFCImporter::LogWarn("skipping unknown IfcSweptAreaSolid entity, type is " + swept.GetClassName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-02-23 13:23:28 +00:00
|
|
|
bool ProcessGeometricItem(const IfcRepresentationItem& geo, unsigned int matid, std::vector<unsigned int>& mesh_indices,
|
2012-10-17 00:04:24 +00:00
|
|
|
ConversionData& conv)
|
2011-06-14 15:58:22 +00:00
|
|
|
{
|
2015-02-23 13:23:28 +00:00
|
|
|
bool fix_orientation = false;
|
2012-11-02 03:29:04 +00:00
|
|
|
boost::shared_ptr< TempMesh > meshtmp = boost::make_shared<TempMesh>();
|
2011-06-14 15:58:22 +00:00
|
|
|
if(const IfcShellBasedSurfaceModel* shellmod = geo.ToPtr<IfcShellBasedSurfaceModel>()) {
|
|
|
|
BOOST_FOREACH(boost::shared_ptr<const IfcShell> shell,shellmod->SbsmBoundary) {
|
|
|
|
try {
|
|
|
|
const EXPRESS::ENTITY& e = shell->To<ENTITY>();
|
|
|
|
const IfcConnectedFaceSet& fs = conv.db.MustGetObject(e).To<IfcConnectedFaceSet>();
|
|
|
|
|
2012-11-02 03:29:04 +00:00
|
|
|
ProcessConnectedFaceSet(fs,*meshtmp.get(),conv);
|
2011-06-14 15:58:22 +00:00
|
|
|
}
|
|
|
|
catch(std::bad_cast&) {
|
|
|
|
IFCImporter::LogWarn("unexpected type error, IfcShell ought to inherit from IfcConnectedFaceSet");
|
|
|
|
}
|
|
|
|
}
|
2015-02-23 13:23:28 +00:00
|
|
|
fix_orientation = true;
|
2011-06-14 15:58:22 +00:00
|
|
|
}
|
2012-01-17 17:40:15 +00:00
|
|
|
else if(const IfcConnectedFaceSet* fset = geo.ToPtr<IfcConnectedFaceSet>()) {
|
2012-11-02 03:29:04 +00:00
|
|
|
ProcessConnectedFaceSet(*fset,*meshtmp.get(),conv);
|
2015-02-23 13:23:28 +00:00
|
|
|
fix_orientation = true;
|
2012-01-17 01:49:17 +00:00
|
|
|
}
|
2012-01-17 17:40:15 +00:00
|
|
|
else if(const IfcSweptAreaSolid* swept = geo.ToPtr<IfcSweptAreaSolid>()) {
|
2012-11-02 03:29:04 +00:00
|
|
|
ProcessSweptAreaSolid(*swept,*meshtmp.get(),conv);
|
2012-01-17 17:40:15 +00:00
|
|
|
}
|
2012-07-11 22:11:16 +00:00
|
|
|
else if(const IfcSweptDiskSolid* disk = geo.ToPtr<IfcSweptDiskSolid>()) {
|
2012-11-02 03:29:04 +00:00
|
|
|
ProcessSweptDiskSolid(*disk,*meshtmp.get(),conv);
|
2012-07-11 22:11:16 +00:00
|
|
|
}
|
2011-06-14 15:58:22 +00:00
|
|
|
else if(const IfcManifoldSolidBrep* brep = geo.ToPtr<IfcManifoldSolidBrep>()) {
|
2012-11-02 03:29:04 +00:00
|
|
|
ProcessConnectedFaceSet(brep->Outer,*meshtmp.get(),conv);
|
2015-02-23 13:23:28 +00:00
|
|
|
fix_orientation = true;
|
2012-01-17 17:40:15 +00:00
|
|
|
}
|
2011-06-14 15:58:22 +00:00
|
|
|
else if(const IfcFaceBasedSurfaceModel* surf = geo.ToPtr<IfcFaceBasedSurfaceModel>()) {
|
|
|
|
BOOST_FOREACH(const IfcConnectedFaceSet& fc, surf->FbsmFaces) {
|
2012-11-02 03:29:04 +00:00
|
|
|
ProcessConnectedFaceSet(fc,*meshtmp.get(),conv);
|
2011-06-14 15:58:22 +00:00
|
|
|
}
|
2015-02-23 13:23:28 +00:00
|
|
|
fix_orientation = true;
|
2012-01-17 17:40:15 +00:00
|
|
|
}
|
2012-02-03 02:28:25 +00:00
|
|
|
else if(const IfcBooleanResult* boolean = geo.ToPtr<IfcBooleanResult>()) {
|
2012-11-02 03:29:04 +00:00
|
|
|
ProcessBoolean(*boolean,*meshtmp.get(),conv);
|
2011-06-14 15:58:22 +00:00
|
|
|
}
|
|
|
|
else if(geo.ToPtr<IfcBoundingBox>()) {
|
|
|
|
// silently skip over bounding boxes
|
|
|
|
return false;
|
2012-01-17 01:49:17 +00:00
|
|
|
}
|
2011-06-14 15:58:22 +00:00
|
|
|
else {
|
|
|
|
IFCImporter::LogWarn("skipping unknown IfcGeometricRepresentationItem entity, type is " + geo.GetClassName());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-02 03:29:04 +00:00
|
|
|
// Do we just collect openings for a parent element (i.e. a wall)?
|
2013-01-27 20:21:30 +00:00
|
|
|
// In such a case, we generate the polygonal mesh as usual,
|
2012-11-02 03:29:04 +00:00
|
|
|
// but attach it to a TempOpening instance which will later be applied
|
|
|
|
// to the wall it pertains to.
|
2013-01-27 20:21:30 +00:00
|
|
|
|
|
|
|
// Note: swep area solids are added in ProcessExtrudedAreaSolid(),
|
|
|
|
// which returns an empty mesh.
|
2012-11-02 03:29:04 +00:00
|
|
|
if(conv.collect_openings) {
|
2013-01-30 12:01:16 +00:00
|
|
|
if (!meshtmp->IsEmpty()) {
|
|
|
|
conv.collect_openings->push_back(TempOpening(geo.ToPtr<IfcSolidModel>(),
|
|
|
|
IfcVector3(0,0,0),
|
|
|
|
meshtmp,
|
2013-02-09 16:42:11 +00:00
|
|
|
boost::shared_ptr<TempMesh>()));
|
2013-01-30 12:01:16 +00:00
|
|
|
}
|
2012-11-02 03:29:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-09-10 01:28:19 +00:00
|
|
|
|
2013-01-30 12:01:16 +00:00
|
|
|
if (meshtmp->IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-27 20:21:30 +00:00
|
|
|
meshtmp->RemoveAdjacentDuplicates();
|
|
|
|
meshtmp->RemoveDegenerates();
|
|
|
|
|
2012-09-10 01:28:19 +00:00
|
|
|
if(fix_orientation) {
|
2015-04-13 14:01:33 +00:00
|
|
|
// meshtmp->FixupFaceOrientation();
|
2012-09-10 01:28:19 +00:00
|
|
|
}
|
2011-06-14 15:58:22 +00:00
|
|
|
|
2012-11-02 03:29:04 +00:00
|
|
|
aiMesh* const mesh = meshtmp->ToMesh();
|
2011-06-14 15:58:22 +00:00
|
|
|
if(mesh) {
|
2015-02-23 13:23:28 +00:00
|
|
|
mesh->mMaterialIndex = matid;
|
2011-06-14 15:58:22 +00:00
|
|
|
mesh_indices.push_back(conv.meshes.size());
|
|
|
|
conv.meshes.push_back(mesh);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2012-10-17 00:04:24 +00:00
|
|
|
void AssignAddedMeshes(std::vector<unsigned int>& mesh_indices,aiNode* nd,
|
|
|
|
ConversionData& /*conv*/)
|
2011-06-14 15:58:22 +00:00
|
|
|
{
|
|
|
|
if (!mesh_indices.empty()) {
|
|
|
|
|
|
|
|
// make unique
|
|
|
|
std::sort(mesh_indices.begin(),mesh_indices.end());
|
|
|
|
std::vector<unsigned int>::iterator it_end = std::unique(mesh_indices.begin(),mesh_indices.end());
|
|
|
|
|
|
|
|
const size_t size = std::distance(mesh_indices.begin(),it_end);
|
|
|
|
|
|
|
|
nd->mNumMeshes = size;
|
|
|
|
nd->mMeshes = new unsigned int[nd->mNumMeshes];
|
|
|
|
for(unsigned int i = 0; i < nd->mNumMeshes; ++i) {
|
|
|
|
nd->mMeshes[i] = mesh_indices[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2012-10-17 00:04:24 +00:00
|
|
|
bool TryQueryMeshCache(const IfcRepresentationItem& item,
|
2015-02-23 13:23:28 +00:00
|
|
|
std::vector<unsigned int>& mesh_indices, unsigned int mat_index,
|
2012-10-17 00:04:24 +00:00
|
|
|
ConversionData& conv)
|
2011-06-14 15:58:22 +00:00
|
|
|
{
|
2015-02-23 13:23:28 +00:00
|
|
|
ConversionData::MeshCacheIndex idx(&item, mat_index);
|
|
|
|
ConversionData::MeshCache::const_iterator it = conv.cached_meshes.find(idx);
|
2011-06-14 15:58:22 +00:00
|
|
|
if (it != conv.cached_meshes.end()) {
|
|
|
|
std::copy((*it).second.begin(),(*it).second.end(),std::back_inserter(mesh_indices));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2012-10-17 00:04:24 +00:00
|
|
|
void PopulateMeshCache(const IfcRepresentationItem& item,
|
2015-02-23 13:23:28 +00:00
|
|
|
const std::vector<unsigned int>& mesh_indices, unsigned int mat_index,
|
2012-10-17 00:04:24 +00:00
|
|
|
ConversionData& conv)
|
2011-06-14 15:58:22 +00:00
|
|
|
{
|
2015-02-23 13:23:28 +00:00
|
|
|
ConversionData::MeshCacheIndex idx(&item, mat_index);
|
|
|
|
conv.cached_meshes[idx] = mesh_indices;
|
2011-06-14 15:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-02-23 13:23:28 +00:00
|
|
|
bool ProcessRepresentationItem(const IfcRepresentationItem& item, unsigned int matid,
|
2012-10-17 00:04:24 +00:00
|
|
|
std::vector<unsigned int>& mesh_indices,
|
|
|
|
ConversionData& conv)
|
2011-06-14 15:58:22 +00:00
|
|
|
{
|
2015-02-23 13:23:28 +00:00
|
|
|
// determine material
|
|
|
|
unsigned int localmatid = ProcessMaterials(item.GetID(), matid, conv, true);
|
|
|
|
|
|
|
|
if (!TryQueryMeshCache(item,mesh_indices,localmatid,conv)) {
|
|
|
|
if(ProcessGeometricItem(item,localmatid,mesh_indices,conv)) {
|
2011-06-14 15:58:22 +00:00
|
|
|
if(mesh_indices.size()) {
|
2015-02-23 13:23:28 +00:00
|
|
|
PopulateMeshCache(item,mesh_indices,localmatid,conv);
|
2011-06-14 15:58:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-17 17:40:15 +00:00
|
|
|
|
2011-06-14 15:58:22 +00:00
|
|
|
} // ! IFC
|
|
|
|
} // ! Assimp
|
|
|
|
|
|
|
|
#endif
|