Added some decorator colors to addon preferences #2987

For ProfileDecorator (editing profiles, roof preview) and DecorationsHandler (openings).
Still need to add CutDecorator colors to preferences
This commit is contained in:
Andrej730
2023-04-18 17:25:21 +05:00
parent 527cbc3ae0
commit 2df4c5825f
4 changed files with 82 additions and 41 deletions
@@ -25,17 +25,14 @@ from mathutils import Vector, Matrix
from gpu_extras.batch import batch_for_shader
white = (1, 1, 1, 1)
white_t = (1, 1, 1, 0.5)
green = (0.545, 0.863, 0, 1)
red = (1, 0.2, 0.322, 1)
blue = (0.157, 0.565, 1, 1)
grey = (0.2, 0.2, 0.2, 1)
blue = (0.157, 0.565, 1, 1)
blue_t = (0.157, 0.565, 1, 0.1)
ERROR_ELEMENTS_COLOR = (1, 0.2, 0.322, 1) # RED
UNSPECIAL_ELEMENT_COLOR = (0.2, 0.2, 0.2, 1) # GREY
faces_color = blue_t
preview_edges_color = blue
def transparent_color(color, alpha=0.1):
color = [i for i in color]
color[3] = alpha
return color
def bm_check_vertex_in_groups(vertex, deform_layer, groups):
@@ -85,9 +82,15 @@ class ProfileDecorator:
bmesh.ops.triangulate(traingulated_bm, faces=traingulated_bm.faces)
face_indices = [[v.index for v in f.verts] for f in traingulated_bm.faces]
faces_color = transparent_color(self.model_props.decorator_color_special)
self.draw_batch("TRIS", vertices_coords, faces_color, face_indices)
def __call__(self, context, get_custom_bmesh=None, draw_faces=False, exit_edit_mode_callback=None):
self.model_props = context.scene.BIMModelProperties
selected_elements_color = self.model_props.decorator_color_selected
unselected_elements_color = self.model_props.decorator_color_unselected
special_elements_color = self.model_props.decorator_color_special
obj = context.active_object
if obj.mode != "EDIT":
@@ -203,16 +206,16 @@ class ProfileDecorator:
if draw_faces:
self.draw_faces(bm, all_vertices)
self.draw_batch("LINES", all_vertices, white_t, unselected_edges)
self.draw_batch("LINES", all_vertices, green, selected_edges)
self.draw_batch("LINES", all_vertices, grey, arc_edges)
self.draw_batch("LINES", all_vertices, preview_edges_color, preview_edges)
self.draw_batch("LINES", all_vertices, blue, roof_angle_edges)
self.draw_batch("LINES", all_vertices, transparent_color(unselected_elements_color), unselected_edges)
self.draw_batch("LINES", all_vertices, selected_elements_color, selected_edges)
self.draw_batch("LINES", all_vertices, UNSPECIAL_ELEMENT_COLOR, arc_edges)
self.draw_batch("LINES", all_vertices, special_elements_color, preview_edges)
self.draw_batch("LINES", all_vertices, special_elements_color, roof_angle_edges)
self.draw_batch("POINTS", unselected_vertices, white_t)
self.draw_batch("POINTS", error_vertices, red)
self.draw_batch("POINTS", special_vertices, blue)
self.draw_batch("POINTS", selected_vertices, green)
self.draw_batch("POINTS", unselected_vertices, transparent_color(unselected_elements_color, 0.5))
self.draw_batch("POINTS", error_vertices, ERROR_ELEMENTS_COLOR)
self.draw_batch("POINTS", special_vertices, self.model_props.decorator_color_special)
self.draw_batch("POINTS", selected_vertices, self.model_props.decorator_color_selected)
# Draw arcs
arc_centroids = []
@@ -237,9 +240,9 @@ class ProfileDecorator:
arc_centroids.append(tuple(centroid))
arc_segments.append(tool.Cad.create_arc_segments(pts=points, num_verts=17, make_edges=True))
self.draw_batch("POINTS", arc_centroids, grey)
self.draw_batch("POINTS", arc_centroids, UNSPECIAL_ELEMENT_COLOR)
for verts, edges in arc_segments:
self.draw_batch("LINES", verts, blue, edges)
self.draw_batch("LINES", verts, special_elements_color, edges)
# Draw circles
circle_centroids = []
@@ -258,9 +261,9 @@ class ProfileDecorator:
segments = [[list(matrix @ Vector(v)) for v in segments[0]], segments[1]]
circle_segments.append(segments)
self.draw_batch("POINTS", circle_centroids, grey)
self.draw_batch("POINTS", circle_centroids, UNSPECIAL_ELEMENT_COLOR)
for verts, edges in circle_segments:
self.draw_batch("LINES", verts, blue, edges)
self.draw_batch("LINES", verts, special_elements_color, edges)
def create_matrix(self, p, x, y, z):
return Matrix([x, y, z, p]).to_4x4().transposed()
@@ -766,6 +766,7 @@ class EditOpenings(Operator, tool.Ifc.Operator):
results.add(obj)
return results
# TODO: merge with ProfileDecorator?
class DecorationsHandler:
installed = None
@@ -792,26 +793,26 @@ class DecorationsHandler:
batch.draw(shader)
def __call__(self, context):
self.model_props = context.scene.BIMModelProperties
selected_elements_color = self.model_props.decorator_color_selected
unselected_elements_color = self.model_props.decorator_color_unselected
special_elements_color = self.model_props.decorator_color_special
def transparent_color(color, alpha=0.1):
color = [i for i in color]
color[3] = alpha
return color
gpu.state.point_size_set(6)
gpu.state.blend_set("ALPHA")
for opening in context.scene.BIMModelProperties.openings:
obj = opening.obj
if not obj:
continue
white = (1, 1, 1, 1)
white_t = (1, 1, 1, 0.5)
green = (0.545, 0.863, 0, 1)
red = (1, 0.2, 0.322, 1)
red_t = (1, 0.2, 0.322, 0.1)
blue = (0.157, 0.565, 1, 1)
blue_t = (0.157, 0.565, 1, 0.1)
grey = (0.2, 0.2, 0.2, 1)
self.line_shader = gpu.shader.from_builtin("3D_POLYLINE_UNIFORM_COLOR")
self.line_shader.bind() # required to be able to change uniforms of the shader
self.line_shader.bind() # required to be able to change uniforms of the shader
# POLYLINE_UNIFORM_COLOR specific uniforms
self.line_shader.uniform_float("viewportSize", (context.region.width, context.region.height))
self.line_shader.uniform_float("lineWidth", 2.0)
@@ -848,21 +849,22 @@ class DecorationsHandler:
else:
unselected_edges.append(edge_indices)
self.draw_batch("LINES", verts, white_t, unselected_edges)
self.draw_batch("LINES", verts, green, selected_edges)
self.draw_batch("POINTS", unselected_vertices, white)
self.draw_batch("POINTS", selected_vertices, green)
self.draw_batch("LINES", verts, transparent_color(unselected_elements_color, 0.5), unselected_edges)
self.draw_batch("LINES", verts, selected_elements_color, selected_edges)
self.draw_batch("POINTS", unselected_vertices, unselected_elements_color)
self.draw_batch("POINTS", selected_vertices, selected_elements_color)
else:
bm = bmesh.new()
bm.from_mesh(obj.data)
verts = [tuple(obj.matrix_world @ v.co) for v in bm.verts]
edges = [tuple([v.index for v in e.verts]) for e in bm.edges]
self.draw_batch("LINES", verts, green if obj in context.selected_objects else blue, edges)
color = selected_elements_color if obj in context.selected_objects else special_elements_color
self.draw_batch("LINES", verts, color, edges)
obj.data.calc_loop_triangles()
tris = [tuple(t.vertices) for t in obj.data.loop_triangles]
self.draw_batch("TRIS", verts, blue_t, tris)
self.draw_batch("TRIS", verts, transparent_color(special_elements_color), tris)
if "HalfSpaceSolid" in obj.name:
# Arrow shape
@@ -875,7 +877,8 @@ class DecorationsHandler:
tuple(obj.matrix_world @ Vector((0, -0.05, 0.45))),
]
edges = [(0, 1), (1, 2), (1, 3), (1, 4), (1, 5)]
self.draw_batch("LINES", verts, green if obj in context.selected_objects else blue, edges)
color = selected_elements_color if obj in context.selected_objects else special_elements_color
self.draw_batch("LINES", verts, color, edges)
if obj.mode != "EDIT":
bm.free()
@@ -141,6 +141,33 @@ class BIMModelProperties(PropertyGroup):
type_class: bpy.props.EnumProperty(items=get_type_class, name="IFC Class", update=update_type_class)
type_predefined_type: bpy.props.EnumProperty(items=get_type_predefined_type, name="Predefined Type", default=None)
type_name: bpy.props.StringProperty(name="Name", default="TYPEX")
decorator_color_selected: bpy.props.FloatVectorProperty(
name="Selected Elements Color",
subtype="COLOR",
default=(0.545, 0.863, 0, 1), # green
min=0.0,
max=1.0,
size=4,
description="Color of selected verts/edges (used in profile editing mode)",
)
decorator_color_unselected: bpy.props.FloatVectorProperty(
name="Not Selected Elements Color",
subtype="COLOR",
default=(1, 1, 1, 1), # green
min=0.0,
max=1.0,
size=4,
description="Color of not selected verts/edges (used in profile editing mode)",
)
decorator_color_special: bpy.props.FloatVectorProperty(
name="Special Elements Color",
subtype="COLOR",
default=(0.157, 0.565, 1, 1), # blue
min=0.0,
max=1.0,
size=4,
description="Color of special selected verts/edges (openings, preview verts/edges in roof editing, verts with arcs/circles in profile editing)",
)
class BIMArrayProperties(PropertyGroup):
@@ -247,6 +274,7 @@ class BIMWindowProperties(PropertyGroup):
)
# number of panels and default mullion/transom values
# fmt: off
window_types_panels = {
"SINGLE_PANEL": (1, ((0, 0 ), (0, 0 ))),
"DOUBLE_PANEL_HORIZONTAL": (2, ((0, 0 ), (0.45, 0 ))),
@@ -258,6 +286,7 @@ class BIMWindowProperties(PropertyGroup):
"TRIPLE_PANEL_HORIZONTAL": (3, ((0, 0 ), (0.3, 0.6))),
"TRIPLE_PANEL_VERTICAL": (3, ((0.2, 0.4), (0, 0 ))),
}
# fmt: on
window_added_previously: bpy.props.BoolProperty(default=False)
is_editing: bpy.props.IntProperty(default=-1)
+6
View File
@@ -173,6 +173,12 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
row = self.layout.row()
row.prop(context.scene.DocProperties, "decorations_colour")
row = self.layout.row()
row.prop(context.scene.BIMModelProperties, "decorator_color_selected")
row = self.layout.row()
row.prop(context.scene.BIMModelProperties, "decorator_color_unselected")
row = self.layout.row()
row.prop(context.scene.BIMModelProperties, "decorator_color_special")
row = self.layout.row(align=True)
row.prop(context.scene.BIMProperties, "schema_dir")