Merge branch '34-selection-visibility-for-non-mesh-objects' into 'master'

Resolve "Selection visibility for non-mesh objects"

Closes #34

See merge request slumber/multi-user!8
This commit is contained in:
Swann Martinez
2019-11-23 15:00:24 +00:00
2 changed files with 39 additions and 14 deletions

View File

@ -56,6 +56,18 @@ def get_target_far(region, rv3d, coord, distance):
return [target.x, target.y, target.z] return [target.x, target.y, target.z]
def get_default_bbox(obj, radius):
coords = [
(-radius, -radius, -radius), (+radius, -radius, -radius),
(-radius, +radius, -radius), (+radius, +radius, -radius),
(-radius, -radius, +radius), (+radius, -radius, +radius),
(-radius, +radius, +radius), (+radius, +radius, +radius)]
base = obj.matrix_world
bbox_corners = [base @ mathutils.Vector(corner) for corner in coords]
return [(point.x, point.y, point.z)
for point in bbox_corners]
def get_client_cam_points(): def get_client_cam_points():
area, region, rv3d = view3d_find() area, region, rv3d = view3d_find()
@ -181,7 +193,7 @@ class DrawFactory(object):
self.d3d_items.clear() self.d3d_items.clear()
self.d2d_items.clear() self.d2d_items.clear()
def flush_selection(self, user): def flush_selection(self, user=None):
key_to_remove = [] key_to_remove = []
select_key = "{}_select".format(user) if user else "select" select_key = "{}_select".format(user) if user else "select"
for k in self.d3d_items.keys(): for k in self.d3d_items.keys():
@ -211,19 +223,13 @@ class DrawFactory(object):
for select_ob in client_selection: for select_ob in client_selection:
drawable_key = "{}_select_{}".format(client_uuid, select_ob) drawable_key = "{}_select_{}".format(client_uuid, select_ob)
indices = (
(0, 1), (1, 2), (2, 3), (0, 3), ob = utils.find_from_attr("uuid", select_ob, bpy.data.objects)
(4, 5), (5, 6), (6, 7), (4, 7),
(0, 4), (1, 5), (2, 6), (3, 7)
)
ob = utils.find_from_attr("uuid",select_ob,bpy.data.objects)
if not ob: if not ob:
return return
item_to_draw = []
if ob.type == 'EMPTY': if ob.type == 'EMPTY':
# Child case # TODO: Child case
# Collection instance case # Collection instance case
if ob.instance_collection: if ob.instance_collection:
for obj in ob.instance_collection.objects: for obj in ob.instance_collection.objects:
@ -234,12 +240,28 @@ class DrawFactory(object):
get_bb_coords_from_obj(obj, parent=ob), get_bb_coords_from_obj(obj, parent=ob),
indices) indices)
if ob.type == 'MESH': if ob.type in ['MESH','META']:
indices = (
(0, 1), (1, 2), (2, 3), (0, 3),
(4, 5), (5, 6), (6, 7), (4, 7),
(0, 4), (1, 5), (2, 6), (3, 7))
self.append_3d_item( self.append_3d_item(
drawable_key, drawable_key,
client_color, client_color,
get_bb_coords_from_obj(ob), get_bb_coords_from_obj(ob),
indices) indices)
else:
indices = (
(0, 1), (0, 2), (1, 3), (2, 3),
(4, 5), (4, 6), (5, 7), (6, 7),
(0, 4), (1, 5), (2, 6), (3, 7))
self.append_3d_item(
drawable_key,
client_color,
get_default_bbox(ob, ob.scale.x),
indices)
def append_3d_item(self,key,color, coords, indices): def append_3d_item(self,key,color, coords, indices):
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR') shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
@ -277,6 +299,9 @@ class DrawFactory(object):
def draw3d_callback(self): def draw3d_callback(self):
bgl.glLineWidth(1.5) bgl.glLineWidth(1.5)
bgl.glEnable(bgl.GL_DEPTH_TEST) bgl.glEnable(bgl.GL_DEPTH_TEST)
bgl.glEnable(bgl.GL_BLEND)
bgl.glEnable(bgl.GL_LINE_SMOOTH)
try: try:
for shader, batch, color in self.d3d_items.values(): for shader, batch, color in self.d3d_items.values():
shader.bind() shader.bind()