Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- import pickle
- import bmesh
- from mathutils import Vector
- try:
- path = bpy.path.abspath("//")
- file = "Planet_data.txt"
- with open(path+file, 'rb') as f:
- MasterList = pickle.load(f)
- print('loaded patch data from disk')
- except:
- print('failed to load')
- scn = bpy.context.scene
- #print(MasterList[0])
- patch = bpy.data.objects['Patch']
- X = {}
- for vert in patch.data.vertices:
- #print(type(vertex))
- #print(vert.index)
- x = round(vert.co.x*16)/16
- if x not in X:
- X[x] = [(vert.index, round(vert.co.y*16)/16)]
- else:
- X[x].append((vert.index,round(vert.co.y*16)/16))
- for entry in X:
- X[entry].sort(key=lambda i: i[1])
- list1 = []
- for item in X[entry]:
- list1.append(item[0])
- #print(item[0])
- X[entry]=list1
- #sort x_keys and strip out the X data
- listA = []
- for entry in X:
- listA.append((entry,X[entry]))
- listA.sort(key=lambda i: i[0])
- listB=[]
- for entry in listA:
- listB.append(entry[1])
- print(str(listB))
- #listB[x][y] = vert_index
- #MasterList = {}
- #print(MasterList)
- for entry in MasterList:
- new_obj = patch.copy()
- new_obj.data = patch.data.copy()
- new_obj.name ="Gen_Patch_"+str(entry)
- scn.objects.link(new_obj)
- new_obj.location = MasterList[entry]["Pos"]
- new_obj.rotation_euler = MasterList[entry]["Rot"]
- #print('added a mesh')
- bpy.context.scene.objects.active = new_obj
- bpy.ops.object.mode_set(mode = 'EDIT')
- bm = bmesh.from_edit_mesh(new_obj.data)
- colors = bm.loops.layers.color.active
- bm.verts.ensure_lookup_table()
- if not colors:
- colors = bm.loops.layers.color.new("Col")
- for x in range(len(listB)):
- for y in range(len(listB[x])):
- data = MasterList[entry][(x,y)]
- bm.verts[listB[x][y]].select = True
- verts = [ v for v in bm.verts if v.select ]
- if verts:
- for v in verts:
- for loop in v.link_loops:
- loop[colors] = data[1]
- v.normal = data[2]
- v.co = Vector(data[0])
- bmesh.update_edit_mesh(new_obj.data)
- bpy.ops.object.mode_set(mode = 'OBJECT')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement