disp_paint - was raising an error when the mesh had no image and texuv was selected, or when the image had no data.

discombobulator - updated to use newer API functions
object_random_loc_sz_rot - improved layout and use new Scene objects.context
This commit is contained in:
2007-01-13 02:03:38 +00:00
parent 75161c24c1
commit 0b89910800
3 changed files with 119 additions and 174 deletions

View File

@@ -80,7 +80,7 @@ You can find more information at the Link above.
# > Using the arrow keys will scroll the gui. # > Using the arrow keys will scroll the gui.
# #
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
# Discombobulator v2.1 # Discombobulator v2.1b
# by Evan J. Rosky, 2005 # by Evan J. Rosky, 2005
# This plugin is protected by the GPL: Gnu Public Licence # This plugin is protected by the GPL: Gnu Public Licence
# GPL - http://www.gnu.org/copyleft/gpl.html # GPL - http://www.gnu.org/copyleft/gpl.html
@@ -109,7 +109,7 @@ You can find more information at the Link above.
#Hit Alt-P to run #Hit Alt-P to run
import Blender import Blender
from Blender import NMesh,Object,Material,Window,Types from Blender import NMesh,Object,Material,Window,Types,Scene
from Blender.NMesh import Vert,Face from Blender.NMesh import Vert,Face
from Blender.Mathutils import * from Blender.Mathutils import *
@@ -126,10 +126,7 @@ def randnum(low,high):
return num return num
#Object Vars #Object Vars
origmesh = NMesh.GetRaw()
newmesh = NMesh.GetRaw() newmesh = NMesh.GetRaw()
origobj = Object.Get()
newobj = Object.Get()
materialArray = [0] materialArray = [0]
#Material Vars #Material Vars
@@ -189,20 +186,6 @@ doodadArray = [1,2,3,4,5,6]
SEL = NMesh.FaceFlags['SELECT'] SEL = NMesh.FaceFlags['SELECT']
def isselectedface(theface):
for vertic in theface.v:
if vertic.sel == 0:
return 0
return 1
def arrayInInclusive(start,end):
arr = []
i = start
while i <= end:
arr.append(i)
i = i + 1
return arr
def makeSubfaceArray(): def makeSubfaceArray():
global subfaceArray global subfaceArray
global subface1 global subface1
@@ -243,52 +226,36 @@ def makeDoodadArray():
if doodad6 > 0: if doodad6 > 0:
doodadArray.append(6) doodadArray.append(6)
def copyObjStuff(startObj,endObj):
endObj.setDeltaLocation(startObj.getDeltaLocation())
endObj.setDrawMode(startObj.getDrawMode())
endObj.setDrawType(startObj.getDrawType())
endObj.setEuler(startObj.getEuler())
if(startObj.getIpo() != None):
endObj.setIpo(startObj.getIpo())
endObj.setLocation(startObj.getLocation())
endObj.setMaterials(startObj.getMaterials())
endObj.setMatrix(startObj.getMatrix())
endObj.setSize(startObj.getSize())
endObj.setTimeOffset(startObj.getTimeOffset())
def extrude(mid,nor,protrusion,v1,v2,v3,v4,tosel=1,flipnor=0): def extrude(mid,nor,protrusion,v1,v2,v3,v4,tosel=1,flipnor=0):
taper = 1 - randnum(minimumtaperpercent,maximumtaperpercent) taper = 1 - randnum(minimumtaperpercent,maximumtaperpercent)
newmesh_verts = newmesh.verts
newmesh_faces = newmesh.faces
vert = newmesh.verts[v1] vert = newmesh_verts[v1]
point = (vert.co - mid)*taper + mid + protrusion*Vector(nor) point = (vert.co - mid)*taper + mid + protrusion*Vector(nor)
ver = Vert(point[0],point[1],point[2]) ver = Vert(point[0],point[1],point[2])
ver.sel = tosel ver.sel = tosel
newmesh.verts.append(ver) newmesh_verts.append(ver)
vert = newmesh.verts[v2] vert = newmesh_verts[v2]
point = (vert.co - mid)*taper + mid + protrusion*Vector(nor) point = (vert.co - mid)*taper + mid + protrusion*Vector(nor)
ver = Vert(point[0],point[1],point[2]) ver = Vert(point[0],point[1],point[2])
ver.sel = tosel ver.sel = tosel
newmesh.verts.append(ver) newmesh_verts.append(ver)
vert = newmesh.verts[v3] vert = newmesh_verts[v3]
point = (vert.co - mid)*taper + mid + protrusion*Vector(nor) point = (vert.co - mid)*taper + mid + protrusion*Vector(nor)
ver = Vert(point[0],point[1],point[2]) ver = Vert(point[0],point[1],point[2])
ver.sel = tosel ver.sel = tosel
newmesh.verts.append(ver) newmesh_verts.append(ver)
vert = newmesh.verts[v4] vert = newmesh_verts[v4]
point = (vert.co - mid)*taper + mid + protrusion*Vector(nor) point = (vert.co - mid)*taper + mid + protrusion*Vector(nor)
ver = Vert(point[0],point[1],point[2]) ver = Vert(point[0],point[1],point[2])
ver.sel = tosel ver.sel = tosel
newmesh.verts.append(ver) newmesh_verts.append(ver)
faceindex = len(newmesh.verts) - 4 faceindex = len(newmesh_verts) - 4
#side face 1 #side face 1
face = Face() face = Face([newmesh_verts[v1], newmesh_verts[v2], newmesh_verts[faceindex+1], newmesh_verts[faceindex]])
face.v.append(newmesh.verts[v1])
face.v.append(newmesh.verts[v2])
face.v.append(newmesh.verts[faceindex+1])
face.v.append(newmesh.verts[faceindex])
if flipnor != 0: if flipnor != 0:
face.v.reverse() face.v.reverse()
if thereAreMats == 1: if thereAreMats == 1:
@@ -296,14 +263,10 @@ def extrude(mid,nor,protrusion,v1,v2,v3,v4,tosel=1,flipnor=0):
face.materialIndex = currmat face.materialIndex = currmat
else: else:
face.materialIndex = protSideMat-1 face.materialIndex = protSideMat-1
newmesh.faces.append(face) newmesh_faces.append(face)
#side face 2 #side face 2
face = Face() face = Face([newmesh_verts[v2], newmesh_verts[v3], newmesh_verts[faceindex+2], newmesh_verts[faceindex+1]])
face.v.append(newmesh.verts[v2])
face.v.append(newmesh.verts[v3])
face.v.append(newmesh.verts[faceindex+2])
face.v.append(newmesh.verts[faceindex+1])
if flipnor != 0: if flipnor != 0:
face.v.reverse() face.v.reverse()
if thereAreMats == 1: if thereAreMats == 1:
@@ -311,14 +274,10 @@ def extrude(mid,nor,protrusion,v1,v2,v3,v4,tosel=1,flipnor=0):
face.materialIndex = currmat face.materialIndex = currmat
else: else:
face.materialIndex = protSideMat-1 face.materialIndex = protSideMat-1
newmesh.faces.append(face) newmesh_faces.append(face)
#side face 3 #side face 3
face = Face() face = Face([newmesh_verts[v3], newmesh_verts[v4], newmesh_verts[faceindex+3], newmesh_verts[faceindex+2]])
face.v.append(newmesh.verts[v3])
face.v.append(newmesh.verts[v4])
face.v.append(newmesh.verts[faceindex+3])
face.v.append(newmesh.verts[faceindex+2])
if flipnor != 0: if flipnor != 0:
face.v.reverse() face.v.reverse()
if thereAreMats == 1: if thereAreMats == 1:
@@ -326,14 +285,10 @@ def extrude(mid,nor,protrusion,v1,v2,v3,v4,tosel=1,flipnor=0):
face.materialIndex = currmat face.materialIndex = currmat
else: else:
face.materialIndex = protSideMat-1 face.materialIndex = protSideMat-1
newmesh.faces.append(face) newmesh_faces.append(face)
#side face 4 #side face 4
face = Face() face = Face([newmesh_verts[v4], newmesh_verts[v1], newmesh_verts[faceindex], newmesh_verts[faceindex+3]])
face.v.append(newmesh.verts[v4])
face.v.append(newmesh.verts[v1])
face.v.append(newmesh.verts[faceindex])
face.v.append(newmesh.verts[faceindex+3])
if flipnor != 0: if flipnor != 0:
face.v.reverse() face.v.reverse()
if thereAreMats == 1: if thereAreMats == 1:
@@ -341,11 +296,10 @@ def extrude(mid,nor,protrusion,v1,v2,v3,v4,tosel=1,flipnor=0):
face.materialIndex = currmat face.materialIndex = currmat
else: else:
face.materialIndex = protSideMat-1 face.materialIndex = protSideMat-1
newmesh.faces.append(face) newmesh_faces.append(face)
#top face #top face
face = Face() face = Face(newmesh_verts[-4:])
face.v = newmesh.verts[-4:]
if flipnor != 0: if flipnor != 0:
face.v.reverse() face.v.reverse()
if tosel == 1: if tosel == 1:
@@ -355,7 +309,7 @@ def extrude(mid,nor,protrusion,v1,v2,v3,v4,tosel=1,flipnor=0):
face.materialIndex = currmat face.materialIndex = currmat
else: else:
face.materialIndex = protTopMat-1 face.materialIndex = protTopMat-1
newmesh.faces.append(face) newmesh_faces.append(face)
return face return face
#Sets the global protrusion values #Sets the global protrusion values
@@ -551,9 +505,8 @@ def discombobulate():
global thereAreMats global thereAreMats
global currmat global currmat
try: origobj = Scene.GetCurrent().objects.active
origobj = Object.GetSelected()[0] if not origobj:
except:
glRasterPos2d(10,50) glRasterPos2d(10,50)
errortext = "YOU MUST SELECT AN OBJECT!" errortext = "YOU MUST SELECT AN OBJECT!"
messagetext = ErrorText(errortext) messagetext = ErrorText(errortext)
@@ -565,16 +518,17 @@ def discombobulate():
if editmode: Window.EditMode(0) if editmode: Window.EditMode(0)
#Get Major Variables #Get Major Variables
newobj = Object.Get()
origmesh = origobj.getData() origmesh = origobj.getData()
if type(origmesh) != Types.NMeshType:
if origobj.type != 'Mesh':
glRasterPos2d(10,50) glRasterPos2d(10,50)
errortext = "OBJECT MUST BE MESH!" errortext = "OBJECT MUST BE MESH!"
messagetext = ErrorText(errortext) messagetext = ErrorText(errortext)
Blender.Redraw() Blender.Redraw()
return return
newmesh = NMesh.GetRaw() newmesh = NMesh.GetRaw()
newmesh.verts = []
materialArray = origmesh.getMaterials() materialArray = origmesh.getMaterials()
if len(materialArray) < 1: if len(materialArray) < 1:
thereAreMats = 0 thereAreMats = 0
@@ -597,7 +551,7 @@ def discombobulate():
#This only does something if there are less than 4 verts #This only does something if there are less than 4 verts
for matind in [protSideMat,protTopMat,doodSideMat,doodTopMat]: for matind in [protSideMat,protTopMat,doodSideMat,doodTopMat]:
if matind > len(materialArray) and matind <= 4: if matind > len(materialArray) and matind <= 4:
for i in arrayInInclusive(len(materialArray),matind): for i in xrange(len(materialArray),matind+1):
materialArray.append(Material.New("AddedMat " + str(i))) materialArray.append(Material.New("AddedMat " + str(i)))
#Sets the materials #Sets the materials
@@ -617,8 +571,7 @@ def discombobulate():
#Check if it is a triangle #Check if it is a triangle
if len(currface.v)<4: if len(currface.v)<4:
face = Face() face = Face([newmesh.verts[currface.v[0].index],newmesh.verts[currface.v[1].index],newmesh.verts[currface.v[2].index]])
face.v.extend([newmesh.verts[currface.v[0].index],newmesh.verts[currface.v[1].index],newmesh.verts[currface.v[2].index]])
if thereAreMats == 1: if thereAreMats == 1:
face.materialIndex = currmat face.materialIndex = currmat
newmesh.faces.append(face) newmesh.faces.append(face)
@@ -626,8 +579,7 @@ def discombobulate():
#Check whether or not to make protrusions #Check whether or not to make protrusions
if makeprots == 0: if makeprots == 0:
face = Face() face = Face([newmesh.verts[currface.v[0].index],newmesh.verts[currface.v[1].index],newmesh.verts[currface.v[2].index],newmesh.verts[currface.v[3].index]])
face.v.extend([newmesh.verts[currface.v[0].index],newmesh.verts[currface.v[1].index],newmesh.verts[currface.v[2].index],newmesh.verts[currface.v[3].index]])
if thereAreMats == 1: if thereAreMats == 1:
face.materialIndex = currmat face.materialIndex = currmat
newmesh.faces.append(face) newmesh.faces.append(face)
@@ -651,8 +603,7 @@ def discombobulate():
if currface.sel: if currface.sel:
a = 1 a = 1
else: else:
face = Face() face = Face([newmesh.verts[currface.v[0].index],newmesh.verts[currface.v[1].index],newmesh.verts[currface.v[2].index],newmesh.verts[currface.v[3].index]])
face.v.extend([newmesh.verts[currface.v[0].index],newmesh.verts[currface.v[1].index],newmesh.verts[currface.v[2].index],newmesh.verts[currface.v[3].index]])
if thereAreMats == 1: if thereAreMats == 1:
face.materialIndex = currmat face.materialIndex = currmat
newmesh.faces.append(face) newmesh.faces.append(face)
@@ -665,8 +616,7 @@ def discombobulate():
continue continue
#Check if face should be modified by random chance #Check if face should be modified by random chance
if randnum(0,1)>faceschangedpercent: if randnum(0,1)>faceschangedpercent:
face = Face() face = Face([newmesh.verts[currface.v[0].index],newmesh.verts[currface.v[1].index],newmesh.verts[currface.v[2].index],newmesh.verts[currface.v[3].index]])
face.v.extend([newmesh.verts[currface.v[0].index],newmesh.verts[currface.v[1].index],newmesh.verts[currface.v[2].index],newmesh.verts[currface.v[3].index]])
if thereAreMats == 1: if thereAreMats == 1:
face.materialIndex = currmat face.materialIndex = currmat
newmesh.faces.append(face) newmesh.faces.append(face)
@@ -687,7 +637,7 @@ def discombobulate():
center = Vector([0,0,0]) center = Vector([0,0,0])
for pt in currface.v: for pt in currface.v:
center = center + pt.co center = center + pt.co
center = divideVectorByInt(center,len(currface.v)) center = center / len(currface.v)
#Determine amount of subfaces #Determine amount of subfaces
subfaces = round(randnum(1,len(subfaceArray)),0) subfaces = round(randnum(1,len(subfaceArray)),0)
@@ -715,7 +665,7 @@ def discombobulate():
orientation = int(round(randnum(0,1))) orientation = int(round(randnum(0,1)))
p1 = currface.v[orientation] p1 = currface.v[orientation]
p2 = currface.v[orientation + 1] p2 = currface.v[orientation + 1]
p3 = divideVectorByInt((p2.co - p1.co),2) + p1.co p3 = ((p2.co - p1.co)/2) + p1.co
ve1 = Vert(p3[0],p3[1],p3[2]) ve1 = Vert(p3[0],p3[1],p3[2])
ve1.sel = 0 ve1.sel = 0
p1 = currface.v[2 + orientation] p1 = currface.v[2 + orientation]
@@ -723,7 +673,7 @@ def discombobulate():
p2 = currface.v[3] p2 = currface.v[3]
else: else:
p2 = currface.v[0] p2 = currface.v[0]
p3 = divideVectorByInt((p2.co - p1.co),2) + p1.co p3 = ((p2.co - p1.co)/2) + p1.co
ve2 = Vert(p3[0],p3[1],p3[2]) ve2 = Vert(p3[0],p3[1],p3[2])
ve2.sel = 0 ve2.sel = 0
if orientation < 0.5: if orientation < 0.5:
@@ -747,8 +697,8 @@ def discombobulate():
v3 = index v3 = index
center = Vector([0, 0, 0]) center = Vector([0, 0, 0])
for pt in [newmesh.verts[v1],newmesh.verts[v2],newmesh.verts[v3],newmesh.verts[v4]]: for pt in [newmesh.verts[v1],newmesh.verts[v2],newmesh.verts[v3],newmesh.verts[v4]]:
center = center + pt.co center += pt.co
center = divideVectorByInt(center,4) center = center/4
prot = randnum(minimumheight,maximumheight) prot = randnum(minimumheight,maximumheight)
tempface = extrude(center,currface.no,prot,v1,v2,v3,v4,selectface2) tempface = extrude(center,currface.no,prot,v1,v2,v3,v4,selectface2)
if makedoodads == 1: if makedoodads == 1:
@@ -779,8 +729,8 @@ def discombobulate():
v2 = p3 v2 = p3
center = Vector([0]*3) center = Vector([0]*3)
for pt in [newmesh.verts[v1],newmesh.verts[v2],newmesh.verts[v3],newmesh.verts[v4]]: for pt in [newmesh.verts[v1],newmesh.verts[v2],newmesh.verts[v3],newmesh.verts[v4]]:
center = center + pt.co center += pt.co
center = divideVectorByInt(center,4) center = center/4
prot = randnum(minimumheight,maximumheight) prot = randnum(minimumheight,maximumheight)
tempface = extrude(center,currface.no,prot,v1,v2,v4,v3,selectface2) tempface = extrude(center,currface.no,prot,v1,v2,v4,v3,selectface2)
if makedoodads == 1: if makedoodads == 1:
@@ -796,16 +746,14 @@ def discombobulate():
newmesh.verts.extend(tempmesh.verts) newmesh.verts.extend(tempmesh.verts)
newmesh.faces.extend(tempmesh.faces) newmesh.faces.extend(tempmesh.faces)
if orientation < 0.5: if orientation < 0.5:
face = Face() face = Face([newmesh.verts[p0],newmesh.verts[p1],newmesh.verts[v3]])
face.v.extend([newmesh.verts[p0],newmesh.verts[p1],newmesh.verts[v3]])
if thereAreMats == 1: if thereAreMats == 1:
if reassignMats == 0 or protSideMat == 0: if reassignMats == 0 or protSideMat == 0:
face.materialIndex = currmat face.materialIndex = currmat
else: else:
face.materialIndex = protSideMat-1 face.materialIndex = protSideMat-1
newmesh.faces.append(face) newmesh.faces.append(face)
face = Face() face = Face([newmesh.verts[p2],newmesh.verts[p3],newmesh.verts[v4]])
face.v.extend([newmesh.verts[p2],newmesh.verts[p3],newmesh.verts[v4]])
if thereAreMats == 1: if thereAreMats == 1:
if reassignMats == 0 or protSideMat == 0: if reassignMats == 0 or protSideMat == 0:
face.materialIndex = currmat face.materialIndex = currmat
@@ -813,16 +761,14 @@ def discombobulate():
face.materialIndex = protSideMat-1 face.materialIndex = protSideMat-1
newmesh.faces.append(face) newmesh.faces.append(face)
else: else:
face = Face() face = Face([newmesh.verts[p1],newmesh.verts[p2],newmesh.verts[v3]])
face.v.extend([newmesh.verts[p1],newmesh.verts[p2],newmesh.verts[v3]])
if thereAreMats == 1: if thereAreMats == 1:
if reassignMats == 0 or protSideMat == 0: if reassignMats == 0 or protSideMat == 0:
face.materialIndex = currmat face.materialIndex = currmat
else: else:
face.materialIndex = protSideMat-1 face.materialIndex = protSideMat-1
newmesh.faces.append(face) newmesh.faces.append(face)
face = Face() face = Face([newmesh.verts[p3],newmesh.verts[p0],newmesh.verts[v4]])
face.v.extend([newmesh.verts[p3],newmesh.verts[p0],newmesh.verts[v4]])
if thereAreMats == 1: if thereAreMats == 1:
if reassignMats == 0 or protSideMat == 0: if reassignMats == 0 or protSideMat == 0:
face.materialIndex = currmat face.materialIndex = currmat
@@ -837,7 +783,7 @@ def discombobulate():
rotation = int(round(randnum(0,1))) rotation = int(round(randnum(0,1)))
p1 = currface.v[orientation] p1 = currface.v[orientation]
p2 = currface.v[orientation + 1] p2 = currface.v[orientation + 1]
p3 = divideVectorByInt((p2.co - p1.co),2) + p1.co p3 = ((p2.co - p1.co)/2) + p1.co
ve1 = Vert(p3[0],p3[1],p3[2]) ve1 = Vert(p3[0],p3[1],p3[2])
ve1.sel = 0 ve1.sel = 0
p1 = currface.v[2 + orientation] p1 = currface.v[2 + orientation]
@@ -845,7 +791,7 @@ def discombobulate():
p2 = currface.v[3] p2 = currface.v[3]
else: else:
p2 = currface.v[0] p2 = currface.v[0]
p3 = divideVectorByInt((p2.co - p1.co),2) + p1.co p3 = ((p2.co - p1.co)/2) + p1.co
ve2 = Vert(p3[0],p3[1],p3[2]) ve2 = Vert(p3[0],p3[1],p3[2])
ve2.sel = 0 ve2.sel = 0
fp = [] fp = []
@@ -875,8 +821,8 @@ def discombobulate():
v3 = index v3 = index
center = Vector([0]*3) center = Vector([0]*3)
for pt in [newmesh.verts[v1],newmesh.verts[v2],newmesh.verts[v3],newmesh.verts[v4]]: for pt in [newmesh.verts[v1],newmesh.verts[v2],newmesh.verts[v3],newmesh.verts[v4]]:
center = center + pt.co center += pt.co
center = divideVectorByInt(center,4) center = center/4
prot = randnum(minimumheight,maximumheight) prot = randnum(minimumheight,maximumheight)
layer2inds.extend([v3,v4]) layer2inds.extend([v3,v4])
tempface = extrude(center,currface.no,prot,v1,v2,v3,v4,selectface3) tempface = extrude(center,currface.no,prot,v1,v2,v3,v4,selectface3)
@@ -917,8 +863,8 @@ def discombobulate():
v3 = index + 1 v3 = index + 1
center = Vector([0]*3) center = Vector([0]*3)
for pt in [newmesh.verts[v1],newmesh.verts[v2],newmesh.verts[v3],newmesh.verts[v4]]: for pt in [newmesh.verts[v1],newmesh.verts[v2],newmesh.verts[v3],newmesh.verts[v4]]:
center = center + pt.co center += pt.co
center = divideVectorByInt(center,4) center = center/4
prot = randnum(minimumheight,maximumheight) prot = randnum(minimumheight,maximumheight)
layer2inds.extend([index, index +1]) layer2inds.extend([index, index +1])
tempface = extrude(center,currface.no,prot,v1,v2,v4,v3,selectface3) tempface = extrude(center,currface.no,prot,v1,v2,v4,v3,selectface3)
@@ -938,12 +884,12 @@ def discombobulate():
#split next rect(pre-arranged, no orientation crud)--make flag in extruder for only one existing vert in mesh #split next rect(pre-arranged, no orientation crud)--make flag in extruder for only one existing vert in mesh
p1 = newmesh.verts[layer2inds[0]] p1 = newmesh.verts[layer2inds[0]]
p2 = newmesh.verts[layer2inds[1]] p2 = newmesh.verts[layer2inds[1]]
p3 = divideVectorByInt((p2.co - p1.co),2) + p1.co p3 = ((p2.co - p1.co)/2) + p1.co
ve3 = Vert(p3[0],p3[1],p3[2]) ve3 = Vert(p3[0],p3[1],p3[2])
ve3.sel = 0 ve3.sel = 0
p1 = layer2verts[0] p1 = layer2verts[0]
p2 = layer2verts[1] p2 = layer2verts[1]
p3 = divideVectorByInt((p2.co - p1.co),2) + p1.co p3 = ((p2.co - p1.co)/2) + p1.co
ve4 = Vert(p3[0],p3[1],p3[2]) ve4 = Vert(p3[0],p3[1],p3[2])
ve4.sel = 0 ve4.sel = 0
newmesh.verts.append(ve3) newmesh.verts.append(ve3)
@@ -955,8 +901,8 @@ def discombobulate():
t0 = verti.index t0 = verti.index
center = Vector([0]*3) center = Vector([0]*3)
for pt in [newmesh.verts[v5],newmesh.verts[v6],newmesh.verts[t0],newmesh.verts[v3]]: for pt in [newmesh.verts[v5],newmesh.verts[v6],newmesh.verts[t0],newmesh.verts[v3]]:
center = center + pt.co center += pt.co
center = divideVectorByInt(center,4) center = center/4
prot = randnum(minimumheight,maximumheight) prot = randnum(minimumheight,maximumheight)
if rotation < 0.5: flino = 1 if rotation < 0.5: flino = 1
else: flino = 0 else: flino = 0
@@ -973,9 +919,8 @@ def discombobulate():
newmesh.verts.extend(tempmesh.verts) newmesh.verts.extend(tempmesh.verts)
newmesh.faces.extend(tempmesh.faces) newmesh.faces.extend(tempmesh.faces)
if rotation < 0.5: if rotation < 0.5:
face = Face()
fpt = t0 fpt = t0
face.v.extend([newmesh.verts[fp[1]],newmesh.verts[fpt],newmesh.verts[v3]]) face = Face([newmesh.verts[fp[1]],newmesh.verts[fpt],newmesh.verts[v3]])
if thereAreMats == 1: if thereAreMats == 1:
if reassignMats == 0 or protSideMat == 0: if reassignMats == 0 or protSideMat == 0:
face.materialIndex = currmat face.materialIndex = currmat
@@ -983,9 +928,8 @@ def discombobulate():
face.materialIndex = protSideMat-1 face.materialIndex = protSideMat-1
newmesh.faces.append(face) newmesh.faces.append(face)
else: else:
face = Face()
fpt = t0 fpt = t0
face.v.extend([newmesh.verts[fp[0]],newmesh.verts[v3],newmesh.verts[fpt]]) face = Face([newmesh.verts[fp[0]],newmesh.verts[v3],newmesh.verts[fpt]])
if thereAreMats == 1: if thereAreMats == 1:
if reassignMats == 0 or protSideMat == 0: if reassignMats == 0 or protSideMat == 0:
face.materialIndex = currmat face.materialIndex = currmat
@@ -996,8 +940,8 @@ def discombobulate():
tempindex = verti.index tempindex = verti.index
center = Vector([0]*3) center = Vector([0]*3)
for pt in [newmesh.verts[v5],newmesh.verts[v6],newmesh.verts[tempindex],newmesh.verts[v4]]: for pt in [newmesh.verts[v5],newmesh.verts[v6],newmesh.verts[tempindex],newmesh.verts[v4]]:
center = center + pt.co center += pt.co
center = divideVectorByInt(center,4) center = center/4
prot = randnum(minimumheight,maximumheight) prot = randnum(minimumheight,maximumheight)
tempface = extrude(center,currface.no,prot,v6,v5,v4,tempindex,selectface3,flino) tempface = extrude(center,currface.no,prot,v6,v5,v4,tempindex,selectface3,flino)
if makedoodads == 1: if makedoodads == 1:
@@ -1013,16 +957,14 @@ def discombobulate():
newmesh.verts.extend(tempmesh.verts) newmesh.verts.extend(tempmesh.verts)
newmesh.faces.extend(tempmesh.faces) newmesh.faces.extend(tempmesh.faces)
if rotation < 0.5: if rotation < 0.5:
face = Face() face = Face([newmesh.verts[tempindex],newmesh.verts[fp[0]],newmesh.verts[v4]])
face.v.extend([newmesh.verts[tempindex],newmesh.verts[fp[0]],newmesh.verts[v4]])
if thereAreMats == 1: if thereAreMats == 1:
if reassignMats == 0 or protSideMat == 0: if reassignMats == 0 or protSideMat == 0:
face.materialIndex = currmat face.materialIndex = currmat
else: else:
face.materialIndex = protSideMat-1 face.materialIndex = protSideMat-1
newmesh.faces.append(face) newmesh.faces.append(face)
face = Face() face = Face([newmesh.verts[fpt],newmesh.verts[tempindex],newmesh.verts[v6]])
face.v.extend([newmesh.verts[fpt],newmesh.verts[tempindex],newmesh.verts[v6]])
if thereAreMats == 1: if thereAreMats == 1:
if reassignMats == 0 or protSideMat == 0: if reassignMats == 0 or protSideMat == 0:
face.materialIndex = currmat face.materialIndex = currmat
@@ -1030,16 +972,14 @@ def discombobulate():
face.materialIndex = protSideMat-1 face.materialIndex = protSideMat-1
newmesh.faces.append(face) newmesh.faces.append(face)
else: else:
face = Face() face = Face([newmesh.verts[tempindex],newmesh.verts[v4],newmesh.verts[fp[1]]])
face.v.extend([newmesh.verts[tempindex],newmesh.verts[v4],newmesh.verts[fp[1]]])
if thereAreMats == 1: if thereAreMats == 1:
if reassignMats == 0 or protSideMat == 0: if reassignMats == 0 or protSideMat == 0:
face.materialIndex = currmat face.materialIndex = currmat
else: else:
face.materialIndex = protSideMat-1 face.materialIndex = protSideMat-1
newmesh.faces.append(face) newmesh.faces.append(face)
face = Face() face = Face([newmesh.verts[tempindex],newmesh.verts[fpt],newmesh.verts[v6]])
face.v.extend([newmesh.verts[tempindex],newmesh.verts[fpt],newmesh.verts[v6]])
if thereAreMats == 1: if thereAreMats == 1:
if reassignMats == 0 or protSideMat == 0: if reassignMats == 0 or protSideMat == 0:
face.materialIndex = currmat face.materialIndex = currmat
@@ -1055,29 +995,29 @@ def discombobulate():
verti = currface.v[1] verti = currface.v[1]
p1 = verti.index p1 = verti.index
pt = divideVectorByInt((newmesh.verts[p1].co - newmesh.verts[p0].co),2) + newmesh.verts[p0].co pt = ((newmesh.verts[p1].co - newmesh.verts[p0].co)/2) + newmesh.verts[p0].co
v1 = Vert(pt[0],pt[1],pt[2]) v1 = Vert(pt[0],pt[1],pt[2])
v1.sel = 0 v1.sel = 0
verti = currface.v[2] verti = currface.v[2]
p2 = verti.index p2 = verti.index
pt = divideVectorByInt((newmesh.verts[p2].co - newmesh.verts[p1].co),2) + newmesh.verts[p1].co pt = ((newmesh.verts[p2].co - newmesh.verts[p1].co)/2) + newmesh.verts[p1].co
v2 = Vert(pt[0],pt[1],pt[2]) v2 = Vert(pt[0],pt[1],pt[2])
v2.sel = 0 v2.sel = 0
verti = currface.v[3] verti = currface.v[3]
p3 = verti.index p3 = verti.index
pt = divideVectorByInt((newmesh.verts[p3].co - newmesh.verts[p2].co),2) + newmesh.verts[p2].co pt = ((newmesh.verts[p3].co - newmesh.verts[p2].co)/2) + newmesh.verts[p2].co
v3 = Vert(pt[0],pt[1],pt[2]) v3 = Vert(pt[0],pt[1],pt[2])
v3.sel = 0 v3.sel = 0
pt = divideVectorByInt((newmesh.verts[p0].co - newmesh.verts[p3].co),2) + newmesh.verts[p3].co pt = ((newmesh.verts[p0].co - newmesh.verts[p3].co)/2) + newmesh.verts[p3].co
v4 = Vert(pt[0],pt[1],pt[2]) v4 = Vert(pt[0],pt[1],pt[2])
v4.sel = 0 v4.sel = 0
pt = divideVectorByInt((v3.co - v1.co),2) + v1.co pt = ((v3.co - v1.co)/2) + v1.co
m = Vert(pt[0],pt[1],pt[2]) m = Vert(pt[0],pt[1],pt[2])
m.sel = 0 m.sel = 0
@@ -1089,8 +1029,8 @@ def discombobulate():
v4 = index + 2 v4 = index + 2
center = Vector([0]*3) center = Vector([0]*3)
for pt in [newmesh.verts[p0],newmesh.verts[v1],newmesh.verts[m],newmesh.verts[v4]]: for pt in [newmesh.verts[p0],newmesh.verts[v1],newmesh.verts[m],newmesh.verts[v4]]:
center = center + pt.co center += pt.co
center = divideVectorByInt(center,4) center = center/4
prot = randnum(minimumheight,maximumheight) prot = randnum(minimumheight,maximumheight)
tempface = extrude(center,currface.no,prot,p0,v1,m,v4,selectface4) tempface = extrude(center,currface.no,prot,p0,v1,m,v4,selectface4)
if makedoodads == 1: if makedoodads == 1:
@@ -1112,8 +1052,8 @@ def discombobulate():
v2 = index v2 = index
center = Vector([0]*3) center = Vector([0]*3)
for pt in [newmesh.verts[m],newmesh.verts[v1],newmesh.verts[p1],newmesh.verts[v2]]: for pt in [newmesh.verts[m],newmesh.verts[v1],newmesh.verts[p1],newmesh.verts[v2]]:
center = center + pt.co center += pt.co
center = divideVectorByInt(center,4) center = center/4
prot = randnum(minimumheight,maximumheight) prot = randnum(minimumheight,maximumheight)
tempface = extrude(center,currface.no,prot,m,v1,p1,v2,selectface4) tempface = extrude(center,currface.no,prot,m,v1,p1,v2,selectface4)
if makedoodads == 1: if makedoodads == 1:
@@ -1135,8 +1075,8 @@ def discombobulate():
v3 = index v3 = index
center = Vector([0]*3) center = Vector([0]*3)
for pt in [newmesh.verts[m],newmesh.verts[v2],newmesh.verts[p2],newmesh.verts[v3]]: for pt in [newmesh.verts[m],newmesh.verts[v2],newmesh.verts[p2],newmesh.verts[v3]]:
center = center + pt.co center += pt.co
center = divideVectorByInt(center,4) center = center/4
prot = randnum(minimumheight,maximumheight) prot = randnum(minimumheight,maximumheight)
tempface = extrude(center,currface.no,prot,m,v2,p2,v3,selectface4) tempface = extrude(center,currface.no,prot,m,v2,p2,v3,selectface4)
if makedoodads == 1: if makedoodads == 1:
@@ -1155,8 +1095,8 @@ def discombobulate():
#extrusion 4 #extrusion 4
center = Vector([0]*3) center = Vector([0]*3)
for pt in [newmesh.verts[m],newmesh.verts[v3],newmesh.verts[p3],newmesh.verts[v4]]: for pt in [newmesh.verts[m],newmesh.verts[v3],newmesh.verts[p3],newmesh.verts[v4]]:
center = center + pt.co center += pt.co
center = divideVectorByInt(center,4) center = center/4
prot = randnum(minimumheight,maximumheight) prot = randnum(minimumheight,maximumheight)
tempface = extrude(center,currface.no,prot,v4,m,v3,p3,selectface4) tempface = extrude(center,currface.no,prot,v4,m,v3,p3,selectface4)
if makedoodads == 1: if makedoodads == 1:
@@ -1172,32 +1112,28 @@ def discombobulate():
newmesh.verts.extend(tempmesh.verts) newmesh.verts.extend(tempmesh.verts)
newmesh.faces.extend(tempmesh.faces) newmesh.faces.extend(tempmesh.faces)
face = Face() face = Face([newmesh.verts[p0],newmesh.verts[p1],newmesh.verts[v1]])
face.v.extend([newmesh.verts[p0],newmesh.verts[p1],newmesh.verts[v1]])
if thereAreMats == 1: if thereAreMats == 1:
if reassignMats == 0 or protSideMat == 0: if reassignMats == 0 or protSideMat == 0:
face.materialIndex = currmat face.materialIndex = currmat
else: else:
face.materialIndex = protSideMat-1 face.materialIndex = protSideMat-1
newmesh.faces.append(face) newmesh.faces.append(face)
face = Face() face = Face([newmesh.verts[p1],newmesh.verts[p2],newmesh.verts[v2]])
face.v.extend([newmesh.verts[p1],newmesh.verts[p2],newmesh.verts[v2]])
if thereAreMats == 1: if thereAreMats == 1:
if reassignMats == 0 or protSideMat == 0: if reassignMats == 0 or protSideMat == 0:
face.materialIndex = currmat face.materialIndex = currmat
else: else:
face.materialIndex = protSideMat-1 face.materialIndex = protSideMat-1
newmesh.faces.append(face) newmesh.faces.append(face)
face = Face() face = Face([newmesh.verts[p2],newmesh.verts[p3],newmesh.verts[v3]])
face.v.extend([newmesh.verts[p2],newmesh.verts[p3],newmesh.verts[v3]])
if thereAreMats == 1: if thereAreMats == 1:
if reassignMats == 0 or protSideMat == 0: if reassignMats == 0 or protSideMat == 0:
face.materialIndex = currmat face.materialIndex = currmat
else: else:
face.materialIndex = protSideMat-1 face.materialIndex = protSideMat-1
newmesh.faces.append(face) newmesh.faces.append(face)
face = Face() face = Face([newmesh.verts[p3],newmesh.verts[p0],newmesh.verts[v4]])
face.v.extend([newmesh.verts[p3],newmesh.verts[p0],newmesh.verts[v4]])
if thereAreMats == 1: if thereAreMats == 1:
if reassignMats == 0 or protSideMat == 0: if reassignMats == 0 or protSideMat == 0:
face.materialIndex = currmat face.materialIndex = currmat
@@ -1210,25 +1146,17 @@ def discombobulate():
for unvert in origmesh.verts: for unvert in origmesh.verts:
newmesh.verts[unvert.index].sel = 0 newmesh.verts[unvert.index].sel = 0
if makenewobj == 1: if makenewobj == 1:
newobj = Object.New('Mesh') newobj = origobj.__copy__()
newobj.link(newmesh) newobj.link(newmesh)
copyObjStuff(origobj,newobj) scene = Blender.Scene.GetCurrent()
scene = Blender.Scene.getCurrent() scene.objects.link(newobj)
scene.link(newobj) origobj.sel = 0
origobj.select(0)
newobj.select(1)
else: else:
origobj.link(newmesh) origobj.link(newmesh)
#Return to Editmode if previously in it #Return to Editmode if previously in it
if editmode: Window.EditMode(1) if editmode: Window.EditMode(1)
def divideVectorByInt(thevect,theint):
thevect.x = thevect.x/theint
thevect.y = thevect.y/theint
thevect.z = thevect.z/theint
return thevect
####################### gui ###################### ####################### gui ######################
from Blender.BGL import * from Blender.BGL import *
from Blender.Draw import * from Blender.Draw import *
@@ -1410,7 +1338,7 @@ def draw():
glClear(GL_COLOR_BUFFER_BIT) glClear(GL_COLOR_BUFFER_BIT)
glColor3f(0.0,0.0,0.0) glColor3f(0.0,0.0,0.0)
glRasterPos2d(8+wadd, thadd+hadd) glRasterPos2d(8+wadd, thadd+hadd)
Text("Discombobulator v2.1") Text("Discombobulator v2.1b")
#Protrusion #Protrusion
colorbox(8+pwadd+wadd,150+phadd+hadd,312+pwadd+wadd,phadd-5+hadd) colorbox(8+pwadd+wadd,150+phadd+hadd,312+pwadd+wadd,phadd-5+hadd)
@@ -1426,34 +1354,45 @@ def draw():
glColor3f(0.0,0.0,0.0) glColor3f(0.0,0.0,0.0)
glRasterPos2d(12+pwadd+wadd, 80+phadd+hadd) glRasterPos2d(12+pwadd+wadd, 80+phadd+hadd)
Text("Protrusion Properties:") Text("Protrusion Properties:")
BeginAlign()
minheight = Number("Min Height: ",EVENT_NONE,12+pwadd+wadd,57+phadd+hadd,145,18,minheight.val,-100.0,100.0,"Minimum height of any protrusion") minheight = Number("Min Height: ",EVENT_NONE,12+pwadd+wadd,57+phadd+hadd,145,18,minheight.val,-100.0,100.0,"Minimum height of any protrusion")
maxheight = Number("Max Height: ",EVENT_NONE,162+pwadd+wadd,57+phadd+hadd,145,18,maxheight.val,-100.0,100.0,"Maximum height of any protrusion") maxheight = Number("Max Height: ",EVENT_NONE,162+pwadd+wadd,57+phadd+hadd,145,18,maxheight.val,-100.0,100.0,"Maximum height of any protrusion")
EndAlign()
BeginAlign()
mintaper = Number("Min Taper %: ",EVENT_NONE,12+pwadd+wadd,37+phadd+hadd,145,18,mintaper.val,0,100,"Minimum taper percentage of protrusion") mintaper = Number("Min Taper %: ",EVENT_NONE,12+pwadd+wadd,37+phadd+hadd,145,18,mintaper.val,0,100,"Minimum taper percentage of protrusion")
maxtaper = Number("Max Taper %: ",EVENT_NONE,162+pwadd+wadd,37+phadd+hadd,145,18,maxtaper.val,0,100,"Maximum taper percentage of protrusion") maxtaper = Number("Max Taper %: ",EVENT_NONE,162+pwadd+wadd,37+phadd+hadd,145,18,maxtaper.val,0,100,"Maximum taper percentage of protrusion")
EndAlign()
glRasterPos2d(19+pwadd+wadd, 22+phadd+hadd) glRasterPos2d(19+pwadd+wadd, 22+phadd+hadd)
Text("Number of protrusions:") Text("Number of protrusions:")
BeginAlign()
sub1 = Toggle("1",EVENT_NONE,12+pwadd+wadd,phadd+hadd,34,18,sub1.val,"One Protrusion") sub1 = Toggle("1",EVENT_NONE,12+pwadd+wadd,phadd+hadd,34,18,sub1.val,"One Protrusion")
sub2 = Toggle("2",EVENT_NONE,48+pwadd+wadd,phadd+hadd,34,18,sub2.val,"Two Protrusions") sub2 = Toggle("2",EVENT_NONE,48+pwadd+wadd,phadd+hadd,34,18,sub2.val,"Two Protrusions")
sub3 = Toggle("3",EVENT_NONE,84+pwadd+wadd,phadd+hadd,34,18,sub3.val,"Three Protrusions") sub3 = Toggle("3",EVENT_NONE,84+pwadd+wadd,phadd+hadd,34,18,sub3.val,"Three Protrusions")
sub4 = Toggle("4",EVENT_NONE,120+pwadd+wadd,phadd+hadd,34,18,sub4.val,"Four Protrusions") sub4 = Toggle("4",EVENT_NONE,120+pwadd+wadd,phadd+hadd,34,18,sub4.val,"Four Protrusions")
EndAlign()
glRasterPos2d(195+pwadd+wadd, 22+phadd+hadd) glRasterPos2d(195+pwadd+wadd, 22+phadd+hadd)
Text("Select tops of:") Text("Select tops of:")
BeginAlign()
selface1 = Toggle("1",EVENT_NONE,165+pwadd+wadd,phadd+hadd,34,18,selface1.val,"Select the tip of the protrusion when it is created") selface1 = Toggle("1",EVENT_NONE,165+pwadd+wadd,phadd+hadd,34,18,selface1.val,"Select the tip of the protrusion when it is created")
selface2 = Toggle("2",EVENT_NONE,201+pwadd+wadd,phadd+hadd,34,18,selface2.val,"Select the tips of each protrusion when they are created") selface2 = Toggle("2",EVENT_NONE,201+pwadd+wadd,phadd+hadd,34,18,selface2.val,"Select the tips of each protrusion when they are created")
selface3 = Toggle("3",EVENT_NONE,237+pwadd+wadd,phadd+hadd,34,18,selface3.val,"Select the tips of each protrusion when they are created") selface3 = Toggle("3",EVENT_NONE,237+pwadd+wadd,phadd+hadd,34,18,selface3.val,"Select the tips of each protrusion when they are created")
selface4 = Toggle("4",EVENT_NONE,273+pwadd+wadd,phadd+hadd,34,18,selface4.val,"Select the tips of each protrusion when they are created") selface4 = Toggle("4",EVENT_NONE,273+pwadd+wadd,phadd+hadd,34,18,selface4.val,"Select the tips of each protrusion when they are created")
EndAlign()
#Doodads #Doodads
colorbox(8+dwadd+wadd,175+dhadd+hadd,312+dwadd+wadd,dhadd-5+hadd) colorbox(8+dwadd+wadd,175+dhadd+hadd,312+dwadd+wadd,dhadd-5+hadd)
glColor3f(0.0,0.0,0.0) glColor3f(0.0,0.0,0.0)
glRasterPos2d(12+dwadd+wadd, 165+dhadd+hadd) glRasterPos2d(12+dwadd+wadd, 165+dhadd+hadd)
Text("Doodads:") Text("Doodads:")
BeginAlign()
dood1 = Toggle("1 Box",EVENT_NONE,12+dwadd+wadd,142+dhadd+hadd,45,18,dood1.val,"Creates a rectangular box") dood1 = Toggle("1 Box",EVENT_NONE,12+dwadd+wadd,142+dhadd+hadd,45,18,dood1.val,"Creates a rectangular box")
dood2 = Toggle("2 Box",EVENT_NONE,61+dwadd+wadd,142+dhadd+hadd,45,18,dood2.val,"Creates 2 side-by-side rectangular boxes") dood2 = Toggle("2 Box",EVENT_NONE,61+dwadd+wadd,142+dhadd+hadd,45,18,dood2.val,"Creates 2 side-by-side rectangular boxes")
dood3 = Toggle("3 Box",EVENT_NONE,110+dwadd+wadd,142+dhadd+hadd,45,18,dood3.val,"Creates 3 side-by-side rectangular boxes") dood3 = Toggle("3 Box",EVENT_NONE,110+dwadd+wadd,142+dhadd+hadd,45,18,dood3.val,"Creates 3 side-by-side rectangular boxes")
EndAlign()
BeginAlign()
dood4 = Toggle("\"L\"",EVENT_NONE,164+dwadd+wadd,142+dhadd+hadd,45,18,dood4.val,"Creates a Tetris-style \"L\" shape") dood4 = Toggle("\"L\"",EVENT_NONE,164+dwadd+wadd,142+dhadd+hadd,45,18,dood4.val,"Creates a Tetris-style \"L\" shape")
dood5 = Toggle("\"T\"",EVENT_NONE,213+dwadd+wadd,142+dhadd+hadd,45,18,dood5.val,"Creates a Tetris-style \"T\" shape") dood5 = Toggle("\"T\"",EVENT_NONE,213+dwadd+wadd,142+dhadd+hadd,45,18,dood5.val,"Creates a Tetris-style \"T\" shape")
dood6 = Toggle("\"S\"",EVENT_NONE,262+dwadd+wadd,142+dhadd+hadd,45,18,dood6.val,"Creates a sort-of \"S\" or \"Z\" shape") dood6 = Toggle("\"S\"",EVENT_NONE,262+dwadd+wadd,142+dhadd+hadd,45,18,dood6.val,"Creates a sort-of \"S\" or \"Z\" shape")
EndAlign()
dodoodads = Toggle("Make Doodads",EVENT_NONE,12+dwadd+wadd,120+dhadd+hadd,145,18,dodoodads.val,"Make Doodads?") dodoodads = Toggle("Make Doodads",EVENT_NONE,12+dwadd+wadd,120+dhadd+hadd,145,18,dodoodads.val,"Make Doodads?")
doodadfacechange = Number("Face %: ",EVENT_NONE,162+dwadd+wadd,120+dhadd+hadd,145,18,doodadfacechange.val,0,100,"Percentage of faces that will gain doodads") doodadfacechange = Number("Face %: ",EVENT_NONE,162+dwadd+wadd,120+dhadd+hadd,145,18,doodadfacechange.val,0,100,"Percentage of faces that will gain doodads")
seldoodad = Toggle("Select Doodads",EVENT_NONE,12+dwadd+wadd,100+dhadd+hadd,145,18,seldoodad.val,"Selects doodads when they are created") seldoodad = Toggle("Select Doodads",EVENT_NONE,12+dwadd+wadd,100+dhadd+hadd,145,18,seldoodad.val,"Selects doodads when they are created")
@@ -1465,12 +1404,18 @@ def draw():
glColor3f(0.0,0.0,0.0) glColor3f(0.0,0.0,0.0)
glRasterPos2d(12+dwadd+wadd, 63+dhadd+hadd) glRasterPos2d(12+dwadd+wadd, 63+dhadd+hadd)
Text("Doodad Properties:") Text("Doodad Properties:")
BeginAlign()
doodadminamount = Number("Min Amount: ",EVENT_NONE,12+dwadd+wadd,40+dhadd+hadd,145,18,doodadminamount.val,0,100,"Minimum number of doodads per face") doodadminamount = Number("Min Amount: ",EVENT_NONE,12+dwadd+wadd,40+dhadd+hadd,145,18,doodadminamount.val,0,100,"Minimum number of doodads per face")
doodadmaxamount = Number("Max Amount: ",EVENT_NONE,162+dwadd+wadd,40+dhadd+hadd,145,18,doodadmaxamount.val,0,100,"Maximum number of doodads per face") doodadmaxamount = Number("Max Amount: ",EVENT_NONE,162+dwadd+wadd,40+dhadd+hadd,145,18,doodadmaxamount.val,0,100,"Maximum number of doodads per face")
EndAlign()
BeginAlign()
doodheightmin = Number("Min Height: ",EVENT_NONE,12+dwadd+wadd,20+dhadd+hadd,145,18,doodheightmin.val,0.0,100.0,"Minimum height of any doodad") doodheightmin = Number("Min Height: ",EVENT_NONE,12+dwadd+wadd,20+dhadd+hadd,145,18,doodheightmin.val,0.0,100.0,"Minimum height of any doodad")
doodheightmax = Number("Max Height: ",EVENT_NONE,162+dwadd+wadd,20+dhadd+hadd,145,18,doodheightmax.val,0.0,100.0,"Maximum height of any doodad") doodheightmax = Number("Max Height: ",EVENT_NONE,162+dwadd+wadd,20+dhadd+hadd,145,18,doodheightmax.val,0.0,100.0,"Maximum height of any doodad")
EndAlign()
BeginAlign()
doodsizemin = Number("Min Size %: ",EVENT_NONE,12+dwadd+wadd,dhadd+hadd,145,18,doodsizemin.val,0.0,100.0,"Minimum size of any doodad in percentage of face") doodsizemin = Number("Min Size %: ",EVENT_NONE,12+dwadd+wadd,dhadd+hadd,145,18,doodsizemin.val,0.0,100.0,"Minimum size of any doodad in percentage of face")
doodsizemax = Number("Max Size %: ",EVENT_NONE,162+dwadd+wadd,dhadd+hadd,145,18,doodsizemax.val,0.0,100.0,"Maximum size of any doodad in percentage of face") doodsizemax = Number("Max Size %: ",EVENT_NONE,162+dwadd+wadd,dhadd+hadd,145,18,doodsizemax.val,0.0,100.0,"Maximum size of any doodad in percentage of face")
EndAlign()
#Materials #Materials
colorbox(8+mwadd+wadd,93+mhadd+hadd,312+mwadd+wadd,mhadd-5+hadd) colorbox(8+mwadd+wadd,93+mhadd+hadd,312+mwadd+wadd,mhadd-5+hadd)

