1
$\begingroup$

I have an object called origin with 272 meshes/faces and Float Property Layers (called random_layer), i.e. every mesh has a its own attribute. You can see random values in the Data -> Outliner -> Data API (see screenshot).

Goal: I want to use the values of the random_layer to manipulate shaders/nodes.

Already tried: To get the values, I tried to use the Attribute Node calling it with the name random_layer, or ["random_layer"], but with no luck. I tried to wire the the three output nodes, but all seem to output 0.0. Setting the name to Col (for Vertex Colors) works fine.

The object has a material ('TheOne') using a Vertex Color node, this is working.

I have searched and found this: Use custom properties (variable values) in the node editor However, this is not actually using the values of the Float Property Layers, but rather the graph editor. Also, my values are static and not dynamic.

NodeEditorFloatPropertyLayers

Any help or pointers are much appreciated.

Setup

  • Win10 Pro
  • Blender 2.81a
  • Engine: Cycles (also tried Eevee)
  • Add-ons: 'Node Wrangler' and 'Sun Position'

Update just to clarify how the float layer is created. mesh_object is an intermediate object for one mesh/cell/face that you see in the screenshot.

random_layer = mesh_object.data.polygon_layers_float.new(name="random_layer")
random_layer.data[mesh_object.data.polygons.active].value = random.uniform(0.0, 1.0)

bpy.ops.object.mode_set(mode='EDIT')

random_layer = bm.faces.layers.float.get(random_layer.name)

Also I am using the experimental 2.82a

$\endgroup$
0
$\begingroup$

Using UV Layer

enter image description here Example showing UVMap

Then use the UV Map node as input.

enter image description here UV layers and vertex color layers are available to the attribute node by name. Not custom polygon float layers. Be careful not to name two layers of different type the same, (which you can) if you are going to use either or both as node input.

Script that sets a float layer to randoms, then for each face sets the uv of each loop vert; u to the face layer value, and v to another random (or ...).

Can only have 8 UV Maps.

import bpy
from random import random
context = bpy.context

def get_mesh_layer(me, type, name="Float Layer"):
    layer = getattr(me, type)
    return layer.get(name) or layer.new(name=name)

#bpy.ops.object.mode_set() 
ob = context.object
me = ob.data

rflayer = get_mesh_layer(me, "polygon_layers_float")
for f in me.polygons:
    rflayer.data[f.index].value = random()

uv_layer = get_mesh_layer(me, "uv_layers", "Random")

for f in me.polygons:
    u, v = rflayer.data[f.index].value, random()
    for l in f.loop_indices:
        uv_layer.data[l].uv = u, v
#bpy.ops.object.mode_set(mode='EDIT') 

Note: needs to be run in object mode. Can be emulated in edit mode using bmesh. Simply wrapped it in change mode ops for screen shot above

$\endgroup$
  • $\begingroup$ please do not delete answer, yet $\endgroup$ – Michael Dec 23 '19 at 15:02
  • $\begingroup$ I had named both "Random"... it was always using the uv layer.. double stumped myself. Looks like the UV could be the way to go. $\endgroup$ – batFINGER Dec 23 '19 at 15:52
  • $\begingroup$ Thanks @batFINGER. Couldn't I skip the float layer all together and assign my values to the uv_layer directly? $\endgroup$ – Michael Dec 23 '19 at 16:05
  • $\begingroup$ Definitely. Added float layer only re q. $\endgroup$ – batFINGER Dec 23 '19 at 16:09
  • $\begingroup$ for example V in the UV Map has been set directly. Give the UV Layer it's own name, not the name of the floatlayer (which was the cause of all my confusion lol) in code above and can ditch the float layer. $\endgroup$ – batFINGER Dec 23 '19 at 16:24

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.