On 19/08/2017 at 11:34, xxxxxxxx wrote:
Since I use neighboor to know which point id are shared with wich polygon id, my script is more a way for dealing with mesh that already exist. At least I think in this way when I builded it. So rry about that and forget it since you are in the creation.
But regarding your question here is a litlle exemple wich create, 2 polygons with uv wich I hope will make more sense.
import c4d
#pt_id are correctly ordered
points = [
c4d.Vector(0, 0, 0),
c4d.Vector(200, 0, 0),
c4d.Vector(200, 0, 200),
c4d.Vector(0, 0, 200),
c4d.Vector(200, 100, 0),
c4d.Vector(200, 100, 200)
]
#uv_id are ordered like points and get same count than points
uvs = [
c4d.Vector(1, 1, 1),
c4d.Vector(0.6, 1, 1),
c4d.Vector(0.6, 0, 1),
c4d.Vector(1, 0, 1),
c4d.Vector(0, 1, 1),
c4d.Vector(0, 0, 1)
]
#hold pt_id
polys = [
[0 ,1, 2 ,3],
[1, 2, 5 ,4]
]
def main() :
doc.StartUndo()
nb_pts = len(points)
nb_polys = len(polys)
obj = c4d.BaseObject(c4d.Opolygon)
uv_tag = c4d.UVWTag(nb_polys)
#Firstly we prepare our polygon object to store this amount of value
obj.ResizeObject(nb_pts, nb_polys)
#Then we build point I could use objet.SetAllPoints(points)
# since my points list is already ordered
for pt_id, pos in enumerate(points) :
obj.SetPoint(pt_id, pos)
#Then we define our polygon and our uv.
# UV belong to pt_id FROM polygon. That mean we need polygon ;)
for poly_id, pt_ids in enumerate(polys) :
poly = None
#Handle triangle
if len(pt_ids) > 3:
poly = c4d.CPolygon(
pt_ids[0],
pt_ids[1],
pt_ids[2],
pt_ids[3]
)
else:
poly = c4d.CPolygon(
pt_ids[0],
pt_ids[1],
pt_ids[2],
pt_ids[2]
)
obj.SetPolygon(poly_id, poly)
#remember poly.a is pt_id. We use poly data since we already managed triangle before
uv_tag.SetSlow(poly_id, uvs[poly.a], uvs[poly.b], uvs[poly.c], uvs[poly.d])
obj.Message(c4d.MSG_UPDATE)
doc.InsertObject(obj)
doc.AddUndo(c4d.UNDOTYPE_NEW, obj)
obj.InsertTag(uv_tag)
doc.AddUndo(c4d.UNDOTYPE_NEW, uv_tag)
c4d.EventAdd()
doc.EndUndo()
if __name__=='__main__':
main()