mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 10:33:20 +00:00
Drawing styles store the render type and include outlines for more CAD-like drawings, and store shadow and lighting settings
This commit is contained in:
@@ -324,7 +324,7 @@ if bpy is not None:
|
||||
|
||||
def on_register(scene):
|
||||
prop.setDefaultProperties(scene)
|
||||
bpy.app.handlers.scene_update_post.remove(on_register)
|
||||
bpy.app.handlers.depsgraph_update_post.remove(on_register)
|
||||
|
||||
def register():
|
||||
for cls in classes:
|
||||
|
||||
@@ -32,6 +32,8 @@ def add_object(self, context):
|
||||
modifier.use_smooth_shade = False
|
||||
modifier.use_normal_calculate = True
|
||||
modifier.use_normal_flip = True
|
||||
modifier.steps = 1
|
||||
modifier.render_steps = 1
|
||||
modifier = obj.modifiers.new('Wall Width', 'SOLIDIFY')
|
||||
modifier.use_even_offset = True
|
||||
modifier.thickness = self.width
|
||||
|
||||
@@ -2108,15 +2108,16 @@ class CutSection(bpy.types.Operator):
|
||||
camera = bpy.context.scene.camera
|
||||
if not (camera.type == 'CAMERA' and camera.data.type == 'ORTHO'):
|
||||
return {'FINISHED'}
|
||||
drawing_style = bpy.context.scene.DocProperties.drawing_styles[camera.data.BIMCameraProperties.active_drawing_style_index]
|
||||
self.diagram_name = camera.name.split('/')[1]
|
||||
bpy.context.scene.render.filepath = os.path.join(
|
||||
bpy.context.scene.BIMProperties.data_dir,
|
||||
'diagrams',
|
||||
'{}.png'.format(self.diagram_name)
|
||||
)
|
||||
if bpy.context.scene.DocProperties.should_render == 'DEFAULT':
|
||||
if drawing_style.render_type == 'DEFAULT':
|
||||
bpy.ops.render.render(write_still=True)
|
||||
elif bpy.context.scene.DocProperties.should_render == 'VIEWPORT':
|
||||
elif drawing_style.render_type == 'VIEWPORT':
|
||||
for obj in camera.users_collection[0].objects:
|
||||
obj.hide_set(True)
|
||||
bpy.ops.render.opengl(write_still=True)
|
||||
@@ -2139,7 +2140,6 @@ class CutSection(bpy.types.Operator):
|
||||
import ifccsv
|
||||
ifc_cutter.ifc_filenames = [i.name for i in bpy.context.scene.DocProperties.ifc_files]
|
||||
ifc_cutter.data_dir = bpy.context.scene.BIMProperties.data_dir
|
||||
drawing_style = bpy.context.scene.DocProperties.drawing_styles[camera.data.BIMCameraProperties.active_drawing_style_index]
|
||||
ifc_cutter.vector_style = drawing_style.vector_style
|
||||
ifc_cutter.diagram_name = self.diagram_name
|
||||
ifc_cutter.background_image = bpy.context.scene.render.filepath
|
||||
@@ -3651,9 +3651,11 @@ class SaveDrawingStyle(bpy.types.Operator):
|
||||
index: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
space = self.get_view_3d()
|
||||
style = {
|
||||
'bpy.data.worlds[0].color': tuple(bpy.data.worlds[0].color),
|
||||
'bpy.context.scene.render.engine': bpy.context.scene.render.engine,
|
||||
'bpy.context.scene.render.film_transparent': bpy.context.scene.render.film_transparent,
|
||||
'bpy.context.scene.display.shading.show_object_outline': bpy.context.scene.display.shading.show_object_outline,
|
||||
'bpy.context.scene.display.shading.show_cavity': bpy.context.scene.display.shading.show_cavity,
|
||||
'bpy.context.scene.display.shading.cavity_type': bpy.context.scene.display.shading.cavity_type,
|
||||
@@ -3663,7 +3665,17 @@ class SaveDrawingStyle(bpy.types.Operator):
|
||||
'bpy.context.scene.display.shading.light': bpy.context.scene.display.shading.light,
|
||||
'bpy.context.scene.display.shading.color_type': bpy.context.scene.display.shading.color_type,
|
||||
'bpy.context.scene.display.shading.single_color': tuple(bpy.context.scene.display.shading.single_color),
|
||||
'bpy.context.scene.display.shading.show_shadows': bpy.context.scene.display.shading.show_shadows,
|
||||
'bpy.context.scene.display.shading.shadow_intensity': bpy.context.scene.display.shading.shadow_intensity,
|
||||
'bpy.context.scene.display.light_direction': tuple(bpy.context.scene.display.light_direction),
|
||||
'bpy.context.scene.view_settings.use_curve_mapping': bpy.context.scene.view_settings.use_curve_mapping,
|
||||
'space.overlay.show_wireframes': space.overlay.show_wireframes,
|
||||
'space.overlay.wireframe_threshold': space.overlay.wireframe_threshold,
|
||||
'space.overlay.show_floor': space.overlay.show_floor,
|
||||
'space.overlay.show_axis_x': space.overlay.show_axis_x,
|
||||
'space.overlay.show_axis_y': space.overlay.show_axis_y,
|
||||
'space.overlay.show_axis_z': space.overlay.show_axis_z,
|
||||
'space.overlay.show_object_origins': space.overlay.show_object_origins,
|
||||
}
|
||||
if self.index:
|
||||
index = int(self.index)
|
||||
@@ -3672,6 +3684,15 @@ class SaveDrawingStyle(bpy.types.Operator):
|
||||
bpy.context.scene.DocProperties.drawing_styles[index].raster_style = json.dumps(style)
|
||||
return {'FINISHED'}
|
||||
|
||||
def get_view_3d(self):
|
||||
for area in bpy.context.screen.areas:
|
||||
if area.type != 'VIEW_3D':
|
||||
continue
|
||||
for space in area.spaces:
|
||||
if space.type != 'VIEW_3D':
|
||||
continue
|
||||
return space
|
||||
|
||||
|
||||
class ActivateDrawingStyle(bpy.types.Operator):
|
||||
bl_idname = 'bim.activate_drawing_style'
|
||||
@@ -3684,9 +3705,11 @@ class ActivateDrawingStyle(bpy.types.Operator):
|
||||
return {'FINISHED'}
|
||||
|
||||
def set_raster_style(self):
|
||||
space = self.get_view_3d()
|
||||
style = json.loads(self.drawing_style.raster_style)
|
||||
bpy.data.worlds[0].color = style['bpy.data.worlds[0].color']
|
||||
bpy.context.scene.render.engine = style['bpy.context.scene.render.engine']
|
||||
bpy.context.scene.render.film_transparent = style['bpy.context.scene.render.film_transparent']
|
||||
bpy.context.scene.display.shading.show_object_outline = style['bpy.context.scene.display.shading.show_object_outline']
|
||||
bpy.context.scene.display.shading.show_cavity = style['bpy.context.scene.display.shading.show_cavity']
|
||||
bpy.context.scene.display.shading.cavity_type = style['bpy.context.scene.display.shading.cavity_type']
|
||||
@@ -3696,7 +3719,18 @@ class ActivateDrawingStyle(bpy.types.Operator):
|
||||
bpy.context.scene.display.shading.light = style['bpy.context.scene.display.shading.light']
|
||||
bpy.context.scene.display.shading.color_type = style['bpy.context.scene.display.shading.color_type']
|
||||
bpy.context.scene.display.shading.single_color = style['bpy.context.scene.display.shading.single_color']
|
||||
bpy.context.scene.display.shading.show_shadows = style['bpy.context.scene.display.shading.show_shadows']
|
||||
bpy.context.scene.display.shading.shadow_intensity = style['bpy.context.scene.display.shading.shadow_intensity']
|
||||
bpy.context.scene.display.light_direction = style['bpy.context.scene.display.light_direction']
|
||||
|
||||
bpy.context.scene.view_settings.use_curve_mapping = style['bpy.context.scene.view_settings.use_curve_mapping']
|
||||
space.overlay.show_wireframes = style['space.overlay.show_wireframes']
|
||||
space.overlay.wireframe_threshold = style['space.overlay.wireframe_threshold']
|
||||
space.overlay.show_floor = style['space.overlay.show_floor']
|
||||
space.overlay.show_axis_x = style['space.overlay.show_axis_x']
|
||||
space.overlay.show_axis_y = style['space.overlay.show_axis_y']
|
||||
space.overlay.show_axis_z = style['space.overlay.show_axis_z']
|
||||
space.overlay.show_object_origins = style['space.overlay.show_object_origins']
|
||||
|
||||
def set_query(self):
|
||||
self.selector = ifcopenshell.util.selector.Selector()
|
||||
@@ -3741,6 +3775,16 @@ class ActivateDrawingStyle(bpy.types.Operator):
|
||||
obj.hide_viewport = True # Note: this breaks alt-H
|
||||
|
||||
|
||||
def get_view_3d(self):
|
||||
for area in bpy.context.screen.areas:
|
||||
if area.type != 'VIEW_3D':
|
||||
continue
|
||||
for space in area.spaces:
|
||||
if space.type != 'VIEW_3D':
|
||||
continue
|
||||
return space
|
||||
|
||||
|
||||
class AddDrawing(bpy.types.Operator):
|
||||
bl_idname = 'bim.add_drawing'
|
||||
bl_label = 'Add Drawing'
|
||||
|
||||
@@ -66,12 +66,15 @@ def setDefaultProperties(scene):
|
||||
if len(bpy.context.scene.DocProperties.drawing_styles) == 0:
|
||||
drawing_style = bpy.context.scene.DocProperties.drawing_styles.add()
|
||||
drawing_style.name = 'Blender Default'
|
||||
drawing_style.render_type = 'DEFAULT'
|
||||
bpy.ops.bim.save_drawing_style(index='0')
|
||||
drawing_style = bpy.context.scene.DocProperties.drawing_styles.add()
|
||||
drawing_style.name = 'Shaded'
|
||||
drawing_style.render_type = 'VIEWPORT'
|
||||
drawing_style.raster_style = json.dumps({
|
||||
'bpy.data.worlds[0].color': (1, 1, 1),
|
||||
'bpy.context.scene.render.engine': 'BLENDER_WORKBENCH',
|
||||
'bpy.context.scene.render.film_transparent': False,
|
||||
'bpy.context.scene.display.shading.show_object_outline': True,
|
||||
'bpy.context.scene.display.shading.show_cavity': True,
|
||||
'bpy.context.scene.display.shading.cavity_type': 'BOTH',
|
||||
@@ -81,13 +84,25 @@ def setDefaultProperties(scene):
|
||||
'bpy.context.scene.display.shading.light': 'STUDIO',
|
||||
'bpy.context.scene.display.shading.color_type': 'MATERIAL',
|
||||
'bpy.context.scene.display.shading.single_color': (1, 1, 1),
|
||||
'bpy.context.scene.display.shading.show_shadows': True,
|
||||
'bpy.context.scene.display.shading.shadow_intensity': 0.5,
|
||||
'bpy.context.scene.display.light_direction': (.5, .5, .5),
|
||||
'bpy.context.scene.view_settings.use_curve_mapping': False,
|
||||
'space.overlay.show_wireframes': True,
|
||||
'space.overlay.wireframe_threshold': 0,
|
||||
'space.overlay.show_floor': False,
|
||||
'space.overlay.show_axis_x': False,
|
||||
'space.overlay.show_axis_y': False,
|
||||
'space.overlay.show_axis_z': False,
|
||||
'space.overlay.show_object_origins': False,
|
||||
})
|
||||
drawing_style = bpy.context.scene.DocProperties.drawing_styles.add()
|
||||
drawing_style.name = 'Technical'
|
||||
drawing_style.render_type = 'VIEWPORT'
|
||||
drawing_style.raster_style = json.dumps({
|
||||
'bpy.data.worlds[0].color': (1, 1, 1),
|
||||
'bpy.context.scene.render.engine': 'BLENDER_WORKBENCH',
|
||||
'bpy.context.scene.render.film_transparent': False,
|
||||
'bpy.context.scene.display.shading.show_object_outline': True,
|
||||
'bpy.context.scene.display.shading.show_cavity': True,
|
||||
'bpy.context.scene.display.shading.cavity_type': 'BOTH',
|
||||
@@ -97,10 +112,18 @@ def setDefaultProperties(scene):
|
||||
'bpy.context.scene.display.shading.light': 'FLAT',
|
||||
'bpy.context.scene.display.shading.color_type': 'SINGLE',
|
||||
'bpy.context.scene.display.shading.single_color': (1, 1, 1),
|
||||
'bpy.context.scene.view_settings.use_curve_mapping': True,
|
||||
'bpy.context.scene.display.shading.show_shadows': False,
|
||||
'bpy.context.scene.display.shading.shadow_intensity': 0.5,
|
||||
'bpy.context.scene.display.light_direction': (.5, .5, .5),
|
||||
'bpy.context.scene.view_settings.use_curve_mapping': False,
|
||||
'space.overlay.show_wireframes': True,
|
||||
'space.overlay.wireframe_threshold': 0,
|
||||
'space.overlay.show_floor': False,
|
||||
'space.overlay.show_axis_x': False,
|
||||
'space.overlay.show_axis_y': False,
|
||||
'space.overlay.show_axis_z': False,
|
||||
'space.overlay.show_object_origins': False,
|
||||
})
|
||||
# TODO: This is used for technical styles, but probably should not be hardcoded
|
||||
bpy.context.scene.view_settings.curve_mapping.curves[3].points.new(.4, 0) # Increase black contrast
|
||||
|
||||
|
||||
def getIfcPredefinedTypes(self, context):
|
||||
@@ -524,6 +547,11 @@ class Sheet(PropertyGroup):
|
||||
class DrawingStyle(PropertyGroup):
|
||||
name: StringProperty(name='Name')
|
||||
raster_style: StringProperty(name='Raster Style')
|
||||
render_type: EnumProperty(items=[
|
||||
('NONE', 'None', ''),
|
||||
('DEFAULT', 'Default', ''),
|
||||
('VIEWPORT', 'Viewport', ''),
|
||||
], name='Render Type', default='VIEWPORT')
|
||||
vector_style: EnumProperty(items=getVectorStyles, name='Vector Style')
|
||||
include_query: StringProperty(name='Include Query')
|
||||
exclude_query: StringProperty(name='Exclude Query')
|
||||
@@ -533,11 +561,6 @@ class DrawingStyle(PropertyGroup):
|
||||
class DocProperties(PropertyGroup):
|
||||
should_recut: BoolProperty(name="Should Recut", default=True)
|
||||
should_recut_selected: BoolProperty(name="Should Recut Selected Only", default=False)
|
||||
should_render: EnumProperty(items=[
|
||||
('NONE', 'None', ''),
|
||||
('DEFAULT', 'Default', ''),
|
||||
('VIEWPORT', 'Viewport', ''),
|
||||
], name='Should Render', default='DEFAULT')
|
||||
should_extract: BoolProperty(name="Should Extract", default=True)
|
||||
drawings: CollectionProperty(name='Drawings', type=Drawing)
|
||||
active_drawing_index: IntProperty(name='Active Drawing Index', update=refreshActiveDrawingIndex)
|
||||
|
||||
@@ -864,8 +864,6 @@ class BIM_PT_camera(Panel):
|
||||
row = layout.row()
|
||||
row.prop(dprops, 'should_recut_selected')
|
||||
row = layout.row()
|
||||
row.prop(dprops, 'should_render')
|
||||
row = layout.row()
|
||||
row.prop(dprops, 'should_extract')
|
||||
|
||||
row = layout.row()
|
||||
@@ -911,6 +909,8 @@ class BIM_PT_camera(Panel):
|
||||
row.prop(drawing_style, 'name')
|
||||
row.operator('bim.remove_drawing_style', icon='X', text='').index = props.active_drawing_style_index
|
||||
|
||||
row = layout.row()
|
||||
row.prop(drawing_style, 'render_type')
|
||||
row = layout.row(align=True)
|
||||
row.prop(drawing_style, 'vector_style')
|
||||
row.operator('bim.edit_vector_style', text='', icon='GREASEPENCIL')
|
||||
|
||||
Reference in New Issue
Block a user