BlenderKit: thumbnailer ball, cube, cloth support now microdisplacement,

also previews now scale textures properly.
This commit is contained in:
Vilém Duha 2019-07-10 10:22:37 +02:00
parent aa3366b780
commit f54338c63b
5 changed files with 45 additions and 6 deletions

View File

@ -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=(

View File

@ -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')

View File

@ -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()

View File

@ -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