uv_to_cloth.py

uv_to_cloth.py#

:uv_to_cloth.py
uv_to_cloth.py

Convert uv islands to the cloth pieces with extra borders to be sewed together

1# this example converts uv islands to the cloth pieces with extra borders to be sewed together
2import coat
3
4# go to the uv-room to set the context
5coat.ui.toRoom("UV")
6border_percent = 0.5
7n_sets = coat.uv.uvSetsCount()
8#first, re-wrap islands with bigger distance
9border = coat.uv.getUnwrapIslandsDistance()
10coat.uv.setUnwrapIslandsDistance(border_percent + 0.2)
11
12# run through all uv-sets
13for s in range(n_sets):
14 # unwrap the uv-set
15 coat.uv.unwrap(s)
16 # get the number of islands
17 n_islands = coat.uv.islandsCount(s)
18 print("n_islands: " + str(n_islands) + "\n")
19 # run through all islands
20 for i in range(n_islands):
21 print("cloth_" + str(s) + "_"+str(i))
22 # convert the island to a mesh
23 island_mesh = coat.uv.islandToMesh(s,i)
24 # expand the open edges to make the borders
25 island_mesh.expandOpenEdges(border_percent / 100.0)
26 # create a volume and add the mesh to it
27 v = coat.Scene.sculptRoot().addChild("uv_" + str(s) + "_island_"+str(i)).Volume()
28 # turn the volume to surface mode
29 v.toSurface()
30 # add some thickness to the mesh, just for pretty look
31 # we scale 100X to make the mesh well visible
32 # we also rotate the mesh to make the normals look upwards
33 island_mesh.toVolume(v, coat.mat4.Scaling(100) * coat.mat4.RotationX(90))
34coat.uv.applyUVSet()
36# go to the sculpt-room, see the result
37coat.ui.toRoom("Sculpt")
:uv_to_cloth.py
 1     # this example converts uv islands to the cloth pieces with extra borders to be sewed together
 2     import coat
 3
 4     # go to the uv-room to set the context
 5     coat.ui.toRoom("UV")
 6     border_percent = 0.5
 7     n_sets = coat.uv.uvSetsCount()
 8     #first, re-wrap islands with bigger distance
 9     border = coat.uv.getUnwrapIslandsDistance()
10     coat.uv.setUnwrapIslandsDistance(border_percent + 0.2)
11
12     # run through all uv-sets
13     for s in range(n_sets):
14             # unwrap the uv-set
15             coat.uv.unwrap(s)
16             # get the number of islands
17             n_islands = coat.uv.islandsCount(s)
18             print("n_islands: " + str(n_islands) + "\n")
19             # run through all islands
20             for i in range(n_islands):
21                     print("cloth_" + str(s) + "_"+str(i))
22                     # convert the island to a mesh
23                     island_mesh = coat.uv.islandToMesh(s,i)
24                     # expand the open edges to make the borders
25                     island_mesh.expandOpenEdges(border_percent / 100.0)
26                     # create a volume and add the mesh to it
27                     v = coat.Scene.sculptRoot().addChild("uv_" + str(s) + "_island_"+str(i)).Volume()
28                     # turn the volume to surface mode
29                     v.toSurface()
30                     # add some thickness to the mesh, just for pretty look
31                     # we scale 100X to make the mesh well visible
32                     # we also rotate the mesh to make the normals look upwards
33                     island_mesh.toVolume(v, coat.mat4.Scaling(100) * coat.mat4.RotationX(90))
34     coat.uv.applyUVSet()
35     coat.uv.setUnwrapIslandsDistance(border)
36     # go to the sculpt-room, see the result
37     coat.ui.toRoom("Sculpt")