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>2019-07-10 11:22:37 +0300
committerVilém Duha <vilda.novak@gmail.com>2019-07-10 11:23:02 +0300
commitf54338c63ba36cbbe83161c0b3d4d2b1aa01c4a9 (patch)
treedd44d5429b6fd48f91dfbc44a3856a21b1213543
parentaa3366b7805bbe4d1afee890bda81b6d91bd47be (diff)
BlenderKit: thumbnailer ball, cube, cloth support now microdisplacement,v2.80-rc1
also previews now scale textures properly.
-rw-r--r--blenderkit/__init__.py13
-rw-r--r--blenderkit/autothumb.py3
-rw-r--r--blenderkit/autothumb_material_bg.py7
-rw-r--r--blenderkit/blendfiles/material_thumbnailer_cycles.blendbin559600 -> 551885 bytes
-rw-r--r--blenderkit/utils.py28
5 files changed, 45 insertions, 6 deletions
diff --git a/blenderkit/__init__.py b/blenderkit/__init__.py
index a3da6025..4fbf3783 100644
--- a/blenderkit/__init__.py
+++ b/blenderkit/__init__.py
@@ -173,6 +173,12 @@ thumbnail_snap = (
('FLOAT', 'floating', ''),
)
+thumbnail_resolutions = (
+ ('256', '256', ''),
+ ('512', '512 - minimum for public', ''),
+ ('1024', '1024', ''),
+ ('2048', '2048', ''),
+)
def get_upload_asset_type(self):
typemapper = {
@@ -633,6 +639,13 @@ class BlenderKitMaterialUploadProps(PropertyGroup, BlenderKitCommonUploadProps):
adaptive_subdivision: BoolProperty(name="Adaptive Subdivide",
description="Use adaptive displacement subdivision", default=False)
+ thumbnail_resolution: EnumProperty(
+ name="Resolution",
+ items=thumbnail_resolutions,
+ description="Thumbnail resolution.",
+ default="512",
+ )
+
thumbnail_generator_type: EnumProperty(
name="Thumbnail Style",
items=(
diff --git a/blenderkit/autothumb.py b/blenderkit/autothumb.py
index 2d05c5ee..c38be3d1 100644
--- a/blenderkit/autothumb.py
+++ b/blenderkit/autothumb.py
@@ -217,6 +217,7 @@ def start_material_thumbnailer(self, context):
"thumbnail_scale": bkit.thumbnail_scale,
"thumbnail_background": bkit.thumbnail_background,
"thumbnail_background_lightness": bkit.thumbnail_background_lightness,
+ "thumbnail_resolution": bkit.thumbnail_resolution,
"thumbnail_samples": bkit.thumbnail_samples,
"thumbnail_denoising": bkit.thumbnail_denoising,
"adaptive_subdivision": bkit.adaptive_subdivision,
@@ -270,6 +271,7 @@ class GenerateThumbnailOperator(bpy.types.Operator):
layout.prop(props, 'thumbnail_angle')
layout.prop(props, 'thumbnail_snap_to')
layout.prop(props, 'thumbnail_samples')
+ layout.prop(props, 'thumbnail_resolution')
layout.prop(props, 'thumbnail_denoising')
def execute(self, context):
@@ -301,6 +303,7 @@ class GenerateMaterialThumbnailOperator(bpy.types.Operator):
layout.prop(props, 'thumbnail_background')
if props.thumbnail_background:
layout.prop(props, 'thumbnail_background_lightness')
+ layout.prop(props, 'thumbnail_resolution')
layout.prop(props, 'thumbnail_samples')
layout.prop(props, 'thumbnail_denoising')
layout.prop(props, 'adaptive_subdivision')
diff --git a/blenderkit/autothumb_material_bg.py b/blenderkit/autothumb_material_bg.py
index 16308433..e54500fc 100644
--- a/blenderkit/autothumb_material_bg.py
+++ b/blenderkit/autothumb_material_bg.py
@@ -88,8 +88,8 @@ if __name__ == "__main__":
else:
ob.cycles.use_adaptive_subdivision = False
ts = data['texture_size_meters']
- # if data["thumbnail_type"] in ['BALL', 'CUBE']:
- # utils.automap(ob.name, tex_size = ts / tscale, bg_exception=True)
+ if data["thumbnail_type"] in ['BALL', 'CUBE', 'CLOTH']:
+ utils.automap(ob.name, tex_size = ts / tscale, just_scale = True, bg_exception=True)
bpy.context.view_layer.update()
s.cycles.volume_step_size = tscale * .1
@@ -115,6 +115,9 @@ if __name__ == "__main__":
img.filepath = ipath
img.reload()
+ bpy.context.scene.render.resolution_x = int(data['thumbnail_resolution'])
+ bpy.context.scene.render.resolution_y = int(data['thumbnail_resolution'])
+
bpy.context.scene.render.filepath = BLENDERKIT_THUMBNAIL_PATH
bg_blender.progress('rendering thumbnail')
render_thumbnails()
diff --git a/blenderkit/blendfiles/material_thumbnailer_cycles.blend b/blenderkit/blendfiles/material_thumbnailer_cycles.blend
index 08607fa3..9b7c0b8a 100644
--- a/blenderkit/blendfiles/material_thumbnailer_cycles.blend
+++ b/blenderkit/blendfiles/material_thumbnailer_cycles.blend
Binary files differ
diff --git a/blenderkit/utils.py b/blenderkit/utils.py
index be17418a..d63f3fc3 100644
--- a/blenderkit/utils.py
+++ b/blenderkit/utils.py
@@ -394,9 +394,22 @@ def get_headers(api_key):
headers["Authorization"] = "Bearer %s" % api_key
return headers
+def scale_2d(v, s, p):
+ '''scale a 2d vector with a pivot'''
+ return (p[0] + s[0] * (v[0] - p[0]), p[1] + s[1] * (v[1] - p[1]))
+
+def scale_uvs(ob, scale = 1.0, pivot = Vector((.5,.5))):
+ mesh = ob.data
+ if len(mesh.uv_layers)>0:
+ uv = mesh.uv_layers[mesh.uv_layers.active_index]
+
+ # Scale a UV map iterating over its coordinates to a given scale and with a pivot point
+ for uvindex in range(len(uv.data)):
+ uv.data[uvindex].uv = scale_2d(uv.data[uvindex].uv, scale, pivot)
+
# map uv cubic and switch of auto tex space and set it to 1,1,1
-def automap(target_object=None, target_slot=None, tex_size=1, bg_exception=False):
+def automap(target_object=None, target_slot=None, tex_size=1, bg_exception=False, just_scale = False):
from blenderkit import bg_blender as bg
s = bpy.context.scene
mat_props = s.blenderkit_mat
@@ -435,10 +448,17 @@ def automap(target_object=None, target_slot=None, tex_size=1, bg_exception=False
bpy.ops.object.material_slot_select()
scale = (scale.x + scale.y + scale.z) / 3.0
- bpy.ops.uv.cube_project(
- cube_size=scale * 2.0 / (tex_size),
- correct_aspect=False) # it's 2.0 because blender can't tell size of a cube :)
+ if not just_scale:
+ bpy.ops.uv.cube_project(
+ cube_size=scale * 2.0 / (tex_size),
+ correct_aspect=False) # it's * 2.0 because blender can't tell size of a unit cube :)
+
bpy.ops.object.editmode_toggle()
tob.data.uv_layers.active = tob.data.uv_layers['automap']
tob.data.uv_layers["automap"].active_render = True
+ # this by now works only for thumbnail preview, but should be extended to work on arbitrary objects.
+ # by now, it takes the basic uv map = 1 meter. also, it now doeasn't respect more materials on one object,
+ # it just scales whole UV.
+ if just_scale:
+ scale_uvs(tob, scale=Vector((1/tex_size, 1/tex_size)))
bpy.context.view_layer.objects.active = actob