[Blender] Сборка ассетов для экспорта #97

Closed
opened 2023-07-06 11:08:53 +03:00 by brothermechanic · 5 comments
brothermechanic commented 2023-07-06 11:08:53 +03:00 (Migrated from gitlab.com)
No description provided.
brothermechanic commented 2023-07-06 11:08:56 +03:00 (Migrated from gitlab.com)

assigned to @brothermechanic

assigned to @brothermechanic
brothermechanic commented 2023-07-06 14:45:39 +03:00 (Migrated from gitlab.com)
import bpy
import os

# COLLECTIONS NAMIG CONVENTION
parts_col_name = 'Import Parts'
lcs_col_name = 'Import LCS'
hierarchy_col_name = 'Import Hierarchy'
lowpoly_col_name = 'Lowpoly Parts'
export_col_name = 'Export Parts'
# LCS POINT'S SUFFIXES CONVENTION
inlet = '_in'
outlet = '_out'
root = '_root'
# CG ASSETS SUFFIXES CONVENTION
hightpoly = '_hp'
lowpoly = '_lp'
render = '_render'


textures_path = '/media/disk/robossembler/project/pipeline/arm/04-blender-edit/textures/'
textures = [png for png in sorted(os.listdir(textures_path)) if png.endswith('.png')]
lowpoly_col = bpy.data.collections[lowpoly_col_name]

export_col = bpy.data.collections.new(export_col_name)
bpy.context.scene.collection.children.link(export_col)

for lowpoly_obj in lowpoly_col.objects:
    export_obj = lowpoly_obj.copy()
    export_obj.data = lowpoly_obj.data.copy()
    export_col.objects.link(export_obj)
    base_name = lowpoly_obj.name.split(lowpoly)[0]
    export_obj.name = 'SM_{}'.format(base_name)
    pbr_mat = bpy.data.materials.new(name='M_{}'.format(base_name))
    pbr_mat.use_nodes = True
    export_obj.material_slots[0].material = pbr_mat
    shader = pbr_mat.node_tree.nodes['Principled BSDF']

    mix_ao = pbr_mat.node_tree.nodes.new(type='ShaderNodeMix')
    mix_ao.location = -600, 300
    mix_ao.blend_type = 'MULTIPLY'
    mix_ao.inputs[0].default_value = 1.0

    mix_c = pbr_mat.node_tree.nodes.new(type='ShaderNodeMix')
    mix_c.location = -300, 300
    mix_c.blend_type = 'MULTIPLY'
    mix_c.inputs[0].default_value = 1.0

    normal = pbr_mat.node_tree.nodes.new(type='ShaderNodeNormalMap')
    normal.location = -300, -1200

    pbr_mat.node_tree.links.new(mix_ao.outputs['Result'], mix_c.inputs['A'])
    pbr_mat.node_tree.links.new(mix_c.outputs['Result'], shader.inputs['Base Color'])
    pbr_mat.node_tree.links.new(normal.outputs['Normal'], shader.inputs['Normal'])

    for texture in textures:
        if base_name not in texture:
            continue
        if '_d.' in texture:
            tex_d_image = bpy.data.images.load(os.path.join(textures_path, texture))
            tex_d = pbr_mat.node_tree.nodes.new(type='ShaderNodeTexImage')
            tex_d.location = -900, 300
            tex_d.label = tex_d_image.name.split('.')[0]
            tex_d.image = bpy.data.images[tex_d_image.name]
            tex_d.image.colorspace_settings.name = 'sRGB'
            pbr_mat.node_tree.links.new(tex_d.outputs['Color'], mix_ao.inputs['A'])

        if '_ao.' in texture:
            tex_ao_image = bpy.data.images.load(os.path.join(textures_path, texture))
            tex_ao = pbr_mat.node_tree.nodes.new(type='ShaderNodeTexImage')
            tex_ao.location = -900, 0
            tex_ao.label = tex_ao_image.name.split('.')[0]
            tex_ao.image = bpy.data.images[tex_ao_image.name]
            tex_ao.image.colorspace_settings.name = 'Non-Color'
            pbr_mat.node_tree.links.new(tex_ao.outputs['Color'], mix_ao.inputs['B'])

        if '_c.' in texture:
            tex_c_image = bpy.data.images.load(os.path.join(textures_path, texture))
            tex_c = pbr_mat.node_tree.nodes.new(type='ShaderNodeTexImage')
            tex_c.location = -900, -300
            tex_c.label = tex_c_image.name.split('.')[0]
            tex_c.image = bpy.data.images[tex_c_image.name]
            tex_c.image.colorspace_settings.name = 'Non-Color'
            pbr_mat.node_tree.links.new(tex_c.outputs['Color'], mix_c.inputs['B'])

        if '_m.' in texture:
            tex_m_image = bpy.data.images.load(os.path.join(textures_path, texture))
            tex_m = pbr_mat.node_tree.nodes.new(type='ShaderNodeTexImage')
            tex_m.location = -900, -600
            tex_m.label = tex_m_image.name.split('.')[0]
            tex_m.image = bpy.data.images[tex_m_image.name]
            tex_m.image.colorspace_settings.name = 'Non-Color'
            pbr_mat.node_tree.links.new(tex_m.outputs['Color'], shader.inputs['Metallic'])

        if '_r.' in texture:
            tex_r_image = bpy.data.images.load(os.path.join(textures_path, texture))
            tex_r = pbr_mat.node_tree.nodes.new(type='ShaderNodeTexImage')
            tex_r.location = -900, -900
            tex_r.label = tex_r_image.name.split('.')[0]
            tex_r.image = bpy.data.images[tex_r_image.name]
            tex_r.image.colorspace_settings.name = 'Non-Color'
            pbr_mat.node_tree.links.new(tex_r.outputs['Color'], shader.inputs['Roughness'])

        if '_n.' in texture:
            tex_n_image = bpy.data.images.load(os.path.join(textures_path, texture))
            tex_n = pbr_mat.node_tree.nodes.new(type='ShaderNodeTexImage')
            tex_n.location = -900, -1200
            tex_n.label = tex_n_image.name.split('.')[0]
            tex_n.image = bpy.data.images[tex_n_image.name]
            tex_n.image.colorspace_settings.name = 'Non-Color'
            pbr_mat.node_tree.links.new(tex_n.outputs['Color'], normal.inputs['Color'])
