Repository navigation
Expand file tree
/
Copy pathui_panels.py
More file actions
5019 lines (4184 loc) · 176 KB
/
Copy pathui_panels.py
File metadata and controls
5019 lines (4184 loc) · 176 KB
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
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
from __future__ import annotations
import logging
import os
import platform
import random
import sys
import time
from typing import Any
from urllib.parse import quote
from webbrowser import open_new_tab
import bpy
from bpy.props import (
BoolProperty,
EnumProperty,
FloatProperty,
FloatVectorProperty,
IntProperty,
StringProperty,
)
from bpy.types import Context, Menu, Panel, UILayout
from .asset_bar import asset_bar_op
from . import (
addon_updater_ops,
autothumb,
categories,
client_lib,
comments_utils,
datas,
download,
global_vars,
icons,
image_utils,
keymap_utils,
paths,
ratings,
ratings_utils,
search,
ui,
unlock_options,
upload,
utils,
)
ACCEPTABLE_ENGINES = ("CYCLES", "BLENDER_EEVEE", "BLENDER_EEVEE_NEXT")
bk_logger = logging.getLogger(__name__)
# Images currently being drawn by AssetPopupCard (protected from timer_image_cleanup).
# Populated during draw(), cleared each timer_image_cleanup() cycle.
_protected_images: set[str] = set()
# Maximum length for manufacturer labels before truncation (e.g. "Ford motor company")
MAX_MANUFACTURER_LABEL_LEN = 17
INVALID_TOKENS = {
"me",
"unknown",
"self",
"none",
"n/a",
}
last_time_overlay_panel_active = 0.0
def set_overlay_panel_active():
"""Record the time a BlenderKit popup/panel/popover was last drawn.
This is read in asset_bar_op.py to cancel asset drag-drop and to ignore
keyboard shortcuts for a short window afterwards. Without it, click-through
events that pass through a popup down to the asset bar underneath would be
wrongly interpreted as clicks/double-clicks on the asset bar.
Every operator popup, dialog and popover that can appear over the asset bar
should call this at the start of its draw() method.
"""
global last_time_overlay_panel_active
last_time_overlay_panel_active = time.time()
def draw_not_logged_in(source, message="Please Login/Signup to use this feature"):
title = "You aren't logged in"
def draw_message(source, context):
set_overlay_panel_active()
layout = source.layout
utils.label_multiline(layout, text=message)
draw_login_buttons(layout)
bpy.context.window_manager.popup_menu(draw_message, title=title, icon="INFO")
def draw_upload_common(layout, props, asset_type, context):
if asset_type == "MODEL":
url = paths.BLENDKIT_MODEL_UPLOAD_INSTRUCTIONS_URL
if asset_type == "MATERIAL":
url = paths.BLENDKIT_MATERIAL_UPLOAD_INSTRUCTIONS_URL
if asset_type == "BRUSH":
url = paths.BLENDKIT_BRUSH_UPLOAD_INSTRUCTIONS_URL
if asset_type == "SCENE":
url = paths.BLENDKIT_SCENE_UPLOAD_INSTRUCTIONS_URL
if asset_type == "HDR":
url = paths.BLENDKIT_HDR_UPLOAD_INSTRUCTIONS_URL
if asset_type == "NODEGROUP":
url = "" # paths.BLENDKIT_NODEGROUP_UPLOAD_INSTRUCTIONS_URL
if asset_type == "PRINTABLE":
url = (
paths.BLENDKIT_PRINTABLE_UPLOAD_INSTRUCTIONS_URL
) # Reuse model instructions since prints are similar
if asset_type == "ADDON":
url = paths.BLENDKIT_ADDON_UPLOAD_INSTRUCTIONS_URL
op = layout.operator(
"wm.url_open", text=f"Read {asset_type} upload instructions", icon="QUESTION"
)
op.url = paths.url_with_utm(url, "upload_docs") if url else url
row = layout.row(align=True)
if props.upload_state != "":
state_lower = props.upload_state.lower()
is_error = any(
k in state_lower
for k in (
"error",
"fail",
"exceed",
"denied",
"invalid",
"remaining",
"quota",
)
)
if is_error:
box = layout.box()
box.alert = True
utils.label_multiline(
box,
text=props.upload_state,
icon="ERROR",
width=context.region.width,
)
else:
utils.label_multiline(
layout, text=props.upload_state, width=context.region.width
)
if props.uploading:
op = layout.operator("object.kill_bg_process", text="", icon="CANCEL")
op.process_source = asset_type
op.process_type = "UPLOAD"
layout = layout.column()
layout.enabled = False
# PRE-RELEASED WARNING
if props.is_private == "PUBLIC" and bpy.app.version_cycle != "release":
layout.row()
utils.label_multiline(
layout,
text="Uploading from Alpha, Beta, or Release Candidate versions of Blender is not recommended. Please use a Stable version.",
icon="ERROR",
width=210,
)
if props.asset_base_id == "":
optext = "Upload %s" % asset_type.lower()
op = layout.operator("object.blenderkit_upload", text=optext, icon="EXPORT")
op.asset_type = asset_type
op.reupload = False
# make sure everything gets uploaded.
op.main_file = True
op.metadata = True
op.thumbnail = True
if utils.profile_is_validator():
op = layout.operator(
"object.blenderkit_dry_run_export",
text="Dry Run Export (validator)",
icon="CHECKBOX_HLT",
)
op.asset_type = asset_type
if props.asset_base_id != "":
op = layout.operator(
"wm.blenderkit_url", text="Edit Details", icon="GREASEPENCIL"
)
op.url = paths.url_with_utm(
f"{paths.BLENDKIT_USER_ASSETS_URL}/{props.asset_base_id}/?edit#",
"uploads_edit",
)
op = layout.operator(
"object.blenderkit_upload", text="Reupload asset", icon="EXPORT"
)
op.asset_type = asset_type
op.reupload = True
op = layout.operator(
"object.blenderkit_upload", text="Upload as new asset", icon="EXPORT"
)
op.asset_type = asset_type
op.reupload = False
layout.label(text="asset has a version online.")
row = layout.row()
if props.is_private == "PUBLIC" and props.category == "NONE":
row.alert = True
row.prop(props, "category")
if props.category != "NONE" and props.subcategory != "EMPTY":
row = layout.row()
if props.is_private == "PUBLIC" and props.subcategory == "NONE":
row.alert = True
row.prop(props, "subcategory")
if props.subcategory != "NONE" and props.subcategory1 != "EMPTY":
row = layout.row()
if props.is_private == "PUBLIC" and props.subcategory1 == "NONE":
row.alert = True
row.prop(props, "subcategory1")
layout.prop(props, "is_private", expand=True)
if props.is_private == "PUBLIC":
layout.prop(props, "license")
layout.prop(props, "is_free", expand=True)
prop_needed(layout, props, "name", props.name)
if props.is_private == "PUBLIC":
prop_needed(layout, props, "description", props.description)
prop_needed(layout, props, "tags", props.tags)
else:
layout.prop(props, "description")
layout.prop(props, "tags")
def prop_needed(layout, props, name, value: Any = "", is_not_filled: Any = ""):
row = layout.row()
if value == is_not_filled:
row.alert = True
row.prop(props, name) # , icon="ERROR")
row.alert = False
else:
row.prop(props, name)
class BLENDERKIT_OT_show_validation_popup(bpy.types.Operator):
bl_idname = "wm.blenderkit_show_validation_popup"
bl_label = "Manufacturer Validation Result"
bl_options = {"REGISTER", "INTERNAL"}
message: StringProperty(name="Message", default="", options={"SKIP_SAVE"}) # type: ignore
def invoke(self, context, event):
# Ensure we always have something to show so the dialog renders on older Blender versions.
if not self.message:
self.message = "No validation output available."
return context.window_manager.invoke_props_dialog(self, width=500)
def execute(self, context):
# The dialog is read-only; nothing to execute beyond closing it.
return {"FINISHED"}
def draw(self, context):
set_overlay_panel_active()
layout = self.layout
clean_text = self.message.replace("\r\n", "\n").replace("\r", "\n")
# Keep rendering even if the text is short or empty.
if not clean_text.strip():
layout.label(text="No validation output available.")
return
for paragraph in clean_text.split("\n"):
utils.label_multiline(layout, text=paragraph, width=480)
class BLENDERKIT_OT_permissions_error_popup(bpy.types.Operator):
"""Show a large centered dialog when Blendkit cannot write to the asset directory.
Dynamically updates to show success when the path is fixed.
"""
bl_idname = "wm.blenderkit_permissions_error_popup"
bl_label = "Blendkit - Directory Permission Error"
bl_options = {"REGISTER", "INTERNAL"}
error_message: StringProperty(name="Error", default="", options={"SKIP_SAVE"}) # type: ignore
directory_path: StringProperty(name="Path", default="", options={"SKIP_SAVE"}) # type: ignore
def invoke(self, context, event):
wm = context.window_manager
try:
return wm.invoke_props_dialog(
self, width=600, confirm_text="Open Preferences"
)
except TypeError:
return wm.invoke_props_dialog(self, width=600)
def execute(self, context):
# Check if path is already fixed (e.g. user clicked Set Default Folder)
current_dir = context.preferences.addons[__package__].preferences.global_dir
current_dir = os.path.normpath(bpy.path.abspath(current_dir))
current_ok, _ = utils._check_dir_permissions(current_dir, "Global directory")
if not current_ok:
bpy.ops.preferences.addon_show(module=__package__)
return {"FINISHED"}
def draw(self, context):
set_overlay_panel_active()
layout = self.layout
# Light check for live UI — draw() runs on each redraw, avoid file I/O here
current_dir = context.preferences.addons[__package__].preferences.global_dir
current_dir = os.path.normpath(bpy.path.abspath(current_dir))
current_ok = os.path.isdir(current_dir)
if current_ok:
# === PATH IS NOW FIXED — show success ===
layout.separator()
row = layout.row()
row.scale_y = 2.0
row.alert = False
row.label(text=" Directory is now accessible!", icon="CHECKMARK")
layout.separator()
layout.label(text=f"Path: {current_dir}")
layout.separator()
layout.label(text="You can close this dialog now.")
return
# === PATH IS BROKEN — show big red warning ===
# Large red alert header
box_header = layout.box()
box_header.alert = True
row = box_header.row()
row.scale_y = 2.0
row.alignment = "CENTER"
row.label(text=" CANNOT ACCESS DOWNLOAD FOLDER ", icon="ERROR")
layout.separator()
# Error details
clean_text = self.error_message.replace("\r\n", "\n").replace("\r", "\n")
for paragraph in clean_text.split("\n"):
if paragraph.strip():
utils.label_multiline(layout, text=paragraph, width=560)
layout.separator()
# === Fix options ===
box = layout.box()
box.label(text="How to fix this:", icon="TOOL_SETTINGS")
box.separator(factor=0.5)
# Option 1: Set default folder (show if parent dir exists)
default_dir = paths.default_global_dict()
default_parent = os.path.dirname(default_dir)
if os.path.isdir(default_dir) or os.path.isdir(default_parent):
row = box.row()
row.scale_y = 1.5
row.operator(
"wm.blenderkit_set_default_directory",
text=f" Set Default Folder: {default_dir} ",
icon="CHECKMARK",
)
box.separator(factor=0.5)
# Option 2: Open preferences
col = box.column(align=True)
col.label(text="Or click 'Open Preferences' below to choose a folder manually.")
layout.separator()
# Current broken path
row = layout.row()
row.alert = True
row.label(text=f"Current folder: {self.directory_path}", icon="INFO")
class BLENDERKIT_OT_set_default_directory(bpy.types.Operator):
"""Set the Global Directory to the default blenderkit_data folder"""
bl_idname = "wm.blenderkit_set_default_directory"
bl_label = "Set Default Folder"
bl_options = {"REGISTER", "INTERNAL"}
def execute(self, context):
default_dir = paths.default_global_dict()
ok, message = utils._check_dir_permissions(default_dir, "Default directory")
if not ok:
self.report({"ERROR"}, f"Default folder is not writable: {message}")
return {"CANCELLED"}
preferences = context.preferences.addons[__package__].preferences
preferences.global_dir = default_dir
self.report({"INFO"}, f"Global directory set to: {default_dir}")
utils.restart_client_after_path_fix()
return {"FINISHED"}
def draw_validated_manufacturer(
layout: bpy.types.UILayout, asset: Any, props: Any = None
) -> None:
"""Show manufacturer validation output when present on an asset's dictParameters."""
if asset is None:
return
asset_data = None
try:
if hasattr(asset, "get"):
asset_data = asset.get("asset_data")
except Exception:
asset_data = None
if asset_data is None:
asset_data = getattr(asset, "asset_data", None)
if not asset_data:
return
validated_output = asset_data.get("dictParameters", {}).get(
"validatedManufacturerOutput"
)
if not validated_output:
return
box = layout.box()
row = box.row(align=True)
row.label(text="Manufacturer validation", icon="ERROR")
row.operator_context = "INVOKE_DEFAULT"
op = row.operator(
"wm.blenderkit_show_validation_popup",
text="Show result",
icon="VIEWZOOM",
emboss=True,
)
op.message = str(validated_output)
def draw_panel_hdr_upload(self, context):
layout = self.layout
ui_props = bpy.context.window_manager.blenderkitUI
layout.prop(ui_props, "hdr_upload_image")
tone_box = layout.box()
tone_box.label(text="Thumbnail Conversion", icon="IMAGE_RGB")
tone_box.prop(ui_props, "hdr_use_custom_thumbnail_tone")
hdr = utils.get_active_HDR()
if hdr is not None:
props = hdr.blenderkit
layout = self.layout
draw_upload_common(layout, props, "HDR", context)
def draw_search_text_field(
layout: UILayout, ui_props: Any, context: bpy.types.Context
) -> None:
"""Draw the search text field and asset bar toggle for asset search panels."""
row = layout.row(align=True)
kwargs = {"text": "", "icon": "VIEWZOOM"}
if bpy.app.version >= (4, 2, 0):
kwargs["placeholder"] = "Search Blendkit"
row.prop(ui_props, "search_keywords", **kwargs)
if (context.region.width) > 700:
row.ui_units_x = 5 + int(context.region.width / 200)
search_field_width = bpy.context.preferences.addons[
__package__
].preferences.search_field_width
has_search_keywords = ui_props.search_keywords != ""
if search_field_width > 0:
row.ui_units_x = search_field_width - has_search_keywords * 0.5
# if there are search keywords, draw an x icon to clear the search keywords
if has_search_keywords:
row.operator("view3d.blenderkit_clear_search_keywords", text="", icon="X")
shortcut = keymap_utils.get_shortcut_label(
"view3d.run_assetbar_fix_context", fallback=""
)
shortcut_hint = f"\nShortcut: {shortcut}" if shortcut else ""
if ui_props.assetbar_on:
icon = "HIDE_OFF"
ttip = f"Click to Hide Asset Bar.{shortcut_hint}"
else:
icon = "HIDE_ON"
ttip = f"Click to Show Asset Bar.{shortcut_hint}"
op = row.operator("view3d.blenderkit_asset_bar_widget", text="", icon=icon)
op.keep_running = False
op.do_search = False
op.tooltip = ttip
def draw_panel_hdr_search(self, context):
s = context.scene
wm = context.window_manager
props = wm.blenderkit_HDR
ui_props = wm.blenderkitUI
layout = self.layout
draw_search_text_field(
layout, ui_props, context
) # Ensure search field is drawn in HDR search panel
utils.label_multiline(layout, text=props.report)
def draw_panel_addon_search(self, context):
wm = context.window_manager
ui_props = wm.blenderkitUI
addon_props = wm.blenderkit_addon
layout = self.layout
draw_search_text_field(
layout, ui_props, context
) # Ensure search field is drawn in addon search panel
utils.label_multiline(layout, text=addon_props.report)
def draw_panel_author_search(self, context):
wm = context.window_manager
ui_props = wm.blenderkitUI
author_props = wm.blenderkit_author
layout = self.layout
draw_search_text_field(
layout, ui_props, context
) # Ensure search field is drawn in author search panel
utils.label_multiline(layout, text=author_props.report)
def draw_panel_nodegroup_upload(self, context):
layout = self.layout
ui_props = bpy.context.window_manager.blenderkitUI
layout.enabled = True
box = layout.box()
box.label(text="Node group to upload:")
box.prop_search(
ui_props,
"nodegroup_upload",
bpy.data,
"node_groups",
text="",
icon="NODETREE",
)
nodegroup = utils.get_active_nodegroup()
if nodegroup is None:
utils.label_multiline(
box,
text="Pick a Geometry Nodes group from the list above to start the upload.",
icon="INFO",
)
else:
props = nodegroup.blenderkit
layout = self.layout
draw_upload_common(layout, props, "NODEGROUP", context)
layout.prop(props, "thumbnail")
def draw_panel_nodegroup_search(self, context):
s = context.scene
wm = context.window_manager
props = wm.blenderkit_nodegroup
ui_props = wm.blenderkitUI
layout = self.layout
draw_search_text_field(
layout,
ui_props,
context,
) # Ensure search field is drawn in nodegroup search panel
utils.label_multiline(layout, text=props.report)
def draw_common_filters(layout, ui_props):
"""Draw common filter elements shared by multiple asset type panels.
Args:
layout: The UI layout to draw in
ui_props: The UI properties containing filter settings
"""
# All "Search filters" panels are shown as popovers over the asset bar,
# so record the redraw time to prevent click-through to the asset bar.
set_overlay_panel_active()
layout.separator()
row = layout.row()
row.prop(ui_props, "search_bookmarks", text="Bookmarks", icon="BOOKMARKS")
row.prop(ui_props, "own_only", icon="USER")
if ui_props.own_only:
layout.prop(ui_props, "own_verification_status", text="Status", icon="LOCKED")
layout.prop(ui_props, "free_only")
layout.prop(ui_props, "quality_limit", slider=True)
layout.prop(ui_props, "search_license")
layout.prop(ui_props, "search_order_by")
def draw_thumbnail_upload_panel(layout, props):
tex = autothumb.get_texture_ui(props.thumbnail, ".upload_preview")
if not tex or not tex.image:
return
box = layout.box()
box.template_icon(icon_value=tex.image.preview.icon_id, scale=6.0)
def draw_wire_thumbnail_upload_panel(layout, props):
tex = autothumb.get_texture_ui(props.wire_thumbnail, ".upload_preview_wire")
if not tex or not tex.image:
return
box = layout.box()
box.template_icon(icon_value=tex.image.preview.icon_id, scale=6.0)
def draw_panel_model_upload(self, context):
"""Draw upload panel for model and printable assets"""
ob = utils.get_active_model()
while ob.parent is not None:
ob = ob.parent
props = ob.blenderkit
layout = self.layout
asset_type = bpy.context.window_manager.blenderkitUI.asset_type
draw_upload_common(layout, props, asset_type, context)
# Add the photo thumbnail field only for printable assets
if asset_type == "PRINTABLE":
layout.prop(props, "photo_thumbnail_will_upload_on_website")
if not props.photo_thumbnail_will_upload_on_website:
col = layout.column()
prop_needed(col, props, "photo_thumbnail", props.photo_thumbnail)
# Wireframe thumbnail is an experimental feature. When enabled, the regular
# "Generate thumbnail" dialog exposes a Regular/Wireframe switch that renders
# into this slot. The wireframe thumbnail is optional and only uploaded when a
# valid image is provided here.
wire_upload_enabled = utils.experimental_enabled()
# Thumbnail previews. When the experimental wireframe feature is enabled show
# the regular and wireframe previews side by side so both can be reviewed at
# the same time; otherwise just show the regular preview.
preview_row = layout.row()
reg_preview = preview_row.column()
reg_preview.enabled = not props.is_generating_thumbnail
if wire_upload_enabled:
reg_preview.label(text="Regular")
draw_thumbnail_upload_panel(reg_preview, props)
if wire_upload_enabled:
wire_preview = preview_row.column()
wire_preview.enabled = not getattr(props, "is_generating_wire_thumbnail", False)
wire_preview.label(text="Wireframe")
draw_wire_thumbnail_upload_panel(wire_preview, props)
col = layout.column()
if props.is_generating_thumbnail:
col.enabled = False
prop_needed(col, props, "thumbnail", props.thumbnail)
# Thumbnail generation relies on the background thumbnailer which requires
# Blender 4.2+, so only expose the button on supported versions.
if bpy.context.scene.render.engine in ACCEPTABLE_ENGINES and bpy.app.version >= (
4,
2,
0,
):
col.operator_context = "INVOKE_DEFAULT"
op = col.operator(
"object.blenderkit_generate_thumbnail",
text="Generate thumbnail",
icon="IMAGE",
)
if wire_upload_enabled:
col = layout.column()
if getattr(props, "is_generating_wire_thumbnail", False):
col.enabled = False
col.prop(props, "wire_thumbnail")
if props.is_generating_thumbnail:
row = layout.row(align=True)
row.label(text=props.thumbnail_generating_state)
op = row.operator("object.kill_bg_process", text="", icon="CANCEL")
op.process_source = asset_type
op.process_type = "THUMBNAILER"
elif props.thumbnail_generating_state != "":
utils.label_multiline(layout, text=props.thumbnail_generating_state)
# must be experimental feature enabled
if wire_upload_enabled:
if getattr(props, "is_generating_wire_thumbnail", False):
row = layout.row(align=True)
row.label(text=props.wire_thumbnail_generating_state)
op = row.operator("object.kill_bg_process", text="", icon="CANCEL")
op.process_source = asset_type
op.process_type = "THUMBNAILER"
elif getattr(props, "wire_thumbnail_generating_state", "") != "":
utils.label_multiline(layout, text=props.wire_thumbnail_generating_state)
# Only show these properties for MODEL type
if asset_type == "MODEL":
layout.prop(props, "style")
layout.prop(props, "production_level")
layout.prop(props, "condition")
layout.prop(props, "pbr")
design_box = layout.box()
design_box.alignment = "EXPAND"
design_box.label(text="Design properties:")
design_box.prop(props, "manufacturer")
design_box.prop(props, "designer")
design_box.prop(props, "design_collection")
design_box.prop(props, "design_variant")
design_box.prop(props, "use_design_year")
if props.use_design_year:
design_box.prop(props, "design_year")
# Show manufacturer validation feedback when available on the asset.
draw_validated_manufacturer(design_box, ob)
row = layout.row()
row.prop(props, "work_hours")
# CONTENT FLAGS
content_flag_box = layout.box()
content_flag_box.alignment = "EXPAND"
content_flag_box.label(text="Sensitive Content Flags:")
content_flag_box.prop(props, "sexualized_content")
def draw_panel_scene_upload(self, context):
s = bpy.context.scene
props = s.blenderkit
layout = self.layout
draw_upload_common(layout, props, "SCENE", context)
col = layout.column()
draw_thumbnail_upload_panel(col, props)
prop_needed(col, props, "thumbnail", props.has_thumbnail, False)
layout.prop(props, "style")
layout.prop(props, "production_level")
layout.prop(props, "use_design_year")
if props.use_design_year:
layout.prop(props, "design_year")
layout.prop(props, "condition")
draw_validated_manufacturer(layout, s)
row = layout.row()
row.prop(props, "work_hours")
def draw_panel_model_search(self, context):
wm = bpy.context.window_manager
props = wm.blenderkit_models
ui_props = wm.blenderkitUI
layout = self.layout
draw_search_text_field(layout, ui_props, context)
icon = "NONE"
if props.report == "You need Full plan to get this item.":
icon = "ERROR"
utils.label_multiline(layout, text=props.report, icon=icon)
if props.report == "You need Full plan to get this item.":
layout.operator("wm.url_open", text="Get Full plan", icon="URL").url = (
paths.url_with_utm(paths.BLENDKIT_PLANS_URL, "premium_wall_panel")
)
def draw_panel_printable_search(self, context):
wm = bpy.context.window_manager
props = wm.blenderkit_printables
ui_props = wm.blenderkitUI
layout = self.layout
draw_search_text_field(layout, ui_props, context)
icon = "NONE"
if props.report == "You need Full plan to get this item.":
icon = "ERROR"
utils.label_multiline(layout, text=props.report, icon=icon)
if props.report == "You need Full plan to get this item.":
layout.operator("wm.url_open", text="Get Full plan", icon="URL").url = (
paths.url_with_utm(paths.BLENDKIT_PLANS_URL, "premium_wall_panel")
)
def draw_panel_scene_search(self, context):
wm = bpy.context.window_manager
props = wm.blenderkit_scene
ui_props = wm.blenderkitUI
layout = self.layout
draw_search_text_field(layout, ui_props, context)
utils.label_multiline(layout, text=props.report)
layout.separator()
def draw_model_context_menu(self, context):
# draw asset properties here
layout = self.layout
o = utils.get_active_model()
if not o:
return
ad = utils.get_asset_data_from_ob(o)
if ad is None:
utils.label_multiline(
layout,
text="To upload this asset to Blendkit, go to the Find and Upload Assets panel.",
)
layout.prop(o, "name")
else:
layout.label(text=str(ad["name"]))
if o.instance_type == "COLLECTION" and o.instance_collection is not None:
layout.operator("object.blenderkit_bring_to_scene", text="Bring to scene")
layout.label(text="Asset tools:")
draw_asset_context_menu(self.layout, context, ad, from_panel=True)
class VIEW3D_PT_blenderkit_model_properties(Panel):
bl_category = "Blendkit"
bl_idname = "VIEW3D_PT_blenderkit_model_properties"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_label = "Selected Model"
bl_context = "objectmode"
@classmethod
def poll(cls, context):
if bpy.context.view_layer.objects.active is None:
return False
preferences = bpy.context.preferences.addons[__package__].preferences
return not preferences.sidebar_panels
def draw(self, context):
draw_model_context_menu(self, context)
class VIEW3D_MT_blenderkit_model_properties(Menu):
bl_idname = "VIEW3D_MT_blenderkit_model_properties"
bl_label = "Selected Model"
def draw(self, context):
draw_model_context_menu(self, context)
class NODE_PT_blenderkit_nodegroup_properties(Panel):
bl_category = "Blendkit"
bl_idname = "NODE_PT_blenderkit_nodegroup_properties"
bl_space_type = "NODE_EDITOR"
bl_region_type = "UI"
bl_label = "Selected Geonode tool"
@classmethod
def poll(cls, context):
if bpy.context.space_data.tree_type != "GeometryNodeTree":
return False
if not bpy.context.space_data.edit_tree:
return False
return bpy.context.space_data.edit_tree.is_tool
def draw(self, context):
# draw asset properties here
layout = self.layout
et = bpy.context.space_data.edit_tree
if et.get("asset_data") is None:
utils.label_multiline(
layout,
text="To upload this asset to Blendkit, go to the Find and Upload Assets panel.",
)
layout.prop(et, "name")
if et.get("asset_data") is not None:
ad = et["asset_data"]
layout.label(text=str(ad["name"]))
layout.label(text="Asset tools:")
draw_asset_context_menu(self.layout, context, ad, from_panel=True)
class NODE_PT_blenderkit_material_properties(Panel):
bl_category = "Blendkit"
bl_idname = "NODE_PT_blenderkit_material_properties"
bl_space_type = "NODE_EDITOR"
bl_region_type = "UI"
bl_label = "Selected Material"
bl_context = "objectmode"
@classmethod
def poll(cls, context):
if bpy.context.space_data.tree_type != "ShaderNodeTree":
return False
p = (
bpy.context.view_layer.objects.active is not None
and bpy.context.active_object.active_material is not None
)
return p
def draw(self, context):
# draw asset properties here
layout = self.layout
m = bpy.context.active_object.active_material
if m.get("asset_data") is None and m.blenderkit.id == "":
utils.label_multiline(
layout,
text="To upload this asset to Blendkit, go to the Find and Upload Assets panel.",
)
layout.prop(m, "name")
if m.get("asset_data") is not None:
ad = m["asset_data"]
layout.label(text=str(ad["name"]))
layout.label(text="Asset tools:")
draw_asset_context_menu(self.layout, context, ad, from_panel=True)
def draw_rating_asset(self, context, layout, index=0):
### draws single asset rating.
# Todo: resolve multiple objects for display, now the props are on respective panel, which isn't great.
col = layout.box()
directory = paths.get_temp_dir(f"{self.asset_data['assetType']}_search")
tpath = os.path.join(directory, self.asset_data["thumbnail_small"])
for image in bpy.data.images:
if image.filepath == tpath:
col.template_icon(icon_value=image.preview.icon_id, scale=6.0)
break
col.label(text=self.asset_data["name"])
ratings.draw_ratings_menu(
bpy.context.window_manager.blenderkit_ratings[index], context, col
)
class VIEW3D_PT_blenderkit_ratings(Panel, ratings_utils.RatingProperties):
bl_category = "Blendkit"
bl_idname = "VIEW3D_PT_blenderkit_ratings"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_label = "Rate assets"
bl_context = "objectmode"
@classmethod
def poll(cls, context):
#
p = bpy.context.view_layer.objects.active is not None
return p
def draw(self, context):
# TODO make a list of assets inside asset appending code, to happen only when assets are added to the scene.
# draw asset properties here
layout = self.layout
assets = ratings.get_assets_for_rating()
if len(assets) > 0:
utils.label_multiline(
layout, text="Please help Blendkit community by rating these assets:"
)
ad = assets[0].get("asset_data")