Hello @m_adam ,
Skip to the edit below.
────────────────────
Thanks again for the reply but the normal tag still doesn't seem to be doing anything.
Here's how the code looks right now :
# Looping through each surface (polygon object/mesh/model) in the scene
for i in range(surfaceCount):
#Create new polygon object
mypoly = c4d.BaseObject(c4d.Opolygon) #Create an empty polygon object
mypoly.SetName(materialName)
uv_tag = c4d.UVWTag(triCount)
# triCount & materialName are variables I use to store the name of the object + the polycount
nrm_tag = CreateNormalTag(mypoly,triCount)
normalList = [] # Fresh new normalList created for each PolygonObject I'm working on
# loop through each triangle/poly and gather it's data from my binary file
for f in range(triCount):
# The points, polys & uv creation part is unnecessary here so I skipped right to normals
a = [normal1[0],normal1[1],normal1[2]]
b = [normal2[0],normal2[1],normal2[2]]
c = [normal3[0],normal3[1],normal3[2]]
d = [0.0, 0.0, 0.0]
# Add normals to normalList
normalList.extend(a)
normalList.extend(b)
normalList.extend(c)
normalList.extend(d)
# After we are done looping through the triangles, all polys are created including their points, polygons, UVs & the normalList
normalListToSet = [int(normal * 32000.0) for normal in normalList] # set of all normals for this polygon object
WriteNormalTag(nrm_tag, normalListToSet)
nrm_tag = mypoly.GetTag(c4d.Tnormal) # This is probably unnecessary but I used it just in case
# Retrieves the raw data stored into the tag
rawNormalData = ReadNormalTag(nrm_tag)
# Prints the current value stored in tag, since data are stored as int16 and not float you have to divide them by 32000.0
print "current data stored in tag - should go from 0 to 1"
print [normal / 32000.0 for normal in rawNormalData]
# Creates a list representing a float gradient value from 0 to 1 then remap these value from float to int16 by multiplying them
valueToSet = [int(float(normalID) / len(rawNormalData) * 32000.0) for normalID in xrange(len(rawNormalData))]
# Writes the previous list to the normal tag.
WriteNormalTag(nrm_tag, valueToSet)
print "new values of normal tag"
print [normal / 32000.0 for normal in ReadNormalTag(nrm_tag)]
Now here are results of few of the normal tags in the scene
old data stored in tag
[0.994125, -0.07825, -0.05478125, 0.994125, -0.07825, -0.05478125, 0.994125, -0.07825, -0.05478125, 0.0, 0.0, 0.0, 0.994125, -0.07825, -0.05478125, 0.994125, -0.07825, -0.05478125, 0.994125, -0.07825, -0.05478125, 0.0, 0.0, 0.0, 0.994125, -0.07825, -0.05478125, 0.994125, -0.07825, -0.05478125, 0.994125, -0.07825, -0.05478125, 0.0, 0.0, 0.0, 0.994125, -0.07825, -0.05478125, 0.994125, -0.07825, -0.05478125, 0.994125, -0.07825, -0.05478125, 0.0, 0.0, 0.0]
new data of normal tag
[0.0, 0.0208125, 0.04165625, 0.0625, 0.0833125, 0.10415625, 0.125, 0.1458125, 0.16665625, 0.1875, 0.2083125, 0.22915625, 0.25, 0.2708125, 0.29165625, 0.3125, 0.3333125, 0.35415625, 0.375, 0.3958125, 0.41665625, 0.4375, 0.4583125, 0.47915625, 0.5, 0.5208125, 0.54165625, 0.5625, 0.5833125, 0.60415625, 0.625, 0.6458125, 0.66665625, 0.6875, 0.7083125, 0.72915625, 0.75, 0.7708125, 0.79165625, 0.8125, 0.8333125, 0.85415625, 0.875, 0.8958125, 0.91665625, 0.9375, 0.9583125, 0.97915625]
old data stored in tag
[1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0]
new data of normal tag
[0.0, 0.0208125, 0.04165625, 0.0625, 0.0833125, 0.10415625, 0.125, 0.1458125, 0.16665625, 0.1875, 0.2083125, 0.22915625, 0.25, 0.2708125, 0.29165625, 0.3125, 0.3333125, 0.35415625, 0.375, 0.3958125, 0.41665625, 0.4375, 0.4583125, 0.47915625, 0.5, 0.5208125, 0.54165625, 0.5625, 0.5833125, 0.60415625, 0.625, 0.6458125, 0.66665625, 0.6875, 0.7083125, 0.72915625, 0.75, 0.7708125, 0.79165625, 0.8125, 0.8333125, 0.85415625, 0.875, 0.8958125, 0.91665625, 0.9375, 0.9583125, 0.97915625]
old data stored in tag
[-1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0]
new data of normal tag
[0.0, 0.0208125, 0.04165625, 0.0625, 0.0833125, 0.10415625, 0.125, 0.1458125, 0.16665625, 0.1875, 0.2083125, 0.22915625, 0.25, 0.2708125, 0.29165625, 0.3125, 0.3333125, 0.35415625, 0.375, 0.3958125, 0.41665625, 0.4375, 0.4583125, 0.47915625, 0.5, 0.5208125, 0.54165625, 0.5625, 0.5833125, 0.60415625, 0.625, 0.6458125, 0.66665625, 0.6875, 0.7083125, 0.72915625, 0.75, 0.7708125, 0.79165625, 0.8125, 0.8333125, 0.85415625, 0.875, 0.8958125, 0.91665625, 0.9375, 0.9583125, 0.97915625]
old data stored in tag
[-1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.7064375, 0.7064375, 0.0, 0.7064375, 0.7064375, 0.0, 0.7064375, 0.7064375, 0.0, 0.0, 0.0, 0.0, 0.7064375, 0.7064375, 0.0, 0.7064375, 0.7064375, 0.0, 0.7064375, 0.7064375, 0.0, 0.0, 0.0, 0.0]
new data of normal tag
[0.0, 0.0208125, 0.04165625, 0.0625, 0.0833125, 0.10415625, 0.125, 0.1458125, 0.16665625, 0.1875, 0.2083125, 0.22915625, 0.25, 0.2708125, 0.29165625, 0.3125, 0.3333125, 0.35415625, 0.375, 0.3958125, 0.41665625, 0.4375, 0.4583125, 0.47915625, 0.5, 0.5208125, 0.54165625, 0.5625, 0.5833125, 0.60415625, 0.625, 0.6458125, 0.66665625, 0.6875, 0.7083125, 0.72915625, 0.75, 0.7708125, 0.79165625, 0.8125, 0.8333125, 0.85415625, 0.875, 0.8958125, 0.91665625, 0.9375, 0.9583125, 0.97915625]
Could this happen because I don't use Phong Tag?
Edit:
Yes it was definitely Phong Tags! Also, this was enough using my initial normal data
# Maps data from float to int16 value
normalListToSet = [int(normal * 32000.0) for normal in normalList]
# Writes the previous list to the normal tag.
WriteNormalTag(nrm_tag, normalListToSet)
Anyway, I imported an .obj file that shares the same data as my binary file, and once I copied the Phong Tag settings and applied to my generated objects it was identical, which means Normal Tags are correct!
I can't seem to find a page for Phong Tag though. How would I create a new Phong Tag, and set it's values?
Your help has already done a lot and I really appreciate your responses.
Thanks,
Sheilan.