Skip to content

Instantly share code, notes, and snippets.

@SAFAD
Created August 4, 2020 10:44
Show Gist options
  • Save SAFAD/c62aa3d5a3fe5dcd0642bcf38bc076ea to your computer and use it in GitHub Desktop.
Save SAFAD/c62aa3d5a3fe5dcd0642bcf38bc076ea to your computer and use it in GitHub Desktop.
import bpy
from math import radians
context = bpy.context
scene = context.scene
vl = context.view_layer
# deselect all to make sure select one at a time
bpy.ops.object.select_all(action='DESELECT')
for obj in scene.objects:
if (obj.type == 'MESH'):
#Remove Original UV
uv_textures = obj.data.uv_textures
uv_textures.remove(uv_textures[0])
#Create new UV using Smart UV Project
vl.objects.active = obj
obj.select_set(True)
print(obj.name)
lm = obj.data.uv_layers.get("LightMap")
if not lm:
lm = obj.data.uv_layers.new(name="LightMap")
lm.active = True
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action='SELECT') # for all faces
bpy.ops.uv.smart_project(angle_limit=66, island_margin = 0.03)
bpy.ops.object.editmode_toggle()
obj.select_set(False)
#Export FBX
bpy.ops.export_scene.fbx(check_existing=False,
filepath=scene.export_folder + "/" + obj.name + ".fbx",
filter_glob="*.fbx",
use_selection=True,
use_armature_deform_only=True,
bake_space_transform=scene.apply_transform,
mesh_smooth_type=scene.export_smoothing,
add_leaf_bones=False,
path_mode='ABSOLUTE')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment