uv_random_rotation.py#
uv_random_rotation.py
Randomly rotate the UV islands and pack them
1# In this example we rotate all islands randomly and then pack them.
2import coat
3
4# go to the uv-room to set the context
6
8n_islands = coat.uv.islandsCount(current_uv_set)
9# run through all islands
10for i in range(n_islands):
11 island_mesh = coat.uv.islandToMesh(current_uv_set,i)
12 # rotate the island randomly
13 center = island_mesh.getBounds().GetCenter()
15 # update the island
16 coat.uv.meshToIsland(island_mesh, current_uv_set, i)
18
1 # In this example we rotate all islands randomly and then pack them.
2 import coat
3
4 # go to the uv-room to set the context
5 coat.ui.toRoom("UV")
6
7 current_uv_set = coat.uv.currentUvSet()
8 n_islands = coat.uv.islandsCount(current_uv_set)
9 # run through all islands
10 for i in range(n_islands):
11 island_mesh = coat.uv.islandToMesh(current_uv_set,i)
12 # rotate the island randomly
13 center = island_mesh.getBounds().GetCenter()
14 island_mesh.transform(coat.mat4.RotationAt(center, coat.vec3.AxisZ, coat.math.Rand(0,360)))
15 # update the island
16 coat.uv.meshToIsland(island_mesh, current_uv_set, i)
17
18 coat.uv.pack(current_uv_set, False, True)