Skip to content

Commit

Permalink
Add visual cues for room status
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Dec 1, 2023
1 parent 231edec commit a7bcdc9
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 59 deletions.
3 changes: 3 additions & 0 deletions addons/io_hubs_addon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from . import preferences
from . import third_party
from . import debugger
from . import icons
bl_info = {
"name": "Hubs Blender Addon",
"author": "Mozilla Hubs",
Expand All @@ -24,6 +25,7 @@


def register():
icons.register()
preferences.register()
nodes.register()
components.register()
Expand All @@ -47,6 +49,7 @@ def unregister():
nodes.unregister()
preferences.unregister()
debugger.unregister()
icons.unregister()


# called by gltf-blender-io after it has loaded
Expand Down
27 changes: 0 additions & 27 deletions addons/io_hubs_addon/components/components_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import importlib
import inspect
import os
from os import listdir
from os.path import join, isfile, isdir, dirname, realpath

from .hubs_component import HubsComponent
Expand Down Expand Up @@ -125,25 +124,6 @@ def unload_components_registry():
module.unregister_module()


def load_icons():
global __component_icons
__component_icons = {}
pcoll = bpy.utils.previews.new()
icons_dir = os.path.join(os.path.dirname(__file__), "icons")
icons = [f for f in listdir(icons_dir) if isfile(join(icons_dir, f))]
for icon in icons:
pcoll.load(icon, os.path.join(icons_dir, icon), 'IMAGE')
print("Loading icon: " + icon)
__component_icons["hubs"] = pcoll


def unload_icons():
global __component_icons
__component_icons["hubs"].close()
del __component_icons


__component_icons = {}
__components_registry = {}


Expand All @@ -152,11 +132,6 @@ def get_components_registry():
return __components_registry


def get_components_icons():
global __component_icons
return __component_icons["hubs"]


def get_component_by_name(component_name):
global __components_registry
return next(
Expand All @@ -166,7 +141,6 @@ def get_component_by_name(component_name):


def register():
load_icons()
load_components_registry()

bpy.utils.register_class(HubsComponentName)
Expand Down Expand Up @@ -201,7 +175,6 @@ def unregister():
glTF2ExportUserExtension.remove_excluded_property("hubs_component_list")

unload_components_registry()
unload_icons()

global __components_registry
del __components_registry
81 changes: 53 additions & 28 deletions addons/io_hubs_addon/components/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

from .types import PanelType, MigrationType
from .utils import get_object_source, has_component, add_component, remove_component, wrap_text, display_wrapped_text, is_dep_required, update_image_editors
from .components_registry import get_components_registry, get_components_icons, get_component_by_name
from .components_registry import get_components_registry, get_component_by_name
from ..preferences import get_addon_pref
from .handlers import migrate_components
from .gizmos import update_gizmos
from .utils import is_linked, redraw_component_ui
from ..icons import get_hubs_icons
import os


Expand All @@ -30,22 +31,26 @@ def poll(cls, context):
if panel_type == PanelType.SCENE:
if is_linked(context.scene):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot add components to linked scenes")
cls.poll_message_set(
"Cannot add components to linked scenes")
return False
elif panel_type == PanelType.OBJECT:
if is_linked(context.active_object):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot add components to linked objects")
cls.poll_message_set(
"Cannot add components to linked objects")
return False
elif panel_type == PanelType.MATERIAL:
if is_linked(context.active_object.active_material):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot add components to linked materials")
cls.poll_message_set(
"Cannot add components to linked materials")
return False
elif panel_type == PanelType.BONE:
if is_linked(context.active_bone):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot add components to linked bones")
cls.poll_message_set(
"Cannot add components to linked bones")
return False

return True
Expand All @@ -72,7 +77,7 @@ def filter_source_type(cmp):
return not component_class.is_dep_only() and PanelType(panel_type) in component_class.get_panel_type() and component_class.poll(PanelType(panel_type), host, ob=context.object)

components_registry = get_components_registry()
components_icons = get_components_icons()
hubs_icons = get_hubs_icons()
filtered_components = dict(
filter(filter_source_type, components_registry.items()))

Expand Down Expand Up @@ -152,11 +157,11 @@ def draw(self, context):
if icon.find('.') != -1:
if has_component(obj, component_name):
op = column.label(
text=component_display_name, icon_value=components_icons[icon].icon_id)
text=component_display_name, icon_value=hubs_icons[icon].icon_id)
else:
op = column.operator(
AddHubsComponent.bl_idname, text=component_display_name,
icon_value=components_icons[icon].icon_id)
icon_value=hubs_icons[icon].icon_id)
op.component_name = component_name
op.panel_type = panel_type
else:
Expand Down Expand Up @@ -214,22 +219,26 @@ def poll(cls, context):
if panel_type == PanelType.SCENE:
if is_linked(context.scene):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot remove components from linked scenes")
cls.poll_message_set(
"Cannot remove components from linked scenes")
return False
elif panel_type == PanelType.OBJECT:
if is_linked(context.active_object):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot remove components from linked objects")
cls.poll_message_set(
"Cannot remove components from linked objects")
return False
elif panel_type == PanelType.MATERIAL:
if is_linked(context.active_object.active_material):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot remove components from linked materials")
cls.poll_message_set(
"Cannot remove components from linked materials")
return False
elif panel_type == PanelType.BONE:
if is_linked(context.active_bone):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot add components to linked bones")
cls.poll_message_set(
"Cannot add components to linked bones")
return False