View File

@@ -720,17 +720,19 @@ def bevent(evt):
OK,MESH=on_MESH() OK,MESH=on_MESH()
if OK and MESH.hasFaceUV(): if OK and MESH.hasFaceUV():
for f in MESH.faces: for f in MESH.faces:
if f.image: im = f.image
im=Blender.Image.Get(f.image.name) if im:
break break
imX,imY = im.getMaxXY() if im and im.has_data:
for f in MESH.faces: imX,imY = im.getMaxXY()
for uv in f.uv: for f in MESH.faces:
color=[int(c*255.0) for c in im.getPixelF(abs(uv[0]*imX%imX), abs(uv[1]*imY%imY))] col = f.col
f.col[f.uv.index(uv)].r=color[0] for uv_index, uv in enumerate(f.uv):
f.col[f.uv.index(uv)].g=color[1] color=[int(c*255.0) for c in im.getPixelF(abs(uv[0]*imX%imX), abs(uv[1]*imY%imY))]
f.col[f.uv.index(uv)].b=color[2] col[uv_index].r=color[0]
f.col[f.uv.index(uv)].a=color[3] col[uv_index].g=color[1]
col[uv_index].b=color[2]
col[uv_index].a=color[3]
MESH.update() MESH.update()
elif (evt == E_SAVECOLORS): elif (evt == E_SAVECOLORS):
OK,MESH=on_MESH() OK,MESH=on_MESH()

