3DCoat Python API
The 3DCoat Python API documentation.
Loading...
Searching...
No Matches
uv_to_cloth.py

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

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
6border_percent = 0.5
7n_sets = coat.uv.uvSetsCount()
8#first, re-wrap islands with bigger distance
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
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))
36# go to the sculpt-room, see the result
37coat.ui.toRoom("Sculpt")
SceneElement sculptRoot()
get the root of all sculpt objects
Definition coat.py:2843
mat4 Scaling(XYZ=float)
Definition coat.py:614
mat4 RotationX(Angle=float)
Definition coat.py:607
toRoom(name=str)
switch to the room
Definition coat.py:3251
float getUnwrapIslandsDistance()
get the border around the islands when we pack it
Definition coat.py:3976
unwrap(uv_set=int)
unwrap the current uv-set
Definition coat.py:4048
Mesh islandToMesh(uv_set=int, island_index=int)
get the mesh that contains the island, xy of each point is the UV coordinate.
Definition coat.py:3991
int islandsCount(uv_set=int)
get the islands count over the current uv-set
Definition coat.py:3985
applyUVSet()
apply uv changes to the paint room mesh (if we use uv/paint context)
Definition coat.py:4121
int uvSetsCount()
get the UV-sets count.
Definition coat.py:3968
setUnwrapIslandsDistance(distance=float)
set the border around the islands when we pack it
Definition coat.py:3972