I am using blenderGIS to create a mesh, out of a large area. I do this frequently at my job. The texture comes in at 650mb or so, and I need to chop it and the mesh up. I found a script which will separate the mesh into a grid for me, so that part works, but I cannot figure out how to bake the textures.

So far I have the script iterating through the objects, creating new textures and UVs and packing the new uvs (though I am not positive the packing is working right now, not sure how to tell (relatively new to blender as well)).

import bpy

sel_objs = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']

for obj in sel_objs: # <<<<<<<<<<
    obj.select_set(False) # <<<<<<<<<<

count = 0
meshName = "terrain_"

while len(sel_objs) >= 1:
    # Process Object
    count += 1
    objName = meshName + str(count)                  
    obj1 = sel_objs.pop()     
    obj1.name = objName
    # Add UV Layer    
    layerExists = False
    for layer in obj1.data.uv_layers:
        if layer.name == 'bake':
            layerExists = True

    if layerExists == False:
    # Edit Mode, Select All
    bpy.context.view_layer.objects.active = obj1     
    # New Image
    newImage = True
    for img in bpy.data.images:
        if img.name == objName:
            newImage = False
            image = img
    if newImage == True:
        image = bpy.ops.image.new(name=objName, width=4096, height=4096, color=(0.0, 0.0, 0.0, 1.0), alpha=True, generated_type='BLANK', float=False, use_stereo_3d=False, tiled=False)
    for uv_face in obj1.data.uv_layers.active.data:
        #uv_face.image = image

    image.file_format = "PNG"
    # Exit Edit Mode and Deselect
    obj1.select_set(False) # <<<<<<<<<<

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.