mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-09 13:52:23 +00:00
Updated IfcBlender.py
Fix gcc compilation (Patch by Jochem Berndsen)
This commit is contained in:
@@ -618,57 +618,4 @@ an absolute waiver of all civil liability in connection with the
|
|||||||
Program, unless a warranty or assumption of liability accompanies a
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
copy of the Program in return for a fee.
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
|
||||||
notice like this when it starts in an interactive mode:
|
|
||||||
|
|
||||||
<program> Copyright (C) <year> <name of author>
|
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, your program's commands
|
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
|
||||||
<http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
|
||||||
may consider it more useful to permit linking proprietary applications with
|
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License. But first, please read
|
|
||||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
|
||||||
@@ -1,51 +1,112 @@
|
|||||||
import bpy, mathutils
|
##############################################################################
|
||||||
|
# #
|
||||||
|
#This file is part of IfcOpenShell. #
|
||||||
|
# #
|
||||||
|
#IfcOpenShell is free software: you can redistribute it and/or modify #
|
||||||
|
#it under the terms of the Lesser GNU General Public License as published by #
|
||||||
|
#the Free Software Foundation, either version 3.0 of the License, or #
|
||||||
|
#(at your option) any later version. #
|
||||||
|
# #
|
||||||
|
#IfcOpenShell is distributed in the hope that it will be useful, #
|
||||||
|
#but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||||
|
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||||
|
#Lesser GNU General Public License for more details. #
|
||||||
|
# #
|
||||||
|
#You should have received a copy of the Lesser GNU General Public License #
|
||||||
|
#along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||||
|
# #
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
|
||||||
|
bl_info = {
|
||||||
|
"name": "IfcBlender",
|
||||||
|
"description": "Import files in the "\
|
||||||
|
"Industry Foundation Classes (.ifc) file format",
|
||||||
|
"author": "Thomas Krijnen, IfcOpenShell",
|
||||||
|
"blender": (2, 5, 6),
|
||||||
|
"api": 32738,
|
||||||
|
"location": "File > Import",
|
||||||
|
"warning": "This addon requires several "\
|
||||||
|
"Open CASCADE libraries to be installed",
|
||||||
|
"wiki_url": "http://sourceforge.net/apps/"\
|
||||||
|
"mediawiki/ifcopenshell/index.php",
|
||||||
|
"tracker_url": "http://sourceforge.net/tracker/?group_id=543113",
|
||||||
|
"category": "Import-Export"}
|
||||||
|
|
||||||
|
|
||||||
|
import bpy
|
||||||
|
import mathutils
|
||||||
from bpy.props import *
|
from bpy.props import *
|
||||||
from io_utils import ImportHelper
|
from io_utils import ImportHelper
|
||||||
|
|
||||||
|
|
||||||
class ImportIFC(bpy.types.Operator, ImportHelper):
|
class ImportIFC(bpy.types.Operator, ImportHelper):
|
||||||
'''Load an IFC File'''
|
|
||||||
bl_idname = "import_scene.ifc"
|
bl_idname = "import_scene.ifc"
|
||||||
bl_label = "Import IFC"
|
bl_label = "Import .ifc file"
|
||||||
|
|
||||||
filename_ext = ".ifc"
|
filename_ext = ".ifc"
|
||||||
filter_glob = StringProperty(default="*.ifc", options={'HIDDEN'})
|
filter_glob = StringProperty(default="*.ifc", options={'HIDDEN'})
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
import IFCimport
|
import IfcImport
|
||||||
IFCimport.init_objs(self.filepath)
|
if not IfcImport.Init(self.filepath):
|
||||||
|
return {'FINISHED'}
|
||||||
ids = {}
|
ids = {}
|
||||||
while True:
|
while True:
|
||||||
ob = IFCimport.current_obj()
|
ob = IfcImport.Get()
|
||||||
print (ob.name)
|
if not ob.type in ['IFCSPACE', 'IFCOPENINGELEMENT']:
|
||||||
if not ob.type in ['IFCSPACE','IFCOPENINGELEMENT']:
|
|
||||||
f = ob.mesh.faces
|
f = ob.mesh.faces
|
||||||
v = ob.mesh.verts
|
v = ob.mesh.verts
|
||||||
m = ob.matrix
|
m = ob.matrix
|
||||||
if ob.mesh.id in ids: me = ids[ob.mesh.id]
|
if ob.mesh.id in ids:
|
||||||
|
me = ids[ob.mesh.id]
|
||||||
else:
|
else:
|
||||||
verts = []
|
verts = []
|
||||||
faces = []
|
faces = []
|
||||||
for i in range(0,len(f),3):
|
for i in range(0, len(f), 3):
|
||||||
faces.append([f[i+0],f[i+1],f[i+2]])
|
faces.append([f[i + 0], f[i + 1], f[i + 2]])
|
||||||
for i in range(0,len(v),3):
|
for i in range(0, len(v), 3):
|
||||||
verts.append([v[i+0],v[i+1],v[i+2]])
|
verts.append([v[i + 0], v[i + 1], v[i + 2]])
|
||||||
me = bpy.data.meshes.new('mesh%d'%ob.mesh.id)
|
me = bpy.data.meshes.new('mesh%d' % ob.mesh.id)
|
||||||
me.from_pydata(verts,[],faces)
|
me.from_pydata(verts, [], faces)
|
||||||
if ob.type in bpy.data.materials:
|
if ob.type in bpy.data.materials:
|
||||||
mat = bpy.data.materials[ob.type]
|
mat = bpy.data.materials[ob.type]
|
||||||
mat.use_fake_user = True
|
mat.use_fake_user = True
|
||||||
else: mat = bpy.data.materials.new(ob.type)
|
else:
|
||||||
|
mat = bpy.data.materials.new(ob.type)
|
||||||
me.materials.append(mat)
|
me.materials.append(mat)
|
||||||
ids[ob.mesh.id] = me
|
ids[ob.mesh.id] = me
|
||||||
bob = bpy.data.objects.new(ob.name,me)
|
bob = bpy.data.objects.new(ob.name, me)
|
||||||
bob.matrix_world = mathutils.Matrix([m[0],m[1],m[2],0],[m[3],m[4],m[5],0],[m[6],m[7],m[8],0],[m[9],m[10],m[11],1])
|
bob.matrix_world = mathutils.Matrix(([m[0], m[1], m[2], 0],
|
||||||
|
[m[3], m[4], m[5], 0],
|
||||||
|
[m[6], m[7], m[8], 0],
|
||||||
|
[m[9], m[10], m[11], 1]))
|
||||||
bpy.context.scene.objects.link(bob)
|
bpy.context.scene.objects.link(bob)
|
||||||
me.update()
|
me.update()
|
||||||
if not IFCimport.next_obj(): break
|
bpy.ops.object.select_all(action='DESELECT')
|
||||||
|
bpy.ops.object.select_name(name=bob.name)
|
||||||
|
bpy.ops.object.mode_set(mode='EDIT')
|
||||||
|
bpy.ops.mesh.normals_make_consistent()
|
||||||
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||||||
|
if not IfcImport.Next():
|
||||||
|
break
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
def menu_func_import(self, context):
|
def menu_func_import(self, context):
|
||||||
self.layout.operator(ImportIFC.bl_idname, text="Industry Foundation Classes (.ifc)")
|
self.layout.operator(ImportIFC.bl_idname,
|
||||||
|
text="Industry Foundation Classes (.ifc)")
|
||||||
|
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
|
bpy.utils.register_module(__name__)
|
||||||
bpy.types.INFO_MT_file_import.append(menu_func_import)
|
bpy.types.INFO_MT_file_import.append(menu_func_import)
|
||||||
register()
|
|
||||||
|
|
||||||
|
def unregister():
|
||||||
|
bpy.utils.unregister_module(__name__)
|
||||||
|
bpy.types.INFO_MT_file_import.remove(menu_func_import)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
register()
|
||||||
|
|||||||
@@ -177,13 +177,13 @@ bool IfcGeom::convert(IfcSchema::Face* IfcFace, TopoDS_Face& face) {
|
|||||||
IfcEntity loop = bound->Loop();
|
IfcEntity loop = bound->Loop();
|
||||||
TopoDS_Wire wire;
|
TopoDS_Wire wire;
|
||||||
if ( ! IfcGeom::convert_wire(loop,wire) ) return false;
|
if ( ! IfcGeom::convert_wire(loop,wire) ) return false;
|
||||||
BRepBuilderAPI_MakeFace mf = BRepBuilderAPI_MakeFace(wire);
|
BRepBuilderAPI_MakeFace mf(wire, false);
|
||||||
BRepBuilderAPI_FaceError er = mf.Error();
|
BRepBuilderAPI_FaceError er = mf.Error();
|
||||||
if ( er == BRepBuilderAPI_NotPlanar ) {
|
if ( er == BRepBuilderAPI_NotPlanar ) {
|
||||||
std::cout << "[Notice] Trying to fix non-planar face" << std::endl;
|
std::cout << "[Notice] Trying to fix non-planar face" << std::endl;
|
||||||
ShapeFix_ShapeTolerance FTol;
|
ShapeFix_ShapeTolerance FTol;
|
||||||
FTol.SetTolerance(wire, 0.01, TopAbs_WIRE);
|
FTol.SetTolerance(wire, 0.01, TopAbs_WIRE);
|
||||||
mf = BRepBuilderAPI_MakeFace(wire);
|
mf = BRepBuilderAPI_MakeFace(wire, false);
|
||||||
er = mf.Error();
|
er = mf.Error();
|
||||||
}
|
}
|
||||||
if ( er != BRepBuilderAPI_FaceDone ) return false;
|
if ( er != BRepBuilderAPI_FaceDone ) return false;
|
||||||
@@ -226,7 +226,7 @@ bool IfcGeom::convert(IfcSchema::ArbitraryClosedProfileDef* IfcArbitraryClosedPr
|
|||||||
bool IfcGeom::convert(IfcSchema::ArbitraryProfileDefWithVoids* IfcArbitraryProfileDefWithVoids, TopoDS_Face& face) {
|
bool IfcGeom::convert(IfcSchema::ArbitraryProfileDefWithVoids* IfcArbitraryProfileDefWithVoids, TopoDS_Face& face) {
|
||||||
TopoDS_Wire profile;
|
TopoDS_Wire profile;
|
||||||
if ( ! IfcGeom::convert_wire(IfcArbitraryProfileDefWithVoids->Polyline(),profile) ) return false;
|
if ( ! IfcGeom::convert_wire(IfcArbitraryProfileDefWithVoids->Polyline(),profile) ) return false;
|
||||||
BRepBuilderAPI_MakeFace mf = BRepBuilderAPI_MakeFace(profile);
|
BRepBuilderAPI_MakeFace mf(profile, false);
|
||||||
IfcEntities voids = IfcArbitraryProfileDefWithVoids->Voids();
|
IfcEntities voids = IfcArbitraryProfileDefWithVoids->Voids();
|
||||||
for( IfcParse::Entities::it it = voids->begin(); it != voids->end(); ++ it ) {
|
for( IfcParse::Entities::it it = voids->begin(); it != voids->end(); ++ it ) {
|
||||||
TopoDS_Wire hole;
|
TopoDS_Wire hole;
|
||||||
@@ -357,16 +357,16 @@ bool IfcGeom::convert_openings(const IfcSchema::BuildingElement* IfcBuildingElem
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool IfcGeom::convert_wire_to_face(const TopoDS_Wire& wire, TopoDS_Face& face) {
|
bool IfcGeom::convert_wire_to_face(const TopoDS_Wire& wire, TopoDS_Face& face) {
|
||||||
BRepBuilderAPI_MakeFace mf = BRepBuilderAPI_MakeFace(wire);
|
BRepBuilderAPI_MakeFace mf(wire, false);
|
||||||
BRepBuilderAPI_FaceError er = mf.Error();
|
BRepBuilderAPI_FaceError er = mf.Error();
|
||||||
if ( er == BRepBuilderAPI_NotPlanar ) {
|
if ( er == BRepBuilderAPI_NotPlanar ) {
|
||||||
std::cout << "[Notice] Trying to fix non-planar face" << std::endl;
|
std::cout << "[Notice] Trying to fix non-planar face" << std::endl;
|
||||||
ShapeFix_ShapeTolerance FTol;
|
ShapeFix_ShapeTolerance FTol;
|
||||||
FTol.SetTolerance(wire, 0.01, TopAbs_WIRE);
|
FTol.SetTolerance(wire, 0.01, TopAbs_WIRE);
|
||||||
mf = BRepBuilderAPI_MakeFace(wire);
|
mf = BRepBuilderAPI_MakeFace(wire, false);
|
||||||
er = mf.Error();
|
er = mf.Error();
|
||||||
}
|
}
|
||||||
if ( er != BRepBuilderAPI_FaceDone ) return false;
|
if ( er != BRepBuilderAPI_FaceDone ) return false;
|
||||||
face = mf.Face();
|
face = mf.Face();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user