Message 1 of 1
How to clear a mesh's "normals" array after lock->unlock normals?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
If you do "lock normals", "unlock normals", "delete history" on a cube then saving the scene results in .normals data to be written along with the maya file:
setAttr -s 24 ".n[0:23]" -type "float3" 1e+20 1e+20 1e+20 1e+20 1e+20
1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20
1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20
1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20
1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20
1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20 1e+20;
Anyone have any idea on how to clear out this data from within the Maya session? 🙂
Here's a reproducable:
# Reproducable
from maya import cmds
cube = cmds.polyCube(constructionHistory=False)[0]
plug = f"{cube}.normals"
print(cmds.getAttr(plug, size=True)) # no data yet
cmds.LockNormals()
print(cmds.getAttr(plug, size=True)) # now there's data
cmds.UnlockNormals()
cmds.delete(cube, constructionHistory=True)
print(cmds.getAttr(plug, size=True)) # data is still there, but bascailly 'cleared' to 1e+20
The question now becomes how I do I clear that attribute so that it's basically zero size again and doesn't write redundant data into the .ma file?
Here are some things I tried:
# Can't remove the indices of the array itself
try:
cmds.removeMultiInstance(plug, allChildren=True, b=True)
except RuntimeError as exc:
print(exc)
# Set empty normals array with MFnMesh API - no errors, but does not seem to work.
import maya.api.OpenMaya as om
shape = cmds.listRelatives(cube, shapes=True, fullPath=True)[0]
sel = om.MSelectionList()
sel.add(shape)
obj = sel.getDependNode(0)
fn = om.MFnMesh(obj)
fn.setNormals([])
# Setting the size or capacityHint using getAttr
cmds.setAttr(plug, size=0)
cmds.setAttr(plug, capacityHint=0)
But all of these didn't work. Tested in Maya 2023.3 and 2024.1 (Windows)
The nodes reference for the "mesh" node states for 'normals':
Special Attribute for file i/o of user specified normals. Gets written if there are any user specified normals on the object. If the default value which is 1e+20 is written out, then it means that system defined normal values are used. |
So it being a "default value" at least describes why it's that value - but it seems like redundant data that I should be able to clear. But how?