Last active
September 30, 2016 14:38
-
-
Save nortikin/1d316cc7d945e521996b to your computer and use it in GitHub Desktop.
rollout uv layout as scripted node to 3D sverchok SN1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import bmesh | |
| from sv_bmesh_utils import * | |
| #import numpy as np | |
| def sv_main(object=[],layout=-1): | |
| in_sockets = [ | |
| ['s', 'object', object], | |
| ['s', 'layout', layout], | |
| ] | |
| def out_sockets(*args): | |
| out_sockets = [ | |
| ['v', 'vertices', args[0]], | |
| ['s', 'polygons', args[1]] | |
| ] | |
| return out_sockets | |
| if not object: | |
| return in_sockets, out_sockets([],[]) | |
| def UV(object): | |
| mesh = object.data | |
| bm = bmesh.new() | |
| bm.from_mesh(mesh) | |
| uv_layer = bm.loops.layers.uv[min(layout, len(bm.loops.layers.uv)-1)] | |
| nFaces = len(bm.faces) | |
| bm.verts.ensure_lookup_table() | |
| bm.faces.ensure_lookup_table() | |
| vertices_dict = {} | |
| polygons_new = [] | |
| for fi in range(nFaces): | |
| polygons_new_pol = [] | |
| for loop in bm.faces[fi].loops: | |
| polygons_new_pol.append(loop.index) | |
| vertices_dict[loop.index] = list(loop[uv_layer].uv[:])+[0] | |
| polygons_new.append(polygons_new_pol) | |
| bm.clear() | |
| del bm | |
| vertices_new = [i for i in vertices_dict.values()] | |
| print(vertices_new) | |
| return [vertices_new], [polygons_new] | |
| v,p = UV(bpy.data.objects[object[0][0][0]]) | |
| return in_sockets, out_sockets(v, p) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment