Loading...
Loading...
UV unwrap, atlas-map, project textures, use alpha decals, bake maps/lightmaps, and prepare texture-driven Blender assets for glTF/GLB export. Use whenever the user provides texture packs, texture atlases, decals, UV layouts, lightmaps, wants a texture to fit a mesh 1:1, or reports stretched/off textures. Pairs with reference-to-3d for template-accurate reconstruction and blender-materials for PBR values.
npx skill4agent add roble3/cc-blender-skill blender-uv-texturingWhat does the texture represent?
├── Whole object from front/reference → Project-from-View style UVs from the validation camera
├── Atlas with separate parts → crop/map each part to its own UV island/rectangle
├── Repeating material → generated/object coords or tiled UVs
├── Face/expression decal → alpha material plane or projected UV island; no black background
├── Roughness/bump/normal map → Non-Color data, correct node type
└── Lightmap → separate UV/lightmap channel or optional multiply helper; not emissionBLENDAlpha HashedAlpha Clipimport bpy
def assign_front_projected_uv(obj_name, uv_name='UV_front_projected'):
obj = bpy.data.objects[obj_name]
mesh = obj.data
uv = mesh.uv_layers.get(uv_name) or mesh.uv_layers.new(name=uv_name)
mesh.uv_layers.active = uv
xs = [v.co.x for v in mesh.vertices]
zs = [v.co.z for v in mesh.vertices]
minx, maxx = min(xs), max(xs)
minz, maxz = min(zs), max(zs)
dx = max(maxx - minx, 1e-8)
dz = max(maxz - minz, 1e-8)
for poly in mesh.polygons:
for li in poly.loop_indices:
co = mesh.vertices[mesh.loops[li].vertex_index].co
uv.data[li].uv = ((co.x - minx) / dx, (co.z - minz) / dz)
mesh.update()[u0, v0, u1, v1]def remap_uv_rect(obj_name, rect, uv_name=None):
obj = bpy.data.objects[obj_name]
layer = obj.data.uv_layers.get(uv_name) if uv_name else obj.data.uv_layers.active
u0, v0, u1, v1 = rect
for item in layer.data:
u, v = item.uv
item.uv = (u0 + u * (u1-u0), v0 + v * (v1-v0))
obj.data.update()import bpy
def image(path, colorspace):
img = bpy.data.images.load(path, check_existing=True)
img.colorspace_settings.name = colorspace
return img
def make_pbr_texture_material(name, basecolor, roughness=None, normal_or_bump=None, alpha=False):
mat = bpy.data.materials.new(name)
mat.use_nodes = True
nt = mat.node_tree
bsdf = nt.nodes.get('Principled BSDF')
tex = nt.nodes.new('ShaderNodeTexImage')
tex.image = image(basecolor, 'sRGB')
nt.links.new(tex.outputs['Color'], bsdf.inputs['Base Color'])
if alpha and 'Alpha' in bsdf.inputs:
nt.links.new(tex.outputs['Alpha'], bsdf.inputs['Alpha'])
mat.blend_method = 'BLEND'
if roughness:
r = nt.nodes.new('ShaderNodeTexImage')
r.image = image(roughness, 'Non-Color')
nt.links.new(r.outputs['Color'], bsdf.inputs['Roughness'])
if normal_or_bump:
btex = nt.nodes.new('ShaderNodeTexImage')
btex.image = image(normal_or_bump, 'Non-Color')
bump = nt.nodes.new('ShaderNodeBump')
bump.inputs['Strength'].default_value = 0.02
nt.links.new(btex.outputs['Color'], bump.inputs['Height'])
nt.links.new(bump.outputs['Normal'], bsdf.inputs['Normal'])
return matimport bpy
obj = bpy.data.objects['GEO-target']
bpy.context.scene.render.engine = 'CYCLES'
img = bpy.data.images.new('BAKE_target', 2048, 2048, alpha=True)
mat = obj.data.materials[0]
mat.use_nodes = True
node = mat.node_tree.nodes.new('ShaderNodeTexImage')
node.image = img
mat.node_tree.nodes.active = node
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
bpy.ops.object.bake(type='DIFFUSE', pass_filter={'COLOR'}, margin=16)
img.filepath_raw = '/tmp/bake_target.png'
img.file_format = 'PNG'
img.save()closed-surface-uv-coverage