[Blender] Композ текстур и заполнение промежутков текстур (margin) #69

Closed
opened 2023-05-03 16:15:55 +03:00 by brothermechanic · 8 comments
brothermechanic commented 2023-05-03 16:15:55 +03:00 (Migrated from gitlab.com)
No description provided.
brothermechanic commented 2023-05-03 16:15:59 +03:00 (Migrated from gitlab.com)

assigned to @brothermechanic

assigned to @brothermechanic
brothermechanic commented 2023-06-16 20:06:40 +03:00 (Migrated from gitlab.com)
import bpy
import os

resolution = 4096

bake_path = '/media/disk/robossembler/project/pipeline/arm/04-blender-edit/textures/bake/'
textures_path = os.path.abspath(os.path.join(bake_path, os.pardir))
baked_images = sorted(os.listdir(bake_path))

bpy.context.scene.render.resolution_x = resolution
bpy.context.scene.render.resolution_y = resolution
bpy.context.scene.render.resolution_percentage = 100
bpy.context.scene.frame_start = 1
bpy.context.scene.frame_end = 1
bpy.context.scene.render.filepath = textures_path
bpy.context.scene.render.image_settings.file_format = 'PNG'
bpy.context.scene.render.image_settings.color_mode = 'RGB'
bpy.context.scene.render.image_settings.compression = 50

bpy.context.scene.display_settings.display_device = 'sRGB'
bpy.context.scene.view_settings.view_transform = 'Standard'
bpy.context.scene.view_settings.look = 'None'
bpy.context.scene.view_settings.exposure = 0
bpy.context.scene.view_settings.gamma = 1
bpy.context.scene.view_settings.use_curve_mapping = False

bpy.context.scene.render.use_compositing = True
bpy.context.scene.render.dither_intensity = 2
bpy.context.scene.use_nodes = True

tree = bpy.context.scene.node_tree
links = tree.links

# clear default nodes
for node in tree.nodes:
    tree.nodes.remove(node)

node_y_pos = 0
# create image nodes
uv_images = [image for image in baked_images if 'UV' in image]
for uv_image in uv_images:
    uv_obj = bpy.data.images.load(os.path.join(bake_path, uv_image))
    uv_node = tree.nodes.new(type='CompositorNodeImage')
    uv_node.image = bpy.data.images[uv_obj.name]
    uv_node.location = 0, (node_y_pos + 500)
    key_node = tree.nodes.new(type="CompositorNodeLumaMatte")
    key_node.location = 250, (node_y_pos + 500)
    key_node.limit_max = 0.01
    links.new(uv_node.outputs['Image'], key_node.inputs['Image'])
    de_node = tree.nodes.new(type="CompositorNodeDilateErode")
    de_node.location = 500, (node_y_pos + 500)
    de_node.distance = -2
    links.new(key_node.outputs['Matte'], de_node.inputs['Mask'])

    slot_name = uv_image.split('_UV')[0]
    for image in baked_images:
        if 'UV' not in image and slot_name in image:
            image_obj = bpy.data.images.load(os.path.join(bake_path, image))
            image_node = tree.nodes.new(type='CompositorNodeImage')
            image_node.location = 0,node_y_pos
            image_node.image = bpy.data.images[image_obj.name]

            aa_node = tree.nodes.new(type="CompositorNodeAntiAliasing")
            aa_node.location = 500,node_y_pos
            aa_node.threshold = 0
            links.new(image_node.outputs['Image'], aa_node.inputs['Image'])

            sa_node = tree.nodes.new(type="CompositorNodeSetAlpha")
            sa_node.location = 1000,node_y_pos
            sa_node.mode = 'REPLACE_ALPHA'
            links.new(aa_node.outputs['Image'], sa_node.inputs['Image'])
            links.new(de_node.outputs['Mask'], sa_node.inputs['Alpha'])

            ip_node = tree.nodes.new(type="CompositorNodeInpaint")
            ip_node.location = 1500,node_y_pos
            ip_node.distance = 512
            links.new(sa_node.outputs['Image'], ip_node.inputs['Image'])

            sc_node = tree.nodes.new(type="CompositorNodeScale")
            sc_node.location = 2000,node_y_pos
            sc_node.space = 'RENDER_SIZE'
            links.new(ip_node.outputs['Image'], sc_node.inputs['Image'])

            out_node = tree.nodes.new(type="CompositorNodeOutputFile")
            out_node.location = 2500,node_y_pos
            out_node.file_slots[0].path = '_'.join((
                slot_name,
                image.split(slot_name)[1].split('.')[0].lower()))
            links.new(sc_node.outputs['Image'], out_node.inputs['Image'])

            node_y_pos -= 500

    node_y_pos -= 1000

# render
bpy.ops.render.render(use_viewport=True)
# fix filenames
for texture in os.listdir(textures_path):
    if texture.endswith('.png'):
        os.rename(
        os.path.join(textures_path, texture),
        os.path.join(textures_path, texture.split('0000')[0] + '.png'))


