| 1 |
############################################################################### |
| 2 |
# # |
| 3 |
# This file is part of IfcOpenShell. # |
| 4 |
# # |
| 5 |
# IfcOpenShell is free software: you can redistribute it and/or modify # |
| 6 |
# it under the terms of the Lesser GNU General Public License as published by # |
| 7 |
# the Free Software Foundation, either version 3.0 of the License, or # |
| 8 |
# (at your option) any later version. # |
| 9 |
# # |
| 10 |
# IfcOpenShell is distributed in the hope that it will be useful, # |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
| 13 |
# Lesser GNU General Public License for more details. # |
| 14 |
# # |
| 15 |
# You should have received a copy of the Lesser GNU General Public License # |
| 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. # |
| 17 |
# # |
| 18 |
############################################################################### |
| 19 |
|
| 20 |
############################################################################### |
| 21 |
# # |
| 22 |
# Do not run this script directly, it is called by run.py # |
| 23 |
# # |
| 24 |
############################################################################### |
| 25 |
|
| 26 |
import os |
| 27 |
import bpy |
| 28 |
import sys |
| 29 |
import time |
| 30 |
try: from io_import_scene_ifc import import_ifc |
| 31 |
except: |
| 32 |
print("[Error] Unable to import IfcOpenShell") |
| 33 |
sys.exit(1) |
| 34 |
from mathutils import Vector as V |
| 35 |
from math import radians |
| 36 |
|
| 37 |
scn = bpy.context.scene |
| 38 |
|
| 39 |
for ob in bpy.data.objects: |
| 40 |
scn.objects.unlink(ob) |
| 41 |
|
| 42 |
if sys.argv[-2] != 'render': sys.exit(0) |
| 43 |
|
| 44 |
fn = sys.argv[-1] |
| 45 |
t1 = time.time() |
| 46 |
succes = import_ifc(fn,True,False) |
| 47 |
if not succes: |
| 48 |
print("[Error] Import of %s failed"%fn) |
| 49 |
sys.exit(1) |
| 50 |
|
| 51 |
dt = time.time()-t1 |
| 52 |
print ("[Notice] Conversion took %.2f seconds"%dt) |
| 53 |
|
| 54 |
cam = bpy.data.cameras.new('cam') |
| 55 |
cam.angle = radians(45) |
| 56 |
cam_ob = bpy.data.objects.new('cam',cam) |
| 57 |
scn.objects.link(cam_ob) |
| 58 |
cam_ob.rotation_euler = (radians(67),0,radians(45)) |
| 59 |
|
| 60 |
scn.camera = cam_ob |
| 61 |
scn.render.resolution_percentage = 100 |
| 62 |
scn.render.resolution_x = 2048 |
| 63 |
scn.render.resolution_y = 2048 |
| 64 |
scn.world.horizon_color = (1,1,1) |
| 65 |
scn.world.ambient_color = (0.05,0.05,0.05) |
| 66 |
try: scn.render.color_mode = 'RGBA' |
| 67 |
except: scn.render.image_settings.color_mode = 'RGBA' |
| 68 |
|
| 69 |
for m in bpy.data.materials: m.specular_intensity = 0 |
| 70 |
def material(name,settings): |
| 71 |
m = bpy.data.materials.get(name) |
| 72 |
if not m: return |
| 73 |
for k,v in settings.items(): |
| 74 |
setattr(m,k,v) |
| 75 |
|
| 76 |
material("IfcWall",{"diffuse_color":[1,1,1],"diffuse_intensity":1}) |
| 77 |
material("IfcWallStandardCase",{"diffuse_color":[1,1,1],"diffuse_intensity":1}) |
| 78 |
material("IfcSite",{"diffuse_color":[0.4,0.5,0.25]}) |
| 79 |
material("IfcSlab",{"diffuse_color":[0.2,0.2,0.2]}) |
| 80 |
material("IfcDoor",{"diffuse_color":[0.25,0.1,0.05]}) |
| 81 |
material("IfcWindow",{"diffuse_color":[0.5,0.7,0.5],"use_transparency":True,"alpha":0.3}) |
| 82 |
material("IfcRoof",{"diffuse_color":[0.35,0.2,0.2]}) |
| 83 |
material("IfcFurnishingElement",{"diffuse_color":[0.8,0.7,0.5]}) |
| 84 |
material("IfcBuildingElementPro",{"diffuse_intensity":0.6}) |
| 85 |
|
| 86 |
def create_lamp(eul): |
| 87 |
l = bpy.data.lamps.new('l','SUN') |
| 88 |
l.energy = 1.3 |
| 89 |
l_ob = bpy.data.objects.new('l',l) |
| 90 |
scn.objects.link(l_ob) |
| 91 |
l_ob.rotation_euler = [radians(e) for e in eul] |
| 92 |
|
| 93 |
create_lamp((20,0,60)) |
| 94 |
create_lamp((0,-120,-50)) |
| 95 |
|
| 96 |
A = V([1e9]*3) |
| 97 |
B = V([-1e9]*3) |
| 98 |
|
| 99 |
for ob in scn.objects: |
| 100 |
if ob.type != 'MESH': continue |
| 101 |
if ob.hide: continue |
| 102 |
bb = [ob.matrix_world*V(x) for x in ob.bound_box] |
| 103 |
for b in bb: |
| 104 |
for i in range(3): |
| 105 |
if b[i] < A[i]: A[i] = b[i] |
| 106 |
if b[i] > B[i]: B[i] = b[i] |
| 107 |
|
| 108 |
C = V((1.2,-1.2,0.6)) |
| 109 |
D = B-A |
| 110 |
E = max(D)*C + (A+B)/2 |
| 111 |
|
| 112 |
cam_ob.location = E |
| 113 |
cam.clip_end = max(D) * 10 |
| 114 |
|
| 115 |
scn.render.filepath = os.path.join("output",os.path.basename(fn)+".png") |
| 116 |
|
| 117 |
bpy.ops.wm.save_mainfile(filepath=os.path.join("output",os.path.basename(fn)+".blend"),compress=True) |
| 118 |
|
| 119 |
bpy.ops.render.render(write_still=True) |
| 120 |
|
| 121 |
sys.exit(0) |