def fill_empty_vect_dict(self): vects = [] for i in range(self.gene_count): v = [] for j in range(3): v_range = self.v_max_list[j] - self.v_min_list[j] v.append(self.v_min_list[j]+ random()*v_range) vects.append(v) self.node_mem[self.node_id] = vects self.write_memory_prop(vects)
def fill_empty_nums_dict(self): nums = [] list_limits = self.get_list_limits() n_range = list_limits[1] - list_limits[0] for i in range(self.gene_count): num = list_limits[0] + random()*n_range if self.number_type == 'int': num = int(num) nums.append(num) self.node_mem[self.node_id] = nums self.write_memory_prop(nums)
def export_ter(filepath): start_time = time.process_time() filename = filepath + '.ter' # start to set all the tags and values needed for the .ter file ter_header = 'TERRAGENTERRAIN ' size_tag = 'SIZE' size = 64 scal_tag = 'SCAL' scalx = 30.0 scaly = 30.0 scalz = 30.0 altw_tag = 'ALTW' HeightScale = 80 BaseHeight = 0 totalpoints = (size + 1) * (size + 1) # set seed for noise.random() noise.seed_set(123) # values are packed as short (i.e = integers max 32767) so we map them in the right range values = [ int(map_range(noise.random(), 0.0, 1.0, 0.0, 32767.0)) for i in range(totalpoints) ] # print(values) eof_tag = 'EOF' # end of file tag with open(filename, "wb") as file: # write the header file.write(ter_header.encode('ascii')) # write the size of the terrain file.write(size_tag.encode('ascii')) file.write(struct.pack('h', size)) # padding byte needed after SIZE file.write(struct.pack('xx')) # padding -> b'\x00\x00' # write the scale tag = SCAL file.write(scal_tag.encode('ascii')) # pack the scaling values as floats file.write(struct.pack('fff', scalx, scaly, scalz)) # write the altitude ALTW tag file.write(altw_tag.encode('ascii')) # pack heightScale and baseHeight file.write(struct.pack('h', HeightScale)) file.write(struct.pack('h', BaseHeight)) # pack as shorts the elvetions values for v in values: file.write(struct.pack('h', v)) # EOF = end of file file.write(eof_tag.encode('ascii')) file.close() print('Terrain exported in %.4f sec.' % (time.process_time() - start_time))
def __init__(self, values = None, random = False): self.values = values self.random = random self.q8 = [] if values: if len(values) != 8: print("Oops, length of values passed in is wrong. DEATH.") sys.exit() self.q8 = values if random: for i in range(0, 8): self.q8.append(noise.random())
def SavePreset(FName): FName = FName.replace("//", "") try: f = open(FName,'w') except: message = "unable to save file." return writeln(f,CurVersion) scn = bpy.context.scene writeln(f, scn.sldDensity) writeln(f, scn.sldGravity) writeln(f, scn.sldSegments) writeln(f, scn.sldLength) writeln(f, scn.sldWidth) writeln(f, scn.sldInit) writeln(f, scn.sldRand) writeln(f, scn.sldRloc) writeln(f, scn.sldFollow) writeln(f, scn.sldControl) writeln(f, scn.sldCtrlSeg) writeln(f, scn.sldSegRand) writeln(f, scn.sldFalloff) if scn.chkPointed: writeln(f, "1") else: writeln(f, "0") if scn.chkVCol: writeln(f, "1") else: writeln(f, "0") if scn.chkWind: writeln(f, "1") else: writeln(f, "0") if scn.chkGuides: writeln(f, "1") else: writeln(f, "0") writeln(f,int(random()*1000)) writeln(f,1) #First Run objects = bpy.context.selected_objects for z in range(len(objects)): writeln(f,objects[z].name) f.close()
def fill_vect_mem(self): if self.node_id in self.node_mem: vects = self.node_mem[self.node_id] else: vects = [] if len(vects) < self.gene_count: for i in range(self.gene_count -len(vects)): v = [] for j in range(3): v_range = self.v_max_list[j] - self.v_min_list[j] v.append(self.v_min_list[j] + random()*v_range) vects.append(v) elif len(vects) > self.gene_count: vects = vects[:self.gene_count] self.node_mem[self.node_id] = vects self.write_memory_prop(vects)
def fill_num_mem(self): if self.node_id in self.node_mem: nums = self.node_mem[self.node_id] else: nums = [] if len(nums) < self.gene_count: list_limits = self.get_list_limits() n_range = list_limits[1] - list_limits[0] for i in range(self.gene_count -len(nums)): num = list_limits[0] + random()*n_range if self.number_type == 'int': num = int(num) nums.append(num) elif len(nums) > self.gene_count: nums = nums[:self.gene_count] self.node_mem[self.node_id] = nums self.write_memory_prop(nums)
def randnum(low=0.0, high=1.0, seed=0): """ randnum( low=0.0, high=1.0, seed=0 ) Create random number Parameters: low - lower range (type=float) high - higher range (type=float) seed - the random seed number, if seed is 0, the current time will be used instead (type=int) Returns: a random number (type=float) """ Noise.seed_set(seed) rnum = Noise.random() rnum = rnum*(high-low) rnum = rnum+low return rnum
def randnum(low=0.0, high=1.0, seed=0): """ randnum( low=0.0, high=1.0, seed=0 ) Create random number Parameters: low - lower range (type=float) high - higher range (type=float) seed - the random seed number, if seed is 0, the current time will be used instead (type=int) Returns: a random number (type=float) """ Noise.seed_set(seed) rnum = Noise.random() rnum = rnum * (high - low) rnum = rnum + low return rnum
def fill_points_colors(vectors_color, data, color_per_point, random_colors): points_color = [] if color_per_point: for cols, sub_data in zip(cycle(vectors_color), data): if random_colors: for n in sub_data: points_color.append([random(), random(), random(), 1]) else: for c, n in zip(cycle(cols), sub_data): points_color.append(c) else: for nums, col in zip(data, cycle(vectors_color[0])): if random_colors: r_color = [random(),random(),random(),1] for n in nums: points_color.append(r_color) else: for n in nums: points_color.append(col) return points_color
def RunFiber(): #_______________________________________________________ #The main routine that is called from outside this script #Parameters: none- loads settings from .fib file. #_______________________________________________________ global firstrun, mat, FpF, UseWind, UseGuides, tempbm firstrun = 1 InitNoise(seed) print ("\n") print ("RipSting's Fiber Generator v3 for 2.6 by Gert De Roost, running on", str(len(bpy.context.selected_objects)), "object(s)") #____________________________________________________________ #Extract properties from the empty "Wind" if enabled #____________________________________________________________ if UseWind == 1: try: Wind = bpy.data.objects.get("Wind") Height = Wind.scale[2] / 50.0 SizeX = Wind.scale[0] SizeY = Wind.scale[1] DirX = Wind.location[0] / 100.0 DirY = Wind.location[1] / 100.0 Falloff = Wind.location[2] /100.0 Roughness = .5 except: print ("Cannot find an empty named \"wind\": Not using wind engine.") UseWind = 0 #____________________________________________________________ #Other variable declarations #____________________________________________________________ vertexcount = 0 objnum = 0 polycenter = [0,0,0] corner1 = [0,0,0] corner2 = [0,0,0] normal = [0,0,0] direc = [0,0,0] basevertex = [0,0,0] vertex = [0,0,0] vertexold = [0,0,0] vertexno = [0,0,0] randomdir = [0,0,0] gravitydir = [0,0,0] WindDir = [0,0,0,0] #First two are initial, second two are incremental vCorner = [0,0] #Vertex color corners vColor1 = [0,0,0] vColor2 = [0,0,0] aColor = [0,0,0] vPercent = [0,0,0] addVariables = [0,0,0] VcolClump = 1 tempbm = bmesh.new() frame = bpy.context.scene.frame_current redoFpF = 0 try: test = FpF except: redoFpF = 1 #____________________________________________________________ #Setup Density if not already initialized #____________________________________________________________ if firstrun == 1 or redoFpF == 1: print ("Storing fiber information for animation") dens = d seg = s FpF = [] newbm = bmesh.new() objects = bpy.context.selected_objects for num in range(len(objects)): mat = adapt(objects[num]) original = objects[num].data bm = bmesh.new() bm.from_mesh(original) for f in bm.faces: if len(f.verts) < 3: break FpF.append(int(fncArea(f, mat) * d)) bm.free() newbm.free() #____________________________________________________________ fnum = -1 for num in range(len(objects)): i=0 #set vertex count to zero original = objects[num].data origbm = bmesh.new() origbm.from_mesh(original) mat = adapt(objects[num]) meshname = original.name if firstrun == 0: me = bpy.data.meshes.get(meshname+"_Fiber."+str(objnum)) newbm.from_mesh(me) else: me = bpy.data.meshes.new(meshname+"_Fiber."+str(objnum)) #____________________________________________________________ #Test for fiber guides #____________________________________________________________ if UseGuides == 1: try: Guides = bpy.data.meshes.get(meshname +"_Fiber.C") Gbm = bmesh.new() Gbm.from_mesh(Guides) GuideOBJ = bpy.data.objects.get(meshname+"_Fiber.C") GMat = adapt(GuideOBJ) if (len(Guides.vertices)/CtrlSeg) != int(len(Guides.vertices)/CtrlSeg): print ("Uneven number of control points non-divisible by" , CtrlSeg ,"\nPlease re-create fiber guides.") print (len(Guides.vertices)) UseGuides = 0 except: UseGuides = 0 #____________________________________________________________ for f in origbm.faces: #Skip over faces with only 2 verts (Edges) v1.3 if len(f.verts) < 3: break fnum += 1 p=0 if UseGuides == 0: #____________________________________________________________ #find normal direction #____________________________________________________________ normal = renormal(multmat(mat, f.verts[0]),multmat(mat, f.verts[1]),multmat(mat, f.verts[2])) #follownormals- 1 = follow, 0 = don't follow normal[0] *= follow normal[1] *= follow normal[2] = (1 - follow) + (normal[2] * follow) #____________________________________________________________ #centerpoint coordinates polycenter = [0,0,0] for va in f.verts: v = multmat(mat, va) for z in range(3): #z is the coordinate plane (x,y,or z) polycenter[z] += v.co[z] for z in range(3): polycenter[z] /= len(f.verts) col_lay = origbm.loops.layers.color.active if UseVCol == 1 and col_lay != None: # colorvalues of centerpoint for z in range(len(f.loops)): aColor[0] += (f.loops[z][col_lay].r) * 255 aColor[1] += (f.loops[z][col_lay].g) * 255 aColor[2] += (f.loops[z][col_lay].b) * 255 for z in range(3): aColor[z] /= len(f.loops) for x in range (FpF[fnum]): #loop for density in each poly #no need to calculate things if density for face is 0 if UseVCol == 1 and col_lay != None: if (f.loops[0][col_lay].b) * 255 + (f.loops[1][col_lay].b) * 255 + (f.loops[1][col_lay].b) * 255 == 0: break vertexcount += s*2 + 2 #_____________________________________________________________ #Find a point on the current face for the fiber to grow out of #My logic behind this: #pick a random point between the center of the poly and any corner #pick a random point between the center and the next corner adjacent to the original #pick a random distance between those other two random points #This ensures that the blade will actually be on the face #____________________________________________________________ cornernum = int(random() * len(f.verts)) #Pick a random corner vCorner[0] = cornernum cornernum += 1 if cornernum > len(f.verts)-1: cornernum = 0 vCorner[1] = cornernum #____________________________________________________________ #Find random location for new fiber on the current face #Much simplified randomization speeds process (v1.3) #____________________________________________________________ percent = pow(random(),.5) #optimized V1.3: replaced 14 different random() statements!!! vPercent[0] = percent vPercent[1] = percent for z in range(3): corner1[z] = (multmat(mat, f.verts[vCorner[0]]).co[z] - polycenter[z]) * percent + polycenter[z] for z in range(3): corner2[z] = (multmat(mat, f.verts[vCorner[1]]).co[z] - polycenter[z]) * percent + polycenter[z] percent = random() vPercent[2] = percent for z in range(3): basevertex[z] = (corner2[z] - corner1[z]) * percent + corner1[z] vertex = basevertex #____________________________________________________________ #Vertex color Stuff (v1.2) #____________________________________________________________ if UseVCol == 1 and col_lay != None: vColor1[0] = (f.loops[vCorner[0]][col_lay].r) * 255 vColor1[1] = (f.loops[vCorner[0]][col_lay].g) * 255 vColor1[2] = (f.loops[vCorner[0]][col_lay].b) * 255 vColor2[0] = (f.loops[vCorner[1]][col_lay].r) * 255 vColor2[1] = (f.loops[vCorner[1]][col_lay].g) * 255 vColor2[2] = (f.loops[vCorner[1]][col_lay].b) * 255 for z in range(2): addVariables[z] = ((aColor[z] * (1-vPercent[0])) + (vColor1[z] * vPercent[0]))/2 addVariables[z] = (addVariables[z] * (1-vPercent[2]) + (((aColor[z] * (1-vPercent[1])) + (vColor2[z] * vPercent[1]))/2) * vPercent[2])/2 addVariables[2] = (vColor1[2] + vColor2[2])/2 else: #Use these values if no vertex colors are present addVariables = [63.75,63.75,255] #Green ties into the length of the fibers #If Using fiber guides, Green ties into clumpiness l = l2 * ((addVariables[1]) / 2) VcolClump = 1 #addVariables[1] / 85.0 #Red ties into the gravity effect on the fibers grav = grav2 * ((addVariables[0]) / 5) #Blue ties into density... x is the faces generated so far for the face... v1.3 FaceDensity = int(FpF[fnum] * addVariables[2]) -1 #print FaceDensity, x if x >= FaceDensity: break #____________________________________________________________ #Wind #____________________________________________________________ if UseWind == 1: WindStrength = ((HTerrain([vertex[0]/SizeX+(frame*DirX), vertex[1]/SizeY+(frame*DirY), frame*Falloff], 1, 1, Height, Roughness) -(Height/2)) * Height)*pow(l,1.5) #Find Y/X Slope that the wind is blowing at if abs(Wind.location[0]) > abs(Wind.location[1]): WindDir[0] = (Wind.location[1] / Wind.location[0]) * WindStrength WindDir[1] = WindStrength if Wind.location[1] < 0: WindDir[1] = -WindDir[1] else: WindDir[0] = WindStrength if Wind.location[1] == 0: Wind.location[1] = .001 WindDir[1] = (Wind.location[0] / Wind.location[1]) * WindStrength if Wind.location[0] < 0: WindDir[0] = -WindDir[0] if Wind.location[1] < 0: WindDir[0] = -WindDir[0] WindDir[2] = 0 WindDir[3] = 0 if UseGuides == 0: #____________________________________________________________ #Normal stuff #____________________________________________________________ for z in range(3): vertexno[z] = normal[z] + (r * (random()-.5)) #____________________________________________________________ #Find random direction that the blade is rotated #(So that it looks good from all angles, and isn't uniform) #____________________________________________________________ rw= [random() -.5, random() -.5] #Find Y/X Slope that the blade is facing if abs(rw[0]) > abs(rw[1]): direc[0] = (rw[1] / rw[0]) * w direc[1] = w if rw[1] < 0: direc[1] = - direc[1] else: direc[0] = w direc[1] = (rw[0] / rw[1]) * w if rw[0] < 0: direc[0] = -direc[0] #direc[2] = rw #____________________________________________________________ #Start the creation process! #____________________________________________________________ i = i + 2 #increment vertex count gravitydir = [0,0,n] #right now I only have gravity working on the Z axis #____________________________________________________________ #If the fiber mesh already exists, simply move the verts instead #of creating new ones. Preserves material data. #____________________________________________________________ if firstrun == 0: #Move base verts for z in range(3): #vertex[z] = me.vertices[i-2].co[z] me.vertices[i-1].co[z] = vertex[z] + direc[z] me.vertices[i-2].co[z] = vertex[z] else: #Create base verts me.vertices.add(2) me.vertices[-1].co = (vertex[0], vertex[1], vertex[2]) me.vertices[-2].co = (vertex[0] + direc[0], vertex[1] + direc[1], vertex[2] + direc[2]) if UseGuides == 0: #____________________________________________________________ #Normal creation routine with gravity, randomdir, etc. #____________________________________________________________ for y in range (s): for z in range(3): randomdir[z] = (random()-.5) * rl vertexold[z] = vertex[z] WindDir[2] += WindDir[0] WindDir[3] += WindDir[1] gravitydir[2] += grav vertex[0] += (vertexno[0]) * l - gravitydir[0] + WindDir[2] + randomdir[0] vertex[1] += (vertexno[1]) * l - gravitydir[1] + WindDir[3] + randomdir[1] vertex[2] += (vertexno[2]) * l - gravitydir[2] + randomdir[2] #____________________________________________________________ #Fix segment length issues with gravity #____________________________________________________________ distance = pow(pow(vertexold[0] - vertex[0],2)+pow(vertexold[1] - vertex[1],2)+pow(vertexold[2] - vertex[2],2),.5) divide = (distance/(l +.001)) #for z in range(3): vertex[0] = (vertex[0]-vertexold[0]) / divide + vertexold[0] vertex[1] = (vertex[1]-vertexold[1]) / divide + vertexold[1] vertex[2] = (vertex[2]-vertexold[2]) / divide + vertexold[2] #____________________________________________________________ already = 0 if pointed == 1 and y == s-1: i += 1 #increment vertex count if firstrun == 0: #Move base verts me.vertices[i-1].co[0] = vertex[0]+direc[0]/2 me.vertices[i-1].co[1] = vertex[1]+direc[1]/2 me.vertices[i-1].co[2] = vertex[2]+direc[2]/2 else: #Create base verts me.vertices.add(1) me.vertices[-1].co = (vertex[0]+direc[0]/2,vertex[1]+direc[1]/2,vertex[2]+direc[2]/2) else: i += 2 #increment vertex count if firstrun == 0: #Move base verts me.vertices[i-2].co[0] = vertex[0] me.vertices[i-2].co[1] = vertex[1] me.vertices[i-2].co[2] = vertex[2] me.vertices[i-1].co[0] = vertex[0]+direc[0] me.vertices[i-1].co[1] = vertex[1]+direc[1] me.vertices[i-1].co[2] = vertex[2]+direc[2] else: #Create base verts me.vertices.add(2) me.vertices[-1].co = (vertex[0],vertex[1],vertex[2]+randomdir[2]) me.vertices[-2].co = (vertex[0]+direc[0],vertex[1]+direc[1],vertex[2]+direc[2]) already = 1 me.tessfaces.add(1) face = me.tessfaces[-1] face.vertices_raw = (i-4, i-2, i-1, i-3) if firstrun == 1: if not(already): me.tessfaces.add(1) face = me.tessfaces[-1] face.vertices = (i-2, i-1, i-3) uv_lay = me.tessface_uv_textures.active if uv_lay == None: uv_lay = me.tessface_uv_textures.new() if uv_lay != None: uv_lay.data[face.index].uv1 = (0,float(y)/s) if pointed == 1 and y == s-1: uv_lay.data[face.index].uv2 = (.5,1) uv_lay.data[face.index].uv3 = (1,float(y)/s) else: uv_lay.data[face.index].uv2 = (0,float(y)/s + (1.0/s)) uv_lay.data[face.index].uv3 = (1,float(y)/s + (1.0/s)) uv_lay.data[face.index].uv4 = (1,float(y)/s) else: #____________________________________________________________ #Use Guides instead of gravity, segment length, etc. (check) #____________________________________________________________ Guide = [] Guide1 = [] Guide2 = [] GuideOBJ = bpy.data.objects.get(original.name+"_Fiber.C") GMat = GuideOBJ.matrix_world gv = Gbm.verts #____________________________________________________________ #Find Closest two fiber guides and store them in c[] (check) #____________________________________________________________ c = [0,CtrlSeg] if fncdistance(multmat(GMat, gv[c[1]]).co, basevertex) < fncdistance(multmat(GMat,gv[c[0]]).co, basevertex): #Swap temp = c[1] c[1] = c[0] c[0] = temp for y in range(CtrlSeg*2,len(gv),CtrlSeg): if fncdistance(multmat(GMat,gv[y]).co,basevertex) < fncdistance(multmat(GMat,gv[c[0]]).co,basevertex): c[1] = c[0] c[0] = y elif fncdistance(multmat(GMat,gv[y]).co,basevertex) < fncdistance(multmat(GMat,gv[c[1]]).co,basevertex): c[1] = y #____________________________________________________________ #Get the coordinates of the guides' control points (check) #____________________________________________________________ Guide0 = [] for y in range(CtrlSeg): Guide1.append ([multmat(GMat,gv[c[0]+y]).co[0],multmat(GMat,gv[c[0]+y]).co[1],multmat(GMat,gv[c[0]+y]).co[2]]) Guide2.append ([multmat(GMat,gv[c[1]+y]).co[0],multmat(GMat,gv[c[1]+y]).co[1],multmat(GMat,gv[c[1]+y]).co[2]]) for y in range(len(Guide1)): Guide0.append([0,0,0]) for z in range(3): Guide0[y][z] = Guide1[y][z] for y in range(1,CtrlSeg): for z in range(3): Guide1[y][z] -= Guide1[0][z] Guide2[y][z] -= Guide2[0][z] #____________________________________________________________ #Determine weight of the two fiber guides () (check) #____________________________________________________________ weight = fncFindWeight(gv[c[0]].co,gv[c[1]].co,vertex) #____________________________________________________________ #Find single, weighted, control fiber (check) #____________________________________________________________ Guide.append ([0,0,0]) for y in range(1,CtrlSeg): Guide.append (fncFindWeightedVert(Guide1[y],Guide2[y],weight)) Flen = SegRnd * random() #print Guide #____________________________________________________________ #Create the Fiber #____________________________________________________________ for y in range(1,s): #____________________________________________________________ #Impliment Wind #____________________________________________________________ WindDir[2] += WindDir[0] WindDir[3] += WindDir[1] for z in range(3): randomdir[z] = (random()-.5) * rl #____________________________________________________________ #Use Bezier interpolation #____________________________________________________________ if CtrlSeg == 3: v = Bezier3(Guide[0],Guide[1],Guide[2],float(y)/s * (1-Flen)) elif CtrlSeg == 4: v = Bezier4(Guide[0],Guide[1],Guide[2],Guide[3],float(y)/s * (1-Flen)) else: v = Bezier(Guide,float(y)/s * (1-Flen)) vertex = [v[0]+basevertex[0],v[1]+basevertex[1],v[2]+basevertex[2]] #____________________________________________________________ #Clumping #____________________________________________________________ if follow != 0: for z in range(1,len(Guide1)): Guide1[z] += Guide0 weight = pow(1-((float(y)/s) * (follow * VcolClump)),Ff) #Ff = Clumpiness Falloff if CtrlSeg == 3: v = Bezier3(Guide0[0],Guide0[1],Guide0[2],float(y)/s * (1-Flen)) #Flen = random fiber length elif CtrlSeg == 4: v = Bezier4(Guide0[0],Guide0[1],Guide0[2],Guide0[3],float(y)/s * (1-Flen)) else: v = Bezier(Guide0,float(y)/s * (1-Flen)) vertex = fncFindWeightedVert(v, vertex, weight) #____________________________________________________________ #Create Verts & Faces #____________________________________________________________ vertex = [vertex[0]+randomdir[0]+WindDir[2],vertex[1]+randomdir[1]+WindDir[3], vertex[2] + randomdir[2]] already = 0 if y == s-1 and pointed == 1: i += 1 if firstrun == 1: me.vertices.add(1) me.vertices[-1].co = (vertex[0] + direc[0]/2, vertex[1] + direc[1]/2, vertex[2] + direc[2]/2) else: me.vertices[i-1].co[0] = vertex[0]+direc[0]/2 me.vertices[i-1].co[1] = vertex[1]+direc[1]/2 me.vertices[i-1].co[2] = vertex[2]+direc[2]/2 else: i +=2 if firstrun == 1: me.vertices.add(2) me.vertices[-1].co = (vertex[0], vertex[1], vertex[2]) me.vertices[-2].co = (vertex[0]+direc[0], vertex[1]+direc[1], vertex[2]+direc[2]) already = 1 me.tessfaces.add(1) face = me.tessfaces[-1] face.vertices_raw = (i-4, i-2, i-1, i-3) else: #Move base verts me.vertices[i-2].co[0] = vertex[0] me.vertices[i-2].co[1] = vertex[1] me.vertices[i-2].co[2] = vertex[2] me.vertices[i-1].co[0] = vertex[0]+direc[0] me.vertices[i-1].co[1] = vertex[1]+direc[1] me.vertices[i-1].co[2] = vertex[2]+direc[2] if firstrun == 1: if not(already): me.tessfaces.add(1) face = me.tessfaces[-1] face.vertices = (i-2, i-1, i-3) uv_lay = me.tessface_uv_textures.active if uv_lay == None: uv_lay = me.tessface_uv_textures.new() if uv_lay != None: uv_lay.data[face.index].uv1 = (0,float(y)/s) if pointed == 1 and y == s-1: uv_lay.data[face.index].uv2 = (.5,1) uv_lay.data[face.index].uv3 = (1,float(y)/s) else: uv_lay.data[face.index].uv2 = (0,float(y)/s + (1.0/s)) uv_lay.data[face.index].uv3 = (1,float(y)/s + (1.0/s)) uv_lay.data[face.index].uv4 = (1,float(y)/s) me.validate() me.update(calc_edges=True, calc_tessface=True) obj = bpy.data.objects.new(name=meshname+"_Fiber."+str(objnum), object_data=me) obj.location = objects[num].location scene = bpy.context.scene scene.objects.link(obj) vertexcount = 0
def set_random_seed(scene): if scene.cycles_random_seed: bpy.context.scene.cycles.seed = noise.random() * 10000 print("New cycles seed", bpy.context.scene.cycles.seed)