```python import bpy import os # COLLECTIONS NAMIG CONVENTION parts_col_name = 'Import Parts' lcs_col_name = 'Import LCS' hierarchy_col_name = 'Import Hierarchy' lowpoly_col_name = 'Lowpoly Parts' export_col_name = 'Export Parts' # LCS POINT'S SUFFIXES CONVENTION inlet = '_in' outlet = '_out' root = '_root' # CG ASSETS SUFFIXES CONVENTION hightpoly = '_hp' lowpoly = '_lp' render = '_render' textures_path = '/media/disk/robossembler/project/pipeline/arm/04-blender-edit/textures/' textures = [png for png in sorted(os.listdir(textures_path)) if png.endswith('.png')] lowpoly_col = bpy.data.collections[lowpoly_col_name] export_col = bpy.data.collections.new(export_col_name) bpy.context.scene.collection.children.link(export_col) for lowpoly_obj in lowpoly_col.objects: export_obj = lowpoly_obj.copy() export_obj.data = lowpoly_obj.data.copy() export_col.objects.link(export_obj) base_name = lowpoly_obj.name.split(lowpoly)[0] export_obj.name = 'SM_{}'.format(base_name) pbr_mat = bpy.data.materials.new(name='M_{}'.format(base_name)) pbr_mat.use_nodes = True export_obj.material_slots[0].material = pbr_mat shader = pbr_mat.node_tree.nodes['Principled BSDF'] mix_ao = pbr_mat.node_tree.nodes.new(type='ShaderNodeMix') mix_ao.location = -600, 300 mix_ao.blend_type = 'MULTIPLY' mix_ao.inputs[0].default_value = 1.0 mix_c = pbr_mat.node_tree.nodes.new(type='ShaderNodeMix') mix_c.location = -300, 300 mix_c.blend_type = 'MULTIPLY' mix_c.inputs[0].default_value = 1.0 normal = pbr_mat.node_tree.nodes.new(type='ShaderNodeNormalMap') normal.location = -300, -1200 pbr_mat.node_tree.links.new(mix_ao.outputs['Result'], mix_c.inputs['A']) pbr_mat.node_tree.links.new(mix_c.outputs['Result'], shader.inputs['Base Color']) pbr_mat.node_tree.links.new(normal.outputs['Normal'], shader.inputs['Normal']) for texture in textures: if base_name not in texture: continue if '_d.' in texture: tex_d_image = bpy.data.images.load(os.path.join(textures_path, texture)) tex_d = pbr_mat.node_tree.nodes.new(type='ShaderNodeTexImage') tex_d.location = -900, 300 tex_d.label = tex_d_image.name.split('.')[0] tex_d.image = bpy.data.images[tex_d_image.name] tex_d.image.colorspace_settings.name = 'sRGB' pbr_mat.node_tree.links.new(tex_d.outputs['Color'], mix_ao.inputs['A']) if '_ao.' in texture: tex_ao_image = bpy.data.images.load(os.path.join(textures_path, texture)) tex_ao = pbr_mat.node_tree.nodes.new(type='ShaderNodeTexImage') tex_ao.location = -900, 0 tex_ao.label = tex_ao_image.name.split('.')[0] tex_ao.image = bpy.data.images[tex_ao_image.name] tex_ao.image.colorspace_settings.name = 'Non-Color' pbr_mat.node_tree.links.new(tex_ao.outputs['Color'], mix_ao.inputs['B']) if '_c.' in texture: tex_c_image = bpy.data.images.load(os.path.join(textures_path, texture)) tex_c = pbr_mat.node_tree.nodes.new(type='ShaderNodeTexImage') tex_c.location = -900, -300 tex_c.label = tex_c_image.name.split('.')[0] tex_c.image = bpy.data.images[tex_c_image.name] tex_c.image.colorspace_settings.name = 'Non-Color' pbr_mat.node_tree.links.new(tex_c.outputs['Color'], mix_c.inputs['B']) if '_m.' in texture: tex_m_image = bpy.data.images.load(os.path.join(textures_path, texture)) tex_m = pbr_mat.node_tree.nodes.new(type='ShaderNodeTexImage') tex_m.location = -900, -600 tex_m.label = tex_m_image.name.split('.')[0] tex_m.image = bpy.data.images[tex_m_image.name] tex_m.image.colorspace_settings.name = 'Non-Color' pbr_mat.node_tree.links.new(tex_m.outputs['Color'], shader.inputs['Metallic']) if '_r.' in texture: tex_r_image = bpy.data.images.load(os.path.join(textures_path, texture)) tex_r = pbr_mat.node_tree.nodes.new(type='ShaderNodeTexImage') tex_r.location = -900, -900 tex_r.label = tex_r_image.name.split('.')[0] tex_r.image = bpy.data.images[tex_r_image.name] tex_r.image.colorspace_settings.name = 'Non-Color' pbr_mat.node_tree.links.new(tex_r.outputs['Color'], shader.inputs['Roughness']) if '_n.' in texture: tex_n_image = bpy.data.images.load(os.path.join(textures_path, texture)) tex_n = pbr_mat.node_tree.nodes.new(type='ShaderNodeTexImage') tex_n.location = -900, -1200 tex_n.label = tex_n_image.name.split('.')[0] tex_n.image = bpy.data.images[tex_n_image.name] tex_n.image.colorspace_settings.name = 'Non-Color' pbr_mat.node_tree.links.new(tex_n.outputs['Color'], normal.inputs['Color']) ```
brothermechanic commented 2023-10-26 00:03:17 +03:00 (Migrated from gitlab.com)

marked this issue as related to #90

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

created branch 97-blender_pbt_textures_material to address this issue

created branch [`97-blender_pbt_textures_material`](/robossembler/framework/-/compare/master...97-blender_pbt_textures_material) to address this issue
brothermechanic commented 2023-10-28 20:11:40 +03:00 (Migrated from gitlab.com)

mentioned in merge request !64

mentioned in merge request !64
movefasta (Migrated from gitlab.com) closed this issue 2023-10-30 12:06:30 +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#97
No description provided.