Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/startup/bl_operators/uvcalc_smart_project.py
| Show First 20 Lines • Show All 265 Lines • ▼ Show 20 Lines | def optiRotateUvIsland(faces): | ||||
| angle = geometry.box_fit_2d(uv_points) | angle = geometry.box_fit_2d(uv_points) | ||||
| if angle != 0.0: | if angle != 0.0: | ||||
| rotate_uvs(uv_points, angle) | rotate_uvs(uv_points, angle) | ||||
| # orient them vertically (could be an option) | # orient them vertically (could be an option) | ||||
| minx, miny, maxx, maxy = boundsIsland(faces) | minx, miny, maxx, maxy = boundsIsland(faces) | ||||
| w, h = maxx - minx, maxy - miny | w, h = maxx - minx, maxy - miny | ||||
| # use epsilon so we dont randomly rotate (almost) perfect squares. | # use epsilon so we don't randomly rotate (almost) perfect squares. | ||||
| if h + 0.00001 < w: | if h + 0.00001 < w: | ||||
| from math import pi | from math import pi | ||||
| angle = pi / 2.0 | angle = pi / 2.0 | ||||
| rotate_uvs(uv_points, angle) | rotate_uvs(uv_points, angle) | ||||
| # Takes an island list and tries to find concave, hollow areas to pack smaller islands into. | # Takes an island list and tries to find concave, hollow areas to pack smaller islands into. | ||||
| def mergeUvIslands(islandList): | def mergeUvIslands(islandList): | ||||
| ▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | while areaIslandIdx < len(decoratedIslandListAreaSort) and not BREAK: | ||||
| else: | else: | ||||
| efficIslandIdx = 0 | efficIslandIdx = 0 | ||||
| while efficIslandIdx < len(decoratedIslandListEfficSort) and not BREAK: | while efficIslandIdx < len(decoratedIslandListEfficSort) and not BREAK: | ||||
| if Window.GetKeyQualifiers() & ctrl: | if Window.GetKeyQualifiers() & ctrl: | ||||
| BREAK = True | BREAK = True | ||||
| break | break | ||||
| # Now we have 2 islands, if the efficiency of the islands lowers theres an | # Now we have 2 islands, if the efficiency of the islands lowers there's an | ||||
| # increasing likely hood that we can fit merge into the bigger UV island. | # increasing likely hood that we can fit merge into the bigger UV island. | ||||
| # this ensures a tight fit. | # this ensures a tight fit. | ||||
| # Just use figures we have about user/unused area to see if they might fit. | # Just use figures we have about user/unused area to see if they might fit. | ||||
| targetIsland = decoratedIslandListEfficSort[efficIslandIdx] | targetIsland = decoratedIslandListEfficSort[efficIslandIdx] | ||||
| if sourceIsland[0] == targetIsland[0] or\ | if sourceIsland[0] == targetIsland[0] or\ | ||||
| ▲ Show 20 Lines • Show All 251 Lines • ▼ Show 20 Lines | while islandIdx < len(islandList): | ||||
| w, h = maxx - minx, maxy - miny | w, h = maxx - minx, maxy - miny | ||||
| if w < SMALL_NUM: | if w < SMALL_NUM: | ||||
| w = SMALL_NUM | w = SMALL_NUM | ||||
| if h < SMALL_NUM: | if h < SMALL_NUM: | ||||
| h = SMALL_NUM | h = SMALL_NUM | ||||
| """Save the offset to be applied later, | """Save the offset to be applied later, | ||||
| we could apply to the UVs now and allign them to the bottom left hand area | we could apply to the UVs now and align them to the bottom left hand area | ||||
| of the UV coords like the box packer imagines they are | of the UV coords like the box packer imagines they are | ||||
| but, its quicker just to remember their offset and | but, its quicker just to remember their offset and | ||||
| apply the packing and offset in 1 pass """ | apply the packing and offset in 1 pass """ | ||||
| islandOffsetList.append((minx, miny)) | islandOffsetList.append((minx, miny)) | ||||
| # Add to boxList. use the island idx for the BOX id. | # Add to boxList. use the island idx for the BOX id. | ||||
| packBoxes.append([0, 0, w, h]) | packBoxes.append([0, 0, w, h]) | ||||
| islandIdx += 1 | islandIdx += 1 | ||||
| ▲ Show 20 Lines • Show All 231 Lines • ▼ Show 20 Lines | # XXX Window.DrawProgressBar(0.1, 'SmartProj UV Unwrapper, mapping "%s", %i faces.' % (me.name, len(meshFaces))) | ||||
| # Pretend that the most unique angle is ages away to start the loop off | # Pretend that the most unique angle is ages away to start the loop off | ||||
| mostUniqueAngle = -1.0 | mostUniqueAngle = -1.0 | ||||
| # This is popped | # This is popped | ||||
| tempMeshFaces = meshFaces[:] | tempMeshFaces = meshFaces[:] | ||||
| # This while only gathers projection vecs, faces are assigned later on. | # This while only gathers projection vecs, faces are assigned later on. | ||||
| while 1: | while 1: | ||||
| # If theres none there then start with the largest face | # If there's none there then start with the largest face | ||||
| # add all the faces that are close. | # add all the faces that are close. | ||||
| for fIdx in range(len(tempMeshFaces) - 1, -1, -1): | for fIdx in range(len(tempMeshFaces) - 1, -1, -1): | ||||
| # Use half the angle limit so we don't overweight faces towards this | # Use half the angle limit so we don't overweight faces towards this | ||||
| # normal and hog all the faces. | # normal and hog all the faces. | ||||
| if newProjectVec.dot(tempMeshFaces[fIdx].no) > USER_PROJECTION_LIMIT_HALF_CONVERTED: | if newProjectVec.dot(tempMeshFaces[fIdx].no) > USER_PROJECTION_LIMIT_HALF_CONVERTED: | ||||
| newProjectMeshFaces.append(tempMeshFaces.pop(fIdx)) | newProjectMeshFaces.append(tempMeshFaces.pop(fIdx)) | ||||
| ▲ Show 20 Lines • Show All 225 Lines • Show Last 20 Lines | |||||