View File

@@ -33,7 +33,7 @@ This script randomizes the selected objects location/size/rotation.
# ***** END GPL LICENCE BLOCK ***** # ***** END GPL LICENCE BLOCK *****
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
from Blender import Object, Draw from Blender import Draw, Scene
from Blender.Mathutils import Rand from Blender.Mathutils import Rand
def rnd(): def rnd():
@@ -76,8 +76,8 @@ def randomize(sel, PREF_LOC, PREF_SIZE, PREF_ROT, PREF_LINK_AXIS, PREF_X_AXIS, P
def main(): def main():
sel= Object.GetSelected() scn = Scene.GetCurrent()
if not sel: if not scn.objects.context:
return return
PREF_LOC= Draw.Create(0.0) PREF_LOC= Draw.Create(0.0)
@@ -89,13 +89,11 @@ def main():
PREF_Z_AXIS= Draw.Create(1) PREF_Z_AXIS= Draw.Create(1)
pup_block = [\ pup_block = [\
'Randomize...',\
('loc:', PREF_LOC, 0.0, 10.0, 'Amount to randomize the location'),\ ('loc:', PREF_LOC, 0.0, 10.0, 'Amount to randomize the location'),\
('size:', PREF_SIZE, 0.0, 10.0, 'Amount to randomize the size'),\ ('size:', PREF_SIZE, 0.0, 10.0, 'Amount to randomize the size'),\
('rot:', PREF_ROT, 0.0, 10.0, 'Amount to randomize the rotation'),\ ('rot:', PREF_ROT, 0.0, 10.0, 'Amount to randomize the rotation'),\
'',\ '',\
('Link Axis', PREF_LINK_AXIS, 'Use the same random value for each objects XYZ'),\ ('Link Axis', PREF_LINK_AXIS, 'Use the same random value for each objects XYZ'),\
'',\
('X Axis', PREF_X_AXIS, 'Enable X axis randomization'),\ ('X Axis', PREF_X_AXIS, 'Enable X axis randomization'),\
('Y Axis', PREF_Y_AXIS, 'Enable Y axis randomization'),\ ('Y Axis', PREF_Y_AXIS, 'Enable Y axis randomization'),\
('Z Axis', PREF_Z_AXIS, 'Enable Z axis randomization'),\ ('Z Axis', PREF_Z_AXIS, 'Enable Z axis randomization'),\
@@ -104,7 +102,7 @@ def main():
if not Draw.PupBlock('Object Randomize', pup_block): if not Draw.PupBlock('Object Randomize', pup_block):
return return
randomize(sel, PREF_LOC.val, PREF_SIZE.val, PREF_ROT.val, PREF_LINK_AXIS.val, PREF_X_AXIS.val, PREF_Y_AXIS.val, PREF_Z_AXIS.val) randomize(scn.objects.context, PREF_LOC.val, PREF_SIZE.val, PREF_ROT.val, PREF_LINK_AXIS.val, PREF_X_AXIS.val, PREF_Y_AXIS.val, PREF_Z_AXIS.val)
if __name__ == '__main__': if __name__ == '__main__':
main() main()