return True
Expand Down Expand Up @@ -257,7 +266,8 @@ class MigrateHubsComponents(Operator):

def execute(self, context):
if self.is_registration:
migrate_components(MigrationType.REGISTRATION, do_beta_versioning=True)
migrate_components(MigrationType.REGISTRATION,
do_beta_versioning=True)
else:
migrate_components(MigrationType.LOCAL, do_beta_versioning=True)

Expand Down Expand Up @@ -288,7 +298,8 @@ def execute(self, context):
wm = context.window_manager
title = wm.hubs_report_last_title
report_string = wm.hubs_report_last_report_string
bpy.ops.wm.hubs_report_viewer('INVOKE_DEFAULT', title=title, report_string=report_string)
bpy.ops.wm.hubs_report_viewer(
'INVOKE_DEFAULT', title=title, report_string=report_string)
return {'FINISHED'}


Expand All @@ -314,12 +325,15 @@ def highlight_info_report(self):
while bpy.ops.info.select_pick(
context_override, report_index=index, extend=False) != {'CANCELLED'}:
index += 1
bpy.ops.info.select_pick(context_override, report_index=index, extend=False)
bpy.ops.info.select_pick(
context_override, report_index=index, extend=False)

def execute(self, context):
messages = split_and_prefix_report_messages(self.report_string)
info_report_string = '\n'.join([message.replace('\n', ' ') for message in messages])
self.report({'INFO'}, f"Hubs {self.title}\n{info_report_string}\nEnd of Hubs {self.title}")
info_report_string = '\n'.join(
[message.replace('\n', ' ') for message in messages])
self.report(
{'INFO'}, f"Hubs {self.title}\n{info_report_string}\nEnd of Hubs {self.title}")
bpy.ops.screen.info_log_show()
bpy.app.timers.register(self.highlight_info_report)
return {'FINISHED'}
Expand Down Expand Up @@ -403,13 +417,15 @@ def draw(self, context):

scroll_up = scroll_column.row()
scroll_up.enabled = start_index > 0
op = scroll_up.operator(ReportScroller.bl_idname, text="", icon="TRIA_UP")
op = scroll_up.operator(ReportScroller.bl_idname,
text="", icon="TRIA_UP")
op.increment = -1
op.maximum = maximum_scrolling

scroll_down = scroll_column.row()
scroll_down.enabled = start_index < maximum_scrolling
op = scroll_down.operator(ReportScroller.bl_idname, text="", icon="TRIA_DOWN")
op = scroll_down.operator(
ReportScroller.bl_idname, text="", icon="TRIA_DOWN")
op.increment = 1
op.maximum = maximum_scrolling

Expand All @@ -419,7 +435,8 @@ def draw(self, context):

scroll_percentage = column.row()
scroll_percentage.enabled = False
scroll_percentage.prop(wm, "hubs_report_scroll_percentage", slider=True)
scroll_percentage.prop(
wm, "hubs_report_scroll_percentage", slider=True)

layout.separator()

Expand Down Expand Up @@ -457,7 +474,8 @@ def init_report_display_blocks(self):
if last_message is None:
final_block = True

current_block_lines = sum([len(message) for message in block_messages])
current_block_lines = sum([len(message)
for message in block_messages])
needed_padding_lines = self.lines_to_show - current_block_lines

message_iter = iter(block_messages)
Expand Down Expand Up @@ -506,7 +524,8 @@ class CopyHubsComponent(Operator):
def poll(cls, context):
if is_linked(context.scene):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot copy components when in linked scenes")
cls.poll_message_set(
"Cannot copy components when in linked scenes")
return False

if hasattr(context, "panel"):
Expand All @@ -518,14 +537,17 @@ def poll(cls, context):

