65 lines
2.3 KiB
Python
65 lines
2.3 KiB
Python
![]() |
# coding: utf-8
|
||
|
# Copyright (C) 2023 Ilia Kurochkin <brothermechanic@gmail.com>
|
||
|
#
|
||
|
# 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 3 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.
|
||
|
'''
|
||
|
DESCRIPTION.
|
||
|
UV unwrapping and UV packing processing.
|
||
|
'''
|
||
|
__version__ = '0.1'
|
||
|
|
||
|
import logging
|
||
|
import math
|
||
|
import bpy
|
||
|
|
||
|
logger = logging.getLogger(__name__)
|
||
|
logging.basicConfig(level=logging.INFO)
|
||
|
|
||
|
|
||
|
def uv_unwrap(objs, angle_limit=30):
|
||
|
''' UV unwrapping and UV packing processing '''
|
||
|
for obj in objs:
|
||
|
obj.select_set(True)
|
||
|
bpy.context.view_layer.objects.active = obj
|
||
|
bpy.ops.object.mode_set(mode='EDIT')
|
||
|
bpy.ops.mesh.select_all(action='SELECT')
|
||
|
|
||
|
# unwrapping
|
||
|
bpy.ops.uv.smart_project(angle_limit=math.radians(angle_limit))
|
||
|
|
||
|
# packing
|
||
|
bpy.ops.uv.pack_islands(udim_source='CLOSEST_UDIM',
|
||
|
rotate=True,
|
||
|
rotate_method='ANY',
|
||
|
scale=True,
|
||
|
merge_overlap=False,
|
||
|
margin_method='ADD',
|
||
|
margin=(1 / 256),
|
||
|
pin=False,
|
||
|
pin_method='LOCKED',
|
||
|
shape_method='CONCAVE')
|
||
|
bpy.ops.uv.pack_islands(udim_source='CLOSEST_UDIM',
|
||
|
rotate=True,
|
||
|
rotate_method='ANY',
|
||
|
scale=True,
|
||
|
merge_overlap=False,
|
||
|
margin_method='ADD',
|
||
|
margin=(1 / 256),
|
||
|
pin=False,
|
||
|
pin_method='LOCKED',
|
||
|
shape_method='CONCAVE')
|
||
|
|
||
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||
|
obj.select_set(False)
|
||
|
|
||
|
logger.info('UV unwrapping and UV packing processing done successfully!')
|
||
|
return objs
|