-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathdebugger.py
1181 lines (953 loc) · 43 KB
/
debugger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from bpy.app.handlers import persistent
import bpy
from bpy.types import Context
from .preferences import EXPORT_TMP_FILE_NAME, EXPORT_TMP_SCREENSHOT_FILE_NAME
from .utils import is_module_available, save_prefs, find_area, image_type_to_file_ext
from .icons import get_hubs_icons
from .hubs_session import HubsSession, PARAMS_TO_STRING
from . import api
from bpy.types import AnyType
DEMO_SERVER_URL = ""
ROOM_FLAGS_DOC_URL = "https://github.com/Hubs-Foundation/hubs-docs/blob/master/docs/hubs-query-string-parameters.md"
def export_scene(context):
export_prefs = context.scene.hubs_scene_debugger_room_export_prefs
import os
extension = '.glb'
args = {
# Settings from "Remember Export Settings"
**dict(bpy.context.scene.get('glTF2ExportSettings', {})),
'export_format': ('GLB' if extension == '.glb' else 'GLTF_SEPARATE'),
'filepath': os.path.join(bpy.app.tempdir, EXPORT_TMP_FILE_NAME),
'export_cameras': export_prefs.export_cameras,
'export_lights': export_prefs.export_lights,
'use_selection': export_prefs.use_selection,
'use_visible': export_prefs.use_visible,
'use_renderable': export_prefs.use_renderable,
'use_active_collection': export_prefs.use_active_collection,
'export_apply': export_prefs.export_apply,
'export_force_sampling': False,
}
if bpy.app.version >= (3, 2, 0):
args['use_active_scene'] = True
bpy.ops.export_scene.gltf(**args)
hubs_session = None
def is_instance_set(context):
prefs = context.window_manager.hubs_scene_debugger_prefs
return prefs.hubs_instance_idx != -1
def is_room_set(context):
prefs = context.window_manager.hubs_scene_debugger_prefs
return prefs.hubs_room_idx != -1
class HubsUpdateRoomOperator(bpy.types.Operator):
bl_idname = "hubs_scene.update_room"
bl_label = "View Scene"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def description(cls, context, properties):
is_scene_update = context.scene.hubs_scene_debugger_room_create_prefs.debugLocalScene
if hubs_session.is_alive():
room_params = hubs_session.room_params
is_scene_update = "debugLocalScene" in room_params
if is_scene_update:
return "Updates the currently opened room scene with the Blender scene"
else:
return "Spawns the Blender scene in the currently opened room as an object"
@classmethod
def poll(cls, context: Context):
return hubs_session and hubs_session.user_logged_in and hubs_session.user_in_room
def execute(self, context):
try:
selected_obs = bpy.context.selected_objects
active_ob = bpy.context.active_object
viewpoint = None
if context.scene.hubs_scene_debugger_room_export_prefs.avatar_to_viewport:
area = find_area("VIEW_3D")
if area is not None:
r3d = area.spaces[0].region_3d
view_mat = r3d.view_matrix.inverted()
loc, rot, _ = view_mat.decompose()
from mathutils import Matrix, Vector, Euler
from math import radians
final_loc = loc + Vector((0, 0, -1.6))
rot_offset = Matrix.Rotation(radians(180), 4, 'Z').to_4x4()
final_rot = rot.to_matrix().to_4x4() @ rot_offset
euler = final_rot.to_euler()
euler.x = 0
euler.y = 0
bpy.ops.object.empty_add(location=final_loc, rotation=(euler.x, euler.y, euler.z), type="ARROWS")
viewpoint = bpy.context.object
viewpoint.name = "__scene_debugger_viewpoint"
from .components.utils import add_component
add_component(viewpoint, "waypoint")
for ob in selected_obs:
ob.select_set(True)
context.view_layer.objects.active = active_ob
export_scene(context)
hubs_session.update()
hubs_session.bring_to_front(context)
if viewpoint:
hubs_session.move_to_waypoint("__scene_debugger_viewpoint")
ob = bpy.context.scene.objects["__scene_debugger_viewpoint"]
if ob:
bpy.data.objects.remove(ob, do_unlink=True)
for ob in selected_obs:
ob.select_set(True)
context.view_layer.objects.active = active_ob
return {'FINISHED'}
except Exception as err:
print(err)
bpy.ops.wm.hubs_report_viewer('INVOKE_DEFAULT', title="Hubs scene debugger report", report_string='\n\n'.join(
["The scene export has failed", "Check the export logs or quit the browser instance and try again", f'{err}']))
if viewpoint:
ob = bpy.context.scene.objects["__scene_debugger_viewpoint"]
if ob:
bpy.data.objects.remove(ob, do_unlink=True)
return {'CANCELLED'}
class HubsCreateRoomOperator(bpy.types.Operator):
bl_idname = "hubs_scene.create_room"
bl_label = "Create a new room"
bl_description = "Creates a new room in the selected instance and opens it in the browser selected in the add-on preferences. The specified room flags will be applied"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context: Context):
return is_instance_set(context)
def execute(self, context):
try:
was_alive = hubs_session.init(context)
prefs = context.window_manager.hubs_scene_debugger_prefs
hubs_instance_url = prefs.hubs_instances[prefs.hubs_instance_idx].url
hubs_session.load(
f'{hubs_instance_url}?new&{hubs_session.url_params_string_from_prefs(context)}')
if was_alive:
hubs_session.bring_to_front(context)
return {'FINISHED'}
except Exception as err:
hubs_session.close()
bpy.ops.wm.hubs_report_viewer('INVOKE_DEFAULT', title="Hubs scene debugger report",
report_string=f'The room creation has failed: {err}')
return {"CANCELLED"}
class HubsOpenRoomOperator(bpy.types.Operator):
bl_idname = "hubs_scene.open_room"
bl_label = "Open selected room"
bl_description = "Opens the selected room in the browser selected in the add-on preferences. The specified room flags will be applied"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context: Context):
return is_room_set(context)
def execute(self, context):
try:
was_alive = hubs_session.init(context)
prefs = context.window_manager.hubs_scene_debugger_prefs
room_url = prefs.hubs_rooms[prefs.hubs_room_idx].url
params = hubs_session.url_params_string_from_prefs(context)
if params:
if "?" in room_url:
hubs_session.load(f'{room_url}&{params}')
else:
hubs_session.load(f'{room_url}?{params}')
else:
hubs_session.load(room_url)
if was_alive:
hubs_session.bring_to_front(context)
return {'FINISHED'}
except Exception as err:
hubs_session.close()
bpy.ops.wm.hubs_report_viewer('INVOKE_DEFAULT', title="Hubs scene debugger report",
report_string=f'An error happened while opening the room: {err}')
return {"CANCELLED"}
class HubsCloseRoomOperator(bpy.types.Operator):
bl_idname = "hubs_scene.close_room"
bl_label = "Close"
bl_description = "Close session"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context: Context):
return hubs_session.is_alive()
def execute(self, context):
try:
hubs_session.close()
return {'FINISHED'}
except Exception as err:
bpy.ops.wm.hubs_report_viewer('INVOKE_DEFAULT', title="Hubs scene debugger report",
report_string=f'An error happened while closing the browser window: {err}')
return {"CANCELLED"}
class HubsOpenAddonPrefsOperator(bpy.types.Operator):
bl_idname = "hubs_scene.open_addon_prefs"
bl_label = "Open Preferences"
bl_description = "Open Preferences"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context: Context):
return not hubs_session.is_alive()
def execute(self, context):
bpy.ops.screen.userpref_show('INVOKE_DEFAULT')
context.preferences.active_section
bpy.ops.preferences.addon_expand(module=__package__)
bpy.ops.preferences.addon_show(module=__package__)
return {'FINISHED'}
class HUBS_PT_ToolsSceneDebuggerCreatePanel(bpy.types.Panel):
bl_idname = "HUBS_PT_ToolsSceneDebuggerCreatePanel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = "Create Room"
bl_context = 'objectmode'
bl_parent_id = "HUBS_PT_ToolsSceneDebuggerPanel"
@classmethod
def poll(cls, context: Context):
return is_module_available("selenium")
def draw(self, context: Context):
prefs = context.window_manager.hubs_scene_debugger_prefs
box = self.layout.box()
row = box.row()
row.label(text="Instances:")
row = box.row()
list_row = row.row()
list_row.template_list(HUBS_UL_ToolsSceneDebuggerServers.bl_idname, "", prefs,
"hubs_instances", prefs, "hubs_instance_idx", rows=3)
col = row.column()
col.operator(HubsSceneDebuggerInstanceAdd.bl_idname,
icon='ADD', text="")
col.operator(HubsSceneDebuggerInstanceRemove.bl_idname,
icon='REMOVE', text="")
row = box.row()
row.operator(HubsCreateRoomOperator.bl_idname)
class HUBS_PT_ToolsSceneDebuggerOpenPanel(bpy.types.Panel):
bl_idname = "HUBS_PT_ToolsSceneDebuggerOpenPanel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = "Open Room"
bl_context = 'objectmode'
bl_parent_id = "HUBS_PT_ToolsSceneDebuggerPanel"
@classmethod
def poll(cls, context: Context):
return is_module_available("selenium")
def draw(self, context: Context):
box = self.layout.box()
prefs = context.window_manager.hubs_scene_debugger_prefs
row = box.row()
row.label(text="Rooms:")
row = box.row()
list_row = row.row()
list_row.template_list(HUBS_UL_ToolsSceneDebuggerRooms.bl_idname, "", prefs,
"hubs_rooms", prefs, "hubs_room_idx", rows=3)
col = row.column()
op = col.operator(HubsSceneDebuggerRoomAdd.bl_idname,
icon='ADD', text="")
op.url = DEMO_SERVER_URL
col.operator(HubsSceneDebuggerRoomRemove.bl_idname,
icon='REMOVE', text="")
row = box.row()
row.operator(HubsOpenRoomOperator.bl_idname)
class HUBS_PT_ToolsSceneDebuggerUpdatePanel(bpy.types.Panel):
bl_idname = "HUBS_PT_ToolsSceneDebuggerUpdatePanel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = "Update Room Scene"
bl_context = 'objectmode'
bl_parent_id = "HUBS_PT_ToolsSceneDebuggerPanel"
@classmethod
def poll(cls, context: Context):
return is_module_available("selenium")
def draw(self, context: Context):
box = self.layout.box()
row = box.row()
row.label(
text="Set the default export options in the glTF export panel")
row = box.row()
col = row.column(heading="Limit To:")
col.use_property_split = True
col.prop(context.scene.hubs_scene_debugger_room_export_prefs,
"use_selection")
col.prop(context.scene.hubs_scene_debugger_room_export_prefs,
"use_visible")
col.prop(context.scene.hubs_scene_debugger_room_export_prefs,
"use_renderable")
col.prop(context.scene.hubs_scene_debugger_room_export_prefs,
"use_active_collection")
if bpy.app.version >= (3, 2, 0):
col_row = col.row()
col_row.enabled = False
col_row.prop(context.scene.hubs_scene_debugger_room_export_prefs,
"use_active_scene")
row = box.row()
col = row.column(heading="Data:")
col.use_property_split = True
col.prop(context.scene.hubs_scene_debugger_room_export_prefs,
"export_cameras")
col.prop(context.scene.hubs_scene_debugger_room_export_prefs,
"export_lights")
row = box.row()
col = row.column(heading="Mesh:")
col.use_property_split = True
col.prop(context.scene.hubs_scene_debugger_room_export_prefs,
"export_apply")
row = box.row()
col = row.column(heading="Animation:")
col.use_property_split = True
col_row = col.row()
col_row.enabled = False
col_row.prop(context.scene.hubs_scene_debugger_room_export_prefs,
"export_force_sampling")
row = box.row()
if not hubs_session.is_alive() or not hubs_session.user_logged_in:
row = box.row()
row.alert = True
row.label(
text="You need to be signed in to Hubs to update the room scene")
update_mode = "Update current scene" if context.scene.hubs_scene_debugger_room_create_prefs.debugLocalScene else "Spawn as object"
if hubs_session.is_alive():
room_params = hubs_session.room_params
update_mode = "Update current scene" if "debugLocalScene" in room_params else "Spawn as object"
row = box.row()
row.operator(HubsUpdateRoomOperator.bl_idname,
text=f'{update_mode}')
row = box.row()
row.prop(context.scene.hubs_scene_debugger_room_export_prefs, "avatar_to_viewport")
if "debugLocalScene" not in hubs_session.room_params:
row.enabled = False
class HUBS_PT_ToolsSceneSessionPanel(bpy.types.Panel):
bl_idname = "HUBS_PT_ToolsSceneSessionPanel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = "Status"
bl_context = 'objectmode'
bl_parent_id = "HUBS_PT_ToolsPanel"
def draw(self, context):
main_box = self.layout.box()
if is_module_available("selenium"):
row = main_box.row(align=True)
row.alignment = "CENTER"
col = row.column()
col.alignment = "LEFT"
col.label(text="Connection Status:")
hubs_icons = get_hubs_icons()
if hubs_session.is_alive():
if hubs_session.user_logged_in:
if hubs_session.user_in_room:
col = row.column()
col.alignment = "LEFT"
col.active_default = True
col.label(
icon_value=hubs_icons["green-dot.png"].icon_id)
row = main_box.row(align=True)
row.alignment = "CENTER"
row.label(text=f'In room: {hubs_session.room_name}')
else:
col = row.column()
col.alignment = "LEFT"
col.label(
icon_value=hubs_icons["orange-dot.png"].icon_id)
row = main_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(icon_value=hubs_icons["orange-dot.png"].icon_id)
row = main_box.row(align=True)
row.alignment = "CENTER"
row.label(text="Waiting for session sign in...")
ret_instance = hubs_session.reticulum_url
if ret_instance:
row = main_box.row(align=True)
row.alignment = "CENTER"
row.label(
text=f'Connected to Instance: {ret_instance}')
else:
col = row.column()
col.alignment = "LEFT"
col.alert = True
col.label(icon_value=hubs_icons["red-dot.png"].icon_id)
row = main_box.row(align=True)
row.alignment = "CENTER"
row.label(text="Waiting for session...")
row = self.layout.row()
row.operator(HubsCloseRoomOperator.bl_idname, text='Close')
else:
row = main_box.row()
row.alert = True
row.label(
text="Selenium needs to be installed for the scene debugger functionality. Install from preferences.")
row = main_box.row()
row.operator(HubsOpenAddonPrefsOperator.bl_idname,
text='Setup')
class HUBS_PT_ToolsSceneDebuggerPanel(bpy.types.Panel):
bl_idname = "HUBS_PT_ToolsSceneDebuggerPanel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = "Debug"
bl_context = 'objectmode'
bl_parent_id = "HUBS_PT_ToolsPanel"
@classmethod
def poll(cls, context: Context):
return is_module_available("selenium")
def draw(self, context):
params_icons = {}
if hubs_session.is_alive():
for key in PARAMS_TO_STRING.keys():
params_icons[key] = 'PANEL_CLOSE'
for param in hubs_session.room_params:
if param in params_icons:
params_icons[param] = 'CHECKMARK'
else:
for key in PARAMS_TO_STRING.keys():
params_icons[key] = 'REMOVE'
box = self.layout.box()
row = box.row(align=True)
row.alignment = "EXPAND"
grid = row.grid_flow(columns=2, align=True,
even_rows=False, even_columns=False)
grid.alignment = "CENTER"
flags_row = grid.row()
flags_row.label(text="Room flags")
op = flags_row.operator("wm.url_open", text="", icon="HELP")
op.url = ROOM_FLAGS_DOC_URL
for key in PARAMS_TO_STRING.keys():
grid.prop(context.scene.hubs_scene_debugger_room_create_prefs,
key)
grid.label(text="Is Active?")
for key in PARAMS_TO_STRING.keys():
grid.label(icon=params_icons[key])
def add_instance(context):
prefs = context.window_manager.hubs_scene_debugger_prefs
new_instance = prefs.hubs_instances.add()
new_instance.name = "Demo Hub"
new_instance.url = DEMO_SERVER_URL
prefs.hubs_instance_idx = len(
prefs.hubs_instances) - 1
save_prefs(context)
class HubsSceneDebuggerInstanceAdd(bpy.types.Operator):
bl_idname = "hubs_scene.scene_debugger_instance_add"
bl_label = "Add Server Instance"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
add_instance(context)
return {'FINISHED'}
class HubsSceneDebuggerInstanceRemove(bpy.types.Operator):
bl_idname = "hubs_scene.scene_debugger_instance_remove"
bl_label = "Remove Server Instance"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
prefs = context.window_manager.hubs_scene_debugger_prefs
prefs.hubs_instances.remove(prefs.hubs_instance_idx)
if prefs.hubs_instance_idx >= len(prefs.hubs_instances):
prefs.hubs_instance_idx -= 1
save_prefs(context)
return {'FINISHED'}
class HubsSceneDebuggerRoomAdd(bpy.types.Operator):
bl_idname = "hubs_scene.scene_debugger_room_add"
bl_label = "Add Room"
bl_description = "Adds the current active room url to the list, if there is no active room it will add an empty string"
bl_options = {'REGISTER', 'UNDO'}
url: bpy.props.StringProperty(name="Room Url")
def execute(self, context):
prefs = context.window_manager.hubs_scene_debugger_prefs
new_room = prefs.hubs_rooms.add()
url = self.url
if hubs_session.is_alive():
current_url = hubs_session.get_url()
if current_url:
url = current_url
if "hub_id=" in url:
url = url.split("&")[0]
else:
url = url.split("?")[0]
new_room.name = "Room Name"
if hubs_session.is_alive():
room_name = hubs_session.room_name
if room_name:
new_room.name = room_name
new_room.url = url
prefs.hubs_room_idx = len(
prefs.hubs_rooms) - 1
save_prefs(context)
return {'FINISHED'}
class HubsSceneDebuggerRoomRemove(bpy.types.Operator):
bl_idname = "hubs_scene.scene_debugger_room_remove"
bl_label = "Remove Room"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context: Context):
prefs = context.window_manager.hubs_scene_debugger_prefs
return prefs.hubs_room_idx >= 0
def execute(self, context):
prefs = context.window_manager.hubs_scene_debugger_prefs
prefs.hubs_rooms.remove(prefs.hubs_room_idx)
if prefs.hubs_room_idx >= len(prefs.hubs_rooms):
prefs.hubs_room_idx -= 1
save_prefs(context)
return {'FINISHED'}
class HUBS_UL_ToolsSceneDebuggerServers(bpy.types.UIList):
bl_idname = "HUBS_UL_ToolsSceneDebuggerServers"
bl_label = "Instances"
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
split = layout.split(factor=0.25)
split.prop(item, "name", text="", emboss=False)
split.prop(item, "url", text="", emboss=False)
class HUBS_UL_ToolsSceneDebuggerRooms(bpy.types.UIList):
bl_idname = "HUBS_UL_ToolsSceneDebuggerRooms"
bl_label = "Rooms"
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
split = layout.split(factor=0.25)
split.prop(item, "name", text="", emboss=False)
split.prop(item, "url", text="", emboss=False)
class HubsPublishSceneOperator(bpy.types.Operator):
bl_idname = "hubs_scene.publish_scene"
bl_label = "Publish"
bl_description = "Publish current Blender scene"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context: Context):
props = context.scene.hubs_scene_debugger_scene_publish_props
return hubs_session.is_alive() and hubs_session.user_logged_in and props.screenshot and props.scene_name
def execute(self, context):
try:
export_scene(context)
import os
url = hubs_session.reticulum_url
scene_data = {}
name = context.scene.hubs_scene_debugger_scene_publish_props.scene_name
scene_data.update({"name": name})
glb_path = os.path.join(bpy.app.tempdir, EXPORT_TMP_FILE_NAME)
glb = open(glb_path, "rb")
glb_data = api.upload_media(url, glb)
scene_data.update({
"model_file_id": glb_data["file_id"],
"model_file_token": glb_data["access_token"]
})
screenshot = context.scene.hubs_scene_debugger_scene_publish_props.screenshot
if screenshot.type in ['RENDER_RESULT', 'COMPOSITING'] or screenshot.packed_file:
screenshot_full = os.path.join(
bpy.app.tempdir, EXPORT_TMP_SCREENSHOT_FILE_NAME +
image_type_to_file_ext(screenshot.file_format))
screenshot.save_render(screenshot_full)
else:
screenshot_full = bpy.path.abspath(screenshot.filepath, library=screenshot.library)
screenshot_norm = os.path.normpath(screenshot_full)
screenshot_data = api.upload_media(
url, open(screenshot_norm, "rb"))
scene_data.update({
"screenshot_file_id": screenshot_data["file_id"],
"screenshot_file_token": screenshot_data["access_token"]
})
scene_data.update({
"allow_remixing": False,
"allow_promotion": False,
"attributions": {
"creator": "",
"content": []
}
})
api.publish_scene(url, hubs_session.get_token(), scene_data)
bpy.ops.wm.hubs_report_viewer('INVOKE_DEFAULT', title="Hubs scene debugger report",
report_string=f'Scene {name} successfully published')
bpy.ops.hubs_scene.get_scenes()
return {'FINISHED'}
except Exception as err:
bpy.ops.wm.hubs_report_viewer('INVOKE_DEFAULT', title="Hubs scene debugger report",
report_string=f'An error happened while publishing the scene: {err}')
return {"CANCELLED"}
class HubsUpdateSceneOperator(bpy.types.Operator):
bl_idname = "hubs_scene.update_scene"
bl_label = "Update"
bl_description = "Updates the selected scene with the Blender scene"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context: Context):
return hubs_session.is_alive() and hubs_session.user_logged_in and context.window_manager.hubs_scene_debugger_scenes_props.scene_idx > -1
def execute(self, context):
try:
export_scene(context)
import os
url = hubs_session.reticulum_url
scenes = context.window_manager.hubs_scene_debugger_scenes_props
scene = scenes.scenes[scenes.scene_idx]
scene_data = {}
glb_path = os.path.join(bpy.app.tempdir, EXPORT_TMP_FILE_NAME)
glb = open(glb_path, "rb")
glb_data = api.upload_media(url, glb)
scene_data.update({
"model_file_id": glb_data["file_id"],
"model_file_token": glb_data["access_token"]
})
api.publish_scene(url, hubs_session.get_token(),
scene_data, scene.scene_id)
bpy.ops.wm.hubs_report_viewer('INVOKE_DEFAULT', title="Hubs scene debugger report",
report_string=f'Scene {scene.name} successfully updated')
return {'FINISHED'}
except Exception as err:
bpy.ops.wm.hubs_report_viewer('INVOKE_DEFAULT', title="Hubs scene debugger report",
report_string=f'An error happened while updated the scene: {err}')
return {"CANCELLED"}
def invoke(self, context, event):
def draw(self, context):
row = self.layout.row()
row.label(
text="Are you sure that you want to overwrite the selected scene?")
row = self.layout.row()
col = row.column()
col.operator(HubsUpdateSceneOperator.bl_idname, text="Yes")
bpy.context.window_manager.popup_menu(draw)
return {'FINISHED'}
class HubsCreateRoomWithSceneOperator(bpy.types.Operator):
bl_idname = "hubs_scene.create_room_with_scene"
bl_label = "Create Room"
bl_description = "Creates a new room in the selected instance and opens it in the browser selected in the add-on preferences. The currently selected scene from the scenes list will be used. The specified room flags will be applied"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context: Context):
return hubs_session.is_alive() and hubs_session.user_logged_in and context.window_manager.hubs_scene_debugger_scenes_props.scene_idx > -1
def execute(self, context):
try:
scenes_props = context.window_manager.hubs_scene_debugger_scenes_props
scene = scenes_props.scenes[scenes_props.scene_idx]
# Try to create a Hubs with credentials
response = api.create_room(
hubs_session.reticulum_url, token=hubs_session.get_token(),
scene_name=scene.name, scene_id=scene.scene_id)
if "error" in response:
hubs_session.set_credentials(None, None)
# Try to create a Hubs anonymously
response = api.create_room(
hubs_session.reticulum_url, scene_name=scene.name, scene_id=scene.scene_id)
if "error" in response:
raise Exception(response["error"])
if "creator_assignment_token" in response:
embed_token = None
creator_token = response["creator_assignment_token"]
if creator_token:
if "embed_token" in response:
embed_token = response["embed_token"]
hubs_session.set_creator_assignment_token(
creator_token, embed_token)
was_alive = hubs_session.init(context)
params = hubs_session.url_params_string_from_prefs(context)
if hubs_session.is_local_instance():
from urllib.parse import urlparse
parsed = urlparse(hubs_session.client_url)
port = str(parsed.port)
url = f'{parsed.scheme}://{parsed.hostname}{":"+port if port else ""}/hub.html?hub_id={response["hub_id"]}&{params}'
else:
url = f'{response["url"]}?{params}'
hubs_session.load(url)
if was_alive:
hubs_session.bring_to_front(context)
return {'FINISHED'}
except Exception as err:
bpy.ops.wm.hubs_report_viewer('INVOKE_DEFAULT', title="Hubs scene debugger report",
report_string=f'An error happened while opening the scene: {err}')
return {"CANCELLED"}
class HubsGetScenesOperator(bpy.types.Operator):
bl_idname = "hubs_scene.get_scenes"
bl_label = "Get Scenes"
bl_description = "Gets the scene list from your account"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context: Context):
return hubs_session.is_alive() and hubs_session.user_logged_in
def execute(self, context):
scenes_props = context.window_manager.hubs_scene_debugger_scenes_props
scenes_props.instance = hubs_session.reticulum_url
scenes_props.scenes.clear()
try:
url = hubs_session.reticulum_url
scenes = api.get_projects(url, hubs_session.get_token())
for scene in scenes:
new_scene = scenes_props.scenes.add()
new_scene["scene_id"] = scene["scene_id"]
new_scene["name"] = scene["name"]
new_scene["url"] = scene["url"]
new_scene["description"] = scene["description"]
new_scene["screenshot_url"] = scene["screenshot_url"]
scenes_props.scene_idx = len(scenes_props.scenes) - 1
if len(scenes_props.scenes) > 0:
scenes_props.scene_idx = 0
save_prefs(context)
return {'FINISHED'}
except Exception as err:
bpy.ops.wm.hubs_report_viewer('INVOKE_DEFAULT', title="Hubs scene debugger report",
report_string=f'An error happened while getting the scenes: {err}')
return {"CANCELLED"}
class HUBS_UL_ToolsSceneDebuggerProjects(bpy.types.UIList):
bl_idname = "HUBS_UL_ToolsSceneDebuggerProjects"
bl_label = "Projects"
def filter_items(self, context: Context, data: AnyType, property: str):
scene_props = context.window_manager.hubs_scene_debugger_scenes_props
items = getattr(data, property)
filtered = [self.bitflag_filter_item] * len(items)
ordered = [i for i, item in enumerate(items)]
ret_instance = hubs_session.reticulum_url if hubs_session.is_alive() else None
filter = not scene_props.instance or ret_instance != scene_props.instance
if filter:
for i, item in enumerate(items):
filtered[i] &= ~self.bitflag_filter_item
return filtered, ordered
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
split = layout.split(factor=0.75)
split.prop(item, "name", text="", emboss=False)
split.prop(item, "scene_id", text="", emboss=False)
class HUBS_PT_ToolsSceneDebuggerPublishScenePanel(bpy.types.Panel):
bl_idname = "HUBS_PT_ToolsSceneDebuggerPublishScenePanel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = "Publish"
bl_context = 'objectmode'
bl_parent_id = "HUBS_PT_ToolsPanel"
@classmethod
def poll(cls, context: Context):
return is_module_available("selenium")
def draw(self, context: Context):
if not hubs_session.is_alive() or not hubs_session.user_logged_in:
box = self.layout.box()
row = box.row()
row.alert = True
row.label(
text="You need to be signed in to Hubs to get, update or publish scenes")
row = box.row()
row.alert = True
row.label(
text="Create or open a room to open a session")
box = self.layout.box()
row = box.row()
row.label(text="Manage:")
row = box.row()
list_row = row.row()
list_row.template_list(
HUBS_UL_ToolsSceneDebuggerProjects.bl_idname, "", context.window_manager.hubs_scene_debugger_scenes_props,
"scenes", context.window_manager.hubs_scene_debugger_scenes_props, "scene_idx", rows=3)
row = box.row()
col = row.column()
col.operator(HubsGetScenesOperator.bl_idname)
col = row.column()
col.operator(HubsUpdateSceneOperator.bl_idname)
row = box.row()
row = row.column()
row.operator(HubsCreateRoomWithSceneOperator.bl_idname)
box = self.layout.box()
row = box.row()
row.label(text="Publish:")
row = box.row()
publish_props_box = row.box()
row = publish_props_box.row()
row.prop(context.scene.hubs_scene_debugger_scene_publish_props, "scene_name")
row = publish_props_box.row()
col = row.column()
col.prop(context.scene.hubs_scene_debugger_scene_publish_props, "screenshot")
col = row.column()
col.context_pointer_set(
"target", context.scene.hubs_scene_debugger_scene_publish_props)
col.context_pointer_set("host", context.scene)
op = col.operator("image.hubs_open_image", text='', icon='FILE_FOLDER')
op.target_property = "screenshot"
row = box.row()
op = row.operator(HubsPublishSceneOperator.bl_idname)
class HubsSceneDebuggerRoomCreatePrefs(bpy.types.PropertyGroup):
newLoader: bpy.props.BoolProperty(
name=PARAMS_TO_STRING["newLoader"]["name"],
default=True, description=PARAMS_TO_STRING["newLoader"]["description"])
ecsDebug: bpy.props.BoolProperty(
name=PARAMS_TO_STRING["ecsDebug"]["name"],
default=True, description=PARAMS_TO_STRING["ecsDebug"]["description"])
vr_entry_type: bpy.props.BoolProperty(
name=PARAMS_TO_STRING["vr_entry_type"]["name"],
default=True, description=PARAMS_TO_STRING["vr_entry_type"]["description"])
debugLocalScene: bpy.props.BoolProperty(name=PARAMS_TO_STRING["debugLocalScene"]["name"], default=True,
description=PARAMS_TO_STRING["debugLocalScene"]["description"])
class HubsSceneDebuggerRoomExportPrefs(bpy.types.PropertyGroup):
export_cameras: bpy.props.BoolProperty(name="Export Cameras", default=False,
description="Export cameras", options=set())
export_lights: bpy.props.BoolProperty(
name="Punctual Lights", default=False,
description="Punctual Lights, Export directional, point, and spot lights. Uses \"KHR_lights_punctual\" glTF extension",
options=set())
use_selection: bpy.props.BoolProperty(name="Selection Only", default=False,
description="Selection Only, Export selected objects only.",
options=set())
export_apply: bpy.props.BoolProperty(
name="Apply Modifiers", default=True,
description="Apply Modifiers, Apply modifiers (excluding Armatures) to mesh objects -WARNING: prevents exporting shape keys.",
options=set())
use_visible: bpy.props.BoolProperty(
name='Visible Objects',
description='Export visible objects only',
default=False,
options=set()
)
use_renderable: bpy.props.BoolProperty(
name='Renderable Objects',
description='Export renderable objects only',
default=False,
options=set()
)
use_active_collection: bpy.props.BoolProperty(
name='Active Collection',
description='Export objects in the active collection only',
default=False,
options=set()
)
use_active_scene: bpy.props.BoolProperty(
name='Active Scene',
description='Export objects in the active scene only. This has been forced ON because Hubs can only use one scene anyway',
default=True, options=set())
export_force_sampling: bpy.props.BoolProperty(
name='Sampling Animations',
description='Apply sampling to all animations. This has been forced OFF because it can break animations in Hubs',
default=False, options=set())
avatar_to_viewport: bpy.props.BoolProperty(
name='Spawn using viewport transform',
description='Spawn the avatar in the current viewport camera position/rotation',
default=False, options=set())
class HubsSceneProject(bpy.types.PropertyGroup):
scene_id: bpy.props.StringProperty(
name="Id",
description="Scene id",
default="Scene id",
get=lambda self: self["scene_id"]
)
name: bpy.props.StringProperty(
name="Name",
description="Scene name",
default="Scene name",
get=lambda self: self["name"]
)