Skip to content

Instantly share code, notes, and snippets.

@guidoschmidt
Created November 25, 2020 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guidoschmidt/d154babd8ad1dec419d9d18a2e014fe7 to your computer and use it in GitHub Desktop.
Save guidoschmidt/d154babd8ad1dec419d9d18a2e014fe7 to your computer and use it in GitHub Desktop.
GLTF Blende export nodes
import bpy
# User variables
UV_MAP_NAME = "BAKETOOL_Job 1"
IMAGE_NAME = "Default_albedo.jpg"
# Gloabls
gltf_settings_node = bpy.data.node_groups['glTF Settings']
y = 2000
selected_objects = bpy.context.selected_objects
for so in selected_objects:
for ms in so.material_slots:
material_name = ms.name
material = bpy.data.materials[material_name]
node_tree = material.node_tree
nodes = node_tree.nodes
# Create new UV map node
uv_map = nodes.new("ShaderNodeUVMap")
uv_map.uv_map = UV_MAP_NAME
uv_map.location = (-200, y)
# Create new Image Texture node
tex_image = nodes.new("ShaderNodeTexImage")
tex_image.location = (0, y)
image_idx = bpy.data.images.find(IMAGE_NAME)
tex_image.image = bpy.data.images[image_idx]
# Create new Shader node group
group = nodes.new("ShaderNodeGroup")
group.node_tree = gltf_settings_node
group.location = (300, y)
# Create links
node_tree.links.new(tex_image.inputs["Vector"], uv_map.outputs["UV"])
node_tree.links.new(group.inputs["Occlusion"], tex_image.outputs["Color"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment