mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 16:21:01 +00:00
Create a python package for IfcBlender [#3412173]
This commit is contained in:
@@ -1,22 +1,29 @@
|
|||||||
##############################################################################
|
###############################################################################
|
||||||
# #
|
# #
|
||||||
#This file is part of IfcOpenShell. #
|
# This file is part of IfcOpenShell. #
|
||||||
# #
|
# #
|
||||||
#IfcOpenShell is free software: you can redistribute it and/or modify #
|
# 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 #
|
# 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 #
|
# the Free Software Foundation, either version 3.0 of the License, or #
|
||||||
#(at your option) any later version. #
|
# (at your option) any later version. #
|
||||||
# #
|
# #
|
||||||
#IfcOpenShell is distributed in the hope that it will be useful, #
|
# IfcOpenShell is distributed in the hope that it will be useful, #
|
||||||
#but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||||
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||||
#Lesser GNU General Public License for more details. #
|
# Lesser GNU General Public License for more details. #
|
||||||
# #
|
# #
|
||||||
#You should have received a copy of the Lesser GNU General Public License #
|
# 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/>. #
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||||
# #
|
# #
|
||||||
##############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
# <pep8 compliant>
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# #
|
||||||
|
# Based on the Wavefront OBJ File importer by Campbell Barton #
|
||||||
|
# #
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
bl_info = {
|
bl_info = {
|
||||||
"name": "IfcBlender",
|
"name": "IfcBlender",
|
||||||
@@ -32,12 +39,17 @@ bl_info = {
|
|||||||
"tracker_url": "http://sourceforge.net/tracker/?group_id=543113",
|
"tracker_url": "http://sourceforge.net/tracker/?group_id=543113",
|
||||||
"category": "Import-Export"}
|
"category": "Import-Export"}
|
||||||
|
|
||||||
|
if "bpy" in locals():
|
||||||
|
import imp
|
||||||
|
if "IfcImport" in locals():
|
||||||
|
imp.reload(IfcImport)
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import mathutils
|
import mathutils
|
||||||
from bpy.props import *
|
from bpy.props import StringProperty
|
||||||
from bpy_extras.io_utils import ImportHelper
|
from bpy_extras.io_utils import ImportHelper
|
||||||
|
|
||||||
|
|
||||||
class ImportIFC(bpy.types.Operator, ImportHelper):
|
class ImportIFC(bpy.types.Operator, ImportHelper):
|
||||||
bl_idname = "import_scene.ifc"
|
bl_idname = "import_scene.ifc"
|
||||||
bl_label = "Import .ifc file"
|
bl_label = "Import .ifc file"
|
||||||
@@ -46,7 +58,7 @@ class ImportIFC(bpy.types.Operator, ImportHelper):
|
|||||||
filter_glob = StringProperty(default="*.ifc", options={'HIDDEN'})
|
filter_glob = StringProperty(default="*.ifc", options={'HIDDEN'})
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
import IfcImport
|
from . import IfcImport
|
||||||
if not IfcImport.Init(self.filepath):
|
if not IfcImport.Init(self.filepath):
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
ids = {}
|
ids = {}
|
||||||
@@ -56,22 +68,19 @@ class ImportIFC(bpy.types.Operator, ImportHelper):
|
|||||||
f = ob.mesh.faces
|
f = ob.mesh.faces
|
||||||
v = ob.mesh.verts
|
v = ob.mesh.verts
|
||||||
m = ob.matrix
|
m = ob.matrix
|
||||||
|
t = ob.type[0:21]
|
||||||
if ob.mesh.id in ids:
|
if ob.mesh.id in ids:
|
||||||
me = ids[ob.mesh.id]
|
me = ids[ob.mesh.id]
|
||||||
else:
|
else:
|
||||||
verts = []
|
verts = [[v[i],v[i+1],v[i+2]] for i in range(0,len(v),3)]
|
||||||
faces = []
|
faces = [[f[i],f[i+1],f[i+2]] 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]])
|
|
||||||
for i in range(0, len(v), 3):
|
|
||||||
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 t in bpy.data.materials:
|
||||||
mat = bpy.data.materials[ob.type]
|
mat = bpy.data.materials[t]
|
||||||
mat.use_fake_user = True
|
mat.use_fake_user = True
|
||||||
else:
|
else:
|
||||||
mat = bpy.data.materials.new(ob.type)
|
mat = bpy.data.materials.new(t)
|
||||||
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)
|
||||||
@@ -80,7 +89,7 @@ class ImportIFC(bpy.types.Operator, ImportHelper):
|
|||||||
[m[6], m[7], m[8], 0],
|
[m[6], m[7], m[8], 0],
|
||||||
[m[9], m[10], m[11], 1]))
|
[m[9], m[10], m[11], 1]))
|
||||||
bpy.context.scene.objects.link(bob)
|
bpy.context.scene.objects.link(bob)
|
||||||
me.update()
|
#me.update()
|
||||||
bpy.ops.object.select_all(action='DESELECT')
|
bpy.ops.object.select_all(action='DESELECT')
|
||||||
bpy.ops.object.select_name(name=bob.name)
|
bpy.ops.object.select_name(name=bob.name)
|
||||||
bpy.ops.object.mode_set(mode='EDIT')
|
bpy.ops.object.mode_set(mode='EDIT')
|
||||||
Reference in New Issue
Block a user