diff --git a/release/scripts/DirectX8Exporter.py b/release/scripts/DirectX8Exporter.py index 0eea95bcc93..bfe6ccbdc88 100644 --- a/release/scripts/DirectX8Exporter.py +++ b/release/scripts/DirectX8Exporter.py @@ -1,12 +1,12 @@ #!BPY """ Registration info for Blender menus: -Name: 'DirectX8 (.x)...' -Blender: 234 +Name: 'DirectX8(.x)...' +Blender: 239 Group: 'Export' -Submenu: 'Export to DX8 file format' export -Submenu: 'How to use this exporter?' help -Tip: 'Export to DirectX8 text file format' +Submenu: 'Export all the scene' export +Submenu: 'Export selected obj' exportsel +Tip: 'Export to DirectX8 text file format format.' """ __author__ = "Arben (Ben) Omari" @@ -17,29 +17,10 @@ __bpydoc__ = """\ This script exports a Blender mesh with armature to DirectX 8's text file format. -Usage: - -1) There should be only one mesh and one armature in the scene; - -2) Before parenting set:
- a) Armature and mesh must have the same origin location -(in the 3d View press N (menu Object->"Transform Properties") for both and set -same LocX, LocY and LocZ);
- b) Armature and mesh must have the same rotation -(select them and press Ctrl + A); - -3) Set the number of the animation frames to export; - -4) Read warnings (if any) in console. - Notes:
Check author's site or the elYsiun forum for a new beta version of the DX exporter. """ - - -# $Id$ -# # DirectX8Exporter.py version 1.0 # Copyright (C) 2003 Arben OMARI -- omariarben@everyday.com # @@ -66,48 +47,6 @@ global new_bon,mat_flip,index_list index_list = [] new_bon = {} mat_flip = Matrix([1, 0, 0, 0], [0, 1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]) - -def draw(): - - # clearing screen - Blender.BGL.glClearColor(0.5, 0.5, 0.5, 1) - Blender.BGL.glColor3f(1.,1.,1.) - Blender.BGL.glClear(Blender.BGL.GL_COLOR_BUFFER_BIT) - - # Buttons - Blender.Draw.Button("Exit", 1, 10, 40, 100, 25) - - #Text - Blender.BGL.glColor3f(1, 1, 1) - Blender.BGL.glRasterPos2d(10, 310) - Blender.Draw.Text("1.Only one mesh and one armature in the scene") - Blender.BGL.glRasterPos2d(10, 290) - Blender.Draw.Text("2.Before parenting set:") - - - - Blender.BGL.glRasterPos2d(10, 270) - Blender.Draw.Text(" a)Armature and mesh must have the same origin location") - Blender.BGL.glRasterPos2d(10, 255) - Blender.Draw.Text(" (press N for both and set the same LocX,LocY and LocZ)") - Blender.BGL.glRasterPos2d(10, 230) - Blender.Draw.Text(" b)Armature and mesh must have the same to rotation") - Blender.BGL.glRasterPos2d(10, 215) - Blender.Draw.Text(" (select them and press Ctrl + A)") - Blender.BGL.glRasterPos2d(10, 195) - Blender.Draw.Text("3.Set the number of the animation frames to export ") - Blender.BGL.glRasterPos2d(10, 175) - Blender.Draw.Text("5.Read warnings in console(if any)") - - - -def event(evt, val): - if evt == Blender.Draw.ESCKEY and not val: Blender.Draw.Exit() - -def bevent(evt): - - if evt == 1: Blender.Draw.Exit() - #*********************************************** @@ -122,49 +61,114 @@ class xExport: #********************************************************************************************************************************************* #*********************************************** - #Export Animation + #Select Scene objects #*********************************************** - def exportMesh(self,arm,arm_ob,tex): + def SelectObjs(self): + print "exporting..." + self.writeHeader() + for obj in Object.Get(): + mesh = obj.getData() + if type(mesh) == Types.NMeshType : + chld_obj = obj.getParent() + if chld_obj : + dt_chld_obj = chld_obj.getData() + if type(dt_chld_obj) == Types.ArmatureType : + self.writeRootBone(chld_obj, obj) + + else : + self.exportMesh(obj) + self.file.write("AnimationSet {\n") + for obj in Object.Get(): + mesh = obj.getData() + if type(mesh) == Types.NMeshType : + ip_list = obj.getIpo() + if ip_list != None : + self.writeAnimationObj(obj) + elif type(mesh) == Types.ArmatureType : + act_list = obj.getAction() + if act_list != None : + self.writeAnimation(obj) + ip_list = obj.getIpo() + if ip_list != None : + self.writeAnimationObjArm(obj) + self.file.write("}\n") + self.writeEnd() + #*********************************************** + #Export Mesh without Armature + #*********************************************** + def exportMesh(self, obj): + tex = [] + mesh = obj.getData() + self.writeTextures(obj, tex) + self.writeMeshcoord(obj, mesh) + self.writeMeshMaterialList(obj, mesh, tex) + self.writeMeshNormals(obj, mesh) + self.writeMeshTextureCoords(obj, mesh) + self.file.write(" }\n") + self.file.write("}\n") - for name in Object.Get(): - obj = name.getData() - if type(obj) == Types.NMeshType : - self.writeMeshcoord(name, obj,arm_ob) - self.writeMeshMaterialList(name, obj, tex) - self.writeMeshNormals(name, obj) - self.writeMeshTextureCoords(name, obj) - self.writeSkinWeights(arm,obj) - self.file.write(" }\n") + + #*********************************************** + #Export the Selected Mesh + #*********************************************** + def exportSelMesh(self): + print "exporting ..." + self.writeHeader() + tex = [] + obj = Object.GetSelected()[0] + mesh = obj.getData() + if type(mesh) == Types.NMeshType : + self.writeTextures(obj, tex) + self.writeMeshcoord(obj, mesh) + self.writeMeshMaterialList(obj, mesh, tex) + self.writeMeshNormals(obj, mesh) + self.writeMeshTextureCoords(obj, mesh) + self.file.write(" }\n") + self.file.write("}\n") + ip_list = obj.getIpo() + if ip_list != None : + self.file.write("AnimationSet {\n") + self.writeAnimationObj(obj) self.file.write("}\n") - self.writeAnimation(name, obj,arm) + print "exporting ..." + else : + print "The selected object is not a mesh" + print "...finished" + #*********************************************** + #Export Mesh with Armature + #*********************************************** + def exportMeshArm(self,arm,arm_ob,ch_obj): + tex = [] + mesh = ch_obj.getData() + self.writeTextures(ch_obj, tex) + self.writeMeshcoordArm(ch_obj, mesh,arm_ob) + self.writeMeshMaterialList(ch_obj, mesh, tex) + self.writeMeshNormals(ch_obj, mesh) + self.writeMeshTextureCoords(ch_obj, mesh) + self.writeSkinWeights(arm,mesh) + self.file.write(" }\n") + self.file.write("}\n") + + #*********************************************** #Export Root Bone #*********************************************** - def writeRootBone(self): + def writeRootBone(self,am_ob,child_obj): global new_bon,mat_flip space = 0 - tex = [] - print "exporting ..." - self.writeHeader() - for name in Object.Get(): - obj = name.getData() - if type(obj) == Types.NMeshType : - self.writeTextures(name, tex) - arm = name.getData() - if type(arm) == Types.ArmatureType : - Blender.Set('curframe',1) - am_ob = Object.Get(name.name) - mat_ob = mat_flip * am_ob.getMatrix() - self.writeArmFrames(mat_ob, "RootFrame", 0) - root_bon = arm.getBones() - mat_r = self.writeCombineMatrix(root_bon[0]) - name_r = root_bon[0].getName() - new_bon[name_r] = len(root_bon[0].getChildren()) - self.writeArmFrames(mat_r, name_r, 1) - self.writeListOfChildrens(root_bon[0],2,arm) - self.file.write("}\n") - self.exportMesh(arm,am_ob, tex) - self.writeEnd() + arm = am_ob.getData() + Blender.Set('curframe',1) + mat_ob = mat_flip * am_ob.matrixWorld + self.writeArmFrames(mat_ob, "RootFrame", 0) + root_bon = arm.getBones() + mat_r = self.writeCombineMatrix(root_bon[0]) + name_r = root_bon[0].getName() + new_bon[name_r] = len(root_bon[0].getChildren()) + self.writeArmFrames(mat_r, name_r, 1) + self.writeListOfChildrens(root_bon[0],2,arm) + self.file.write("}\n") + self.exportMeshArm(arm,am_ob,child_obj) + #*********************************************** #Export Children Bones #*********************************************** @@ -348,13 +352,16 @@ class xExport: self.file.write("%s" % (tab * space)) self.file.write(" FrameTransformMatrix {\n") self.file.write("%s" % (tab * space)) - self.file.write(" %s,%s,%s,%s," % + self.file.write(" %s,%s,%s,%s,\n" % (round(matx[0][0],4),round(matx[0][1],4),round(matx[0][2],4),round(matx[0][3],4))) - self.file.write("%s,%s,%s,%s," % - (round(matx[1][0],4),round(matx[1][1],4),round(matx[1][2],4),round(matx[1][3],4))) - self.file.write("%s,%s,%s,%s," % + self.file.write("%s" % (tab * space)) + self.file.write(" %s,%s,%s,%s,\n" % + (round(matx[1][0],4),round(matx[1][1],4),round(matx[1][2],4),round(matx[1][3],4))) + self.file.write("%s" % (tab * space)) + self.file.write(" %s,%s,%s,%s,\n" % (round(matx[2][0],4),round(matx[2][1],4),round(matx[2][2],4),round(matx[2][3],4))) - self.file.write("%s,%s,%s,%s;;\n" % + self.file.write("%s" % (tab * space)) + self.file.write(" %s,%s,%s,%s;;\n" % (round(matx[3][0],4),round(matx[3][1],4),round(matx[3][2],4),round(matx[3][3],6))) self.file.write("%s" % (tab * space)) self.file.write(" }\n") @@ -365,13 +372,16 @@ class xExport: def writeOffsFrames(self, matx, name, space): tab = " " self.file.write("%s" % (tab * space)) - self.file.write(" %s,%s,%s,%s," % + self.file.write(" %s,%s,%s,%s,\n" % (round(matx[0][0],4),round(matx[0][1],4),round(matx[0][2],4),round(matx[0][3],4))) - self.file.write("%s,%s,%s,%s," % - (round(matx[1][0],4),round(matx[1][1],4),round(matx[1][2],4),round(matx[1][3],4))) - self.file.write("%s,%s,%s,%s," % + self.file.write("%s" % (tab * space)) + self.file.write(" %s,%s,%s,%s,\n" % + (round(matx[1][0],4),round(matx[1][1],4),round(matx[1][2],4),round(matx[1][3],4))) + self.file.write("%s" % (tab * space)) + self.file.write(" %s,%s,%s,%s,\n" % (round(matx[2][0],4),round(matx[2][1],4),round(matx[2][2],4),round(matx[2][3],4))) - self.file.write("%s,%s,%s,%s;;\n" % + self.file.write("%s" % (tab * space)) + self.file.write(" %s,%s,%s,%s;;\n" % (round(matx[3][0],4),round(matx[3][1],4),round(matx[3][2],4),round(matx[3][3],6))) self.file.write("%s" % (tab * space)) self.file.write(" }\n") @@ -425,18 +435,80 @@ template SkinWeights {\n\ #*********************************************** - #EXPORT MESH DATA + #EXPORT MESH DATA with Armature #*********************************************** - def writeMeshcoord(self, name, mesh,armat): + def writeMeshcoordArm(self, name, meshEX,arm_ob): global index_list #ROTATION - mat_ob = name.getMatrix() - mat_ar = armat.getInverseMatrix() - mat_f = mat_ob * mat_ar - self.writeArmFrames(mat_f, "body", 1) + mat_arm = arm_ob.matrixWorld + mat_ob = name.getMatrix('localspace') + mat_ob.invert() + mat = mat_arm * mat_ob + mat.invert() + self.writeArmFrames(mat, name.name, 1) + mesh = NMesh.GetRawFromObject(name.name) + self.file.write("Mesh {\n") + numface=len(mesh.faces) + #VERTICES NUMBER + numvert = 0 + for face in mesh.faces: + numvert = numvert + len(face.v) + self.file.write("%s;\n" % (numvert)) + #VERTICES COORDINATES + counter = 0 + for face in mesh.faces: + counter += 1 + for n in range(len(face.v)): + index_list.append(face.v[n].index) + vec_vert = Vector([face.v[n].co[0], face.v[n].co[1], face.v[n].co[2], 1]) + f_vec_vert = VecMultMat(vec_vert, mat) + self.file.write("%s; %s; %s;" % (f_vec_vert[0], f_vec_vert[1], f_vec_vert[2])) + if counter == numface : + if n == len(face.v)-1 : + self.file.write(";\n") + else : + self.file.write(",\n") + else : + self.file.write(",\n") + + #FACES NUMBER + self.file.write("%s;\n" % (numface)) + coun,counter = 0, 0 + for face in mesh.faces : + coun += 1 + if coun == numface: + if len(face.v) == 3: + self.file.write("3; %s, %s, %s;;\n" % (counter, counter + 2, counter + 1)) + counter += 3 + elif len(face.v) == 4: + self.file.write("4; %s, %s, %s, %s;;\n" % (counter, counter + 3, counter + 2, counter + 1)) + counter += 4 + elif len(face.v) < 3: + print "WARNING:the mesh has faces with less then 3 vertices" + print " It my be not exported correctly." + else: + + if len(face.v) == 3: + self.file.write("3; %s, %s, %s;,\n" % (counter, counter + 2, counter + 1)) + counter += 3 + elif len(face.v) == 4: + self.file.write("4; %s, %s, %s, %s;,\n" % (counter, counter + 3, counter + 2, counter + 1)) + counter += 4 + elif len(face.v) < 3: + print "WARNING:the mesh has faces with less then 3 vertices" + print " It my be not exported correctly." + + #*********************************************** + #EXPORT MESH DATA without Armature + #*********************************************** + def writeMeshcoord(self, name, mesh): + global index_list + #ROTATION + mat_ob = mat_flip * name.matrixWorld + self.writeArmFrames(mat_ob, name.name, 0) self.file.write("Mesh {\n") - numfaces=len(mesh.faces) + numface=len(mesh.faces) #VERTICES NUMBER numvert = 0 for face in mesh.faces: @@ -449,7 +521,7 @@ template SkinWeights {\n\ for n in range(len(face.v)): index_list.append(face.v[n].index) self.file.write("%s; %s; %s;" % (face.v[n].co[0], face.v[n].co[1], face.v[n].co[2])) - if counter == numfaces : + if counter == numface : if n == len(face.v)-1 : self.file.write(";\n") else : @@ -458,9 +530,7 @@ template SkinWeights {\n\ self.file.write(",\n") #FACES NUMBER - self.file.write("%s;\n" % (numfaces)) - #FACES INDEX - numface=len(mesh.faces) + self.file.write("%s;\n" % (numface)) coun,counter = 0, 0 for face in mesh.faces : coun += 1 @@ -468,69 +538,24 @@ template SkinWeights {\n\ if len(face.v) == 3: self.file.write("3; %s, %s, %s;;\n" % (counter, counter + 2, counter + 1)) counter += 3 - else : + elif len(face.v) == 4: self.file.write("4; %s, %s, %s, %s;;\n" % (counter, counter + 3, counter + 2, counter + 1)) counter += 4 + elif len(face.v) < 3: + print "WARNING:the mesh has faces with less then 3 vertices(edges and points)" + print " It my be not exported correctly." else: if len(face.v) == 3: self.file.write("3; %s, %s, %s;,\n" % (counter, counter + 2, counter + 1)) counter += 3 - else : + elif len(face.v) == 4: self.file.write("4; %s, %s, %s, %s;,\n" % (counter, counter + 3, counter + 2, counter + 1)) counter += 4 - - - - #*********************************************** - #VERTEX DUPLICATION INDEX - #*********************************************** - def writeVertDupInd(self, mesh): - self.file.write(" VertexDuplicationIndices {\n") - numvert = 0 - numfaces=len(mesh.faces) - for face in mesh.faces: - numvert = numvert + len(face.v) - self.file.write(" %s;\n" % (numvert+len(mesh.verts))) - self.file.write(" %s;\n" % (len(mesh.verts))) - #VERTICES INDEX - cou = 0 - for vert in mesh.verts: - cou += 1 - self.file.write(" %s" % ((vert.index))) - if cou == len(mesh.verts): - self.file.write(";\n") - else: - self.file.write(",\n") - - counter = 0 - for face in mesh.faces: - counter += 1 - if counter == numfaces: - if len(face.v) == 4: - self.file.write(" %s,\n" % ((face.v[0].index))) - self.file.write(" %s,\n" % ((face.v[1].index))) - self.file.write(" %s,\n" % ((face.v[2].index))) - self.file.write(" %s;\n" % ((face.v[3].index))) - elif len(face.v) == 3 : - self.file.write(" %s,\n" % ((face.v[0].index))) - self.file.write(" %s,\n" % ((face.v[1].index))) - self.file.write(" %s;\n" % ((face.v[2].index))) - - else : - if len(face.v) == 4: - self.file.write(" %s,\n" % ((face.v[0].index))) - self.file.write(" %s,\n" % ((face.v[1].index))) - self.file.write(" %s,\n" % ((face.v[2].index))) - self.file.write(" %s,\n" % ((face.v[3].index))) - elif len(face.v) == 3 : - self.file.write(" %s,\n" % ((face.v[0].index))) - self.file.write(" %s,\n" % ((face.v[1].index))) - self.file.write(" %s,\n" % ((face.v[2].index))) - - self.file.write(" }\n") - - + elif len(face.v) < 3: + print "WARNING:the mesh has faces with less then 3 vertices(edges and points)\n" + print " It my be not exported correctly." + #*********************************************** #MESH MATERIAL LIST @@ -585,7 +610,7 @@ template SkinWeights {\n\ self.file.write(" 1.0; 1.0; 1.0;;\n") self.file.write(" 0.0; 0.0; 0.0;;\n") self.file.write(" TextureFilename {\n") - self.file.write(' "%s" ;'% (face.image.name)) + self.file.write(' "%s" ;'% (mat)) self.file.write(" }\n") self.file.write(" }\n") self.file.write(" }\n") @@ -690,40 +715,132 @@ template SkinWeights {\n\ #*********************************************** #WRITE ANIMATION KEYS #*********************************************** - def writeAnimation(self, name, obj, arm): - self.file.write("AnimationSet {\n") - startFr = Blender.Get('staframe') - endFr = Blender.Get('endframe') + def writeAnimation(self,arm_ob): + arm = arm_ob.getData() + act_list = arm_ob.getAction() + ip = act_list.getAllChannelIpos() for bon in arm.getBones() : + point_list = [] + try : + ip_bon_channel = ip[bon.name] + ip_bon_name = ip_bon_channel.getName() - self.file.write(" Animation { \n") - self.file.write(" {%s}\n" %(bon.getName())) - self.file.write(" AnimationKey { \n") - self.file.write(" 4;\n") - self.file.write(" %s; \n" % (endFr)) + ip_bon = Blender.Ipo.Get(ip_bon_name) + poi = ip_bon.getCurves() + for po in poi[3].getPoints(): + a = po.getPoints() + point_list.append(int(a[0])) + point_list.pop(0) + + + self.file.write(" Animation { \n") + self.file.write(" {%s}\n" %(bon.getName())) + self.file.write(" AnimationKey { \n") + self.file.write(" 4;\n") + self.file.write(" %s; \n" % (len(point_list)+1)) - self.file.write(" %s;" % (1)) - self.file.write("16;") - mat = self.writeCombineMatrix(bon) - self.writeFrames(mat) - self.file.write(",\n") - - for fr in range(startFr+1,endFr + 1) : - self.file.write(" %s;" % (fr)) + self.file.write(" %s;" % (1)) self.file.write("16;") - Blender.Set('curframe',fr) + mat = self.writeCombineMatrix(bon) + self.writeFrames(mat) + self.file.write(",\n") + + for fr in point_list: + self.file.write(" %s;" % (fr)) + self.file.write("16;") + Blender.Set('curframe',fr) - mat_new = self.writeCombineAnimMatrix(bon) - self.writeFrames(mat_new) + mat_new = self.writeCombineAnimMatrix(bon) + self.writeFrames(mat_new) - if fr == endFr: - self.file.write(";\n") - else: - self.file.write(",\n") - self.file.write(" }\n") - self.file.write(" }\n") - self.file.write("\n") - self.file.write("}\n") + if fr == point_list[len(point_list)-1]: + self.file.write(";\n") + else: + self.file.write(",\n") + self.file.write(" }\n") + self.file.write(" }\n") + self.file.write("\n") + except: + pass + + + + #*********************************************** + #WRITE ANIMATION KEYS + #*********************************************** + def writeAnimationObj(self, obj): + point_list = [] + ip = obj.getIpo() + poi = ip.getCurves() + for po in poi[0].getPoints(): + a = po.getPoints() + point_list.append(int(a[0])) + point_list.pop(0) + + self.file.write(" Animation {\n") + self.file.write(" {") + self.file.write("%s }\n" % (obj.name)) + self.file.write(" AnimationKey { \n") + self.file.write(" 4;\n") + self.file.write(" %s; \n" % (len(point_list)+1)) + self.file.write(" %s;" % (1)) + self.file.write("16;") + Blender.Set('curframe',1) + mat = obj.matrixWorld * mat_flip + self.writeFrames(mat) + self.file.write(",\n") + for fr in point_list: + self.file.write(" %s;" % (fr)) + self.file.write("16;") + Blender.Set('curframe',fr) + + mat_new = obj.matrixWorld * mat_flip + self.writeFrames(mat_new) + + if fr == point_list[len(point_list)-1]: + self.file.write(";\n") + else: + self.file.write(",\n") + self.file.write(" }\n") + self.file.write(" }\n") + + #*********************************************** + #WRITE ANIMATION KEYS + #*********************************************** + def writeAnimationObjArm(self, obj): + point_list = [] + ip = obj.getIpo() + poi = ip.getCurves() + for po in poi[0].getPoints(): + a = po.getPoints() + point_list.append(int(a[0])) + point_list.pop(0) + + self.file.write(" Animation {\n") + self.file.write(" {RootFrame}\n" ) + self.file.write(" AnimationKey { \n") + self.file.write(" 4;\n") + self.file.write(" %s; \n" % (len(point_list)+1)) + self.file.write(" %s;" % (1)) + self.file.write("16;") + Blender.Set('curframe',1) + mat = mat_flip * obj.getMatrix('worldspace') + self.writeFrames(mat) + self.file.write(",\n") + for fr in point_list: + self.file.write(" %s;" % (fr)) + self.file.write("16;") + Blender.Set('curframe',fr) + + mat_new = mat_flip * obj.getMatrix('worldspace') + self.writeFrames(mat_new) + + if fr == point_list[len(point_list)-1]: + self.file.write(";\n") + else: + self.file.write(",\n") + self.file.write(" }\n") + self.file.write(" }\n") #***********************************************#***********************************************#*********************************************** @@ -736,12 +853,19 @@ template SkinWeights {\n\ def my_callback(filename): if filename.find('.x', -2) <= 0: filename += '.x' xexport = xExport(filename) - xexport.writeRootBone() + xexport.SelectObjs() +def my_callback_sel(filename): + if filename.find('.x', -2) <= 0: filename += '.x' + xexport = xExport(filename) + xexport.exportSelMesh() arg = __script__['arg'] -if arg == 'help': - Blender.Draw.Register(draw,event,bevent) + +if arg == 'exportsel': + fname = Blender.sys.makename(ext = ".x") + Blender.Window.FileSelector(my_callback_sel, "Export DirectX8", fname) else: fname = Blender.sys.makename(ext = ".x") Blender.Window.FileSelector(my_callback, "Export DirectX8", fname) + diff --git a/release/scripts/bpymodules/defaultdoodads.py b/release/scripts/bpymodules/defaultdoodads.py index b36f285e904..987b8b8ae71 100644 --- a/release/scripts/bpymodules/defaultdoodads.py +++ b/release/scripts/bpymodules/defaultdoodads.py @@ -61,13 +61,35 @@ seltopsonly = 0 tempx = [] doodadMesh = NMesh.GetRaw() +global materialArray +global reassignMats +global thereAreMats +global currmat +global doodSideMat +global doodTopMat + #face is the face to add the doodad to. #sizeX and sizeY are values from 0.0 to 1.0 that represents a percentage the face that is covered by the doodad. #height is how tall the doodad is. -def topsonly(seltops): +def settings(seltops,matArr,reasMats,therMats,sidemat,topmat): global seltopsonly + global materialArray + global reassignMats + global thereAreMats + global currmat + global doodSideMat + global doodTopMat + materialArray = matArr + reassignMats = reasMats + thereAreMats = therMats seltopsonly = seltops + doodSideMat = sidemat + doodTopMat = topmat + +def setCurrMat(curma): + global currmat + currmat = curma #Find center and orientation of doodad def findDoodadCenter(sizeX, sizeY): @@ -92,13 +114,13 @@ def findDoodadCenter(sizeX, sizeY): center = Vector([0,0,0]) for pt in face.v: center = center + pt.co - center = center/len(face.v) + center = divideVectorByInt(center,len(face.v)) #Find Temp Location Range by looking at the sizes - txmin = (((face.v[0].co + face.v[3].co)/2) - center)*(1-sizeX) + center - txmax = (((face.v[1].co + face.v[2].co)/2) - center)*(1-sizeX) + center - tymin = (((face.v[0].co + face.v[1].co)/2) - center)*(1-sizeY) + center - tymax = (((face.v[2].co + face.v[3].co)/2) - center)*(1-sizeY) + center + txmin = ((divideVectorByInt((face.v[0].co + face.v[3].co),2)) - center)*(1-sizeX) + center + txmax = ((divideVectorByInt((face.v[1].co + face.v[2].co),2)) - center)*(1-sizeX) + center + tymin = ((divideVectorByInt((face.v[0].co + face.v[1].co),2)) - center)*(1-sizeY) + center + tymax = ((divideVectorByInt((face.v[2].co + face.v[3].co),2)) - center)*(1-sizeY) + center #Find Center of doodad amtx = randnum(0.0,1.0) @@ -107,10 +129,10 @@ def findDoodadCenter(sizeX, sizeY): doodadCenter = Vector([thepoint[0],thepoint[1],thepoint[2]]) #Find Main Range by looking at the sizes - mxmin = (face.v[0].co + face.v[3].co)/2 - mxmax = (face.v[1].co + face.v[2].co)/2 - mymin = (face.v[0].co + face.v[1].co)/2 - mymax = (face.v[2].co + face.v[3].co)/2 + mxmin = divideVectorByInt((face.v[0].co + face.v[3].co),2) + mxmax = divideVectorByInt((face.v[1].co + face.v[2].co),2) + mymin = divideVectorByInt((face.v[0].co + face.v[1].co),2) + mymax = divideVectorByInt((face.v[2].co + face.v[3].co),2) #Find x/y equivs for whole face ve1 = (txmin - txmax)*amtx + txmax @@ -144,10 +166,10 @@ def findDoodadCenter(sizeX, sizeY): tempx.append((((((mxmin - mxmax)*amtx + mxmax) - ((mymin - mymax)*amty + mymax))*.5 + ((mymin - mymax)*amty + mymax)) - center)*2 + center) #Find New Location Range by looking at the sizes - xmin = (tempx[0] + tempx[3])/2 - xmax = (tempx[1] + tempx[2])/2 - ymin = (tempx[0] + tempx[1])/2 - ymax = (tempx[2] + tempx[3])/2 + xmin = divideVectorByInt((tempx[0] + tempx[3]),2) + xmax = divideVectorByInt((tempx[1] + tempx[2]),2) + ymin = divideVectorByInt((tempx[0] + tempx[1]),2) + ymax = divideVectorByInt((tempx[2] + tempx[3]),2) #Make a point def makePoint(x,y,z=0): @@ -193,11 +215,21 @@ def extrudedoodad(vArray,heig): face = Face() face.v.extend([vArray[ind],vArray[ind+1],topVArray[ind+1],topVArray[ind]]) if tosel == 1 and seltopsonly == 0: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodSideMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([vArray[len(vArray) - 1],vArray[0],topVArray[0],topVArray[len(topVArray) - 1]]) if tosel == 1 and seltopsonly == 0: - face.sel = 1 + face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodSideMat-1 doodadMesh.faces.append(face) return topVArray @@ -234,6 +266,7 @@ def createDoodad(indexArray,facec,minsi,maxsi,minhei,maxhei,selec,amtmin,amtmax, #Determine orientation orient = int(round(randnum(0.0,3.0))) + #face to use as range facer = Face() facer.v.extend([facec.v[orient],facec.v[fixvertindex(1+orient)],facec.v[fixvertindex(2+orient)],facec.v[fixvertindex(3+orient)]]) @@ -255,6 +288,12 @@ def createDoodad(indexArray,facec,minsi,maxsi,minhei,maxhei,selec,amtmin,amtmax, return doodadMesh +def divideVectorByInt(thevect,theint): + thevect.x = thevect.x/theint + thevect.y = thevect.y/theint + thevect.z = thevect.z/theint + return thevect + #Single Box Doodad def singleBox(facel, Xsize, Ysize, height): #globaling junk @@ -284,6 +323,11 @@ def singleBox(facel, Xsize, Ysize, height): face.v.extend(topVertArray) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) #Double Box Doodad @@ -315,6 +359,11 @@ def doubleBox(facel, Xsize, Ysize, height): face.v.extend(topVertArray) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) vertArray = [] @@ -334,6 +383,11 @@ def doubleBox(facel, Xsize, Ysize, height): face.v.extend(topVertArray) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) #Triple Box Doodad @@ -365,6 +419,11 @@ def tripleBox(facel, Xsize, Ysize, height): face.v.extend(topVertArray) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) vertArray = [] @@ -384,6 +443,11 @@ def tripleBox(facel, Xsize, Ysize, height): face.v.extend(topVertArray) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) vertArray = [] @@ -403,6 +467,11 @@ def tripleBox(facel, Xsize, Ysize, height): face.v.extend(topVertArray) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) #The "L" Shape @@ -433,33 +502,65 @@ def LShape(facel, Xsize, Ysize, height): vertArray.append(makePoint(rcon2,0)) topVertArray = extrudedoodad(vertArray,height) + #This fills in the bottom of doodad with faceness face = Face() face.v.extend([vertArray[0],vertArray[1],vertArray[4],vertArray[7]]) face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([vertArray[1],vertArray[2],vertArray[3],vertArray[4]]) face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([vertArray[4],vertArray[5],vertArray[6],vertArray[7]]) face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) + #This fills in the top with faceness face = Face() face.v.extend([topVertArray[0],topVertArray[1],topVertArray[4],topVertArray[7]]) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([topVertArray[1],topVertArray[2],topVertArray[3],topVertArray[4]]) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([topVertArray[4],topVertArray[5],topVertArray[6],topVertArray[7]]) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) #The "T" Shape @@ -493,42 +594,84 @@ def TShape(facel, Xsize, Ysize, height): vertArray.append(makePoint(rconx1,0)) topVertArray = extrudedoodad(vertArray,height) + #fills bottom with faceness face = Face() face.v.extend([vertArray[0],vertArray[1],vertArray[2],vertArray[9]]) face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([vertArray[2],vertArray[3],vertArray[4],vertArray[5]]) face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([vertArray[5],vertArray[6],vertArray[7],vertArray[8]]) face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([vertArray[8],vertArray[9],vertArray[2],vertArray[5]]) face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) + #fills top with faceness face = Face() face.v.extend([topVertArray[0],topVertArray[1],topVertArray[2],topVertArray[9]]) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([topVertArray[2],topVertArray[3],topVertArray[4],topVertArray[5]]) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([topVertArray[5],topVertArray[6],topVertArray[7],topVertArray[8]]) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([topVertArray[8],topVertArray[9],topVertArray[2],topVertArray[5]]) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) #The "S" or "Z" Shapes @@ -565,51 +708,103 @@ def SShape(facel, Xsize, Ysize, height): vertArray.append(makePoint(rconx1,0)) topVertArray = extrudedoodad(vertArray,height) + #fills bottom with faceness face = Face() face.v.extend([vertArray[0],vertArray[1],vertArray[2],vertArray[11]]) face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([vertArray[2],vertArray[9],vertArray[10],vertArray[11]]) face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([vertArray[2],vertArray[3],vertArray[8],vertArray[9]]) face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([vertArray[3],vertArray[4],vertArray[5],vertArray[8]]) face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([vertArray[5],vertArray[6],vertArray[7],vertArray[8]]) face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) + #fills top with faceness face = Face() face.v.extend([topVertArray[0],topVertArray[1],topVertArray[2],topVertArray[11]]) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([topVertArray[2],topVertArray[9],topVertArray[10],topVertArray[11]]) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([topVertArray[2],topVertArray[3],topVertArray[8],topVertArray[9]]) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([topVertArray[3],topVertArray[4],topVertArray[5],topVertArray[8]]) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([topVertArray[5],topVertArray[6],topVertArray[7],topVertArray[8]]) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) def ZShape(facel, Xsize, Ysize, height): @@ -645,50 +840,102 @@ def ZShape(facel, Xsize, Ysize, height): vertArray.append(makePoint(rconx1,0)) topVertArray = extrudedoodad(vertArray,height) + #fills bottom with faceness face = Face() face.v.extend([vertArray[0],vertArray[1],vertArray[10],vertArray[11]]) face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([vertArray[1],vertArray[2],vertArray[3],vertArray[10]]) face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([vertArray[3],vertArray[4],vertArray[9],vertArray[10]]) face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([vertArray[4],vertArray[7],vertArray[8],vertArray[9]]) face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([vertArray[4],vertArray[5],vertArray[6],vertArray[7]]) face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) + #fills top with faceness face = Face() face.v.extend([topVertArray[0],topVertArray[1],topVertArray[10],topVertArray[11]]) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([topVertArray[1],topVertArray[2],topVertArray[3],topVertArray[10]]) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([topVertArray[3],topVertArray[4],topVertArray[9],topVertArray[10]]) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([topVertArray[4],topVertArray[7],topVertArray[8],topVertArray[9]]) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) face = Face() face.v.extend([topVertArray[4],topVertArray[5],topVertArray[6],topVertArray[7]]) if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or doodTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = doodTopMat-1 doodadMesh.faces.append(face) diff --git a/release/scripts/discombobulator.py b/release/scripts/discombobulator.py index 1128c51c731..be7df1dbc07 100644 --- a/release/scripts/discombobulator.py +++ b/release/scripts/discombobulator.py @@ -2,14 +2,14 @@ """ Name: 'Discombobulator' -Blender: 236 +Blender: 237 Group: 'Mesh' Tip: 'Adds random geometry to a mesh' """ __author__ = "Evan J. Rosky (syrux)" __url__ = ("Script's homepage, http://evan.nerdsofparadise.com/programs/discombobulator/index.html") -__version__ = "236" +__version__ = "237" __bpydoc__ = """\ Discombobulator adds random geometry to a mesh. @@ -27,7 +27,19 @@ about the top of a protrusion or face. Usage:
Input your settings, make sure the mesh you would like to modify -is selected (active) and then click on "Discombobulate". +is selected (active) and then click on "Discombobulate".
+ See the scripts tutorial page (on the homepage) for more info. + + +New Features:
+ - Will use existing materials if there are any.
+ - Clicking "Assign materials by part" will allow assigning +of different material indices to Protrusion or Doodad Sides +and Tops in the gui element below it.
+ - Setting a material index to 0 will use whatever material +is assigned to the face that is discombobulated. + - You can now scroll using the arrow keys. + Notes:
- Modifications can be restricted to selected faces @@ -55,9 +67,20 @@ You can find more information at the Link above. # $Id$ -# +# +# Updated 2006-09-26 +# Changes since last version: +# > Works with Blender CVS and hopefully with Blender 2.40. +# > Swaps min/max values when min>max rather than complaining. +# > Will keep previously assigned materials. +# > Now allows user to assign custom material indices to +# Protrusion and Doodad Sides and Tops. +# > The initial Gui Layout will change depending on the aspect +# ratio of the window it is in. +# > Using the arrow keys will scroll the gui. +# # -------------------------------------------------------------------------- -# Discombobulator v5.3.5.406893.potato +# Discombobulator v2.1 # by Evan J. Rosky, 2005 # This plugin is protected by the GPL: Gnu Public Licence # GPL - http://www.gnu.org/copyleft/gpl.html @@ -86,7 +109,7 @@ You can find more information at the Link above. #Hit Alt-P to run import Blender -from Blender import NMesh,Object,Material,Window +from Blender import NMesh,Object,Material,Window,Types from Blender.NMesh import Vert,Face from Blender.Mathutils import * @@ -102,11 +125,21 @@ def randnum(low,high): num = num+low return num - +#Object Vars origmesh = NMesh.GetRaw() newmesh = NMesh.GetRaw() origobj = Object.Get() newobj = Object.Get() +materialArray = [0] + +#Material Vars +reassignMats = 0 +protSideMat = 1 +protTopMat = 2 +doodSideMat = 3 +doodTopMat = 4 +thereAreMats = 0 +currmat = 0 #Global Vars makenewobj = 1 @@ -132,7 +165,6 @@ selectface2 = 1 selectface3 = 1 selectface4 = 1 deselface = 1 -#vertselected = 0 #Doodad Vars makedoodads = 1 @@ -163,6 +195,14 @@ def isselectedface(theface): return 0 return 1 +def arrayInInclusive(start,end): + arr = [] + i = start + while i <= end: + arr.append(i) + i = i + 1 + return arr + def makeSubfaceArray(): global subfaceArray global subface1 @@ -243,7 +283,7 @@ def extrude(mid,nor,protrusion,v1,v2,v3,v4,tosel=1,flipnor=0): faceindex = len(newmesh.verts) - 4 - #face 1 + #side face 1 face = Face() face.v.append(newmesh.verts[v1]) face.v.append(newmesh.verts[v2]) @@ -251,9 +291,14 @@ def extrude(mid,nor,protrusion,v1,v2,v3,v4,tosel=1,flipnor=0): face.v.append(newmesh.verts[faceindex]) if flipnor != 0: face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or protSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protSideMat-1 newmesh.faces.append(face) - #face 2 + #side face 2 face = Face() face.v.append(newmesh.verts[v2]) face.v.append(newmesh.verts[v3]) @@ -261,9 +306,14 @@ def extrude(mid,nor,protrusion,v1,v2,v3,v4,tosel=1,flipnor=0): face.v.append(newmesh.verts[faceindex+1]) if flipnor != 0: face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or protSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protSideMat-1 newmesh.faces.append(face) - #face 3 + #side face 3 face = Face() face.v.append(newmesh.verts[v3]) face.v.append(newmesh.verts[v4]) @@ -271,9 +321,14 @@ def extrude(mid,nor,protrusion,v1,v2,v3,v4,tosel=1,flipnor=0): face.v.append(newmesh.verts[faceindex+2]) if flipnor != 0: face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or protSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protSideMat-1 newmesh.faces.append(face) - #face 4 + #side face 4 face = Face() face.v.append(newmesh.verts[v4]) face.v.append(newmesh.verts[v1]) @@ -281,18 +336,160 @@ def extrude(mid,nor,protrusion,v1,v2,v3,v4,tosel=1,flipnor=0): face.v.append(newmesh.verts[faceindex+3]) if flipnor != 0: face.v.reverse() + if thereAreMats == 1: + if reassignMats == 0 or protSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protSideMat-1 newmesh.faces.append(face) - + + #top face face = Face() face.v = newmesh.verts[-4:] if flipnor != 0: face.v.reverse() if tosel == 1: face.sel = 1 + if thereAreMats == 1: + if reassignMats == 0 or protTopMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protTopMat-1 newmesh.faces.append(face) return face -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): +#Sets the global protrusion values +def setProtrusionValues(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15): + + #Protrusions + global makeprots + global minimumtaperpercent + global maximumtaperpercent + global faceschangedpercent + global minimumheight + global maximumheight + global subface1 + global subface2 + global subface3 + global subface4 + global useselectedfaces + global selectface1 + global selectface2 + global selectface3 + global selectface4 + global deselface + global subfaceArray + + #Protrusions + makeprots = p0 + faceschangedpercent = p1 + minimumheight = p2 + maximumheight = p3 + subface1 = p4 + subface2 = p5 + subface3 = p6 + subface4 = p7 + minimumtaperpercent = p8 + maximumtaperpercent = p9 + useselectedfaces = p10 + selectface1 = p11 + selectface2 = p12 + selectface3 = p13 + selectface4 = p14 + deselface = p15 + makeSubfaceArray() + if len(subfaceArray) == 0: + makeprots = 0 + + if minimumheight > maximumheight: + a = maximumheight + maximimheight = minimumheight + minimumheight = a + elif minimumtaperpercent > maximumtaperpercent: + a = maximumtaperpercent + maximimtaperpercent = minimumtaperpercent + minimumtaperpercent = a + +#Sets the global Doodad values +def setDoodadValues(d0,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15,d16,d17): + + #Doodads + global makedoodads + global doodadfacepercent + global selectdoodad + global onlyonprotrusions + global doodad1 + global doodad2 + global doodad3 + global doodad4 + global doodad5 + global doodad6 + global doodadminperface + global doodadmaxperface + global doodadminsize + global doodadmaxsize + global doodadminheight + global doodadmaxheight + global doodadArray + global doodonselectedfaces + global selectdoodadtoponly + + #Doodads + makedoodads = d0 + doodadfacepercent = d1 + selectdoodad = d2 + onlyonprotrusions = d3 + doodad1 = d4 + doodad2 = d5 + doodad3 = d6 + doodad4 = d7 + doodad5 = d8 + doodad6 = d9 + doodadminperface = d10 + doodadmaxperface = d11 + doodadminsize = d12 + doodadmaxsize = d13 + doodadminheight = d14 + doodadmaxheight = d15 + doodonselectedfaces = d16 + selectdoodadtoponly = d17 + makeDoodadArray() + if len(doodadArray) == 0: + makedoodads = 0 + + elif doodadminperface > doodadmaxperface: + a = doodadmaxperface + doodadmaxperface = doodadminperface + doodadminperface = a + elif doodadminsize > doodadmaxsize: + a = doodadmaxsize + doodadmaxsize = doodadminsize + doodadminsize = a + elif doodadminheight > doodadmaxheight: + a = doodadmaxheight + doodadmaxheight = doodadminheight + doodadminheight = a + +#Sets other global values +def setOtherValues(g0,m0,m1,m2,m3,m4): + + #Global + global reassignMats + global makenewobj + global protSideMat + global protTopMat + global doodSideMat + global doodTopMat + + #Get Misc Variables + makenewobj = g0 + reassignMats = m0 + protSideMat = m1 + protTopMat = m2 + doodSideMat = m3 + doodTopMat = m4 + +def discombobulate(): #Global global origmesh @@ -321,7 +518,6 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d global selectface3 global selectface4 global deselface - #global vertselected global subfaceArray #Doodads @@ -346,6 +542,15 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d global selectdoodadtoponly #Global + global materialArray + global reassignMats + global protSideMat + global protTopMat + global doodSideMat + global doodTopMat + global thereAreMats + global currmat + try: origobj = Object.GetSelected()[0] except: @@ -359,102 +564,63 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d editmode = Window.EditMode() if editmode: Window.EditMode(0) + #Get Major Variables newobj = Object.Get() origmesh = origobj.getData() + if type(origmesh) != Types.NMeshType: + glRasterPos2d(10,50) + errortext = "OBJECT MUST BE MESH!" + messagetext = ErrorText(errortext) + Blender.Redraw() + return newmesh = NMesh.GetRaw() newmesh.verts = [] - makenewobj = g0 + materialArray = origmesh.getMaterials() + if len(materialArray) < 1: + thereAreMats = 0 + else: + thereAreMats = 1 - #Protrusions - makeprots = p0 - faceschangedpercent = p1 - minimumheight = p2 - maximumheight = p3 - subface1 = p4 - subface2 = p5 - subface3 = p6 - subface4 = p7 - minimumtaperpercent = p8 - maximumtaperpercent = p9 - useselectedfaces = p10 - selectface1 = p11 - selectface2 = p12 - selectface3 = p13 - selectface4 = p14 - deselface = p15 - makeSubfaceArray() - if len(subfaceArray) == 0: - makeprots = 0 + #add material indices if necessary (only up to 4) + if thereAreMats == 1 and reassignMats == 1: + if len(materialArray) < 4: + if protSideMat > 4: protSideMat = 4 + if protTopMat > 4: protTopMat = 4 + if doodSideMat > 4: doodSideMat = 4 + if doodTopMat > 4: doodTopMat = 4 + else: + if protSideMat > len(materialArray): protSideMat = len(materialArray) + if protTopMat > len(materialArray): protTopMat = len(materialArray) + if doodSideMat > len(materialArray): doodSideMat = len(materialArray) + if doodTopMat > len(materialArray): doodTopMat = len(materialArray) + + #This only does something if there are less than 4 verts + for matind in [protSideMat,protTopMat,doodSideMat,doodTopMat]: + if matind > len(materialArray) and matind <= 4: + for i in arrayInInclusive(len(materialArray),matind): + materialArray.append(Material.New("AddedMat " + str(i))) + + #Sets the materials + newmesh.setMaterials(materialArray) - - #Doodads - makedoodads = d0 - doodadfacepercent = d1 - selectdoodad = d2 - onlyonprotrusions = d3 - doodad1 = d4 - doodad2 = d5 - doodad3 = d6 - doodad4 = d7 - doodad5 = d8 - doodad6 = d9 - doodadminperface = d10 - doodadmaxperface = d11 - doodadminsize = d12 - doodadmaxsize = d13 - doodadminheight = d14 - doodadmaxheight = d15 - doodonselectedfaces = d16 - selectdoodadtoponly = d17 - makeDoodadArray() - if len(doodadArray) == 0: - makedoodads = 0 - defaultdoodads.topsonly(selectdoodadtoponly) - - if minimumheight > maximumheight: - glColor3f(1.0,0.0,0.0) - glRasterPos2d(10,50) - errortext = "MIN HEIGHT MUST BE LESS THAN OR EQUAL TO MAX HEIGHT!" - messagetext = ErrorText(errortext) - Blender.Redraw() - return - elif minimumtaperpercent > maximumtaperpercent: - glColor3f(1.0,0.0,0.0) - glRasterPos2d(10,50) - errortext = "MIN TAPER MUST BE LESS THAN OR EQUAL TO MAX TAPER!" - messagetext = ErrorText(errortext) - Blender.Redraw() - return - elif doodadminperface > doodadmaxperface: - glColor3f(1.0,0.0,0.0) - glRasterPos2d(10,50) - errortext = "MIN NUMBER OF DOODADS MUST BE LESS THAN OR EQUAL TO MAX!" - messagetext = ErrorText(errortext) - Blender.Redraw() - return - elif doodadminsize > doodadmaxsize: - glColor3f(1.0,0.0,0.0) - glRasterPos2d(10,50) - errortext = "MIN DOODAD SIZE MUST BE LESS THAN OR EQUAL TO MAX!" - messagetext = ErrorText(errortext) - Blender.Redraw() - return - elif doodadminheight > doodadmaxheight: - glColor3f(1.0,0.0,0.0) - glRasterPos2d(10,50) - errortext = "MIN DOODAD HEIGHT MUST BE LESS THAN OR EQUAL TO MAX!" - messagetext = ErrorText(errortext) - Blender.Redraw() - return + #Set the doodad settings + defaultdoodads.settings(selectdoodadtoponly,materialArray,reassignMats,thereAreMats,doodSideMat,doodTopMat) + #defaultdoodads.settings(selectdoodadtoponly,materialArray,reassignMats,thereAreMats,currmat) newmesh.verts.extend(origmesh.verts) + #Start modifying faces for currface in origmesh.faces: + currmat = currface.materialIndex + defaultdoodads.setCurrMat(currmat) + #Check if it is a triangle if len(currface.v)<4: face = Face() face.v.extend([newmesh.verts[currface.v[0].index],newmesh.verts[currface.v[1].index],newmesh.verts[currface.v[2].index]]) + if thereAreMats == 1: + face.materialIndex = currmat newmesh.faces.append(face) continue @@ -462,6 +628,8 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d if makeprots == 0: face = Face() 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: + face.materialIndex = currmat newmesh.faces.append(face) if makedoodads == 1 and onlyonprotrusions == 0: if doodonselectedfaces == 1: @@ -485,6 +653,8 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d else: face = Face() 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: + face.materialIndex = currmat newmesh.faces.append(face) if makedoodads == 1 and onlyonprotrusions == 0: if doodonselectedfaces != 1: @@ -497,6 +667,8 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d if randnum(0,1)>faceschangedpercent: face = Face() 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: + face.materialIndex = currmat newmesh.faces.append(face) if makedoodads == 1 and onlyonprotrusions == 0: if doodonselectedfaces == 1: @@ -515,12 +687,14 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d center = Vector([0,0,0]) for pt in currface.v: center = center + pt.co - center = center/len(currface.v) + center = divideVectorByInt(center,len(currface.v)) #Determine amount of subfaces subfaces = round(randnum(1,len(subfaceArray)),0) subfaces = subfaceArray[(int(subfaces) - 1)] + ######################## START DEALING WITH PROTRUSIONS ##################### + if subfaces == 1: prot = randnum(minimumheight,maximumheight) tempface = extrude(center,currface.no,prot,currface.v[0].index,currface.v[1].index,currface.v[2].index,currface.v[3].index,selectface1) @@ -541,7 +715,7 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d orientation = int(round(randnum(0,1))) p1 = currface.v[orientation] p2 = currface.v[orientation + 1] - p3 = (p2.co - p1.co)/2 + p1.co + p3 = divideVectorByInt((p2.co - p1.co),2) + p1.co ve1 = Vert(p3[0],p3[1],p3[2]) ve1.sel = 0 p1 = currface.v[2 + orientation] @@ -549,7 +723,7 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d p2 = currface.v[3] else: p2 = currface.v[0] - p3 = (p2.co - p1.co)/2 + p1.co + p3 = divideVectorByInt((p2.co - p1.co),2) + p1.co ve2 = Vert(p3[0],p3[1],p3[2]) ve2.sel = 0 if orientation < 0.5: @@ -574,7 +748,7 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d center = Vector([0, 0, 0]) for pt in [newmesh.verts[v1],newmesh.verts[v2],newmesh.verts[v3],newmesh.verts[v4]]: center = center + pt.co - center = center/4 + center = divideVectorByInt(center,4) prot = randnum(minimumheight,maximumheight) tempface = extrude(center,currface.no,prot,v1,v2,v3,v4,selectface2) if makedoodads == 1: @@ -606,7 +780,7 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d center = Vector([0]*3) for pt in [newmesh.verts[v1],newmesh.verts[v2],newmesh.verts[v3],newmesh.verts[v4]]: center = center + pt.co - center = center/4 + center = divideVectorByInt(center,4) prot = randnum(minimumheight,maximumheight) tempface = extrude(center,currface.no,prot,v1,v2,v4,v3,selectface2) if makedoodads == 1: @@ -624,16 +798,36 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d if orientation < 0.5: face = Face() face.v.extend([newmesh.verts[p0],newmesh.verts[p1],newmesh.verts[v3]]) + if thereAreMats == 1: + if reassignMats == 0 or protSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protSideMat-1 newmesh.faces.append(face) face = Face() face.v.extend([newmesh.verts[p2],newmesh.verts[p3],newmesh.verts[v4]]) + if thereAreMats == 1: + if reassignMats == 0 or protSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protSideMat-1 newmesh.faces.append(face) else: face = Face() face.v.extend([newmesh.verts[p1],newmesh.verts[p2],newmesh.verts[v3]]) + if thereAreMats == 1: + if reassignMats == 0 or protSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protSideMat-1 newmesh.faces.append(face) face = Face() face.v.extend([newmesh.verts[p3],newmesh.verts[p0],newmesh.verts[v4]]) + if thereAreMats == 1: + if reassignMats == 0 or protSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protSideMat-1 newmesh.faces.append(face) elif subfaces == 3: @@ -643,7 +837,7 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d rotation = int(round(randnum(0,1))) p1 = currface.v[orientation] p2 = currface.v[orientation + 1] - p3 = (p2.co - p1.co)/2 + p1.co + p3 = divideVectorByInt((p2.co - p1.co),2) + p1.co ve1 = Vert(p3[0],p3[1],p3[2]) ve1.sel = 0 p1 = currface.v[2 + orientation] @@ -651,7 +845,7 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d p2 = currface.v[3] else: p2 = currface.v[0] - p3 = (p2.co - p1.co)/2 + p1.co + p3 = divideVectorByInt((p2.co - p1.co),2) + p1.co ve2 = Vert(p3[0],p3[1],p3[2]) ve2.sel = 0 fp = [] @@ -682,7 +876,7 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d center = Vector([0]*3) for pt in [newmesh.verts[v1],newmesh.verts[v2],newmesh.verts[v3],newmesh.verts[v4]]: center = center + pt.co - center = center/4 + center = divideVectorByInt(center,4) prot = randnum(minimumheight,maximumheight) layer2inds.extend([v3,v4]) tempface = extrude(center,currface.no,prot,v1,v2,v3,v4,selectface3) @@ -724,7 +918,7 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d center = Vector([0]*3) for pt in [newmesh.verts[v1],newmesh.verts[v2],newmesh.verts[v3],newmesh.verts[v4]]: center = center + pt.co - center = center/4 + center = divideVectorByInt(center,4) prot = randnum(minimumheight,maximumheight) layer2inds.extend([index, index +1]) tempface = extrude(center,currface.no,prot,v1,v2,v4,v3,selectface3) @@ -744,12 +938,12 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d #split next rect(pre-arranged, no orientation crud)--make flag in extruder for only one existing vert in mesh p1 = newmesh.verts[layer2inds[0]] p2 = newmesh.verts[layer2inds[1]] - p3 = (p2.co - p1.co)/2 + p1.co + p3 = divideVectorByInt((p2.co - p1.co),2) + p1.co ve3 = Vert(p3[0],p3[1],p3[2]) ve3.sel = 0 p1 = layer2verts[0] p2 = layer2verts[1] - p3 = (p2.co - p1.co)/2 + p1.co + p3 = divideVectorByInt((p2.co - p1.co),2) + p1.co ve4 = Vert(p3[0],p3[1],p3[2]) ve4.sel = 0 newmesh.verts.append(ve3) @@ -762,7 +956,7 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d center = Vector([0]*3) for pt in [newmesh.verts[v5],newmesh.verts[v6],newmesh.verts[t0],newmesh.verts[v3]]: center = center + pt.co - center = center/4 + center = divideVectorByInt(center,4) prot = randnum(minimumheight,maximumheight) if rotation < 0.5: flino = 1 else: flino = 0 @@ -782,18 +976,28 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d face = Face() fpt = t0 face.v.extend([newmesh.verts[fp[1]],newmesh.verts[fpt],newmesh.verts[v3]]) + if thereAreMats == 1: + if reassignMats == 0 or protSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protSideMat-1 newmesh.faces.append(face) else: face = Face() fpt = t0 face.v.extend([newmesh.verts[fp[0]],newmesh.verts[v3],newmesh.verts[fpt]]) + if thereAreMats == 1: + if reassignMats == 0 or protSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protSideMat-1 newmesh.faces.append(face) verti = layer2verts[1] tempindex = verti.index center = Vector([0]*3) for pt in [newmesh.verts[v5],newmesh.verts[v6],newmesh.verts[tempindex],newmesh.verts[v4]]: center = center + pt.co - center = center/4 + center = divideVectorByInt(center,4) prot = randnum(minimumheight,maximumheight) tempface = extrude(center,currface.no,prot,v6,v5,v4,tempindex,selectface3,flino) if makedoodads == 1: @@ -811,16 +1015,36 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d if rotation < 0.5: face = Face() face.v.extend([newmesh.verts[tempindex],newmesh.verts[fp[0]],newmesh.verts[v4]]) + if thereAreMats == 1: + if reassignMats == 0 or protSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protSideMat-1 newmesh.faces.append(face) face = Face() face.v.extend([newmesh.verts[fpt],newmesh.verts[tempindex],newmesh.verts[v6]]) + if thereAreMats == 1: + if reassignMats == 0 or protSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protSideMat-1 newmesh.faces.append(face) else: face = Face() face.v.extend([newmesh.verts[tempindex],newmesh.verts[v4],newmesh.verts[fp[1]]]) + if thereAreMats == 1: + if reassignMats == 0 or protSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protSideMat-1 newmesh.faces.append(face) face = Face() face.v.extend([newmesh.verts[tempindex],newmesh.verts[fpt],newmesh.verts[v6]]) + if thereAreMats == 1: + if reassignMats == 0 or protSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protSideMat-1 newmesh.faces.append(face) else: @@ -831,29 +1055,29 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d verti = currface.v[1] p1 = verti.index - pt = (newmesh.verts[p1].co - newmesh.verts[p0].co)/2 + newmesh.verts[p0].co + pt = divideVectorByInt((newmesh.verts[p1].co - newmesh.verts[p0].co),2) + newmesh.verts[p0].co v1 = Vert(pt[0],pt[1],pt[2]) v1.sel = 0 verti = currface.v[2] p2 = verti.index - pt = (newmesh.verts[p2].co - newmesh.verts[p1].co)/2 + newmesh.verts[p1].co + pt = divideVectorByInt((newmesh.verts[p2].co - newmesh.verts[p1].co),2) + newmesh.verts[p1].co v2 = Vert(pt[0],pt[1],pt[2]) v2.sel = 0 verti = currface.v[3] p3 = verti.index - pt = (newmesh.verts[p3].co - newmesh.verts[p2].co)/2 + newmesh.verts[p2].co + pt = divideVectorByInt((newmesh.verts[p3].co - newmesh.verts[p2].co),2) + newmesh.verts[p2].co v3 = Vert(pt[0],pt[1],pt[2]) v3.sel = 0 - pt = (newmesh.verts[p0].co - newmesh.verts[p3].co)/2 + newmesh.verts[p3].co + pt = divideVectorByInt((newmesh.verts[p0].co - newmesh.verts[p3].co),2) + newmesh.verts[p3].co v4 = Vert(pt[0],pt[1],pt[2]) v4.sel = 0 - pt = (v3.co - v1.co)/2 + v1.co + pt = divideVectorByInt((v3.co - v1.co),2) + v1.co m = Vert(pt[0],pt[1],pt[2]) m.sel = 0 @@ -866,7 +1090,7 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d center = Vector([0]*3) for pt in [newmesh.verts[p0],newmesh.verts[v1],newmesh.verts[m],newmesh.verts[v4]]: center = center + pt.co - center = center/4 + center = divideVectorByInt(center,4) prot = randnum(minimumheight,maximumheight) tempface = extrude(center,currface.no,prot,p0,v1,m,v4,selectface4) if makedoodads == 1: @@ -889,7 +1113,7 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d center = Vector([0]*3) for pt in [newmesh.verts[m],newmesh.verts[v1],newmesh.verts[p1],newmesh.verts[v2]]: center = center + pt.co - center = center/4 + center = divideVectorByInt(center,4) prot = randnum(minimumheight,maximumheight) tempface = extrude(center,currface.no,prot,m,v1,p1,v2,selectface4) if makedoodads == 1: @@ -912,7 +1136,7 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d center = Vector([0]*3) for pt in [newmesh.verts[m],newmesh.verts[v2],newmesh.verts[p2],newmesh.verts[v3]]: center = center + pt.co - center = center/4 + center = divideVectorByInt(center,4) prot = randnum(minimumheight,maximumheight) tempface = extrude(center,currface.no,prot,m,v2,p2,v3,selectface4) if makedoodads == 1: @@ -932,7 +1156,7 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d center = Vector([0]*3) for pt in [newmesh.verts[m],newmesh.verts[v3],newmesh.verts[p3],newmesh.verts[v4]]: center = center + pt.co - center = center/4 + center = divideVectorByInt(center,4) prot = randnum(minimumheight,maximumheight) tempface = extrude(center,currface.no,prot,v4,m,v3,p3,selectface4) if makedoodads == 1: @@ -950,15 +1174,35 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d face = Face() face.v.extend([newmesh.verts[p0],newmesh.verts[p1],newmesh.verts[v1]]) + if thereAreMats == 1: + if reassignMats == 0 or protSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protSideMat-1 newmesh.faces.append(face) face = Face() face.v.extend([newmesh.verts[p1],newmesh.verts[p2],newmesh.verts[v2]]) + if thereAreMats == 1: + if reassignMats == 0 or protSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protSideMat-1 newmesh.faces.append(face) face = Face() face.v.extend([newmesh.verts[p2],newmesh.verts[p3],newmesh.verts[v3]]) + if thereAreMats == 1: + if reassignMats == 0 or protSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protSideMat-1 newmesh.faces.append(face) face = Face() face.v.extend([newmesh.verts[p3],newmesh.verts[p0],newmesh.verts[v4]]) + if thereAreMats == 1: + if reassignMats == 0 or protSideMat == 0: + face.materialIndex = currmat + else: + face.materialIndex = protSideMat-1 newmesh.faces.append(face) #NMesh.PutRaw(newmesh) @@ -967,8 +1211,8 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d newmesh.verts[unvert.index].sel = 0 if makenewobj == 1: newobj = Object.New('Mesh') - copyObjStuff(origobj,newobj) newobj.link(newmesh) + copyObjStuff(origobj,newobj) scene = Blender.Scene.getCurrent() scene.link(newobj) origobj.select(0) @@ -979,6 +1223,11 @@ def discombobulate(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,g0,d0,d #Return to Editmode if previously in it 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 ###################### from Blender.BGL import * @@ -1032,16 +1281,37 @@ doodheightmax = Create(doodadmaxheight) doodonselface = Create(doodonselectedfaces) seldoodtop = Create(selectdoodadtoponly) +#Material Buttons +assignNewMats = Create(reassignMats) +replProtSideIndex = Create(protSideMat) +replProtTopIndex = Create(protTopMat) +replDoodSideIndex = Create(doodSideMat) +replDoodTopIndex = Create(doodTopMat) # Events EVENT_NONE = 1 EVENT_DISCOMBOBULATE = 2 EVENT_EXIT = 3 +# Additions for moving gui +hadd = 0 +wadd = 0 +thadd = 410 +phadd = 245 +pwadd = 0 +dhadd = 55 +dwadd = 0 +ghadd = 10 +gwadd = 0 +mhadd = 55 +mwadd = 312 + def colorbox(x,y,xright,bottom): glColor3f(0.75, 0.75, 0.75) glRecti(x + 1, y + 1, xright - 1, bottom - 1) +firstDraw = 1 + def draw(): #Protrusions @@ -1083,90 +1353,164 @@ def draw(): global doodonselface global seldoodtop + #Materials + global assignNewMats + global replProtSideIndex + global replProtTopIndex + global replDoodSideIndex + global replDoodTopIndex + #Global Settings global makenewobject global messagetext global errortext - global EVENT_NONE,EVENT_DRAW,EVENT_EXIT + global EVENT_NONE,EVENT_DRAW,EVENT_EXIT,EVENT_UP,EVENT_DOWN,EVENT_LEFT,EVENT_RIGHT + + # Additions for moving gui + global hadd + global wadd + global thadd + global phadd + global pwadd + global dhadd + global dwadd + global ghadd + global gwadd + global mhadd + global mwadd + + #This is for creating the initial layout + global firstDraw + if(firstDraw == 1): + if(((Window.GetAreaSize()[1])*1.7) < Window.GetAreaSize()[0]): + thadd = 180 + phadd = 10 + dhadd = 10 + mhadd = 55 + ghadd = 10 + pwadd = 0 + dwadd = 305 + mwadd = 610 + gwadd = 610 + else: + thadd = 505 + phadd = 346 + dhadd = 160 + mhadd = 56 + ghadd = 10 + pwadd = 0 + dwadd = 0 + mwadd = 0 + gwadd = 0 + firstDraw = 0 - #Height Addition, this is for changing the gui - hadd = 10 #Title :420high glClearColor(0.6, 0.6, 0.6, 1.0) glClear(GL_COLOR_BUFFER_BIT) glColor3f(0.0,0.0,0.0) - glRasterPos2d(8, 400+hadd) - Text("Discombobulator v5.3.5.406893.potato") + glRasterPos2d(8+wadd, thadd+hadd) + Text("Discombobulator v2.1") #Protrusion - colorbox(8,385+hadd,312,230+hadd) + colorbox(8+pwadd+wadd,150+phadd+hadd,312+pwadd+wadd,phadd-5+hadd) glColor3f(0.0,0.0,0.0) - glRasterPos2d(12, 375+hadd) + glRasterPos2d(12+pwadd+wadd, 140+phadd+hadd) Text("Protrusions:") - doprots = Toggle("Make Protrusions",EVENT_NONE,12,352+hadd,145,18,doprots.val,"Make Protrusions?") - facechange = Number("Face %: ",EVENT_NONE,162,352+hadd,145,18,facechange.val,0,100,"Percentage of faces that will grow protrusions") - useselected = Toggle("Only selected faces",EVENT_NONE,12,332+hadd,145,18,useselected.val,"If on, only selected faces will be modified") - deselectvertices = Toggle("Deselect Selected",EVENT_NONE,162,332+hadd,145,18,deselectvertices.val,"Deselects any selected vertex except for ones selected by \"Select Tops\"") + doprots = Toggle("Make Protrusions",EVENT_NONE,12+pwadd+wadd,117+phadd+hadd,145,18,doprots.val,"Make Protrusions?") + facechange = Number("Face %: ",EVENT_NONE,162+pwadd+wadd,117+phadd+hadd,145,18,facechange.val,0,100,"Percentage of faces that will grow protrusions") + useselected = Toggle("Only selected faces",EVENT_NONE,12+pwadd+wadd,97+phadd+hadd,145,18,useselected.val,"If on, only selected faces will be modified") + deselectvertices = Toggle("Deselect Selected",EVENT_NONE,162+pwadd+wadd,97+phadd+hadd,145,18,deselectvertices.val,"Deselects any selected vertex except for ones selected by \"Select Tops\"") #Protrusion properties glColor3f(0.0,0.0,0.0) - glRasterPos2d(12, 315+hadd) + glRasterPos2d(12+pwadd+wadd, 80+phadd+hadd) Text("Protrusion Properties:") - minheight = Number("Min Height: ",EVENT_NONE,12,292+hadd,145,18,minheight.val,-100.0,100.0,"Minimum height of any protrusion") - maxheight = Number("Max Height: ",EVENT_NONE,162,292+hadd,145,18,maxheight.val,-100.0,100.0,"Maximum height of any protrusion") - mintaper = Number("Min Taper %: ",EVENT_NONE,12,272+hadd,145,18,mintaper.val,0,100,"Minimum taper percentage of protrusion") - maxtaper = Number("Max Taper %: ",EVENT_NONE,162,272+hadd,145,18,maxtaper.val,0,100,"Maximum taper percentage of protrusion") - glRasterPos2d(19, 257+hadd) + 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") + 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") + glRasterPos2d(19+pwadd+wadd, 22+phadd+hadd) Text("Number of protrusions:") - sub1 = Toggle("1",EVENT_NONE,12,235+hadd,34,18,sub1.val,"One Protrusion") - sub2 = Toggle("2",EVENT_NONE,48,235+hadd,34,18,sub2.val,"Two Protrusions") - sub3 = Toggle("3",EVENT_NONE,84,235+hadd,34,18,sub3.val,"Three Protrusions") - sub4 = Toggle("4",EVENT_NONE,120,235+hadd,34,18,sub4.val,"Four Protrusions") - glRasterPos2d(195, 257+hadd) + 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") + 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") + glRasterPos2d(195+pwadd+wadd, 22+phadd+hadd) Text("Select tops of:") - selface1 = Toggle("1",EVENT_NONE,165,235+hadd,34,18,selface1.val,"Select the tip of the protrusion when it is created") - selface2 = Toggle("2",EVENT_NONE,201,235+hadd,34,18,selface2.val,"Select the tips of each protrusion when they are created") - selface3 = Toggle("3",EVENT_NONE,237,235+hadd,34,18,selface3.val,"Select the tips of each protrusion when they are created") - selface4 = Toggle("4",EVENT_NONE,273,235+hadd,34,18,selface4.val,"Select the tips of each protrusion when they are 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") + 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") - #Doodad - colorbox(8,220+hadd,312,40+hadd) + #Doodads + colorbox(8+dwadd+wadd,175+dhadd+hadd,312+dwadd+wadd,dhadd-5+hadd) glColor3f(0.0,0.0,0.0) - glRasterPos2d(12, 210+hadd) + glRasterPos2d(12+dwadd+wadd, 165+dhadd+hadd) Text("Doodads:") - dood1 = Toggle("1 Box",EVENT_NONE,12,207+hadd-20,45,18,dood1.val,"Creates a rectangular box") - dood2 = Toggle("2 Box",EVENT_NONE,61,207+hadd-20,45,18,dood2.val,"Creates 2 side-by-side rectangular boxes") - dood3 = Toggle("3 Box",EVENT_NONE,110,207+hadd-20,45,18,dood3.val,"Creates 3 side-by-side rectangular boxes") - dood4 = Toggle("\"L\"",EVENT_NONE,164,207+hadd-20,45,18,dood4.val,"Creates a Tetris-style \"L\" shape") - dood5 = Toggle("\"T\"",EVENT_NONE,213,207+hadd-20,45,18,dood5.val,"Creates a Tetris-style \"T\" shape") - dood6 = Toggle("\"S\"",EVENT_NONE,262,207+hadd-20,45,18,dood6.val,"Creates a sort-of \"S\" or \"Z\" shape") - dodoodads = Toggle("Make Doodads",EVENT_NONE,12,165+hadd,145,18,dodoodads.val,"Make Doodads?") - doodadfacechange = Number("Face %: ",EVENT_NONE,162,165+hadd,145,18,doodadfacechange.val,0,100,"Percentage of faces that will gain doodads") - seldoodad = Toggle("Select Doodads",EVENT_NONE,12,145+hadd,145,18,seldoodad.val,"Selects doodads when they are created") - seldoodtop = Toggle("Only Select Tops",EVENT_NONE,162,145+hadd,145,18,seldoodtop.val,"Only Selects tops of doodads when\"Select Doodads\" is on") - doodonselface = Toggle("Only selected faces",EVENT_NONE,12,125+hadd,145,18,doodonselface.val,"Only create doodads on selected faces") - onprot = Toggle("Only on Protrusions",EVENT_NONE,162,125+hadd,145,18,onprot.val,"Only place doodads on protrusions") + 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") + dood3 = Toggle("3 Box",EVENT_NONE,110+dwadd+wadd,142+dhadd+hadd,45,18,dood3.val,"Creates 3 side-by-side rectangular boxes") + 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") + dood6 = Toggle("\"S\"",EVENT_NONE,262+dwadd+wadd,142+dhadd+hadd,45,18,dood6.val,"Creates a sort-of \"S\" or \"Z\" shape") + 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") + seldoodad = Toggle("Select Doodads",EVENT_NONE,12+dwadd+wadd,100+dhadd+hadd,145,18,seldoodad.val,"Selects doodads when they are created") + seldoodtop = Toggle("Only Select Tops",EVENT_NONE,162+dwadd+wadd,100+dhadd+hadd,145,18,seldoodtop.val,"Only Selects tops of doodads when\"Select Doodads\" is on") + doodonselface = Toggle("Only selected faces",EVENT_NONE,12+dwadd+wadd,80+dhadd+hadd,145,18,doodonselface.val,"Only create doodads on selected faces") + onprot = Toggle("Only on Protrusions",EVENT_NONE,162+dwadd+wadd,80+dhadd+hadd,145,18,onprot.val,"Only place doodads on protrusions") + + #Doodad Properties glColor3f(0.0,0.0,0.0) - glRasterPos2d(12, 108+hadd) + glRasterPos2d(12+dwadd+wadd, 63+dhadd+hadd) Text("Doodad Properties:") - doodadminamount = Number("Min Amount: ",EVENT_NONE,12,85+hadd,145,18,doodadminamount.val,0,100,"Minimum number of doodads per face") - doodadmaxamount = Number("Max Amount: ",EVENT_NONE,162,85+hadd,145,18,doodadmaxamount.val,0,100,"Maximum number of doodads per face") - doodheightmin = Number("Min Height: ",EVENT_NONE,12,65+hadd,145,18,doodheightmin.val,0.0,100.0,"Minimum height of any doodad") - doodheightmax = Number("Max Height: ",EVENT_NONE,162,65+hadd,145,18,doodheightmax.val,0.0,100.0,"Maximum height of any doodad") - 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") - 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") + 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") + 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") + 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") + + #Materials + colorbox(8+mwadd+wadd,93+mhadd+hadd,312+mwadd+wadd,mhadd-5+hadd) + glColor3f(0.0,0.0,0.0) + glRasterPos2d(12+mwadd+wadd, 83+mhadd+hadd) + Text("Materials:") + glRasterPos2d(12+mwadd+wadd, 43+mhadd+hadd) + Text("Assigned Material Indices:") + assignNewMats = Toggle("Assign materials by part",EVENT_NONE,32+mwadd+wadd,60+mhadd+hadd,256,18,assignNewMats.val,"Otherwise, previous materials will be preserved") + replProtSideIndex = Number("Protrusion Sides:",EVENT_NONE,12+mwadd+wadd,20+mhadd+hadd,145,18,replProtSideIndex.val,0,16,"Material index assigned to sides of protrusions") + replProtTopIndex = Number("Protrusion Tops:",EVENT_NONE,162+mwadd+wadd,20+mhadd+hadd,145,18,replProtTopIndex.val,0,16,"Material index assigned to tops of protrusions") + replDoodSideIndex = Number("Doodad Sides:",EVENT_NONE,12+mwadd+wadd,mhadd+hadd,145,18,replDoodSideIndex.val,0,16,"Material index assigned to sides of doodads") + replDoodTopIndex = Number("Doodad Tops:",EVENT_NONE,162+mwadd+wadd,mhadd+hadd,145,18,replDoodTopIndex.val,0,16,"Material index assigned to tops and bottoms of doodads") #Global Parts + colorbox(8+gwadd+wadd,35+ghadd+hadd,312+gwadd+wadd,ghadd-5+hadd) glColor3f(1.0,0.0,0.0) - glRasterPos2d(10,35) + glRasterPos2d(12+gwadd+wadd,25+ghadd+hadd) messagetext = Text(errortext) glColor3f(0.0,0.0,0.0) - 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") - Button("Discombobulate",EVENT_DISCOMBOBULATE,12,10,100,18) - Button("Exit",EVENT_EXIT,120,10,30,18) + makenewobject = Toggle("Copy Before Modifying",EVENT_NONE,162+gwadd+wadd,ghadd+hadd,145,18,makenewobject.val,"If selected, the original object will be copied before it is changed") + Button("Discombobulate",EVENT_DISCOMBOBULATE,12+gwadd+wadd,ghadd+hadd,100,18) + Button("Exit",EVENT_EXIT,120+gwadd+wadd,ghadd+hadd,30,18) -def event(evt, val): +def event(evt, val): + global wadd + global hadd + + if (evt == RIGHTARROWKEY and val): + wadd = wadd + 20 + Redraw(1) + if (evt == LEFTARROWKEY and val): + wadd = wadd - 20 + Redraw(1) + if (evt == UPARROWKEY and val): + hadd = hadd + 20 + Redraw(1) + if (evt == DOWNARROWKEY and val): + hadd = hadd - 20 + Redraw(1) if (evt == QKEY and not val): Exit() @@ -1211,6 +1555,13 @@ def bevent(evt): global doodonselface global seldoodtop + #Materials + global assignNewMats + global replProtSideIndex + global replProtTopIndex + global replDoodSideIndex + global replDoodTopIndex + #Global Settings global makenewobject global messagetext @@ -1222,7 +1573,10 @@ def bevent(evt): Exit() elif evt==EVENT_DISCOMBOBULATE: Window.WaitCursor(1) - 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) + setProtrusionValues(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) + setDoodadValues(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) + setOtherValues(makenewobject.val,assignNewMats.val,replProtSideIndex.val,replProtTopIndex.val,replDoodSideIndex.val,replDoodTopIndex.val) + discombobulate() Window.WaitCursor(0) Blender.Redraw() diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index 4da5dfc74ae..5b8fc3024cd 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -2087,7 +2087,11 @@ static PyObject *Object_setMaterials( BPy_Object * self, PyObject * args ) PyObject *list; int len; int i; - Material **matlist; + Material **matlist = NULL; + + if (!self->object->data) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "object must be linked to object data (e.g. to a mesh) first" ); if( !PyArg_ParseTuple( args, "O!", &PyList_Type, &list ) ) return EXPP_ReturnPyObjError( PyExc_TypeError, @@ -2095,14 +2099,20 @@ static PyObject *Object_setMaterials( BPy_Object * self, PyObject * args ) len = PyList_Size(list); - if( len > MAXMAT ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "list must have from 1 up to 16 materials" ); + /* Object_getMaterials can return '[]' (zero-length list), so that must + * also be accepted by this method for + * ob2.setMaterials(ob1.getMaterials()) to always work. + * In other words, list can be '[]' and so len can be zero. */ + if (len > 0) { + if( len > MAXMAT ) + return EXPP_ReturnPyObjError( PyExc_TypeError, + "list must have from 1 up to 16 materials" ); - matlist = EXPP_newMaterialList_fromPyList( list ); - if( !matlist ) { - return ( EXPP_ReturnPyObjError( PyExc_AttributeError, - "material list must be a list of valid materials!" ) ); + matlist = EXPP_newMaterialList_fromPyList( list ); + if( !matlist ) { + return ( EXPP_ReturnPyObjError( PyExc_AttributeError, + "material list must be a list of valid materials!" ) ); + } } if( self->object->mat )