def get_selected_bones(self, context):
selected_bones = context.selected_pose_bones if context.mode == "POSE" else context.selected_editable_bones
selected_armatures = [sel_ob for sel_ob in context.selected_objects if sel_ob.type == "ARMATURE"]
selected_armatures = [
sel_ob for sel_ob in context.selected_objects if sel_ob.type == "ARMATURE"]
selected_hosts = []
for armature in selected_armatures:
armature_bones = armature.pose.bones if context.mode == "POSE" else armature.data.edit_bones
target_armature_bones = armature.data.bones if context.mode == "POSE" else armature.data.edit_bones
target_bones = [bone for bone in armature_bones if bone in selected_bones]
target_bones = [
bone for bone in armature_bones if bone in selected_bones]
for target_bone in target_bones:
selected_hosts.extend([bone for bone in target_armature_bones if target_bone.name == bone.name])
selected_hosts.extend(
[bone for bone in target_armature_bones if target_bone.name == bone.name])
return selected_hosts

def get_selected_hosts(self, context):
Expand Down Expand Up @@ -628,12 +650,14 @@ def execute(self, context):

# Load/Reload the first image and assign it to the target property, then load the rest of the images if they're not already loaded. This mimics Blender's default open files behavior.
primary_filepath = os.path.join(dirname, self.files[0].name)
primary_img = bpy.data.images.load(filepath=primary_filepath, check_existing=True)
primary_img = bpy.data.images.load(
filepath=primary_filepath, check_existing=True)
primary_img.reload()
self.hubs_component[self.target_property] = primary_img

for f in self.files[1:]:
bpy.data.images.load(filepath=os.path.join(dirname, f.name), check_existing=True)
bpy.data.images.load(filepath=os.path.join(
dirname, f.name), check_existing=True)

update_image_editors(old_img, primary_img)
redraw_component_ui(context)
Expand All @@ -657,7 +681,8 @@ def register():
bpy.utils.register_class(ViewReportInInfoEditor)
bpy.utils.register_class(CopyHubsComponent)
bpy.utils.register_class(OpenImage)
bpy.types.WindowManager.hubs_report_scroll_index = IntProperty(default=0, min=0)
bpy.types.WindowManager.hubs_report_scroll_index = IntProperty(
default=0, min=0)
bpy.types.WindowManager.hubs_report_scroll_percentage = IntProperty(
name="Scroll Position", default=0, min=0, max=100, subtype='PERCENTAGE')
bpy.types.WindowManager.hubs_report_last_title = StringProperty()
Expand Down
24 changes: 20 additions & 4 deletions addons/io_hubs_addon/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from bpy.types import Context
from .preferences import get_addon_pref, EXPORT_TMP_FILE_NAME
from .utils import isModuleAvailable, get_browser_profile_directory
from .icons import get_hubs_icons

JS_DROP_FILE = """
var target = arguments[0],
Expand Down Expand Up @@ -272,34 +273,49 @@ def draw(self, context):
row.operator(HubsUpdateSceneOperator.bl_idname,
text='Update')

box = main_box.box()
row = box.row(align=True)
row.alignment = "CENTER"
col = row.column()
col.alignment = "LEFT"
col.label(text="Status:")
hubs_icons = get_hubs_icons()
if isWebdriverAlive():
if is_user_logged_in():
if is_user_in_room():
col = row.column()
col.alignment = "LEFT"
col.active_default = True
col.label(
text="In room")
icon_value=hubs_icons["green-dot.png"].icon_id)
row = box.row(align=True)
row.alignment = "CENTER"
row.label(text="In room")

else:
col = row.column()
col.alignment = "LEFT"
col.label(
text="Entering the room...")
icon_value=hubs_icons["orange-dot.png"].icon_id)
row = box.row(align=True)
row.alignment = "CENTER"
row.label(text="Entering the room...")
else:
col = row.column()
col.alignment = "LEFT"
col.alert = True
col.label(text="Waiting for sign in...")
col.label(icon_value=hubs_icons["orange-dot.png"].icon_id)
row = box.row(align=True)
row.alignment = "CENTER"
row.label(text="Waiting for sign in...")
else:
col = row.column()
col.alignment = "LEFT"
col.alert = True
col.label(text="Waiting for room...")
col.label(icon_value=hubs_icons["red-dot.png"].icon_id)
row = box.row(align=True)
row.alignment = "CENTER"
row.label(text="Waiting for room...")

else:
row = main_box.row()
Expand Down
Loading

0 comments on commit a7bcdc9

Please sign in to comment.