On 21/08/2017 at 12:05, xxxxxxxx wrote:
I got a list of normals and a bunch of polygons:
# get points, normals, faces, uvs
indices = gltf_get_accessor(mesh["primitives"][0]["indices"], d, buffer)
coords = gltf_get_accessor(mesh["primitives"][0]["attributes"]["POSITION"], d, buffer)
uvs = gltf_get_accessor(mesh["primitives"][0]["attributes"]["TEXCOORD_0"], d, buffer)
normals = gltf_get_accessor(mesh["primitives"][0]["attributes"]["NORMAL"], d, buffer)
faces = [tuple(indices[i:i + 3]) for i in range(0, len(indices), 3)]
# create object to hold points
obj = c4d.BaseObject(c4d.Opolygon)
obj.SetName(mesh["name"])
obj.ResizeObject(len(coords), len(faces))
# add a UV tag to the object
uvtag = c4d.UVWTag(len(faces))
obj.InsertTag(uvtag)
# add a normal tag to the object
ntag = c4d.NormalTag(len(faces))
obj.InsertTag(ntag)
# fill points into polygon object
for i, v in enumerate(coords) :
obj.SetPoint(i, c4d.Vector(v[0], v[1], v[2]))
# fill trangles into polygon object and set UV coords
for i, f in enumerate(faces) :
obj.SetPolygon(i, c4d.CPolygon(f[0], f[1], f[2]))
uvtag.SetSlow(i, c4d.Vector(uvs[f[0]][0], uvs[f[0]][1], 0),
c4d.Vector(uvs[f[1]][0], uvs[f[1]][1], 0),
c4d.Vector(uvs[f[2]][0], uvs[f[2]][1], 0),
c4d.Vector())
HOW DO I SET NORMALS?
doc.InsertObject(obj)
With generous help for people here, I got pretty much all of it working, except how to set the normal vector for a polygon. The normal tag doesn't seem to have a way to set the normal (unlike the uvtag which has SetSlow)?