On 13/07/2018 at 03:08, xxxxxxxx wrote:
Hi, first of all, welcome in the PluginCafe forum BloomingShade.
Something important, you should make sure when you ask a question is to tell us in which context you are (a script, a generator?)
But in any, cases to set custom normal you have to use NormalTag.
Here a little example which writes your own normal
import c4d
def main() :
obj = op
if not obj:
return
polyCount = obj.GetPolygonCount()
tag = c4d.VariableTag(c4d.Tnormal, polyCount) # create tag
normals = list()
for polyIndex in xrange(polyCount) :
poly = obj.GetPolygon(polyIndex)
# Calculate vertex normal for each point
pointIndexArray = [poly.a, poly.b, poly.c, poly.d]
for pointIndex in pointIndexArray: # append vectors sequentially split
vNorms = c4d.Vector(1,0,0)
normals.append(vNorms.x)
normals.append(vNorms.y)
normals.append(vNorms.z)
obj.InsertTag(tag) # Apply tag
tag.SetAllHighlevelData(normals) # write normal to tag
c4d.EventAdd()
doc.AddUndo(c4d.UNDOTYPE_NEW, tag)
if __name__=='__main__':
main()
And here to read
import c4d
def main() :
obj = op
if not obj:
return
polyCount = obj.GetPolygonCount()
tag = obj.GetTag(c4d.Tnormal)
normals = tag.GetAllHighlevelData() # read normal from tag
for polyIndex in xrange(obj.GetPolygonCount()) :
poly = obj.GetPolygon(polyIndex)
pointIndexArray = [poly.a, poly.b, poly.c, poly.d]
for pointIndex in pointIndexArray:
vNorms = c4d.Vector(normals[pointIndex+polyIndex], normals[pointIndex+polyIndex+1], normals[pointIndex+polyIndex+2])
print "PolyID: {} - PtID: {} - {}".format(polyIndex, pointIndex, vNorms)
if __name__=='__main__':
main()
If you have any question please let me know.
Cheers,
Maxime