0

for the past few weeks I've been trying to write a python script that accesses the rotation of the custom split normals on my object. I then want it to transfer the x,y and z rotation of the custom split normals to the coordinates of separate uv maps. I've managed to access the split normals using calc_normals_split but now I'm having trouble isolating and transferring the xyz coordinates to the uv maps.Here is the python script I'm using.

import bpy
import numpy as np

context = bpy.context

ob = context.object me = ob.data

calc split normals

me.calc_normals_split()

normal = Loop.normal ob.data.uv_layers["xy"].data[loop.normal].uv = (normal.x, normal.y) ob.data.uv_layers["z"].data[loop.normal].uv = (normal.z, 0)

I need to transfer the normal x,y, and z coordinates to separate uv maps because uv maps are 2 dimensional.

1 Answers1

2

The code from your last question was closer. All you needed was to calc_normal_split and to use the loop.normal instead of the vertex.normal.

import bpy

ob = bpy.context.object

ob.data.calc_normals_split()

for loop in ob.data.loops: normal = loop.normal ob.data.uv_layers["XY"].data[loop.index].uv = (normal.x, normal.y) ob.data.uv_layers["ZW"].data[loop.index].uv = (normal.z, 0)

Note that this calculates and stores the normals of the mesh as it looks in edit mode, ie. before any modifiers. Your armature modifier for example will change the normals.

You can swap out the reconstructed normal for the actual normal in the shader to see that it works.

Swapping out reconstruction for Geometry>Normal in the shader

scurest
  • 10,349
  • 13
  • 31
  • 1
    Perhaps this could be consolidated as answer to previous question https://blender.stackexchange.com/questions/240587/calculating-split-normals-using-python and this one could be closed as dupe. (or vice versa) – batFINGER Oct 16 '21 at 13:54