```python import bpy import os resolution = 4096 bake_path = '/media/disk/robossembler/project/pipeline/arm/04-blender-edit/textures/bake/' textures_path = os.path.abspath(os.path.join(bake_path, os.pardir)) baked_images = sorted(os.listdir(bake_path)) bpy.context.scene.render.resolution_x = resolution bpy.context.scene.render.resolution_y = resolution bpy.context.scene.render.resolution_percentage = 100 bpy.context.scene.frame_start = 1 bpy.context.scene.frame_end = 1 bpy.context.scene.render.filepath = textures_path bpy.context.scene.render.image_settings.file_format = 'PNG' bpy.context.scene.render.image_settings.color_mode = 'RGB' bpy.context.scene.render.image_settings.compression = 50 bpy.context.scene.display_settings.display_device = 'sRGB' bpy.context.scene.view_settings.view_transform = 'Standard' bpy.context.scene.view_settings.look = 'None' bpy.context.scene.view_settings.exposure = 0 bpy.context.scene.view_settings.gamma = 1 bpy.context.scene.view_settings.use_curve_mapping = False bpy.context.scene.render.use_compositing = True bpy.context.scene.render.dither_intensity = 2 bpy.context.scene.use_nodes = True tree = bpy.context.scene.node_tree links = tree.links # clear default nodes for node in tree.nodes: tree.nodes.remove(node) node_y_pos = 0 # create image nodes uv_images = [image for image in baked_images if 'UV' in image] for uv_image in uv_images: uv_obj = bpy.data.images.load(os.path.join(bake_path, uv_image)) uv_node = tree.nodes.new(type='CompositorNodeImage') uv_node.image = bpy.data.images[uv_obj.name] uv_node.location = 0, (node_y_pos + 500) key_node = tree.nodes.new(type="CompositorNodeLumaMatte") key_node.location = 250, (node_y_pos + 500) key_node.limit_max = 0.01 links.new(uv_node.outputs['Image'], key_node.inputs['Image']) de_node = tree.nodes.new(type="CompositorNodeDilateErode") de_node.location = 500, (node_y_pos + 500) de_node.distance = -2 links.new(key_node.outputs['Matte'], de_node.inputs['Mask']) slot_name = uv_image.split('_UV')[0] for image in baked_images: if 'UV' not in image and slot_name in image: image_obj = bpy.data.images.load(os.path.join(bake_path, image)) image_node = tree.nodes.new(type='CompositorNodeImage') image_node.location = 0,node_y_pos image_node.image = bpy.data.images[image_obj.name] aa_node = tree.nodes.new(type="CompositorNodeAntiAliasing") aa_node.location = 500,node_y_pos aa_node.threshold = 0 links.new(image_node.outputs['Image'], aa_node.inputs['Image']) sa_node = tree.nodes.new(type="CompositorNodeSetAlpha") sa_node.location = 1000,node_y_pos sa_node.mode = 'REPLACE_ALPHA' links.new(aa_node.outputs['Image'], sa_node.inputs['Image']) links.new(de_node.outputs['Mask'], sa_node.inputs['Alpha']) ip_node = tree.nodes.new(type="CompositorNodeInpaint") ip_node.location = 1500,node_y_pos ip_node.distance = 512 links.new(sa_node.outputs['Image'], ip_node.inputs['Image']) sc_node = tree.nodes.new(type="CompositorNodeScale") sc_node.location = 2000,node_y_pos sc_node.space = 'RENDER_SIZE' links.new(ip_node.outputs['Image'], sc_node.inputs['Image']) out_node = tree.nodes.new(type="CompositorNodeOutputFile") out_node.location = 2500,node_y_pos out_node.file_slots[0].path = '_'.join(( slot_name, image.split(slot_name)[1].split('.')[0].lower())) links.new(sc_node.outputs['Image'], out_node.inputs['Image']) node_y_pos -= 500 node_y_pos -= 1000 # render bpy.ops.render.render(use_viewport=True) # fix filenames for texture in os.listdir(textures_path): if texture.endswith('.png'): os.rename( os.path.join(textures_path, texture), os.path.join(textures_path, texture.split('0000')[0] + '.png')) ```
brothermechanic commented 2023-07-06 11:07:08 +03:00 (Migrated from gitlab.com)

обновил скрипт

обновил скрипт
brothermechanic commented 2023-10-23 08:59:45 +03:00 (Migrated from gitlab.com)

changed title from [Blender] {-Инструмент: З-}аполнение промежутков текстур (margin) to [Blender] {+Композ текстур и з+}аполнение промежутков текстур (margin)

changed title from **[Blender] {-Инструмент: З-}аполнение промежутков текстур (margin)** to **[Blender] {+Композ текстур и з+}аполнение промежутков текстур (margin)**
brothermechanic commented 2023-10-23 08:59:45 +03:00 (Migrated from gitlab.com)

changed the description

changed the description
brothermechanic commented 2023-10-23 08:59:59 +03:00 (Migrated from gitlab.com)

marked this issue as related to #90

marked this issue as related to #90
brothermechanic commented 2023-10-26 10:30:58 +03:00 (Migrated from gitlab.com)

created branch 69-blender_compose_textures to address this issue

created branch [`69-blender_compose_textures`](/robossembler/framework/-/compare/master...69-blender_compose_textures) to address this issue
brothermechanic commented 2023-10-26 10:31:10 +03:00 (Migrated from gitlab.com)

mentioned in merge request !63

mentioned in merge request !63
movefasta (Migrated from gitlab.com) closed this issue 2023-10-26 10:51:07 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: robossembler/framework#69
No description provided.