Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVilém Duha <vilda.novak@gmail.com>2021-03-30 15:42:46 +0300
committerVilém Duha <vilda.novak@gmail.com>2021-03-30 15:42:55 +0300
commit19675aa14d7559020c75936b1b92ac9d004e04f4 (patch)
treebcc10fb36e8ec799d2ad87596fec34468fa26a5d
parent62ca4b75774fa5d96404b67198c1120dc24053e8 (diff)
BlenderKit: Handle HDR importing better.
User can now pick the resolution before download. Swapping didn't work properly
-rw-r--r--blenderkit/download.py3
-rw-r--r--blenderkit/ui.py61
-rw-r--r--blenderkit/ui_panels.py3
3 files changed, 41 insertions, 26 deletions
diff --git a/blenderkit/download.py b/blenderkit/download.py
index ac83594e..7e152532 100644
--- a/blenderkit/download.py
+++ b/blenderkit/download.py
@@ -632,7 +632,8 @@ def timer_update():
l.reload()
if tcom.passargs.get('replace_resolution'):
- # try to relink first.
+ # try to relink
+ # HDRs are always swapped, so their swapping is handled without the replace_resolution option
ain, resolution = asset_in_scene(asset_data)
diff --git a/blenderkit/ui.py b/blenderkit/ui.py
index d15aba88..c3cbd412 100644
--- a/blenderkit/ui.py
+++ b/blenderkit/ui.py
@@ -390,7 +390,7 @@ def draw_tooltip(x, y, text='', author='', img=None, gravatar=None):
xtext += int(isizex / ncolumns)
column_lines = 1
- i=0
+ i = 0
for l in alines:
if gravatar is not None:
if column_lines == 1:
@@ -399,20 +399,20 @@ def draw_tooltip(x, y, text='', author='', img=None, gravatar=None):
xtext -= gsize + textmargin
ytext = y - column_lines * line_height - nameline_height - ttipmargin - textmargin - isizey + texth
- if False:#i == 0:
+ if False: # i == 0:
ytext = y - name_height + 5 - isizey + texth - textmargin
elif i == len(lines) - 1:
ytext = y - (nlines - 1) * line_height - nameline_height - ttipmargin * 2 - isizey + texth
tcol = textcol
tsize = font_height
- if (i> 0 and alines[i-1][:7] == 'Author:'):
+ if (i > 0 and alines[i - 1][:7] == 'Author:'):
tcol = textcol_strong
fsize = font_height + 2
else:
fsize = font_height
tcol = textcol
- if l[:4] == 'Tip:' or l[:11] == 'Please rate' :
+ if l[:4] == 'Tip:' or l[:11] == 'Please rate':
tcol = textcol_strong
fsize = font_height + 1
@@ -892,15 +892,16 @@ def draw_callback_3d(self, context):
if ui.draw_snapped_bounds:
draw_bbox(ui.snapped_location, ui.snapped_rotation, ui.snapped_bbox_min, ui.snapped_bbox_max)
+
def object_in_particle_collection(o):
'''checks if an object is in a particle system as instance, to not snap to it and not to try to attach material.'''
for p in bpy.data.particles:
- if p.render_type =='COLLECTION':
+ if p.render_type == 'COLLECTION':
if p.instance_collection:
for o1 in p.instance_collection.objects:
if o1 == o:
return True
- if p.render_type =='COLLECTION':
+ if p.render_type == 'COLLECTION':
if p.instance_object == o:
return True
return False
@@ -923,12 +924,14 @@ def deep_ray_cast(depsgraph, ray_origin, vec):
try_has_hit, try_snapped_location, try_snapped_normal, try_face_index, try_object, try_matrix = bpy.context.scene.ray_cast(
depsgraph, ray_origin, vec)
if try_has_hit:
- #this way only good hits are returned, otherwise
+ # this way only good hits are returned, otherwise
has_hit, snapped_location, snapped_normal, face_index, object, matrix = try_has_hit, try_snapped_location, try_snapped_normal, try_face_index, try_object, try_matrix
- if not (object.display_type == 'BOUNDS' or object_in_particle_collection(try_object)):# or not object.visible_get()):
+ if not (object.display_type == 'BOUNDS' or object_in_particle_collection(
+ try_object)): # or not object.visible_get()):
return has_hit, snapped_location, snapped_normal, face_index, object, matrix
return empty_set
+
def mouse_raycast(context, mx, my):
r = context.region
rv3d = context.region_data
@@ -940,7 +943,7 @@ def mouse_raycast(context, mx, my):
view_position = rv3d.view_matrix.inverted().translation
ray_origin = view3d_utils.region_2d_to_location_3d(r, rv3d, coord, depth_location=view_position)
else:
- ray_origin = view3d_utils.region_2d_to_origin_3d(r, rv3d, coord, clamp = 1.0)
+ ray_origin = view3d_utils.region_2d_to_origin_3d(r, rv3d, coord, clamp=1.0)
ray_target = ray_origin + (view_vector * 1000000000)
@@ -949,8 +952,8 @@ def mouse_raycast(context, mx, my):
has_hit, snapped_location, snapped_normal, face_index, object, matrix = deep_ray_cast(
bpy.context.view_layer.depsgraph, ray_origin, vec)
- #backface snapping inversion
- if view_vector.angle(snapped_normal)<math.pi/2:
+ # backface snapping inversion
+ if view_vector.angle(snapped_normal) < math.pi / 2:
snapped_normal = -snapped_normal
# print(has_hit, snapped_location, snapped_normal, face_index, object, matrix)
# rote = mathutils.Euler((0, 0, math.pi))
@@ -1104,7 +1107,6 @@ def mouse_in_area(mx, my, x, y, w, h):
def mouse_in_asset_bar(mx, my):
-
ui_props = bpy.context.scene.blenderkitUI
# search_results = bpy.context.window_manager.get('search results')
# if search_results == None:
@@ -1222,6 +1224,7 @@ class ParticlesDropDialog(bpy.types.Operator):
wm = context.window_manager
return wm.invoke_props_dialog(self, width=400)
+
# class MaterialDropDialog(bpy.types.Operator):
# """Tooltip"""
# bl_idname = "object.blenderkit_material_drop"
@@ -1626,7 +1629,7 @@ class AssetBarOperator(bpy.types.Operator):
return {'RUNNING_MODAL'}
# Drag-drop interaction
- if ui_props.dragging and mouse_in_region(r, mx, my):# and ui_props.drag_length>10:
+ if ui_props.dragging and mouse_in_region(r, mx, my): # and ui_props.drag_length>10:
asset_search_index = ui_props.active_index
# raycast here
ui_props.active_index = -3
@@ -1729,7 +1732,8 @@ class AssetBarOperator(bpy.types.Operator):
model_location=loc,
model_rotation=rotation,
target_object=target_object,
- material_target_slot=target_slot)
+ material_target_slot=target_slot,
+ )
elif ui_props.asset_type == 'MODEL':
@@ -1754,9 +1758,17 @@ class AssetBarOperator(bpy.types.Operator):
model_rotation=rotation,
target_object=target_object)
+ elif ui_props.asset_type == 'HDR':
+ bpy.ops.scene.blenderkit_download('INVOKE_DEFAULT',
+ asset_index=asset_search_index,
+ # replace_resolution=True,
+ invoke_resolution=True,
+ max_resolution = asset_data.get('max_resolution', 0)
+ )
else:
bpy.ops.scene.blenderkit_download( # asset_type=ui_props.asset_type,
- asset_index=asset_search_index)
+ asset_index=asset_search_index,
+ )
ui_props.dragging = False
return {'RUNNING_MODAL'}
@@ -1929,6 +1941,7 @@ def draw_callback_3d_dragging(self, context):
if self.has_hit:
draw_bbox(self.snapped_location, self.snapped_rotation, self.snapped_bbox_min, self.snapped_bbox_max)
+
def find_and_activate_instancers(object):
for ob in bpy.context.visible_objects:
if ob.instance_type == 'COLLECTION' and ob.instance_collection and object.name in ob.instance_collection.objects:
@@ -1980,10 +1993,10 @@ class AssetDragOperator(bpy.types.Operator):
# action
else:
if object.is_library_indirect:
- ui_panels.ui_message(title = 'This object is linked from outer file',
- message = "Please select the model,"
- "go to the 'Selected Model' panel "
- "in BlenderKit and hit 'Bring to Scene' first.")
+ ui_panels.ui_message(title='This object is linked from outer file',
+ message="Please select the model,"
+ "go to the 'Selected Model' panel "
+ "in BlenderKit and hit 'Bring to Scene' first.")
self.report({'WARNING'}, "Invalid or library object as input:")
target_object = ''
@@ -2039,11 +2052,11 @@ class AssetDragOperator(bpy.types.Operator):
target_object=target_object)
else:
- if ui_props.asset_type =='SCENE':
- ui_panels.ui_message(title = 'Scene will be appended after download',
- message = 'After the scene is appended, you have to switch to it manually.'
- 'If you want to switch to scenes automatically after appending,'
- ' you can set it in import settings.')
+ if ui_props.asset_type == 'SCENE':
+ ui_panels.ui_message(title='Scene will be appended after download',
+ message='After the scene is appended, you have to switch to it manually.'
+ 'If you want to switch to scenes automatically after appending,'
+ ' you can set it in import settings.')
bpy.ops.scene.blenderkit_download( # asset_type=ui_props.asset_type,
asset_index=self.asset_search_index)
diff --git a/blenderkit/ui_panels.py b/blenderkit/ui_panels.py
index 69957365..0c460f29 100644
--- a/blenderkit/ui_panels.py
+++ b/blenderkit/ui_panels.py
@@ -1227,7 +1227,8 @@ def draw_asset_context_menu(layout, context, asset_data, from_panel=False):
op.max_resolution = asset_data.get('max_resolution',
0) # str(utils.get_param(asset_data, 'textureResolutionMax'))
- elif asset_data['assetBaseId'] in s['assets used'].keys():
+ elif asset_data['assetBaseId'] in s['assets used'].keys() and asset_data['assetType'] != 'hdr':
+ #HDRs are excluded from replacement, since they are always replaced.
# called from asset bar:
print('context menu')
op = col.operator('scene.blenderkit_download', text='Replace asset resolution')