home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2005 November / WNnov2005.iso / Windows / Equipement / Blender / blender-2.37a-windows.exe / $_5_ / .blender / scripts / discombobulator.py < prev    next >
Text File  |  2005-05-17  |  44KB  |  1,230 lines

  1. #!BPY
  2.  
  3. """
  4. Name: 'Discombobulator'
  5. Blender: 236
  6. Group: 'Mesh'
  7. Tip: 'Adds random geometry to a mesh'
  8. """
  9.  
  10. __author__ = "Evan J. Rosky (syrux)"
  11. __url__ = ("Script's homepage, http://evan.nerdsofparadise.com/programs/discombobulator/index.html")
  12. __version__ = "236"
  13. __bpydoc__ = """\
  14. Discombobulator adds random geometry to a mesh.
  15.  
  16. As an example, this script can easily give a "high-tech"
  17. look to walls and spaceships.
  18.  
  19. Definitions:<br>
  20.   - Protrusions: extrusions of each original face on the mesh.
  21. You may have from 1 to 4 protrusions on each face.<br>
  22.   - Taper: The tips of each protrusion will be a percentage
  23. smaller than the base.<br>
  24.   - Doodads: small extruded blocks/shapes that are randomly placed
  25. about the top of a protrusion or face.
  26.  
  27.  
  28. Usage:<br>
  29.   Input your settings, make sure the mesh you would like to modify
  30. is selected (active) and then click on "Discombobulate".
  31.  
  32. Notes:<br>
  33.   - Modifications can be restricted to selected faces
  34. by setting "Only selected faces" for protrusions and/or
  35. doodads.<br>
  36.   - It's possible to restrict mesh generation to add only
  37. protrusions or only doodads instead of both.<br>
  38.   - You may also choose to have Discombobulator select the
  39. tops of created protrusions by clicking the corresponding
  40. number of protrusion buttons under "Select Tops". You may 
  41. also do the same for doodads by choosing "Select Doodads" and
  42. "Only Select Tops". You may choose to select the whole doodads 
  43. by leaving "Only Select Tops" off.<br>
  44.   - By selecting "Deselect Selected" you can have
  45. discombobulator deselect everything but the selections it
  46. makes.<br>
  47.   - The "Face %" option will set the percentage of faces that
  48. will be modified either for the doodads or the protrusions.<br>
  49.   - "Copy Before Modifying" will create a new object with the
  50. modifications where leaving it off will overwrite the original
  51. mesh.<br>
  52.  
  53. You can find more information at the Link above.
  54. """
  55.  
  56.  
  57. # $Id: discombobulator.py,v 1.1 2005/05/17 19:56:29 ianwill Exp $
  58. #
  59. # --------------------------------------------------------------------------
  60. # Discombobulator v5.3.5.406893.potato
  61. # by Evan J. Rosky, 2005
  62. # This plugin is protected by the GPL: Gnu Public Licence
  63. # GPL - http://www.gnu.org/copyleft/gpl.html
  64. # --------------------------------------------------------------------------
  65. # ***** BEGIN GPL LICENSE BLOCK *****
  66. #
  67. # Copyright (C) 2005: Evan J. Rosky
  68. #
  69. # This program is free software; you can redistribute it and/or
  70. # modify it under the terms of the GNU General Public License
  71. # as published by the Free Software Foundation; either version 2
  72. # of the License, or (at your option) any later version.
  73. #
  74. # This program is distributed in the hope that it will be useful,
  75. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  76. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
  77. # GNU General Public License for more details.
  78. #
  79. # You should have received a copy of the GNU General Public License
  80. # along with this program; if not, write to the Free Software Foundation,
  81. # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  82. #
  83. # ***** END GPL LICENCE BLOCK *****
  84. # --------------------------------------------------------------------------
  85.  
  86. #Hit Alt-P to run
  87.  
  88. import Blender
  89. from Blender import NMesh,Object,Material,Window
  90. from Blender.NMesh import Vert,Face
  91. from Blender.Mathutils import *
  92.  
  93. import defaultdoodads
  94. import BPyMathutils
  95. from BPyMathutils import genrand
  96. a = BPyMathutils.sgenrand(int(round(Rand(1000,99999),0)))
  97.  
  98. #Create random numbers
  99. def randnum(low,high):
  100.     num = genrand()
  101.     num = num*(high-low)
  102.     num = num+low
  103.     return num
  104.  
  105.  
  106. origmesh = NMesh.GetRaw()
  107. newmesh = NMesh.GetRaw()
  108. origobj = Object.Get()
  109. newobj = Object.Get()
  110.  
  111. #Global Vars
  112. makenewobj = 1
  113. errortext = "Remember to select an object."
  114. editmode = 0
  115.  
  116. #Protrusion Vars
  117. makeprots = 1
  118. faceschangedpercent = 1.0
  119. minimumheight = 0.2
  120. maximumheight = 0.4
  121. subface1 = 1
  122. subface2 = 1
  123. subface3 = 1
  124. subface4 = 1
  125. subfaceArray = [1,2,3,4]
  126. minsubfaces = 1
  127. minimumtaperpercent = 0.15
  128. maximumtaperpercent = 0.35
  129. useselectedfaces = 0
  130. selectface1 = 1
  131. selectface2 = 1
  132. selectface3 = 1
  133. selectface4 = 1
  134. deselface = 1
  135. #vertselected = 0
  136.  
  137. #Doodad Vars
  138. makedoodads = 1
  139. doodadfacepercent = 1.0
  140. selectdoodad = 0
  141. onlyonprotrusions = 0
  142. doodonselectedfaces = 0
  143. selectdoodadtoponly = 0
  144. doodad1 = 1
  145. doodad2 = 1
  146. doodad3 = 1
  147. doodad4 = 1
  148. doodad5 = 1
  149. doodad6 = 1
  150. doodadminperface = 2
  151. doodadmaxperface = 6
  152. doodadminsize = 0.15
  153. doodadmaxsize = 0.45
  154. doodadminheight = 0.0
  155. doodadmaxheight = 0.1
  156. doodadArray = [1,2,3,4,5,6]
  157.  
  158. SEL = NMesh.FaceFlags['SELECT']
  159.  
  160. def isselectedface(theface):
  161.     for vertic in theface.v:
  162.         if vertic.sel == 0:
  163.             return 0
  164.     return 1
  165.  
  166. def makeSubfaceArray():
  167.     global subfaceArray
  168.     global subface1
  169.     global subface2
  170.     global subface3
  171.     global subface4
  172.     
  173.     subfaceArray = []
  174.     if subface1 > 0:
  175.         subfaceArray.append(1)
  176.     if subface2 > 0:
  177.         subfaceArray.append(2)
  178.     if subface3 > 0:
  179.         subfaceArray.append(3)
  180.     if subface4 > 0:
  181.         subfaceArray.append(4)
  182.  
  183. def makeDoodadArray():
  184.     global doodadArray
  185.     global doodad1
  186.     global doodad2
  187.     global doodad3
  188.     global doodad4
  189.     global doodad5
  190.     global doodad6
  191.     
  192.     doodadArray = []
  193.     if doodad1 > 0:
  194.         doodadArray.append(1)
  195.     if doodad2 > 0:
  196.         doodadArray.append(2)
  197.     if doodad3 > 0:
  198.         doodadArray.append(3)
  199.     if doodad4 > 0:
  200.         doodadArray.append(4)
  201.     if doodad5 > 0:
  202.         doodadArray.append(5)
  203.     if doodad6 > 0:
  204.         doodadArray.append(6)
  205.  
  206. def copyObjStuff(startObj,endObj):
  207.     endObj.setDeltaLocation(startObj.getDeltaLocation())
  208.     endObj.setDrawMode(startObj.getDrawMode())
  209.     endObj.setDrawType(startObj.getDrawType())
  210.     endObj.setEuler(startObj.getEuler())
  211.     if(startObj.getIpo() != None):
  212.         endObj.setIpo(startObj.getIpo())
  213.     endObj.setLocation(startObj.getLocation())
  214.     endObj.setMaterials(startObj.getMaterials())
  215.     endObj.setMatrix(startObj.getMatrix())
  216.     endObj.setSize(startObj.getSize())
  217.     endObj.setTimeOffset(startObj.getTimeOffset())
  218.     
  219.  
  220. def extrude(mid,nor,protrusion,v1,v2,v3,v4,tosel=1,flipnor=0):
  221.     taper = 1 - randnum(minimumtaperpercent,maximumtaperpercent)
  222.     
  223.     vert = newmesh.verts[v1]
  224.     point = (vert.co - mid)*taper + mid + protrusion*Vector(nor)
  225.     ver = Vert(point[0],point[1],point[2])
  226.     ver.sel = tosel
  227.     newmesh.verts.append(ver)
  228.     vert = newmesh.verts[v2]
  229.     point = (vert.co - mid)*taper + mid + protrusion*Vector(nor)
  230.     ver = Vert(point[0],point[1],point[2])
  231.     ver.sel = tosel
  232.     newmesh.verts.append(ver)
  233.     vert = newmesh.verts[v3]
  234.     point = (vert.co - mid)*taper + mid + protrusion*Vector(nor)
  235.     ver = Vert(point[0],point[1],point[2])
  236.     ver.sel = tosel
  237.     newmesh.verts.append(ver)
  238.     vert = newmesh.verts[v4]
  239.     point = (vert.co - mid)*taper + mid + protrusion*Vector(nor)
  240.     ver = Vert(point[0],point[1],point[2])
  241.     ver.sel = tosel
  242.     newmesh.verts.append(ver)
  243.     
  244.     faceindex = len(newmesh.verts) - 4
  245.     
  246.     #face 1
  247.     face = Face()
  248.     face.v.append(newmesh.verts[v1])
  249.     face.v.append(newmesh.verts[v2])
  250.     face.v.append(newmesh.verts[faceindex+1])
  251.     face.v.append(newmesh.verts[faceindex])
  252.     if flipnor != 0:
  253.         face.v.reverse()
  254.     newmesh.faces.append(face)
  255.     
  256.     #face 2
  257.     face = Face()
  258.     face.v.append(newmesh.verts[v2])
  259.     face.v.append(newmesh.verts[v3])
  260.     face.v.append(newmesh.verts[faceindex+2])
  261.     face.v.append(newmesh.verts[faceindex+1])
  262.     if flipnor != 0:
  263.         face.v.reverse()
  264.     newmesh.faces.append(face)
  265.     
  266.     #face 3
  267.     face = Face()
  268.     face.v.append(newmesh.verts[v3])
  269.     face.v.append(newmesh.verts[v4])
  270.     face.v.append(newmesh.verts[faceindex+3])
  271.     face.v.append(newmesh.verts[faceindex+2])
  272.     if flipnor != 0:
  273.         face.v.reverse()
  274.     newmesh.faces.append(face)
  275.     
  276.     #face 4
  277.     face = Face()
  278.     face.v.append(newmesh.verts[v4])
  279.     face.v.append(newmesh.verts[v1])
  280.     face.v.append(newmesh.verts[faceindex])
  281.     face.v.append(newmesh.verts[faceindex+3])
  282.     if flipnor != 0:
  283.         face.v.reverse()
  284.     newmesh.faces.append(face)
  285.         
  286.     face = Face()
  287.     face.v = newmesh.verts[-4:]
  288.     if flipnor != 0:
  289.         face.v.reverse()
  290.     if tosel == 1:
  291.         face.sel = 1
  292.     newmesh.faces.append(face)
  293.     return face
  294.  
  295. def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15,d16,d17):
  296.     
  297.     #Global
  298.     global origmesh
  299.     global newmesh
  300.     global makenewobj
  301.     global origobj
  302.     global newobj
  303.     global messagetext
  304.     global errortext
  305.     global editmode
  306.     
  307.     #Protrusions
  308.     global makeprots
  309.     global minimumtaperpercent
  310.     global maximumtaperpercent
  311.     global faceschangedpercent
  312.     global minimumheight
  313.     global maximumheight
  314.     global subface1
  315.     global subface2
  316.     global subface3
  317.     global subface4
  318.     global useselectedfaces
  319.     global selectface1
  320.     global selectface2
  321.     global selectface3
  322.     global selectface4
  323.     global deselface
  324.     #global vertselected
  325.     global subfaceArray
  326.     
  327.     #Doodads
  328.     global makedoodads
  329.     global doodadfacepercent
  330.     global selectdoodad
  331.     global onlyonprotrusions
  332.     global doodad1
  333.     global doodad2
  334.     global doodad3
  335.     global doodad4
  336.     global doodad5
  337.     global doodad6
  338.     global doodadminperface
  339.     global doodadmaxperface
  340.     global doodadminsize
  341.     global doodadmaxsize
  342.     global doodadminheight
  343.     global doodadmaxheight
  344.     global doodadArray
  345.     global doodonselectedfaces
  346.     global selectdoodadtoponly
  347.     
  348.     #Global
  349.     try:
  350.         origobj = Object.GetSelected()[0]
  351.     except:
  352.         glRasterPos2d(10,50)
  353.         errortext = "YOU MUST SELECT AN OBJECT!"
  354.         messagetext = ErrorText(errortext)
  355.         Blender.Redraw()
  356.         return
  357.  
  358.     #Leave Editmode
  359.     editmode = Window.EditMode()
  360.     if editmode: Window.EditMode(0)
  361.  
  362.     newobj = Object.Get()
  363.     origmesh = origobj.getData()
  364.     newmesh = NMesh.GetRaw()
  365.     newmesh.verts = []
  366.     makenewobj = g0
  367.     
  368.     #Protrusions
  369.     makeprots = p0
  370.     faceschangedpercent = p1
  371.     minimumheight = p2
  372.     maximumheight = p3
  373.     subface1 = p4
  374.     subface2 = p5
  375.     subface3 = p6
  376.     subface4 = p7
  377.     minimumtaperpercent = p8
  378.     maximumtaperpercent = p9
  379.     useselectedfaces = p10
  380.     selectface1 = p11
  381.     selectface2 = p12
  382.     selectface3 = p13
  383.     selectface4 = p14
  384.     deselface = p15
  385.     makeSubfaceArray()
  386.     if len(subfaceArray) == 0:
  387.         makeprots = 0
  388.     
  389.     
  390.     #Doodads
  391.     makedoodads = d0
  392.     doodadfacepercent = d1
  393.     selectdoodad = d2
  394.     onlyonprotrusions = d3
  395.     doodad1 = d4
  396.     doodad2 = d5
  397.     doodad3 = d6
  398.     doodad4 = d7
  399.     doodad5 = d8
  400.     doodad6 = d9
  401.     doodadminperface = d10
  402.     doodadmaxperface = d11
  403.     doodadminsize = d12
  404.     doodadmaxsize = d13
  405.     doodadminheight = d14
  406.     doodadmaxheight = d15
  407.     doodonselectedfaces = d16
  408.     selectdoodadtoponly = d17
  409.     makeDoodadArray()
  410.     if len(doodadArray) == 0:
  411.         makedoodads = 0
  412.     defaultdoodads.topsonly(selectdoodadtoponly)
  413.     
  414.     if minimumheight > maximumheight:
  415.         glColor3f(1.0,0.0,0.0)
  416.         glRasterPos2d(10,50)
  417.         errortext = "MIN HEIGHT MUST BE LESS THAN OR EQUAL TO MAX HEIGHT!"
  418.         messagetext = ErrorText(errortext)
  419.         Blender.Redraw()
  420.         return
  421.     elif minimumtaperpercent > maximumtaperpercent:
  422.         glColor3f(1.0,0.0,0.0)
  423.         glRasterPos2d(10,50)
  424.         errortext = "MIN TAPER MUST BE LESS THAN OR EQUAL TO MAX TAPER!"
  425.         messagetext = ErrorText(errortext)
  426.         Blender.Redraw()
  427.         return
  428.     elif doodadminperface > doodadmaxperface:
  429.         glColor3f(1.0,0.0,0.0)
  430.         glRasterPos2d(10,50)
  431.         errortext = "MIN NUMBER OF DOODADS MUST BE LESS THAN OR EQUAL TO MAX!"
  432.         messagetext = ErrorText(errortext)
  433.         Blender.Redraw()
  434.         return
  435.     elif doodadminsize > doodadmaxsize:
  436.         glColor3f(1.0,0.0,0.0)
  437.         glRasterPos2d(10,50)
  438.         errortext = "MIN DOODAD SIZE MUST BE LESS THAN OR EQUAL TO MAX!"
  439.         messagetext = ErrorText(errortext)
  440.         Blender.Redraw()
  441.         return
  442.     elif doodadminheight > doodadmaxheight:
  443.         glColor3f(1.0,0.0,0.0)
  444.         glRasterPos2d(10,50)
  445.         errortext = "MIN DOODAD HEIGHT MUST BE LESS THAN OR EQUAL TO MAX!"
  446.         messagetext = ErrorText(errortext)
  447.         Blender.Redraw()
  448.         return
  449.     
  450.     newmesh.verts.extend(origmesh.verts)
  451.     
  452.     for currface in origmesh.faces:
  453.         
  454.         #Check if it is a triangle
  455.         if len(currface.v)<4:
  456.             face = Face()
  457.             face.v.extend([newmesh.verts[currface.v[0].index],newmesh.verts[currface.v[1].index],newmesh.verts[currface.v[2].index]])
  458.             newmesh.faces.append(face)
  459.             continue
  460.         
  461.         #Check whether or not to make protrusions
  462.         if makeprots == 0:
  463.             face = Face()
  464.             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]])
  465.             newmesh.faces.append(face)
  466.             if makedoodads == 1 and onlyonprotrusions == 0:
  467.                 if doodonselectedfaces == 1:
  468.                     if currface.sel:
  469.                         tempmesh = NMesh.GetRaw()
  470.                         tempmesh = defaultdoodads.createDoodad(doodadArray,face, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  471.                         newmesh.verts.extend(tempmesh.verts)
  472.                         newmesh.faces.extend(tempmesh.faces)
  473.                 else:
  474.                     tempmesh = NMesh.GetRaw()
  475.                     tempmesh = defaultdoodads.createDoodad(doodadArray,face, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  476.                     newmesh.verts.extend(tempmesh.verts)
  477.                     newmesh.faces.extend(tempmesh.faces)
  478.             continue
  479.         
  480.         #Check if only changing selected faces
  481.         if useselectedfaces == 1:
  482.             #check if currface is selected
  483.             if currface.sel:
  484.                 a = 1
  485.             else:
  486.                 face = Face()
  487.                 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]])
  488.                 newmesh.faces.append(face)
  489.                 if makedoodads == 1 and onlyonprotrusions == 0:
  490.                     if doodonselectedfaces != 1:
  491.                         tempmesh = NMesh.GetRaw()
  492.                         tempmesh = defaultdoodads.createDoodad(doodadArray,face, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  493.                         newmesh.verts.extend(tempmesh.verts)
  494.                         newmesh.faces.extend(tempmesh.faces)
  495.                 continue
  496.         #Check if face should be modified by random chance
  497.         if randnum(0,1)>faceschangedpercent: 
  498.             face = Face()
  499.             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]])
  500.             newmesh.faces.append(face)
  501.             if makedoodads == 1 and onlyonprotrusions == 0:
  502.                 if doodonselectedfaces == 1:
  503.                     if currface.sel:
  504.                         tempmesh = NMesh.GetRaw()
  505.                         tempmesh = defaultdoodads.createDoodad(doodadArray,face, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  506.                         newmesh.verts.extend(tempmesh.verts)
  507.                         newmesh.faces.extend(tempmesh.faces)
  508.                 else:
  509.                     tempmesh = NMesh.GetRaw()
  510.                     tempmesh = defaultdoodads.createDoodad(doodadArray,face, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  511.                     newmesh.verts.extend(tempmesh.verts)
  512.                     newmesh.faces.extend(tempmesh.faces)
  513.             continue
  514.         
  515.         center = Vector([0,0,0])
  516.         for pt in currface.v:
  517.             center = center + pt.co
  518.         center = center/len(currface.v)
  519.         
  520.         #Determine amount of subfaces
  521.         subfaces = round(randnum(1,len(subfaceArray)),0)
  522.         subfaces = subfaceArray[(int(subfaces) - 1)]
  523.         
  524.         if subfaces == 1:
  525.             prot = randnum(minimumheight,maximumheight)
  526.             tempface = extrude(center,currface.no,prot,currface.v[0].index,currface.v[1].index,currface.v[2].index,currface.v[3].index,selectface1)
  527.             if makedoodads == 1:
  528.                 if doodonselectedfaces == 1:
  529.                     if currface.sel:
  530.                         tempmesh = NMesh.GetRaw()
  531.                         tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  532.                         newmesh.verts.extend(tempmesh.verts)
  533.                         newmesh.faces.extend(tempmesh.faces)
  534.                 else:
  535.                     tempmesh = NMesh.GetRaw()
  536.                     tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  537.                     newmesh.verts.extend(tempmesh.verts)
  538.                     newmesh.faces.extend(tempmesh.faces)
  539.         
  540.         elif subfaces == 2:
  541.             orientation = int(round(randnum(0,1)))
  542.             p1 = currface.v[orientation]
  543.             p2 = currface.v[orientation + 1]
  544.             p3 = (p2.co - p1.co)/2 + p1.co
  545.             ve1 = Vert(p3[0],p3[1],p3[2])
  546.             ve1.sel = 0
  547.             p1 = currface.v[2 + orientation]
  548.             if orientation < 0.5:
  549.                 p2 = currface.v[3]
  550.             else:
  551.                 p2 = currface.v[0]
  552.             p3 = (p2.co - p1.co)/2 + p1.co
  553.             ve2 = Vert(p3[0],p3[1],p3[2])
  554.             ve2.sel = 0
  555.             if orientation < 0.5:
  556.                 verti = currface.v[3]
  557.                 p3 = verti.index
  558.                 v1 = p3
  559.                 verti = currface.v[0]
  560.                 p0 = verti.index
  561.                 v2 = p0
  562.             else:
  563.                 verti = currface.v[0]
  564.                 p0 = verti.index
  565.                 v1 = p0
  566.                 verti = currface.v[1]
  567.                 p1 = verti.index
  568.                 v2 = p1
  569.             newmesh.verts.append(ve1)
  570.             newmesh.verts.append(ve2)
  571.             index = len(newmesh.verts) - 2
  572.             v4 = index + 1
  573.             v3 = index
  574.             center = Vector([0, 0, 0])
  575.             for pt in [newmesh.verts[v1],newmesh.verts[v2],newmesh.verts[v3],newmesh.verts[v4]]:
  576.                 center = center + pt.co
  577.             center = center/4
  578.             prot = randnum(minimumheight,maximumheight)
  579.             tempface = extrude(center,currface.no,prot,v1,v2,v3,v4,selectface2)
  580.             if makedoodads == 1:
  581.                 if doodonselectedfaces == 1:
  582.                     if currface.sel:
  583.                         tempmesh = NMesh.GetRaw()
  584.                         tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  585.                         newmesh.verts.extend(tempmesh.verts)
  586.                         newmesh.faces.extend(tempmesh.faces)
  587.                 else:
  588.                     tempmesh = NMesh.GetRaw()
  589.                     tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  590.                     newmesh.verts.extend(tempmesh.verts)
  591.                     newmesh.faces.extend(tempmesh.faces)
  592.             if orientation < 0.5:
  593.                 verti = currface.v[1]
  594.                 p1 = verti.index
  595.                 v1 = p1
  596.                 verti = currface.v[2]
  597.                 p2 = verti.index
  598.                 v2 = p2
  599.             else:
  600.                 verti = currface.v[2]
  601.                 p2 = verti.index
  602.                 v1 = p2
  603.                 verti = currface.v[3]
  604.                 p3 = verti.index
  605.                 v2 = p3
  606.             center = Vector([0]*3)
  607.             for pt in [newmesh.verts[v1],newmesh.verts[v2],newmesh.verts[v3],newmesh.verts[v4]]:
  608.                 center = center + pt.co
  609.             center = center/4
  610.             prot = randnum(minimumheight,maximumheight)
  611.             tempface = extrude(center,currface.no,prot,v1,v2,v4,v3,selectface2)
  612.             if makedoodads == 1:
  613.                 if doodonselectedfaces == 1:
  614.                     if currface.sel:
  615.                         tempmesh = NMesh.GetRaw()
  616.                         tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  617.                         newmesh.verts.extend(tempmesh.verts)
  618.                         newmesh.faces.extend(tempmesh.faces)
  619.                 else:
  620.                     tempmesh = NMesh.GetRaw()
  621.                     tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  622.                     newmesh.verts.extend(tempmesh.verts)
  623.                     newmesh.faces.extend(tempmesh.faces)
  624.             if orientation < 0.5:
  625.                 face = Face()
  626.                 face.v.extend([newmesh.verts[p0],newmesh.verts[p1],newmesh.verts[v3]])
  627.                 newmesh.faces.append(face)
  628.                 face = Face()
  629.                 face.v.extend([newmesh.verts[p2],newmesh.verts[p3],newmesh.verts[v4]])
  630.                 newmesh.faces.append(face)
  631.             else:
  632.                 face = Face()
  633.                 face.v.extend([newmesh.verts[p1],newmesh.verts[p2],newmesh.verts[v3]])
  634.                 newmesh.faces.append(face)
  635.                 face = Face()
  636.                 face.v.extend([newmesh.verts[p3],newmesh.verts[p0],newmesh.verts[v4]])
  637.                 newmesh.faces.append(face)
  638.             
  639.         elif subfaces == 3:
  640.             layer2inds = []
  641.             layer2verts = []
  642.             orientation = int(round(randnum(0,1)))
  643.             rotation = int(round(randnum(0,1)))
  644.             p1 = currface.v[orientation]
  645.             p2 = currface.v[orientation + 1]
  646.             p3 = (p2.co - p1.co)/2 + p1.co
  647.             ve1 = Vert(p3[0],p3[1],p3[2])
  648.             ve1.sel = 0
  649.             p1 = currface.v[2 + orientation]
  650.             if orientation < 0.5:
  651.                 p2 = currface.v[3]
  652.             else:
  653.                 p2 = currface.v[0]
  654.             p3 = (p2.co - p1.co)/2 + p1.co
  655.             ve2 = Vert(p3[0],p3[1],p3[2])
  656.             ve2.sel = 0
  657.             fp = []
  658.     
  659.             #make first protrusion
  660.             if rotation < 0.5:
  661.                 if orientation < 0.5:
  662.                     verti = currface.v[3]
  663.                     fp.append(verti.index)
  664.                     v1 = verti.index
  665.                     verti = currface.v[0]
  666.                     fp.append(verti.index)
  667.                     v2 = verti.index
  668.                     layer2verts.extend([newmesh.verts[currface.v[1].index],newmesh.verts[currface.v[2].index]])
  669.                 else:
  670.                     verti = currface.v[0]
  671.                     fp.append(verti.index)
  672.                     v1 = verti.index
  673.                     verti = currface.v[1]
  674.                     fp.append(verti.index)
  675.                     v2 = verti.index
  676.                     layer2verts.extend([newmesh.verts[currface.v[2].index],newmesh.verts[currface.v[3].index]])
  677.                 newmesh.verts.append(ve1)
  678.                 newmesh.verts.append(ve2)
  679.                 index = len(newmesh.verts) - 2
  680.                 v4 = index + 1
  681.                 v3 = index
  682.                 center = Vector([0]*3)
  683.                 for pt in [newmesh.verts[v1],newmesh.verts[v2],newmesh.verts[v3],newmesh.verts[v4]]:
  684.                     center = center + pt.co
  685.                 center = center/4
  686.                 prot = randnum(minimumheight,maximumheight)
  687.                 layer2inds.extend([v3,v4])
  688.                 tempface = extrude(center,currface.no,prot,v1,v2,v3,v4,selectface3)
  689.                 if makedoodads == 1:
  690.                     if doodonselectedfaces == 1:
  691.                         if currface.sel:
  692.                             tempmesh = NMesh.GetRaw()
  693.                             tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  694.                             newmesh.verts.extend(tempmesh.verts)
  695.                             newmesh.faces.extend(tempmesh.faces)
  696.                     else:
  697.                         tempmesh = NMesh.GetRaw()
  698.                         tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  699.                         newmesh.verts.extend(tempmesh.verts)
  700.                         newmesh.faces.extend(tempmesh.faces)
  701.             #Still first protrusion
  702.             else:
  703.                 if orientation < 0.5:
  704.                     verti = currface.v[1]
  705.                     fp.append(verti.index)
  706.                     v1 = verti.index
  707.                     verti = currface.v[2]
  708.                     fp.append(verti.index)
  709.                     v2 = verti.index
  710.                     layer2verts.extend([newmesh.verts[currface.v[0].index],newmesh.verts[currface.v[3].index]])
  711.                 else:
  712.                     verti = currface.v[2]
  713.                     fp.append(verti.index)
  714.                     v1 = verti.index
  715.                     verti = currface.v[3]
  716.                     fp.append(verti.index)
  717.                     v2 = verti.index
  718.                     layer2verts.extend([newmesh.verts[currface.v[1].index],newmesh.verts[currface.v[0].index]])
  719.                 newmesh.verts.append(ve2)
  720.                 newmesh.verts.append(ve1)
  721.                 index = len(newmesh.verts) - 2
  722.                 v4 = index
  723.                 v3 = index + 1
  724.                 center = Vector([0]*3)
  725.                 for pt in [newmesh.verts[v1],newmesh.verts[v2],newmesh.verts[v3],newmesh.verts[v4]]:
  726.                     center = center + pt.co
  727.                 center = center/4
  728.                 prot = randnum(minimumheight,maximumheight)
  729.                 layer2inds.extend([index, index +1])
  730.                 tempface = extrude(center,currface.no,prot,v1,v2,v4,v3,selectface3)
  731.                 if makedoodads == 1:
  732.                     if doodonselectedfaces == 1:
  733.                         if currface.sel:
  734.                             tempmesh = NMesh.GetRaw()
  735.                             tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  736.                             newmesh.verts.extend(tempmesh.verts)
  737.                             newmesh.faces.extend(tempmesh.faces)
  738.                     else:
  739.                         tempmesh = NMesh.GetRaw()
  740.                         tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  741.                         newmesh.verts.extend(tempmesh.verts)
  742.                         newmesh.faces.extend(tempmesh.faces)
  743.             
  744.             #split next rect(pre-arranged, no orientation crud)--make flag in extruder for only one existing vert in mesh
  745.             p1 = newmesh.verts[layer2inds[0]]
  746.             p2 = newmesh.verts[layer2inds[1]]
  747.             p3 = (p2.co - p1.co)/2 + p1.co
  748.             ve3 = Vert(p3[0],p3[1],p3[2])
  749.             ve3.sel = 0
  750.             p1 = layer2verts[0]
  751.             p2 = layer2verts[1]
  752.             p3 = (p2.co - p1.co)/2 + p1.co
  753.             ve4 = Vert(p3[0],p3[1],p3[2])
  754.             ve4.sel = 0
  755.             newmesh.verts.append(ve3)
  756.             newmesh.verts.append(ve4)
  757.             tempindex = len(newmesh.verts) - 2
  758.             v5 = tempindex
  759.             v6 = tempindex + 1
  760.             verti = layer2verts[0]
  761.             t0 = verti.index
  762.             center = Vector([0]*3)
  763.             for pt in [newmesh.verts[v5],newmesh.verts[v6],newmesh.verts[t0],newmesh.verts[v3]]:
  764.                 center = center + pt.co
  765.             center = center/4
  766.             prot = randnum(minimumheight,maximumheight)
  767.             if rotation < 0.5: flino = 1
  768.             else: flino = 0
  769.             tempface = extrude(center,currface.no,prot,v3,v5,v6,t0,selectface3,flino)
  770.             if makedoodads == 1:
  771.                 if doodonselectedfaces == 1:
  772.                     if currface.sel:
  773.                         tempmesh = NMesh.GetRaw()
  774.                         tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  775.                         newmesh.verts.extend(tempmesh.verts)
  776.                         newmesh.faces.extend(tempmesh.faces)
  777.                     tempmesh = NMesh.GetRaw()
  778.                     tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  779.                     newmesh.verts.extend(tempmesh.verts)
  780.                     newmesh.faces.extend(tempmesh.faces)
  781.             if rotation < 0.5:
  782.                 face = Face()
  783.                 fpt = t0
  784.                 face.v.extend([newmesh.verts[fp[1]],newmesh.verts[fpt],newmesh.verts[v3]])
  785.                 newmesh.faces.append(face)
  786.             else:
  787.                 face = Face()
  788.                 fpt = t0
  789.                 face.v.extend([newmesh.verts[fp[0]],newmesh.verts[v3],newmesh.verts[fpt]])
  790.                 newmesh.faces.append(face)
  791.             verti = layer2verts[1]
  792.             tempindex = verti.index
  793.             center = Vector([0]*3)
  794.             for pt in [newmesh.verts[v5],newmesh.verts[v6],newmesh.verts[tempindex],newmesh.verts[v4]]:
  795.                 center = center + pt.co
  796.             center = center/4
  797.             prot = randnum(minimumheight,maximumheight)
  798.             tempface = extrude(center,currface.no,prot,v6,v5,v4,tempindex,selectface3,flino)
  799.             if makedoodads == 1:
  800.                 if doodonselectedfaces == 1:
  801.                     if currface.sel:
  802.                         tempmesh = NMesh.GetRaw()
  803.                         tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  804.                         newmesh.verts.extend(tempmesh.verts)
  805.                         newmesh.faces.extend(tempmesh.faces)
  806.                 else:
  807.                     tempmesh = NMesh.GetRaw()
  808.                     tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  809.                     newmesh.verts.extend(tempmesh.verts)
  810.                     newmesh.faces.extend(tempmesh.faces)
  811.             if rotation < 0.5:
  812.                 face = Face()
  813.                 face.v.extend([newmesh.verts[tempindex],newmesh.verts[fp[0]],newmesh.verts[v4]])
  814.                 newmesh.faces.append(face)
  815.                 face = Face()
  816.                 face.v.extend([newmesh.verts[fpt],newmesh.verts[tempindex],newmesh.verts[v6]])
  817.                 newmesh.faces.append(face)
  818.             else:
  819.                 face = Face()
  820.                 face.v.extend([newmesh.verts[tempindex],newmesh.verts[v4],newmesh.verts[fp[1]]])
  821.                 newmesh.faces.append(face)
  822.                 face = Face()
  823.                 face.v.extend([newmesh.verts[tempindex],newmesh.verts[fpt],newmesh.verts[v6]])
  824.                 newmesh.faces.append(face)
  825.             
  826.         else:
  827.             #get all points
  828.             verti = currface.v[0]
  829.             p0 = verti.index
  830.             
  831.             verti = currface.v[1]
  832.             p1 = verti.index
  833.         
  834.             pt = (newmesh.verts[p1].co - newmesh.verts[p0].co)/2 + newmesh.verts[p0].co
  835.             v1 = Vert(pt[0],pt[1],pt[2])
  836.             v1.sel = 0
  837.     
  838.             verti = currface.v[2]
  839.             p2 = verti.index
  840.  
  841.             pt = (newmesh.verts[p2].co - newmesh.verts[p1].co)/2 + newmesh.verts[p1].co
  842.             v2 = Vert(pt[0],pt[1],pt[2])
  843.             v2.sel = 0
  844.  
  845.             verti = currface.v[3]
  846.             p3 = verti.index
  847.  
  848.             pt = (newmesh.verts[p3].co - newmesh.verts[p2].co)/2 + newmesh.verts[p2].co
  849.             v3 = Vert(pt[0],pt[1],pt[2])
  850.             v3.sel = 0
  851.  
  852.             pt = (newmesh.verts[p0].co - newmesh.verts[p3].co)/2 + newmesh.verts[p3].co
  853.             v4 = Vert(pt[0],pt[1],pt[2])
  854.             v4.sel = 0
  855.  
  856.             pt = (v3.co - v1.co)/2 + v1.co
  857.             m = Vert(pt[0],pt[1],pt[2])
  858.             m.sel = 0
  859.             
  860.             #extrusion 1
  861.             newmesh.verts.extend([v1,m,v4])
  862.             index = len(newmesh.verts) - 3
  863.             v1 = index
  864.             m = index + 1
  865.             v4 = index + 2
  866.             center = Vector([0]*3)
  867.             for pt in [newmesh.verts[p0],newmesh.verts[v1],newmesh.verts[m],newmesh.verts[v4]]:
  868.                 center = center + pt.co
  869.             center = center/4
  870.             prot = randnum(minimumheight,maximumheight)
  871.             tempface = extrude(center,currface.no,prot,p0,v1,m,v4,selectface4)
  872.             if makedoodads == 1:
  873.                 if doodonselectedfaces == 1:
  874.                     if currface.sel:
  875.                         tempmesh = NMesh.GetRaw()
  876.                         tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  877.                         newmesh.verts.extend(tempmesh.verts)
  878.                         newmesh.faces.extend(tempmesh.faces)
  879.                 else:
  880.                     tempmesh = NMesh.GetRaw()
  881.                     tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  882.                     newmesh.verts.extend(tempmesh.verts)
  883.                     newmesh.faces.extend(tempmesh.faces)
  884.             
  885.             #extrusion 2
  886.             newmesh.verts.extend([v2])
  887.             index = len(newmesh.verts) - 1
  888.             v2 = index
  889.             center = Vector([0]*3)
  890.             for pt in [newmesh.verts[m],newmesh.verts[v1],newmesh.verts[p1],newmesh.verts[v2]]:
  891.                 center = center + pt.co
  892.             center = center/4
  893.             prot = randnum(minimumheight,maximumheight)
  894.             tempface = extrude(center,currface.no,prot,m,v1,p1,v2,selectface4)
  895.             if makedoodads == 1:
  896.                 if doodonselectedfaces == 1:
  897.                     if currface.sel:
  898.                         tempmesh = NMesh.GetRaw()
  899.                         tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  900.                         newmesh.verts.extend(tempmesh.verts)
  901.                         newmesh.faces.extend(tempmesh.faces)
  902.                 else:
  903.                     tempmesh = NMesh.GetRaw()
  904.                     tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  905.                     newmesh.verts.extend(tempmesh.verts)
  906.                     newmesh.faces.extend(tempmesh.faces)
  907.             
  908.             #extrusion 3
  909.             newmesh.verts.extend([v3])
  910.             index = len(newmesh.verts) - 1
  911.             v3 = index
  912.             center = Vector([0]*3)
  913.             for pt in [newmesh.verts[m],newmesh.verts[v2],newmesh.verts[p2],newmesh.verts[v3]]:
  914.                 center = center + pt.co
  915.             center = center/4
  916.             prot = randnum(minimumheight,maximumheight)
  917.             tempface = extrude(center,currface.no,prot,m,v2,p2,v3,selectface4)
  918.             if makedoodads == 1:
  919.                 if doodonselectedfaces == 1:
  920.                     if currface.sel:
  921.                         tempmesh = NMesh.GetRaw()
  922.                         tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  923.                         newmesh.verts.extend(tempmesh.verts)
  924.                         newmesh.faces.extend(tempmesh.faces)
  925.                 else:
  926.                     tempmesh = NMesh.GetRaw()
  927.                     tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  928.                     newmesh.verts.extend(tempmesh.verts)
  929.                     newmesh.faces.extend(tempmesh.faces)
  930.             
  931.             #extrusion 4
  932.             center = Vector([0]*3)
  933.             for pt in [newmesh.verts[m],newmesh.verts[v3],newmesh.verts[p3],newmesh.verts[v4]]:
  934.                 center = center + pt.co
  935.             center = center/4
  936.             prot = randnum(minimumheight,maximumheight)
  937.             tempface = extrude(center,currface.no,prot,v4,m,v3,p3,selectface4)
  938.             if makedoodads == 1:
  939.                 if doodonselectedfaces == 1:
  940.                     if currface.sel:
  941.                         tempmesh = NMesh.GetRaw()
  942.                         tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  943.                         newmesh.verts.extend(tempmesh.verts)
  944.                         newmesh.faces.extend(tempmesh.faces)
  945.                 else:
  946.                     tempmesh = NMesh.GetRaw()
  947.                     tempmesh = defaultdoodads.createDoodad(doodadArray, tempface, doodadminsize, doodadmaxsize, doodadminheight,doodadmaxheight, selectdoodad, doodadminperface, doodadmaxperface, doodadfacepercent)
  948.                     newmesh.verts.extend(tempmesh.verts)
  949.                     newmesh.faces.extend(tempmesh.faces)
  950.             
  951.             face = Face()
  952.             face.v.extend([newmesh.verts[p0],newmesh.verts[p1],newmesh.verts[v1]])
  953.             newmesh.faces.append(face)
  954.             face = Face()
  955.             face.v.extend([newmesh.verts[p1],newmesh.verts[p2],newmesh.verts[v2]])
  956.             newmesh.faces.append(face)
  957.             face = Face()
  958.             face.v.extend([newmesh.verts[p2],newmesh.verts[p3],newmesh.verts[v3]])
  959.             newmesh.faces.append(face)
  960.             face = Face()
  961.             face.v.extend([newmesh.verts[p3],newmesh.verts[p0],newmesh.verts[v4]])
  962.             newmesh.faces.append(face)
  963.             
  964.     #NMesh.PutRaw(newmesh)
  965.     if deselface == 1:
  966.         for unvert in origmesh.verts:
  967.             newmesh.verts[unvert.index].sel = 0
  968.     if makenewobj == 1:
  969.         newobj = Object.New('Mesh')
  970.         copyObjStuff(origobj,newobj)
  971.         newobj.link(newmesh)
  972.         scene = Blender.Scene.getCurrent()
  973.         scene.link(newobj)
  974.         origobj.select(0)
  975.         newobj.select(1)
  976.     else:
  977.         origobj.link(newmesh)
  978.     
  979.     #Return to Editmode if previously in it
  980.     if editmode: Window.EditMode(1)
  981.  
  982.  
  983. ####################### gui ######################
  984. from Blender.BGL import *
  985. from Blender.Draw import *
  986.  
  987. def ErrorText(errortext):
  988.     Window.WaitCursor(0)
  989.     Text(errortext)
  990.     PupMenu("ERROR: %s" % errortext.lower())
  991.  
  992. #Global Buttons
  993. makenewobject = Create(makenewobj)
  994. messagetext = Create(errortext)
  995.  
  996. #Protrusion Buttons
  997. doprots = Create(makeprots)
  998. facechange = Create(faceschangedpercent*100)
  999. minheight = Create(minimumheight)
  1000. maxheight = Create(maximumheight)
  1001. sub1 = Create(subface1)
  1002. sub2 = Create(subface2)
  1003. sub3 = Create(subface3)
  1004. sub4 = Create(subface4)
  1005. mintaper = Create(minimumtaperpercent*100)
  1006. maxtaper = Create(maximumtaperpercent*100)
  1007. useselected = Create(useselectedfaces)
  1008. selface1 = Create(selectface1)
  1009. selface2 = Create(selectface2)
  1010. selface3 = Create(selectface3)
  1011. selface4 = Create(selectface4)
  1012. deselectvertices = Create(deselface)
  1013. #selectbyverts = Create(vertselected)
  1014.  
  1015. #Doodad Buttons
  1016. dodoodads = Create(makedoodads)
  1017. doodadfacechange = Create(doodadfacepercent*100)
  1018. seldoodad = Create(selectdoodad)
  1019. onprot = Create(onlyonprotrusions)
  1020. dood1 = Create(doodad1)
  1021. dood2 = Create(doodad2)
  1022. dood3 = Create(doodad3)
  1023. dood4 = Create(doodad4)
  1024. dood5 = Create(doodad5)
  1025. dood6 = Create(doodad6)
  1026. doodadminamount = Create(doodadminperface)
  1027. doodadmaxamount = Create(doodadmaxperface)
  1028. doodsizemin = Create(doodadminsize*100)
  1029. doodsizemax = Create(doodadmaxsize*100)
  1030. doodheightmin = Create(doodadminheight)
  1031. doodheightmax = Create(doodadmaxheight)
  1032. doodonselface = Create(doodonselectedfaces)
  1033. seldoodtop = Create(selectdoodadtoponly)
  1034.  
  1035.  
  1036. # Events
  1037. EVENT_NONE = 1
  1038. EVENT_DISCOMBOBULATE = 2
  1039. EVENT_EXIT = 3
  1040.  
  1041. def colorbox(x,y,xright,bottom):
  1042.    glColor3f(0.75, 0.75, 0.75)
  1043.    glRecti(x + 1, y + 1, xright - 1, bottom - 1)
  1044.  
  1045. def draw():
  1046.     
  1047.     #Protrusions
  1048.     global doprots
  1049.     global facechange
  1050.     global minheight
  1051.     global maxheight
  1052.     global sub1
  1053.     global sub2
  1054.     global sub3
  1055.     global sub4
  1056.     global mintaper
  1057.     global maxtaper
  1058.     global useselected
  1059.     global selface1
  1060.     global selface2
  1061.     global selface3
  1062.     global selface4
  1063.     global deselectvertices
  1064.     #global selectbyverts
  1065.     
  1066.     #Doodads
  1067.     global dodoodads
  1068.     global doodadfacechange
  1069.     global seldoodad
  1070.     global onprot
  1071.     global dood1
  1072.     global dood2
  1073.     global dood3
  1074.     global dood4
  1075.     global dood5
  1076.     global dood6
  1077.     global doodadminamount
  1078.     global doodadmaxamount
  1079.     global doodsizemin
  1080.     global doodsizemax
  1081.     global doodheightmin
  1082.     global doodheightmax
  1083.     global doodonselface
  1084.     global seldoodtop
  1085.     
  1086.     #Global Settings
  1087.     global makenewobject
  1088.     global messagetext
  1089.     global errortext
  1090.     global EVENT_NONE,EVENT_DRAW,EVENT_EXIT
  1091.     
  1092.     #Height Addition, this is for changing the gui
  1093.     hadd = 10
  1094.     
  1095.     #Title :420high
  1096.     glClearColor(0.6, 0.6, 0.6, 1.0)
  1097.     glClear(GL_COLOR_BUFFER_BIT)
  1098.     glColor3f(0.0,0.0,0.0)
  1099.     glRasterPos2d(8, 400+hadd)
  1100.     Text("Discombobulator v5.3.5.406893.potato")
  1101.     
  1102.     #Protrusion
  1103.     colorbox(8,385+hadd,312,230+hadd)
  1104.     glColor3f(0.0,0.0,0.0)
  1105.     glRasterPos2d(12, 375+hadd)
  1106.     Text("Protrusions:")
  1107.     doprots = Toggle("Make Protrusions",EVENT_NONE,12,352+hadd,145,18,doprots.val,"Make Protrusions?")
  1108.     facechange = Number("Face %: ",EVENT_NONE,162,352+hadd,145,18,facechange.val,0,100,"Percentage of faces that will grow protrusions")
  1109.     useselected = Toggle("Only selected faces",EVENT_NONE,12,332+hadd,145,18,useselected.val,"If on, only selected faces will be modified")
  1110.     deselectvertices = Toggle("Deselect Selected",EVENT_NONE,162,332+hadd,145,18,deselectvertices.val,"Deselects any selected vertex except for ones selected by \"Select Tops\"")
  1111.     
  1112.     #Protrusion properties
  1113.     glColor3f(0.0,0.0,0.0)
  1114.     glRasterPos2d(12, 315+hadd)
  1115.     Text("Protrusion Properties:")
  1116.     minheight = Number("Min Height: ",EVENT_NONE,12,292+hadd,145,18,minheight.val,-100.0,100.0,"Minimum height of any protrusion")
  1117.     maxheight = Number("Max Height: ",EVENT_NONE,162,292+hadd,145,18,maxheight.val,-100.0,100.0,"Maximum height of any protrusion")
  1118.     mintaper = Number("Min Taper %: ",EVENT_NONE,12,272+hadd,145,18,mintaper.val,0,100,"Minimum taper percentage of protrusion")
  1119.     maxtaper = Number("Max Taper %: ",EVENT_NONE,162,272+hadd,145,18,maxtaper.val,0,100,"Maximum taper percentage of protrusion")
  1120.     glRasterPos2d(19, 257+hadd)
  1121.     Text("Number of protrusions:")
  1122.     sub1 = Toggle("1",EVENT_NONE,12,235+hadd,34,18,sub1.val,"One Protrusion")
  1123.     sub2 = Toggle("2",EVENT_NONE,48,235+hadd,34,18,sub2.val,"Two Protrusions")
  1124.     sub3 = Toggle("3",EVENT_NONE,84,235+hadd,34,18,sub3.val,"Three Protrusions")
  1125.     sub4 = Toggle("4",EVENT_NONE,120,235+hadd,34,18,sub4.val,"Four Protrusions")
  1126.     glRasterPos2d(195, 257+hadd)
  1127.     Text("Select tops of:")
  1128.     selface1 = Toggle("1",EVENT_NONE,165,235+hadd,34,18,selface1.val,"Select the tip of the protrusion when it is created")
  1129.     selface2 = Toggle("2",EVENT_NONE,201,235+hadd,34,18,selface2.val,"Select the tips of each protrusion when they are created")
  1130.     selface3 = Toggle("3",EVENT_NONE,237,235+hadd,34,18,selface3.val,"Select the tips of each protrusion when they are created")
  1131.     selface4 = Toggle("4",EVENT_NONE,273,235+hadd,34,18,selface4.val,"Select the tips of each protrusion when they are created")
  1132.     
  1133.     #Doodad
  1134.     colorbox(8,220+hadd,312,40+hadd)
  1135.     glColor3f(0.0,0.0,0.0)
  1136.     glRasterPos2d(12, 210+hadd)
  1137.     Text("Doodads:")
  1138.     dood1 = Toggle("1 Box",EVENT_NONE,12,207+hadd-20,45,18,dood1.val,"Creates a rectangular box")
  1139.     dood2 = Toggle("2 Box",EVENT_NONE,61,207+hadd-20,45,18,dood2.val,"Creates 2 side-by-side rectangular boxes")
  1140.     dood3 = Toggle("3 Box",EVENT_NONE,110,207+hadd-20,45,18,dood3.val,"Creates 3 side-by-side rectangular boxes")
  1141.     dood4 = Toggle("\"L\"",EVENT_NONE,164,207+hadd-20,45,18,dood4.val,"Creates a Tetris-style \"L\" shape")
  1142.     dood5 = Toggle("\"T\"",EVENT_NONE,213,207+hadd-20,45,18,dood5.val,"Creates a Tetris-style \"T\" shape")
  1143.     dood6 = Toggle("\"S\"",EVENT_NONE,262,207+hadd-20,45,18,dood6.val,"Creates a sort-of \"S\" or \"Z\" shape")
  1144.     dodoodads = Toggle("Make Doodads",EVENT_NONE,12,165+hadd,145,18,dodoodads.val,"Make Doodads?")
  1145.     doodadfacechange = Number("Face %: ",EVENT_NONE,162,165+hadd,145,18,doodadfacechange.val,0,100,"Percentage of faces that will gain doodads")
  1146.     seldoodad = Toggle("Select Doodads",EVENT_NONE,12,145+hadd,145,18,seldoodad.val,"Selects doodads when they are created")
  1147.     seldoodtop = Toggle("Only Select Tops",EVENT_NONE,162,145+hadd,145,18,seldoodtop.val,"Only Selects tops of doodads when\"Select Doodads\" is on")
  1148.     doodonselface = Toggle("Only selected faces",EVENT_NONE,12,125+hadd,145,18,doodonselface.val,"Only create doodads on selected faces")
  1149.     onprot = Toggle("Only on Protrusions",EVENT_NONE,162,125+hadd,145,18,onprot.val,"Only place doodads on protrusions")
  1150.     glColor3f(0.0,0.0,0.0)
  1151.     glRasterPos2d(12, 108+hadd)
  1152.     Text("Doodad Properties:")
  1153.     doodadminamount = Number("Min Amount: ",EVENT_NONE,12,85+hadd,145,18,doodadminamount.val,0,100,"Minimum number of doodads per face")
  1154.     doodadmaxamount = Number("Max Amount: ",EVENT_NONE,162,85+hadd,145,18,doodadmaxamount.val,0,100,"Maximum number of doodads per face")
  1155.     doodheightmin = Number("Min Height: ",EVENT_NONE,12,65+hadd,145,18,doodheightmin.val,0.0,100.0,"Minimum height of any doodad")
  1156.     doodheightmax = Number("Max Height: ",EVENT_NONE,162,65+hadd,145,18,doodheightmax.val,0.0,100.0,"Maximum height of any doodad")
  1157.     doodsizemin = Number("Min Size %: ",EVENT_NONE,12,45+hadd,145,18,doodsizemin.val,0.0,100.0,"Minimum size of any doodad in percentage of face")
  1158.     doodsizemax = Number("Max Size %: ",EVENT_NONE,162,45+hadd,145,18,doodsizemax.val,0.0,100.0,"Maximum size of any doodad in percentage of face")
  1159.     
  1160.     #Global Parts
  1161.     glColor3f(1.0,0.0,0.0)
  1162.     glRasterPos2d(10,35)
  1163.     messagetext = Text(errortext)
  1164.     glColor3f(0.0,0.0,0.0)
  1165.     makenewobject = Toggle("Copy Before Modifying",EVENT_NONE,162,10,145,18,makenewobject.val,"If selected, the original object will be copied before it is changed")
  1166.     Button("Discombobulate",EVENT_DISCOMBOBULATE,12,10,100,18)
  1167.     Button("Exit",EVENT_EXIT,120,10,30,18)
  1168.  
  1169. def event(evt, val):    
  1170.     if (evt == QKEY and not val): 
  1171.         Exit()
  1172.  
  1173. def bevent(evt):
  1174.     
  1175.     #Protrusions
  1176.     global doprots
  1177.     global facechange
  1178.     global minheight
  1179.     global maxheight
  1180.     global sub1
  1181.     global sub2
  1182.     global sub3
  1183.     global sub4
  1184.     global mintaper
  1185.     global maxtaper
  1186.     global useselected
  1187.     global selface1
  1188.     global selface2
  1189.     global selface3
  1190.     global selface4
  1191.     global deselectvertices
  1192.     #global selectbyverts
  1193.     
  1194.     #Doodads
  1195.     global dodoodads
  1196.     global doodadfacechange
  1197.     global seldoodad
  1198.     global onprot
  1199.     global dood1
  1200.     global dood2
  1201.     global dood3
  1202.     global dood4
  1203.     global dood5
  1204.     global dood6
  1205.     global doodadminamount
  1206.     global doodadmaxamount
  1207.     global doodsizemin
  1208.     global doodsizemax
  1209.     global doodheightmin
  1210.     global doodheightmax
  1211.     global doodonselface
  1212.     global seldoodtop
  1213.     
  1214.     #Global Settings
  1215.     global makenewobject
  1216.     global messagetext
  1217.     global errortext
  1218.     global EVENT_NONE,EVENT_DRAW,EVENT_EXIT
  1219.  
  1220.     ######### Manages GUI events
  1221.     if evt==EVENT_EXIT: 
  1222.         Exit()
  1223.     elif evt==EVENT_DISCOMBOBULATE:
  1224.         Window.WaitCursor(1)
  1225.         discombobulate(doprots.val,facechange.val/100,minheight.val,maxheight.val,sub1.val,sub2.val,sub3.val,sub4.val,mintaper.val/100,maxtaper.val/100,useselected.val,selface1.val,selface2.val,selface3.val,selface4.val,deselectvertices.val,makenewobject.val,dodoodads.val,doodadfacechange.val/100,seldoodad.val,onprot.val,dood1.val,dood2.val,dood3.val,dood4.val,dood5.val,dood6.val,doodadminamount.val,doodadmaxamount.val,doodsizemin.val/100,doodsizemax.val/100,doodheightmin.val,doodheightmax.val,doodonselface.val,seldoodtop.val)
  1226.         Window.WaitCursor(0)
  1227.         Blender.Redraw()
  1228.  
  1229. Register(draw, event, bevent)
  1230.