I was reading this post and this one :
Other than copy new data to specific "known" vertex attribute like "Color" for example.
There is way to read custom vertex attributes in the Attribute node \ shader network
shader script ?
This code example and related image demonstrate creation of new vertex attributes and using them in the shader network.
import bpy
from bpy import data as data, context as context
from mathutils import Vector
import bmesh
import numpy as np
#clean objects in scene
for object in data.objects :
if object.type == 'MESH':
data.objects.remove(object, do_unlink=True)
bpy.ops.mesh.primitive_cube_add()
obj_a = data.objects["Cube"]
obj_a.name = "A"
bpy.ops.mesh.primitive_cube_add()
obj_b = data.objects["Cube"]
obj_b.name = "B"
obj_b.hide_viewport = True
a_mesh = obj_a.data
bm = bmesh.new()
bm.from_mesh(a_mesh)
Create a new vertex attributes
color: 0-1 value 4 element float (it will clamp if > 1)
float_color: non normalzied 4 elemnet vector
float: single float
vector_float: non normalized 3 element vector
string :was not able to create string vertex attribute
knafeh_color = bm.loops.layers.color.new("knafeh_color")
malabi_color_float = bm.loops.layers.float_color.new("malabi_color_float")
falafel_float = bm.loops.layers.float.new("falafel_float")
salad_vector_float = bm.loops.layers.float_vector.new("salad_vector_float")
baklava_str = bm.loops.layers.string.new("baklava_str")
bm_faces = bm.faces
for bm_face in bm_faces:
face_loops = bm_face.loops
for bm_loop in face_loops:
# Assign color to vertex.
bm_loop[knafeh_color] = [0.9,0.5,0,1]
bm_loop[malabi_color_float] = [7,0.1,9999,1]
bm_loop[salad_vector_float] = [1,1,0]
bm_loop[falafel_float] = 0.1
bm.to_mesh(a_mesh)
bm.free()
Wrote this question while ago: https://blender.stackexchange.com/questions/231304/access-and-using-geometry-nodes-as-functions-in-python
– barakooda Jul 28 '21 at 06:05