diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-01-29 13:20:21 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-01-29 13:20:21 +0300 |
commit | 5db31cb5710e0cf2a27cfc7c61eac3d870224f4b (patch) | |
tree | e1dd4dc8513370aed128ee03fcd04f734009a1af /release/scripts | |
parent | 803d66a3a53f9ffb942a37d5943519d5dcb2cfb1 (diff) |
removing redundant scripts because of new features in blender after discussion with LetterRip.
disp_paint.py - Displacement modifier and sculpt mode replace.
uv_paint.py - making can be used to write colors to an image.
animation_empties2armature.py - Was made when BVH importer could not import direct to armature, Resulting animation has visible errors, errors have been known about for a long time and not fixed.
knife.py - Old slow code, No Multi-UV's, We now have a knife tool that has snap!
If anyone wants to maintain these scripts and have them added back in, mail the bf-python ML.
Scripts that are removed can be found here.
http://projects.blender.org/viewcvs/viewcvs.cgi/blender/release/scripts/Attic/?cvsroot=bf-blender
Diffstat (limited to 'release/scripts')
-rw-r--r-- | release/scripts/animation_empties2armature.py | 675 | ||||
-rw-r--r-- | release/scripts/disp_paint.py | 767 | ||||
-rw-r--r-- | release/scripts/knife.py | 725 | ||||
-rw-r--r-- | release/scripts/uvpaint.py | 690 |
4 files changed, 0 insertions, 2857 deletions
diff --git a/release/scripts/animation_empties2armature.py b/release/scripts/animation_empties2armature.py deleted file mode 100644 index 53b0c4f55f4..00000000000 --- a/release/scripts/animation_empties2armature.py +++ /dev/null @@ -1,675 +0,0 @@ -#!BPY -""" -Name: 'Empties to Armature' -Blender: 241 -Group: 'Animation' -Tooltip: 'Create Armature from a parented-empties chain' -""" -__author__ = " Jean-Baptiste PERIN (jb_perin(at)yahoo.fr) with valuable help from Vincent BILLET " -__url__ = ("blender", "elysiun", -"BVH 2 ARMATURE, http://perso.wanadoo.fr/jb.perin/", -"Communicate problems and errors, http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender") - -__version__ = "2.42" - -__bpydoc__ = """ - -Script for generating armature on BVH empties. - -This script generates an armature upon an empty-made parented chain, -and make the armature follow the empties - -Usage:<br> - - Import a bvh in Blender (File->Import->BVH);<br> - - Rotate some empties to match your model and insert Rot key for them. <br> - - Select the root empty of the hierarchical chain.<br> - - Launch this script ;<br> - - Set up variables:<br> - "hipbonename": the name of the main bone (automatically set to the selected empty).<br> - "startframe": the first frame of your anim;<br> - "endframe": the last frame of your anim;<br> - "decimation": the frequency (in number of frame) to which the armature's pos is updated;<br> -- Press "Create Armature". -Notes: <br> -- The start frame configuration is used as the rest pose for the armature.<br> -- If the armature already exists when script is launched, the current armature is re-used. -""" -# -------------------------------------------------------------------------- -# ***** BEGIN GPL LICENSE BLOCK ***** -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# ***** END GPL LICENCE BLOCK ***** -# -------------------------------------------------------------------------- - - - -import Blender -from Blender import Mathutils -import math - -dicEmptiesRestMatrix= {} -dicEmptiesInvRestMatrix= {} -dicBoneRestMatrix= {} -dicBone={} -dicEmptyChild={} -dicBoneRestInvEmpRest={} -dicEmpRestInvBoneRest={} -restFrame = 1 -bonerest={} -emprest={} -emp2bone={} - -######################################################################## -# -# UTILITY FUNCTIONS FOR HANDLING BONES AND EMPTIES -# -######################################################################## - -def names(ob): return ob.getName() - -######### -# Cette fonction renvoie la liste des empties attaches a root -# in : -# out : emp_list (List of Object) la liste des objets de type "Empty" -######### -def getTree(emp_list, root): - empties=getAllEmpties() - chlds = getChildren(root, empties) - dicEmptyChild[root.getName()]=chlds - for ch in chlds: - emp_list.append(ch) - getTree(emp_list,ch) - -######### -# Cette fonction renvoie la liste des empties attaches a root -# in : -# out : emp_list (List of Object) la liste des objets de type "Empty" -######### -def getEmpties(): - global hipbonename - emp_list = [] - root = Blender.Object.Get(hipbonename) - emp_list.append(root) - getTree(emp_list, root) - return emp_list - -######### -# Cette fonction renvoie la liste des empties -# in : -# out : emp_list (List of Object) la liste des objets de type "Empty" -######### -def getAllEmpties(): - emp_list = [] - objs = Blender.Object.Get() - for o in objs: - if o.getType()=="Empty": - emp_list.append(o) - return emp_list - -######### -# Cette fonction renvoie la liste des empties -# in : -# out : emp_list (List of Object) la liste des objets de type "Empty" -######### -def getEmpty(name): - p = None - objs = Blender.Object.Get() - for o in objs: - if o.getType()=="Empty" and o.getName()==name: - p = o - return p - -##def getChild(emp, emp_list): -## return dicEmptyChild[emp.getName()] - - -######### -# Cette fonction fournit la liste des enfants d'un empty -# in : emp (Object) un empty -# emp_list (List of Object) la liste des empties -# out : children (List of Object) la liste des empties enfants de 'empty' -######### -def getChildren(emp, emp_list): - children = [] - root_emp = getRootEmpties(emp_list) - for em in emp_list: - if (em.getName() != emp.getName()) and (em not in root_emp): - if (em.getParent().getName() == emp.getName()): - children.append(em) - return children - - - -######### -# Cette fonction renvoie la liste des empties n'ayant pas de parent -# in : emp_list (List) une liste d'empties -# out : root (List) le (ou les) empty n'ayant pas de parent -######### -def getRootEmpties(emp_list): - root = [] - for em in emp_list: - if em.getParent() == None: - root.append(em) - return root - - -######### -# Cette fonction renvoie le bone de nom 'name' dans l'armature 'armature' -# in : armature (Armature) l'armature dans laquelle cherchait le bone -# name (String) le nom de l'os a chercher -# out : p (Bone) -######### -#def getBone(armature, name): -# return (dicBone[name]) - #p = None - #bones = armature.getBones() - #for i in bones: - # if i.getName() == name: - # p = i - # break - #return p - - -def eraseIPO (objectname): - object = Blender.Object.Get(objectname) - lIpo = object.getIpo() - if lIpo != None: - nbCurves = lIpo.getNcurves() - for i in range(nbCurves): - nbBezPoints = lIpo.getNBezPoints(i) - for j in range(nbBezPoints): - lIpo.delBezPoint(i) - - - - -def GetOrCreateIPO(name): - - ipos = Blender.Ipo.Get() - if name in map(names,ipos): - myipo = Blender.Ipo.Get(name) - print name+' exists' - else: - myipo = Blender.Ipo.New('Object',name) - print name+' was created' - return myipo - - -def GetOrCreateCurve(ipo, curvename): - curves = ipo.getCurves() - if curvename in map(names,curves): - mycurve = ipo.getCurve(curvename) - print curvename+' exists' - else: - mycurve = ipo.addCurve(curvename) - print curvename+' was created' - return mycurve - - - - -######################################################################## -# -# FUNCTIONS FOR COMPUTING POSITION AND ROTATION OF BONES -# -######################################################################## - - - -######### -# Cette fonction -# in : -# out : -######### -def computeScaledPos(vec): - global scalef - vec2 = Mathutils.Vector([vec[0]*scalef, vec[1]*scalef, vec[2]*scalef]) - return vec2 - -######################################################################## -# -# FUNCTIONS FOR CREATING AND MOVING ARMATURES -# -######################################################################## - -######### -# Cette fonction -# in : -# out : -######### -def createBone (armature, empty, bone, empties): - global bonerest, emprest - children = getChildren(empty, empties) - if len(children) != 0: - for ch in children: - if len(children) >= 2: - bonename = empty.getName()[1:len(empty.getName())]+'_'+ch.getName()[1:len(ch.getName())] - else : - bonename = empty.getName()[1:len(empty.getName())] - print "creating Bone %s"%(bonename) - b=Blender.Armature.Editbone() - b.head = (computeScaledPos(empty.getMatrix('worldspace').translationPart())) - b.tail = (computeScaledPos(ch.getMatrix('worldspace').translationPart())) - b.parent = bone - # armature.makeEditable() should already be editable???? - armature.bones[bonename] = b - #print b.matrix - bonerest[bonename]=Blender.Mathutils.Matrix(b.matrix).resize4x4() - emprest[empty.getName()]=Blender.Mathutils.Matrix(empty.getMatrix('localspace')).resize4x4() - #M = Blender.Mathutils.Matrix(emprest[empty.getName()]) - #emp2bone[bonename] = Blender.Mathutils.Matrix(M.invert().rotationPart()*bonerest[bonename].rotationPart()).resize4x4() - #print emp2bone[bonename].rotationPart().toEuler() - dicBone[b.name]=b - createBone(armature, ch, b, empties) - -######### -# Cette fonction -# in : -# out : -######### -def f_createBone (armData, empty, bone, empties): - bones = armData.bones.values() - def getBone(bonename): - bone = None - for b in bones: - #print b.getName() - if b.name == bonename: - bone = b - return bone - - children = getChildren(empty, empties) - for ch in children: - if len(children) >= 2: - bonename = empty.getName()[1:len(empty.getName())]+'_'+ch.getName()[1:len(ch.getName())] - else : - bonename = empty.getName()[1:len(empty.getName())] - #b=Blender.Armature.Bone.New(bonename) - b=getBone(bonename) - b.head = (computeScaledPos(empty.getMatrix('worldspace').translationPart())) - b.tail = (computeScaledPos(ch.getMatrix('worldspace').translationPart())) - b.parent = bone - bonerest[bonename]=Blender.Mathutils.Matrix(b.matrix).resize4x4() - emprest[empty.getName()]=Blender.Mathutils.Matrix(empty.getMatrix('localspace')).resize4x4() - dicBone[b.name]=b - #print "Ajout de ", b.getName()," au dictionnaire" - f_createBone(armData, ch, b, empties) - -######### -# Cette fonction fabrique une arma -# in : -# out : -######### -def createArmature (armObj, rootEmpty, empties): - global bonerest, emprest - armData=Blender.Armature.Armature('monArmature') - children = getChildren(rootEmpty, empties) - armObj.link(armData) - armData.makeEditable() - for ch in children: - b=Blender.Armature.Editbone() - bonename = rootEmpty.getName()[1:len(rootEmpty.getName())] + ch.getName()[1:len(ch.getName())] - print "creating Bone %s"%(bonename) - - #print b, dir([b]) - b.head=(computeScaledPos(rootEmpty.getMatrix('worldspace').translationPart())) - b.tail=(computeScaledPos(ch.getMatrix('worldspace').translationPart())) - - bonerest[bonename]=Blender.Mathutils.Matrix(b.matrix).resize4x4() - emprest[rootEmpty.getName()]=Blender.Mathutils.Matrix(rootEmpty.getMatrix('localspace')).resize4x4() - armData.bones[bonename] = b - dicBone[b.name]=b - createBone(armData, ch, b, empties) - armData.update() - return armData - - - -######### -# Cette fonction fabrique une arma -# in : -# out : -######### -def f_createArmature (rootEmpty, empties, armData): - armData.makeEditable() - bones = armData.bones.values() - - def getBone(bonename): - bone = None - for b in bones: - #print b.getName() - if b.name == bonename: - bone = b - return bone - - children = getChildren(rootEmpty, empties) - for ch in children: - b=getBone(rootEmpty.getName()[1:len(rootEmpty.getName())] + ch.getName()[1:len(ch.getName())]) - dicBone[b.name]=b - #print "Ajout de ", b.getName()," au dictionnaire" - bonerest[b.name]=Blender.Mathutils.Matrix(b.matrix).resize4x4() - emprest[rootEmpty.getName()]=Blender.Mathutils.Matrix(rootEmpty.getMatrix('localspace')).resize4x4() - f_createBone(armData, ch, b, empties) - - armData.update() - - -######### -# Cette fonction -# in : -# out : -######### -def moveBones(larmature, empty, empties): - #print "move bones" - global bonerest, emprest - children = dicEmptyChild[empty.getName()] - thepose = larmature.getPose() - for ch in children: - if len(children) >= 2: - bonename = empty.getName()[1:len(empty.getName())]+'_'+ch.getName()[1:len(ch.getName())] - else : - bonename = empty.getName()[1:len(empty.getName())] - thebone = thepose.bones[bonename] - trMatrix = empty.getMatrix('localspace') - bonerestmat = Blender.Mathutils.Matrix(bonerest[bonename]) - invbonerestmat = Blender.Mathutils.Matrix(bonerest[bonename]) - invbonerestmat.invert() - trMatrix[3][0] = 0.0 - trMatrix[3][1] = 0.0 - trMatrix[3][2] = 0.0 - invemprestmat = Blender.Mathutils.Matrix(emprest[empty.getName()].rotationPart()).resize4x4() - invemprestmat.invert() - emprestmat = Blender.Mathutils.Matrix(emprest[empty.getName()].rotationPart()).resize4x4() - thebone.localMatrix = bonerestmat* invemprestmat *trMatrix * invbonerestmat - thepose.update() - thebone.insertKey(larmature, Blender.Get('curframe'), [Blender.Object.Pose.ROT, Blender.Object.Pose.LOC]) - thepose.update() - chch = dicEmptyChild[ch.getName()] - if len(chch) >= 1: - moveBones(larmature, ch, empties) - - -######### -# Cette fonction -# in : -# out : -######### -def moveArmature (larmature, empties): - global bonerest, emprest - #print "move armature" - thepose = larmature.getPose() - #armature.makeEditable() - root = Blender.Object.Get(hipbonename) - children = dicEmptyChild[hipbonename] - for ch in children: - b=dicBone[hipbonename[1:len(hipbonename)] + ch.getName()[1:len(ch.getName())]] - - moveBones(larmature, ch, empties) - #armature.update() - - - - -######################################################################## -# -# MAIN PROGRAM -# -######################################################################## - -def RemoveEmpties(): - - global endframe, startframe,hipbonename - - lesEmpties = getEmpties() - scn = Blender.Scene.getCurrent() - #scn.link (armObj) - for em in lesEmpties: - eraseIPO (em.getName()) - scn.unlink(em) - Blender.Redraw() - - -def Main(): - - global endframe, startframe,hipbonename, framedecimation - - - print "*****START*****" - - Blender.Set("curframe",restFrame) - - ##----------- - ## Positionnement des empties - ##----------- - em0 = Blender.Object.Get(hipbonename) - - Blender.Redraw() - - - - ##----------- - ## Creation de l'armature et des os - ##----------- - - lesEmpties = getEmpties() - #print dicEmptyChild - print "creating armature" - #armData = createArmature(em0, lesEmpties) - objects = Blender.Object.Get() - if 'OBArmature' in map(names,objects): - armObj = Blender.Object.Get('OBArmature') - armData = armObj.getData() - print 'OBArmature'+' exists' - eraseIPO ('OBArmature') - #print armData.getBones() - f_createArmature(em0, lesEmpties, armData) - else: - armObj=Blender.Object.New('Armature', 'OBArmature') - armData= createArmature(armObj, em0, lesEmpties) - #armObj.link(armData) - scn = Blender.Scene.getCurrent() - scn.link (armObj) - - print 'OBArmature'+' was created' - #return myobj - print emprest - armData.drawType = Blender.Armature.STICK - ##----------- - ## Creation de l'ipo de l'armature - ##----------- - lipo = GetOrCreateIPO('BVHIpo') - armObj.setIpo(lipo) - curvX = GetOrCreateCurve(lipo, 'LocX') - curvY = GetOrCreateCurve(lipo, 'LocY') - curvZ = GetOrCreateCurve(lipo, 'LocZ') - curvrX = GetOrCreateCurve(lipo, 'RotX') - curvrY = GetOrCreateCurve(lipo, 'RotY') - curvrZ = GetOrCreateCurve(lipo, 'RotZ') - - print "animating armature" - - #armData.drawAxes(1) - #armData.drawNames(1) - - - - Blender.Redraw() - - action = Blender.Armature.NLA.NewAction() - action.setActive(armObj) - - - - ##----------- - ## Enregistrement de la position de l'armature - ##----------- - - bones = armData.bones.values() - - curvX.addBezier((Blender.Get("curframe"), getEmpty(hipbonename).getMatrix('worldspace').translationPart()[0]*scalef)) - curvY.addBezier((Blender.Get("curframe"), getEmpty(hipbonename).getMatrix('worldspace').translationPart()[1]*scalef)) - curvZ.addBezier((Blender.Get("curframe"), getEmpty(hipbonename).getMatrix('worldspace').translationPart()[2]*scalef)) - curvX.setInterpolation('Linear') - curvX.setExtrapolation('Constant') - curvY.setInterpolation('Linear') - curvY.setExtrapolation('Constant') - curvZ.setInterpolation('Linear') - curvZ.setExtrapolation('Constant') - curvrX.setInterpolation('Linear') - curvrX.setExtrapolation('Constant') - curvrY.setInterpolation('Linear') - curvrY.setExtrapolation('Constant') - curvrZ.setInterpolation('Linear') - curvrZ.setExtrapolation('Constant') - - Blender.Redraw() - - Blender.Set("curframe",startframe) - while endframe >= Blender.Get("curframe"): - - ##----------- - ## Positionnement des os - ##----------- - - moveArmature(armObj, lesEmpties) - - - ##----------- - ## Enregistrement de la position de l'armature - ##----------- - - curvX.addBezier((Blender.Get("curframe"), (getEmpty(hipbonename).getMatrix('worldspace').translationPart()[0])*scalef)) - curvY.addBezier((Blender.Get("curframe"), (getEmpty(hipbonename).getMatrix('worldspace').translationPart()[1])*scalef)) - curvZ.addBezier((Blender.Get("curframe"), (getEmpty(hipbonename).getMatrix('worldspace').translationPart()[2])*scalef)) - curvrX.addBezier((Blender.Get("curframe"), (getEmpty(hipbonename).getMatrix('worldspace').rotationPart().toEuler()[0])*scalef/10)) - curvrY.addBezier((Blender.Get("curframe"), (getEmpty(hipbonename).getMatrix('worldspace').rotationPart().toEuler()[1])*scalef/10)) - curvrZ.addBezier((Blender.Get("curframe"), (getEmpty(hipbonename).getMatrix('worldspace').rotationPart().toEuler()[2])*scalef/10)) - - ##----------- - ## Passage a la frame suivante - ##----------- - num_frame = Blender.Get("curframe")+framedecimation - print num_frame - Blender.Set("curframe", num_frame) - - curvX.Recalc() - curvY.Recalc() - curvZ.Recalc() - curvrX.Recalc() - curvrY.Recalc() - curvrZ.Recalc() - Blender.Set("curframe",startframe) - Blender.Redraw() - - print "*****END*****" - - -######################################################################## -# -# GUI FUNCTIONS AND VARIABLES -# -######################################################################## - -EFrame = Blender.Draw.Create(5) -IFrame = Blender.Draw.Create(6) -SFrame2 = Blender.Draw.Create(5) -HBName = Blender.Draw.Create(0) -FrameDecimation = Blender.Draw.Create(5) -ScaleF = Blender.Draw.Create(0) - -Msg = ' ' - -def event (evt, val): - if evt == Blender.Draw.ESCKEY: - Blender.Draw.Exit() - return - -def button_event(evt): - global EFrame, IFrame, SFrame2, HBName, Msg , FrameDecimation, ScaleF - global endframe, startframe, insertionframe, hipbonename, framedecimation , scalef - if evt==1: - startframe = SFrame2.val - insertionframe = 100 #IFrame.val - endframe = EFrame.val - hipbonename = HBName.val - framedecimation = FrameDecimation.val - scalef= 1.0 #eval(str(ScaleF.val)) - #print "scalef = ", scalef - if startframe>=endframe: - Msg = 'Start frame must be lower than End frame' - error_txt = "Error|Start frame must be lower than End frame" - Blender.Draw.PupMenu(error_txt) - else: - ob = getEmpty(hipbonename) - if (ob!=None): - if ob.getParent()!=None: - Msg = 'Empty '+hipbonename+ ' is not a root bone.' - error_txt = "Error|Empty %s is not a root bone"%hipbonename - Blender.Draw.PupMenu(error_txt) - else: - if (0.0 > scalef): - Msg = 'Scale factor must be greater than 0' - error_txt = "Error|Scale factor must be greater than 0" - Blender.Draw.PupMenu(error_txt) - else: - #Blender.Draw.Exit() - Main() - #Main() - else: - error_txt = "Error|Empty %s not found"%hipbonename - Blender.Draw.PupMenu(error_txt) - Msg = 'Empty '+ hipbonename+ ' not found' - - #Blender.Draw.Redraw(1) - elif evt==2: - hipbonename = HBName.val - ob = getEmpty(hipbonename) - if (ob!=None): - if ob.getParent()!=None: - error_txt = "Error|Empty %s is not a root bone"%hipbonename - Blender.Draw.PupMenu(error_txt) - - Msg = 'Empty '+hipbonename+ ' is not a root bone.' - else: - #Blender.Draw.Exit() - RemoveEmpties() - else: - Msg = 'Empty '+ hipbonename+ ' not found' - - #else: - # print "evt = ",evt - -def GUI(): - global EFrame, SFrame2, HBName, Msg , ScaleF, FrameDecimation - Blender.BGL.glClearColor(0,0,1,1) - Blender.BGL.glClear(Blender.BGL.GL_COLOR_BUFFER_BIT) - Blender.BGL.glColor3f(1,1,1) - Blender.BGL.glRasterPos2i(20,200) - selobj = Blender.Object.GetSelected() - if len(selobj) == 1 and type (selobj[0]) == Blender.Types.ObjectType: - hipname = selobj[0].getName() - else: - hipname = '_Hips' - Blender.Draw.Text ("BVH 2 ARMATURE v%s by %s"%(__version__, __author__), 'normal') - HBName = Blender.Draw.String("HipBoneName: ", 0, 20, 175, 250, 20, hipname, 100) - SFrame2 = Blender.Draw.Number("Startframe: ", 0, 20, 150, 250, 20, 1, 1,3000,"Start frame of anim") - EFrame = Blender.Draw.Number("Endframe: ", 0, 20, 125, 250, 20, Blender.Get("endframe"), 1,3000,"Last frame of anim") - FrameDecimation = Blender.Draw.Number("FrameDecimation: ", 0, 20, 75, 250, 20,1, 1,10,'number of frame to skip between two action keys') - Blender.Draw.Toggle("Create Armature", 1, 20, 10, 100, 20, 0, "Create Armature") - Blender.BGL.glRasterPos2i(20,40) - Blender.Draw.Text (Msg, 'normal') - - -Blender.Draw.Register(GUI, event, button_event) diff --git a/release/scripts/disp_paint.py b/release/scripts/disp_paint.py deleted file mode 100644 index ec79ab1b043..00000000000 --- a/release/scripts/disp_paint.py +++ /dev/null @@ -1,767 +0,0 @@ -#!BPY - -""" Registration info for Blender menus: <- these words are ignored -Name: 'Dispaint' -Blender: 237 -Group: 'Mesh' -Tip: 'use vertex paint color value to modify shape displacing vertices along normal' -""" - -__author__ = "Jean-Michel Soler (jms)" -__url__ = ("blender", "elysiun", -"Script's homepage, http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_displacementpainting.htm", -"Communicate problems and errors, http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender") -__version__ = "237" - -__bpydoc__ = """\ -This script displaces mesh vertices according to vertex color values. - -Usage: - -Select the mesh, enter Edit Mode and run this script to open its GUI. Options -include setting mode, orientation, size and number of repetitions of the -displacement. You can enter Vertex Paint mode and alternate applying -displacements and painting parts of the mesh. - -Orientation includes vertex normals, local coordinates and noise (you may need -to resize the scripts window to view the noise menu below the "Last Error:" -line. This menu lets you define noise type from the many options available in -Blender. - -Notes:<br> - The "Create" button will make at any time a copy of the active mesh in its -current state, so you can keep it and continue working on the copy;<br> - One of the great possible uses of this script is to "raise" terrain from a -subdivided plane, for example, with good control of the process by setting -options, defining orientation and alternating vertex painting with -displacements. -""" - -#---------------------------------------------- -# jm soler, displacement paint 03/2002 - > 05/2004: disp_paintf -# Terrain Noise added suugered by Jimmy Haze -#---------------------------------------------- -# Page officielle : -# http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_displacementpainting.htm -# Communiquer les problemes et erreurs sur: -# http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender -#--------------------------------------------- -# ce script est proposé sous licence GPL pour etre associe -# a la distribution de Blender 2.33 -#---------------------------------------------- -# this script is released under GPL licence -# for the Blender 2.33 scripts package -#---------------------------------------------- -# ***** BEGIN GPL LICENSE BLOCK ***** -# -# Copyright (C) 2003, 2004: Jean-Michel Soler -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# ***** END GPL LICENCE BLOCK ***** -# -------------------------------------------------------------------------- -# 09/07/04 : Noise functions based on a piece of script by Jimmy Haze. -# -------------------------------------------------------------------------- - -import Blender -from Blender import * -from Blender.Draw import * -from Blender.BGL import * -from Blender.Noise import * -from Blender.Scene import * -from Blender.Window import * -sc=Scene.getCurrent() - -# niveau du deplacement -ng=0.5 - -# noise default -NOISE=1 - -# profondeur des couleurs primaires rgb -maxcol=255.0*3 - -# limitation de la zone de travail sur le -# le materiau numer mat du tableau d'indices -# des materiaux. Par defaut mat =-1 ce qui signifie -# que toute la surface est traitee -mat=[] -vindex=[] -ORIName='' -NEWName='' -ERROR=0 -TextERROR='' - -E_EXIT = 1 -E_MODE = 2 -E_ORIENT = 3 -E_NSIZE = 4 -E_REPEAT = 5 -E_ACTION = 16 -E_CREATE = 17 -E_DOCMAT = 24 -E_MATVAL = [32,33,34,35,36,37,38,39,40,41,42,43,44] -E_AXESEL = 45 -E_AXESELX = 46 -E_AXESELY = 47 -E_AXESELZ = 48 - - -E_NOISEME = 49 -E_NOISEH = 50 -E_NOISELAC = 51 -E_NOISEOCT = 52 -E_NOISEOFF = 53 -E_NOISEBAS = 54 -E_NOISEVAL=[E_NOISEH,E_NOISELAC,E_NOISEOCT,E_NOISEOFF,E_NOISEBAS] -E_NOISEDIM = 55 - -E_GETCOLORS = 56 -E_UVCOLORS = 57 -E_SAVECOLORS = 58 -B_SAVECOLORS = 0 - -E_RESTCOLORS = 60 -V_RESTCOL=0 -F_RESTCOL=0 - -BUF_COLORS=[] - -RVBA_VALUE=61 -RVBA_VERTICES=62 -RVBA_FACES=63 - -ExitTIP="Exit from this script session " -CreateTIP="Create a new copy of the selected shape" -ActionTIP="Do the current selected actions" - -UVCOLORSTIP="Get colrs from first available UV image " -GETCOLORSTIP="Get color from textures " -REPEATTIP="Replay the same action with new values ." - -def copy_transform(ozero,Obis): - Obis.setSize(ozero.getSize()); - Obis.setEuler(ozero.getEuler()); - Obis.setLocation(ozero.getLocation()) - return Obis - -def traite_face(f): - global vindexm, ng, NOISE, NOISEDIM - global H,lacunarity,octaves,offset,basis - - if ORIENTMenu.val==1: - for z in range(len(f.v)): - c=0.0 - if vindex[f.v[z].index]!=0: - c=float(f.col[z].r+f.col[z].b+f.col[z].g)/maxcol*ng/vindex[f.v[z].index] - else: - c=0 - - f.v[z].co[0]=f.v[z].co[0]+f.v[z].no[0]*c - f.v[z].co[1]=f.v[z].co[1]+f.v[z].no[1]*c - f.v[z].co[2]=f.v[z].co[2]+f.v[z].no[2]*c - - elif ORIENTMenu.val==2: - for z in range(len(f.v)): - c=0.0 - if vindex[f.v[z].index]!=0: - c=float(f.col[z].r+f.col[z].b+f.col[z].g)/maxcol*ng/vindex[f.v[z].index] - else: - c=0 - for t in range(3): - if TAXEList[1][t].val==1: - f.v[z].co[t]=f.v[z].co[t]+c - - elif ORIENTMenu.val==3 and NOISE<9: - for z in range(len(f.v)): - c=0.0 - if vindex[f.v[z].index]!=0: - nx=f.v[z].co[0]/NOISEDIM - ny=f.v[z].co[1]/NOISEDIM - nz=f.v[z].co[2]/NOISEDIM - nn = ng * noise((nx,ny,nz),NOISE) - c=float(f.col[z].r+f.col[z].b+f.col[z].g)/maxcol*nn/vindex[f.v[z].index] - else: - c=0 - f.v[z].co[0]=f.v[z].co[0]+f.v[z].no[0]*c - f.v[z].co[1]=f.v[z].co[1]+f.v[z].no[1]*c - f.v[z].co[2]=f.v[z].co[2]+f.v[z].no[2]*c - - elif ORIENTMenu.val==3 and NOISE==9: - for z in range(len(f.v)): - c=0.0 - if vindex[f.v[z].index]!=0: - nx=f.v[z].co[0]/NOISEDIM - ny=f.v[z].co[1]/NOISEDIM - nz=f.v[z].co[2]/NOISEDIM - nn = ng * cellNoise((nx,ny,nz)) - c=float(f.col[z].r+f.col[z].b+f.col[z].g)/maxcol*nn/vindex[f.v[z].index] - else: - c=0 - f.v[z].co[0]=f.v[z].co[0]+f.v[z].no[0]*c - f.v[z].co[1]=f.v[z].co[1]+f.v[z].no[1]*c - f.v[z].co[2]=f.v[z].co[2]+f.v[z].no[2]*c - - elif ORIENTMenu.val==3 and NOISE==10: - for z in range(len(f.v)): - c=0.0 - if vindex[f.v[z].index]!=0: - nx=f.v[z].co[0]/NOISEDIM - ny=f.v[z].co[1]/NOISEDIM - nz=f.v[z].co[2]/NOISEDIM - nn = ng * heteroTerrain((nx,ny,nz),H,lacunarity,octaves,offset,basis) - c=float(f.col[z].r+f.col[z].b+f.col[z].g)/maxcol*nn/vindex[f.v[z].index] - else: - c=0 - f.v[z].co[0]=f.v[z].co[0]+f.v[z].no[0]*c - f.v[z].co[1]=f.v[z].co[1]+f.v[z].no[1]*c - f.v[z].co[2]=f.v[z].co[2]+f.v[z].no[2]*c - - -def paint(): - global MODEMenu, vindex,ng, mat, ORIName, NEWName - global ERROR, TextERROR - - Me=Object.GetSelected() - if Me!=[]: - if Me[0].getType()=='Mesh': - - vindex=[] - ORIName=Me[0].getData(name_only=1) - me=NMesh.GetRaw(Me[0].getData(name_only=1)) - - try: - for m in me.verts: - vindex.append(0) - - for f in me.faces: - for v in f.v: - if MODEMenu.val!=2: - if MODEMenu.val==1: - vindex[v.index]+=1 - else: - if v.sel==1: - vindex[v.index]+=1 - else: - #print mat - if f.mat in mat: - vindex[v.index]+=1 - for f in me.faces: - if MODEMenu.val==2: - if f.mat in mat: - traite_face(f) - else: - traite_face(f) - #Me[0].link(me) - me.update() - Me[0].makeDisplayList() - except: - ERROR=2 - TextERROR='No color on this Object.' - -def NEWMEcreation(obj): - - if obj.getType()=='Mesh': - nomdelobjet=""; - objnumber=-1; namelist=[] - OBJ=Object.Get() - - for ozero in OBJ: - if ozero.getType()=='Mesh': - namelist.append(ozero.getData(name_only=1)) - - ozero=obj - nomdelobjet=ozero.getName() - Mesh=Blender.NMesh.GetRawFromObject(nomdelobjet) - name=obj.getData(name_only=1) - n=0; name2=name[:];ok=0 - - while ok==0: - for n0 in namelist: - if n0.find(name2)==0: - ok=0;name2=name[0:name.find('.')+1]+'%s'%(n+1) - else: ok=1 - n+=1 - - Mesh.name=name2 - Obis = Blender.NMesh.PutRaw(Mesh,name2) - copy_transform(ozero,Obis) - Obis.makeDisplayList() - -def DOCMat_list(TMATList): - global mat - Me=Object.GetSelected() - if Me!=[]: - if Me[0].getType()=='Mesh': - me=NMesh.GetRaw(Me[0].getData(name_only=1)) - if len(me.materials)!=0: - n=0 - for mat in me.materials: - TMATList[1][n][0]=mat.R - TMATList[1][n][1]=mat.G - TMATList[1][n][2]=mat.B - n+=1 - TMATList[0]=n - else: - TMATList[0]=0 - return TMATList - -MOname = "MODE MENU %t|Normal %x1|Material %x2|Selected %x3| Find color %x4" -MOname_doc=["", - "Displace all vertices", - "Displace vertices only on selected materials . ", - "Displace only selected vertices .", - "Try to find and set selected the vertices with this color."] - -ORname = "ORIENT MENU %t|From Normal %x1|Local Axes %x2| Noise %x3" -ORname_doc=["", - "Use normal orientation to calculate displacement", - "Use selected axes value to calculate displacement", - "Blend the color value with Nosie values to calculate the displacement"] - -NOname = "NOISE MENU %t|BLENDER %x1|STDPERLIN %x2|\ -NEWPERLIN %x3|VORONOI_F1%x4|VORONOI_F2%x5|\ -VORONOI_F3%x6|VORONOI_F4%x7|VORONOI_F2F1%x8|\ -VORONOI_CRACKLE%x9|CELLNOISE%x10|HETEROTENOISE%x11" - -MODEMenu = Create(1) -ORIENTMenu = Create(1) -NOISEMenu = Create(1) - -NSIZE = Create(1.0) -TDOCMat = Create(0) -NRepeat = Create(1) - -H=1.0 -lacunarity=2.0 -octaves=5.0 -offset=1.0 -basis=3 - -NOISEDIM=4 -NOISEDIMbout=Create(NOISEDIM) -HBout=Create(H) -lacunarityBout=Create(lacunarity) -octavesBout=Create(octaves) -offsetBout=Create(offset) -basisBout=Create(basis) - - -noiseTYPE={0:'BLENDER', - 1:'STDPERLIN', - 2:'STDPERLIN', - 3:'NEWPERLIN', - 4:'VORONOI_F1', - 5:'VORONOI_F2', - 6:'VORONOI_F3', - 7:'VORONOI_F2F1', - 8:'VORONOI_CRACKLE', - 9:'CELLNOISE'} - -TMATList= [0,[],[]] - -for t in range(16): - TMATList[1].append([0.0,0.0,0.0]) - TMATList[2].append(Create(0)) - -TAXEList=[['X','Y','Z'],[]] -for t in range(3): - TAXEList[1].append(Create(0)) - -glCr=glRasterPos2d -glCl3=glColor3f -glCl4=glColor4f -glRct=glRectf - -def triangle(a,b,c): - glBegin(GL_TRIANGLES); - glColor3f(a[2],a[3],a[4]) - glVertex2f(a[0],a[1]); - glVertex2f(b[0],b[1]); - glVertex2f(c[0],c[1]); - glEnd(); - -def triangleFcolor(a,b,c): - glBegin(GL_TRIANGLES); - glColor4f(a[2],a[3],a[4],a[5]) - glVertex2f(a[0],a[1]); - glColor4f(b[2],b[3],b[4],a[5]) - glVertex2f(b[0],b[1]); - glColor4f(c[2],c[3],c[4],a[5]) - glVertex2f(c[0],c[1]); - glEnd(); - -def Ltriangle(a,b,c,LC=0.5): - TL=[a,b,c,a] - for v in [0,1,2] : - glBegin(GL_LINES); - glColor3f(LC,LC,LC) - glVertex2f(TL[v][0],TL[v][1]); - glVertex2f(TL[v+1][0],TL[v+1][1]); - glEnd(); - - -def carreFcolor(a,b,c,d): - triangleFcolor(a,b,c) - triangleFcolor(a,c,d) - -RVBA=[Create(255),Create(255),Create(255),Create(255),Create(0)] - -# _*_ p1 -# _/ \_ -# _/ \_ -# / \_ -# p0*_ /* p2 -# | \_ _/ | -# | \_ _/ | -# | \_ _/ | -# | * p3 | -# | | | -# *_ | /* p4 -# p6 \_ | _/ -# \_ | _/ -# \_|_/ -# * p5 - -def flatcolorcube(r,g,b,a,m,x,y): - h0=60 - v0=40 - A=[x, y, (r-m)/255.0,g/255.0,b/255.0,a/255.0] #p0 - B=[x+h0,y-v0, r/255.0,g/255.0,b/255.0,a/255.0] #p3 - c=[x+h0*2,y, r/255.0, g/255.0, (b-m)/255.0,a/255.0] #p2 - d=[x+h0,y+v0, (r-m)/255.0,g/255.0,(b-m)/255.0,a/255.0] #p1 - carreFcolor(A,B,c,d) - - - A=[x,y,(r-m)/255.0,g/255.0,b/255.0,a/255.0] #p0 - B=[x+h0,y-v0,r/255.0,g/255.0,b/255.0,a/255.0] #p3 - c=[x+h0,y-v0*2.5, r/255.0, (g-m)/255.0, b/255.0,a/255.0] #p5 - d=[x,y-v0*1.5,(r-m)/255.0,(g-m)/255.0,b/255.0,a/255.0] #p6 - carreFcolor(A,B,c,d) - - d=[x+h0,y-v0,r/255.0,g/255.0,b/255.0,a/255.0] #p3 - A=[x+h0*2,y,r/255.0,g/255.0,(b-m)/255.0,a/255.0] #p2 - B=[x+h0*2,y-v0*1.5, r/255.0, (g-m)/255.0,(b-m)/255.0,a/255.0] #p4 - c=[x+h0,y-v0*2.5,r/255.0,(g-m)/255.0,b/255.0,a/255.0] #p5 - carreFcolor(A,B,c,d) - -def col_egal2col(col,RVBA): - eps=RVBA[4].val - if ( (RVBA[0].val-col[0]>=0 and RVBA[0].val-col[0]<=eps) and - (RVBA[1].val-col[1]>=0 and RVBA[1].val-col[1]<=eps) and - (RVBA[2].val-col[2]>=0 and RVBA[2].val-col[2]<=eps) and - (RVBA[3].val-col[3]>=0 and RVBA[3].val-col[3]<=eps) ) : - #print 'ok',col, [RVBA[n].val-col[n] for n in 0,1,2,3] - return 1 - else: - #print 'not',col, [RVBA[n].val-col[n] for n in 0,1,2,3] - return 0 - -def select_bycolors(TYPE,RVBA): - global RVBA_VERTICES, RVBA_FACES - SEL = Blender.NMesh.FaceFlags['SELECT'] - try: - ME=Blender.Scene.getCurrent().getActiveObject().getData() - VC={} - for f in ME.faces: - for v in f.v: - try: - VC[v].append(f) - except: - VC[v]=[f] - #print '.', - for C in VC.iteritems(): - color=[0,0,0] - for f in C[1]: - col=f.col[f.v.index(C[0])] - col=[col.r,col.g,col.b,col.a] - if col_egal2col(col,RVBA): - if TYPE== RVBA_VERTICES: - C[0].sel=1 - else: - f.sel=1 - f.flag |= SEL - #VC[C[0]].append(color[:]) - ME.update() - except: - pass - -def draw(): - global MODEMenu, NSIZE, TDOCMat,TMATList, TAXEList - global mat, ORIName, NEWName, ORIENTMenu - global NRepeat, ERROR, TextERROR , NOISE, NOISEMenu - global NOISEDIMbout,NOISEDIM, RVBA,RVB_VALUE, RVBA_VERTICES - global HBout,lacunarityBout,octavesBout,offsetBout,basisBout - global noiseTYPE, ExitTIP, CreateTIP, ActionTIP, E_GETCOLORS - global E_UVCOLORS, UVCOLORSTIP, GETCOLORSTIP, REPEATTIP,RVBA_FACES - global E_SAVECOLORS, B_SAVECOLORS, E_RESTCOLORS, MOname_doc, ORname_doc - - size=Buffer(GL_FLOAT, 4) - glGetFloatv(GL_SCISSOR_BOX, size) - size= size.list - - for s in [0,1,2,3]: size[s]=int(size[s]) - - glClearColor(0.72,0.72,0.72,1.0) - glClear(GL_COLOR_BUFFER_BIT) - - glColor3f(0.66,0.66,0.66) - glRectf(4,size[3]-4,404,size[3]-32 ) - - glColor3f(0.76,0.76,0.76) - glRectf(4,size[3]-32,404,size[3]-294 ) - - triangle([4+9,size[3],0.72,0.72,0.72], - [4,size[3],], - [4,size[3]-9]) - - triangle([404-9,size[3],0.72,0.72,0.72], - [404,size[3],], - [404,size[3]-9]) - - triangle([404,size[3]-294,.72,0.72,0.72], - [404,size[3]-294+9,], - [404-9,size[3]-294]) - - triangle([4,size[3]-294,.72,0.72,0.72], - [4,size[3]-294+9,], - [4+9,size[3]-294]) - - glColor3f(1.0,1.0,1.0) - glRasterPos2f(20, size[3]-15) - Text("Script Python de displacement painting") - - glRasterPos2f(20, size[3]-28) - Text("Jean-michel Soler, Aout 2005") - - - n0=70 - n1=55 - if MODEMenu.val<4 : - Button("Create" ,E_CREATE ,5 ,size[3]-n0+11 ,60 ,20,CreateTIP) - Button("Action" ,E_ACTION ,5 ,size[3]-n0-11 ,60 ,20,ActionTIP) - NRepeat=Number("repeat" ,E_REPEAT ,5 ,size[3]-n0-56 ,75 ,20, NRepeat.val,1,10,REPEATTIP) - - Button("Exit" ,E_EXIT ,5 ,size[3]-n0-32 ,60 ,20,ExitTIP) - Button("Tex colors" ,E_GETCOLORS ,5 ,size[3]-n0-80 ,75 ,20,GETCOLORSTIP) - Button("UV colors" ,E_UVCOLORS ,5 ,size[3]-n0-102 ,75 ,20,UVCOLORSTIP) - if B_SAVECOLORS : - Button("Rest colors" ,E_RESTCOLORS ,5 ,size[3]-n0-146 ,75 ,20,UVCOLORSTIP) - else: - Button("Save colors" ,E_SAVECOLORS ,5 ,size[3]-n0-124 ,75 ,20,GETCOLORSTIP) - - - - glColor3f(0.0,0.0,0.0) - glRasterPos2f(80 ,size[3]-n0+24) - Text("MODE") - - MODEMenu= Menu(MOname, E_MODE ,80 ,size[3]-n0 ,100,20, MODEMenu.val, MOname_doc[MODEMenu.val]) - - if MODEMenu.val==2: - TDOCMat=Toggle("Doc Mat" ,E_DOCMAT ,180 ,size[3]-n0 ,60 ,20,TDOCMat.val) - if TDOCMat.val==1: - #print TMATList - for t in range(TMATList[0]): - glCl3(TMATList[1][t][0], - TMATList[1][t][1], - TMATList[1][t][2]) - - if t<=7: - glRct(80+t*40, - size[3]-n0-60, - 80+t*40+40, - size[3]-n0-60+40) - TMATList[2][t]=Toggle("%s"%(t+1) , 32+t ,80+t*40+5 ,size[3]-n0-50 ,30 , 20,TMATList[2][t].val) - else: - glRct(80+(t-8)*40, - size[3]-n0-50-50, - 80+(t-8)*40+40, - size[3]-n0-60) - TMATList[2][t]=Toggle("%s"%(t+1) , 32+t ,80+(t-8)*40+5 ,size[3]-n0-45*2 ,30 , 20,TMATList[2][t].val) - - glColor3f(1.0,0.3,0.0) - glRasterPos2f(80+40+5 ,size[3]-n0-110) - if ERROR>1: - Text('Last error : '+TextERROR) - else: - Text('Last error : ') - - glColor3f(0.0,0.0,0.0) - glRasterPos2f(240 ,size[3]-n0+24) - - if MODEMenu.val<4: - Text("ORIENTATION") - ORIENTMenu= Menu(ORname, E_ORIENT ,240 ,size[3]-n0 ,100,20, ORIENTMenu.val, ORname_doc[ORIENTMenu.val]) - if ORIENTMenu.val==2 : - for t in [0,1]: - TAXEList[1][t]=Toggle("%s"%TAXEList[0][t], - E_AXESEL+t, - 240+100+t*30+2 , size[3]-n0+10 ,28 , 18, - TAXEList[1][t].val) - TAXEList[1][2]=Toggle("%s"%TAXEList[0][2], - E_AXESEL+2, - int(240+100+.5*30+2) , size[3]-n0-10 ,28 , 18, - TAXEList[1][2].val) - if ORIENTMenu.val==3 : - glRasterPos2f(240 ,size[3]-n0-120-4) - Text("NOISE") - NOISEMenu= Menu(NOname, E_NOISEME , 240 ,size[3]-n0-148 ,110,20, NOISEMenu.val, "NOISE menu.") - NOISEDIMbout=Number(" Dim: " ,E_NOISEDIM , 240 ,size[3]-n0-172 ,110,20, NOISEDIMbout.val, 1,100) - if NOISEMenu.val==11: - basisBout=Slider(noiseTYPE[basisBout.val], - E_NOISEBAS ,40 ,size[3]-n0-178 ,175,20, basisBout.val, 0,9,) - HBout= Slider("H", E_NOISEH ,40 ,size[3]-n0-198 ,175,20, HBout.val, -2.0,+2.0,0,) - lacunarityBout=Slider("lacunarity", E_NOISELAC ,40 ,size[3]-n0-218 ,175,20, lacunarityBout.val, -4.0,+4.0,0,) - octavesBout=Slider("octave", E_NOISEOCT ,219 ,size[3]-n0-198 ,175,20, octavesBout.val, -10.0,+10.0,0,) - offsetBout=Slider("offset", E_NOISEOFF ,219 ,size[3]-n0-218 ,175,20, offsetBout.val, -5.0,+5.0,0,) - NSIZE= Slider("Disp Size", E_NSIZE ,80 ,size[3]-n0-20 ,260,20, NSIZE.val, -4.0,+4.0,0,"SIZE.") - - - else: - # degrades de couleurs - glShadeModel(GL_SMOOTH) - #transparence - glEnable(GL_BLEND) - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) - - RVBA[0]=Slider("Red :", RVBA_VALUE , 105 ,size[3]-n0-25 ,280,20, RVBA[0].val, 0,255,0,"") - RVBA[1]=Slider("Green :", RVBA_VALUE , 105 ,size[3]-n0-47 ,280,20, RVBA[1].val, 0,255,0,"") - RVBA[2]=Slider("Blue :", RVBA_VALUE , 105 ,size[3]-n0-69 ,280,20, RVBA[2].val, 0,255,0,"") - RVBA[3]=Slider("Alpha :", RVBA_VALUE , 105 ,size[3]-n0-91 ,150,20, RVBA[3].val, 0,255,0,"") - RVBA[4]=Slider("margin :", RVBA_VALUE , 105 ,size[3]-n0-113 ,150,20, RVBA[4].val, 0,255,0,"") - flatcolorcube(RVBA[0].val, - RVBA[1].val, - RVBA[2].val, - RVBA[3].val, - RVBA[4].val, - 270,size[3]-n0-120) - - Button("Vertex" ,RVBA_VERTICES ,5 ,size[3]-n0-148 ,75 ,20,CreateTIP) - Button("Faces" ,RVBA_FACES ,5 ,size[3]-n0-169 ,75 ,20,ActionTIP) - - -def on_MESH(): - Me=Object.GetSelected() - if Me!=[] and Me[0].getType()=='Mesh': - editmode = Window.EditMode() - if editmode: Window.EditMode(0) - return 1,Me[0].getData() - else: - return 0, None - -def event(evt, val): - if (evt== QKEY and not val): Exit() - -def bevent(evt): - global MODEMenu, NSIZE, ng, TMATList - global mat, ORIENTMenu, NRepeat, TAXEList - global ERROR,TextERROR, NOISE, NOISEMenu, NOISEDIMbout,NOISEDIM - global HBout,lacunarityBout,octavesBout,offsetBout,basisBout - global H,lacunarity,octaves,offset,basis, E_RESTCOLORS, RVBA_VERTICES - global E_GETCOLORS, E_UVCOLORS, E_SAVECOLORS, B_SAVECOLORS - global V_RESTCOLORS, F_RESTCOLORS, BUF_COLORS, RVBA, RVBA_FACES - - if (evt== E_EXIT): - Exit() - elif (evt== E_ACTION): - for n in range(NRepeat.val): - paint() - elif (evt== E_NSIZE): - ng=NSIZE.val - elif (evt== E_DOCMAT) or (evt in E_MATVAL): - Me=Object.GetSelected() - - if Me!=[]: - if Me[0].getType()=='Mesh': - TMATList=DOCMat_list(TMATList) - mat=[] - for TMat in TMATList[2]: - if TMat.val==1.0: - mat.append(TMATList[2].index(TMat)) - ERROR=0 - else: - ERROR=1 - TextERROR='Selected Object is not a mesh.' - else: - ERROR=1 - TextERROR='No Selected Object.' - elif (evt== E_CREATE): - NEWMEcreation(Blender.Object.GetSelected()[0]) - Blender.Draw.Redraw() - ERROR=1 - TextERROR='No Selected Object.' - elif (evt== E_NOISEME): - NOISE=NOISEMenu.val-1 - elif (evt in E_NOISEVAL): - H=HBout.val - lacunarity=lacunarityBout.val - octaves=octavesBout.val - offset=offsetBout.val - basis=basisBout.val - elif (evt== E_NOISEDIM): - NOISEDIM=NOISEDIMbout.val - elif (evt == E_GETCOLORS): - OK,MESH=on_MESH() - if OK: MESH.update(1,0,1) - elif (evt == E_UVCOLORS): - OK,MESH=on_MESH() - if OK and MESH.hasFaceUV(): - for f in MESH.faces: - im = f.image - if im: - break - if im and im.has_data: - imX,imY = im.getMaxXY() - for f in MESH.faces: - col = f.col - for uv_index, uv in enumerate(f.uv): - color=[int(c*255.0) for c in im.getPixelF(abs(uv[0]*imX%imX), abs(uv[1]*imY%imY))] - col[uv_index].r=color[0] - col[uv_index].g=color[1] - col[uv_index].b=color[2] - col[uv_index].a=color[3] - MESH.update() - elif (evt == E_SAVECOLORS): - OK,MESH=on_MESH() - print OK, MESH - if OK and (MESH.hasFaceUV() or MESH.hasVertexColours()): - F_RESTCOLORS=1 - for f in MESH.faces: - b=[MESH.faces.index(f)] - for c in f.col: - b.append([c.r,c.g,c.b,c.a]) - BUF_COLORS.append(b) - B_SAVECOLORS = 1 - else: - B_SAVECOLORS = 0 - elif (evt == E_RESTCOLORS): - OK,MESH=on_MESH() - print F_RESTCOLORS, len(BUF_COLORS),len(MESH.faces) - if OK and F_RESTCOLORS==1 and len(BUF_COLORS)==len(MESH.faces): - for b in BUF_COLORS: - ncol=0 - for c in MESH.faces[b[0]].col : - print b[ncol+1] - c.r,c.g,c.b,c.a= b[ncol+1] - ncol+=1 - F_RESTCOLORS=0 - B_SAVECOLORS = 0 - BUF_COLORS=[] - MESH.update() - elif (evt == RVBA_VERTICES or evt == RVBA_FACES): - select_bycolors(evt,RVBA) - Blender.Draw.Redraw() -Register(draw, event, bevent) diff --git a/release/scripts/knife.py b/release/scripts/knife.py deleted file mode 100644 index eecee4f89e9..00000000000 --- a/release/scripts/knife.py +++ /dev/null @@ -1,725 +0,0 @@ -#!BPY - -""" -Name: 'Knife Tool' -Blender: 232 -Group: 'Object' -Tooltip: 'Cut selected mesh(es) along an active plane w/o creating doubles' -""" - -__author__ = ["Stefano <S68> Selleri", "Wim Van Hoydonck"] -__url__ = ("blender", "elysiun") -__version__ = "0.0.8b 05/13/06" - -__bpydoc__ = """\ -"Blender Knife Tool" uses the active mesh plane to cut all selected meshes. - -Usage: - -Create, resize and position a "cutting plane", which will be used to cut -the mesh(es), then: - -- select mesh(es) to be cut;<br> -- select cutting plane (it will be the active object);<br> -- run this script from 3d View's "Object->Scripts" menu. - -Options: - -- edit object: knife creates new vertices in the selected mesh(es);<br> -- create new object: knife duplicates objects and creates new vertices in the -new objects;<br> -- create two new objects: knife creates two new separate objects. -""" - -# $Id$ -# -#################################################################### -# # -# Blender Knife Tool # -# # -# v. 0.0.0 - 0.0.6 (C) December 2002 Stefano <S68> Selleri # -# v. 0.0.7 (C) March 2004 Wim Van Hoydonck # -# v. 0.0.8 (C) March 2004 Wim Van Hoydonck & Stefano <S68> Selleri # -# ( May 2006 jm soler( jms) for material management )# -# # -# Released under the Blender Artistic Licence (BAL) # -# See www.blender.org # -# # -# Works in Blender 2.32 and higher # -# # -# this script can be found online at: # -# http://users.pandora.be/tuinbels/scripts/knife-0.0.8.py # -# http://www.selleri.org/Blender # -# http://cobalt3d.free.fr/didacticiel/blender/tutor/images/python/knife_in_color/knife_color.py -# # -# email: tuinbels@hotmail.com # -# selleri@det.unifi.it # -#################################################################### -# History # -# V: 0.0.0 - 08-12-02 - The script starts to take shape, a # -# history is now deserved :) # -# 0.0.1 - 09-12-02 - The faces are correctly selected and # -# assigned to the relevant objects now the # -# hard (splitting) part... # -# 0.0.2 - 14-12-02 - Still hacking on the splitting... # -# It works, but I have to de-globalize # -# the intersection coordinates # -# 0.0.3 - 15-12-02 - First Alpha version # -# 0.0.4 - 17-12-02 - Upgraded accordingly to eeshlo tips # -# Use Matrices for coordinate transf. # -# Add a GUI # -# Make it Run on 2.23 # -# 0.0.5 - 17-12-02 - Eeshlo solved some problems.... # -# Theeth too adviced me # -# 0.0.6 - 18-12-02 - Better error messages # -# 0.0.7 - 26-03-04 - Developer team doubles! # -# This version is by Wim! # -# Doesn't create doubles (AFAIK) # -# - Faster (for small meshes), global # -# coordinates of verts are calculated only # -# once # -# - Editing the CutPlane in editmode (move) # -# shouldn't cause problems anymore # -# - Menu button added to choose between the # -# different Edit Methods # -# - If a mesh is cut twice at the same place, # -# this gives errors :( (also happened in # -# previous versions) # -# - Willian Padovani Germano solved # -# a problem, many thanks :) # -# - Stefano Selleri made some good # -# suggestions, thanks :) # -# 0.0.8 - 26-03-04 - General Interface rewrite (Stefano) # -# 0.0.8a- 31-03-04 - Added some error messages # -# - Cut multiple meshes at once # -# # -# O.0.8b -13-05-06 - Added multi-material management (jms) # -################################################################### - -import Blender -from Blender import * -from Blender.sys import time -from math import * - -Epsilon = 0.00001 -msg = '' -RBmesh0 = Draw.Create(0) -RBmesh1 = Draw.Create(0) -RBmesh2 = Draw.Create(1) - -VERSION = '0.0.8' - -# see if time module is available -#try: -# import time -# timport = 1 -#except: -# timport = 0 - - -BL_VERSION = Blender.Get('version') -if (BL_VERSION<=223): - import Blender210 - -lenface = [] -vertglob = [] -vertidx = [] -vertdist = [] -facemat = [] - -#=================================# -# Vector and matrix manipulations # -#=================================# - -# vector addition -def vecadd(a, b): - return [a[0] - b[0], a[1] - b[1], a[2] + b[2]] - -# vector substration -def vecsub(a, b): - return [a[0] - b[0], a[1] - b[1], a[2] - b[2]] - -# vector crossproduct -def veccross(x, y): - v = [0, 0, 0] - v[0] = x[1]*y[2] - x[2]*y[1] - v[1] = x[2]*y[0] - x[0]*y[2] - v[2] = x[0]*y[1] - x[1]*y[0] - return v - -# vector dotproduct -def vecdot(x, y): - return x[0]*y[0] + x[1]*y[1] + x[2]*y[2] - -# vector length -def length(v): - return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]) - -# vector multiplied by constant s -def vecmul(a, s): - return[a[0]*s, a[1]*s, a[2]*s] - -# vector divided by constant s -def vecdiv(a, s): - if s!=0.0: s = 1.0/s - return vecmul(a, s) - -# matrix(4x3) vector multiplication -def mulmatvec4x3(a, b): - # a is vector, b is matrix - r = [0, 0, 0] - r[0] = a[0]*b[0][0] + a[1]*b[1][0] + a[2]*b[2][0] + b[3][0] - r[1] = a[0]*b[0][1] + a[1]*b[1][1] + a[2]*b[2][1] + b[3][1] - r[2] = a[0]*b[0][2] + a[1]*b[1][2] + a[2]*b[2][2] + b[3][2] - return r - -# Normalization of a vector -def Normalize(a): - lengte = length(a) - return vecdiv(a, lengte) - -# calculate normal from 3 verts -def Normal(v0, v1, v2): - return veccross(vecsub(v0, v1),vecsub(v0, v2)) - -#===========================# -# Coordinatetransformations # -#===========================# - -def GlobalPosition(P, Obj): - - if (BL_VERSION<=223): - m = Obj.matrix - else: - m = Obj.getMatrix() - - return mulmatvec4x3(P, m) - -def LocalPosition(P, Obj): - - if (BL_VERSION<=223): - m = Blender210.getObject(Obj.name).inverseMatrix - else: - m = Obj.getInverseMatrix() - - return mulmatvec4x3(P, m) - -#================# -# Get Plane Data # -#================# - -def PlaneData(Plane): - global msg - # - # Calculate: - # - the normal of the plane, - # - the offset of the plane wrt the global coordinate system - # in the direction of the normal of the plane - # - PlaneMesh = NMesh.GetRawFromObject(Plane.name) - - if (len(PlaneMesh.faces)>1): - msg = "ERROR: Active object must be a single face plane" - return ((0,0,0),(0,0,0),1) - else: - if (len(PlaneMesh.verts)<3): - msg = "ERROR: 3 vertices needed to define a plane" - return ((0,0,0),(0,0,0),1) - else: - v0 = GlobalPosition(PlaneMesh.faces[0].v[0].co, Plane) - v1 = GlobalPosition(PlaneMesh.faces[0].v[1].co, Plane) - v2 = GlobalPosition(PlaneMesh.faces[0].v[2].co, Plane) - - # the normal of the plane, calculated from the first 3 verts - PNormal = Normalize(Normal(v0,v1,v2)) - - # offset of the plane, using 1st vertex instead of Plane.getLocaction() - POffset = vecdot(v0,PNormal) - - return PNormal, POffset, 0 - -#====================================# -# Position with respect to Cut Plane # -#====================================# - -def Distance(P, N, d0): - # - # distance from a point to a plane - # - return vecdot(P, N) - d0 - -def FacePosition(dist): - # - # position of a face wrt to the plane - # - np, nn, nz = 0, 0, 0 - - for d in dist: - - # the distances are calculated in advance - if d > 0: - np += 1 - elif d < 0: - nn += 1 - else: - nz += 1 - - if np == 0: - return -1 - if nn == 0: - return 1 - return 0 - -#==========================================# -# Append existing faces / create new faces # -#==========================================# - -def FaceAppend(me, fidx, fmat): - # - # append a face to a mesh based on a list of vertex-indices - # - nf = NMesh.Face() - nf.mat=fmat - - for i in fidx: - nf.v.append(me.verts[i]) - - me.faces.append(nf) - -def FaceMake(me, vl, fmat): - # - # make one or two new faces based on a list of vertex-indices - # - idx = len(me.verts) - - if len(vl) <= 4: - nf = NMesh.Face() - nf.mat=fmat - for i in range(len(vl)): - nf.v.append(me.verts[vl[i]]) - me.faces.append(nf) - else: - nf = NMesh.Face() - nf.mat=fmat - nf.v.append(me.verts[vl[0]]) - nf.v.append(me.verts[vl[1]]) - nf.v.append(me.verts[vl[2]]) - nf.v.append(me.verts[vl[3]]) - me.faces.append(nf) - - nf = NMesh.Face() - nf.mat=fmat - nf.v.append(me.verts[vl[3]]) - nf.v.append(me.verts[vl[4]]) - nf.v.append(me.verts[vl[0]]) - me.faces.append(nf) - -#=====================================# -# Generate vertex lists for new faces # -#=====================================# - -def Split(Obj, MeshPos, MeshNeg, Vglob, Vidx, N, d0, newvidx, newvcoo, totverts, d): - # - # - calculate intersectionpoints of the plane with faces - # - see if this intersectionpoint already exists (look for vertices close to the new vertex) - # - if it does not yet exist, append a vertex to the mesh, - # remember its index and location and append the index to the appropriate vertex-lists - # - if it does, use that vertex (and its index) to create the face - # - - vp = [] - vn = [] - - # distances of the verts wrt the plane are calculated in main part of script - - for i in range(len(d)): - # the previous vertex - dim1 = d[int(fmod(i-1,len(d)))] - Vim1 = Vglob[int(fmod(i-1,len(d)))] - - if abs(d[i]) < Epsilon: - # if the vertex lies in the cutplane - vp.append(Vidx[i]) - vn.append(Vidx[i]) - else: - if abs(dim1) < Epsilon: - # if the previous vertex lies in cutplane - if d[i] > 0: - vp.append(Vidx[i]) - else: - vn.append(Vidx[i]) - else: - if d[i]*dim1 > 0: - # if they are on the same side of the plane - if d[i] > 0: - vp.append(Vidx[i]) - else: - vn.append(Vidx[i]) - else: - # the vertices are not on the same side of the plane, so we have an intersection - - Den = vecdot(vecsub(Vglob[i],Vim1),N) - - Vi = [] - Vi.append ( ((Vim1[0]*Vglob[i][1]-Vim1[1]*Vglob[i][0])*N[1]+(Vim1[0]*Vglob[i][2]-Vim1[2]*Vglob[i][0])*N[2]+(Vglob[i][0]-Vim1[0])*d0)/Den) - Vi.append ( ((Vim1[1]*Vglob[i][0]-Vim1[0]*Vglob[i][1])*N[0]+(Vim1[1]*Vglob[i][2]-Vim1[2]*Vglob[i][1])*N[2]+(Vglob[i][1]-Vim1[1])*d0)/Den) - Vi.append ( ((Vim1[2]*Vglob[i][0]-Vim1[0]*Vglob[i][2])*N[0]+(Vim1[2]*Vglob[i][1]-Vim1[1]*Vglob[i][2])*N[1]+(Vglob[i][2]-Vim1[2])*d0)/Den) - - ViL = LocalPosition(Vi, Obj) - - if newvidx == []: - # if newvidx is empty (the first time Split is called), append a new vertex - # to the mesh and remember its vertex-index and location - ViLl = NMesh.Vert(ViL[0],ViL[1],ViL[2]) - - if MeshPos == MeshNeg: - MeshPos.verts.append(ViLl) - - else: - MeshPos.verts.append(ViLl) - MeshNeg.verts.append(ViLl) - - nvidx = totverts - newvidx.append(nvidx) - newvcoo.append(ViL) - - vp.append(nvidx) - vn.append(nvidx) - else: - # newvidx is not empty - dist1 = [] - tlr = 0 - for j in range(len(newvidx)): - # calculate the distance from the new vertex to the vertices - # in the list with new vertices - dist1.append(length(vecsub(ViL, newvcoo[j]))) - for k in range(len(dist1)): - if dist1[k] < Epsilon: - # if distance is smaller than epsilon, use the other vertex - # use newvidx[k] as vert - vp.append(newvidx[k]) - vn.append(newvidx[k]) - break # get out of closest loop - else: - tlr += 1 - - if tlr == len(newvidx): - nvidx = totverts + len(newvidx) - ViLl = NMesh.Vert(ViL[0],ViL[1],ViL[2]) - - if MeshPos == MeshNeg: - MeshPos.verts.append(ViLl) - - else: - MeshPos.verts.append(ViLl) - MeshNeg.verts.append(ViLl) - - newvidx.append(nvidx) - newvcoo.append(ViL) - vp.append(nvidx) - vn.append(nvidx) - - if d[i] > 0: - vp.append(Vidx[i]) - else: - vn.append(Vidx[i]) - - return vp, vn, newvidx, newvcoo - -#===========# -# Main part # -#===========# - -def CutMesh(): - global msg - global RBmesh0,RBmesh1,RBmesh2 - global lenface, vertglob, vertidx, vertdist, facemat - - #if timport == 1: - # start = time.clock() - start = time() - - selected_obs = Object.GetSelected() - - total = len(selected_obs) - - NoErrors=0 - - meshes = 0 - - # check to see if every selected object is a mesh - for ob in selected_obs: - type = ob.getType() - if type == 'Mesh': - meshes += 1 - - # at least select two objects - if meshes <= 1: - msg = "ERROR: At least two objects should be selected" - NoErrors = 1 - - # if not every object is a mesh - if meshes != total: - msg = "ERROR: You should only select meshobjects" - NoErrors=1 - - # everything is ok - if NoErrors == 0: - Pln = selected_obs[0] - PNormal, POffset, NoErrors = PlaneData(Pln) - - # loop to cut multiple meshes at once - for o in range(1, total): - Obj = selected_obs[o] - if (NoErrors == 0) : - m = Obj.getData() - if RBmesh1.val == 1: - MeshNew = NMesh.GetRaw() - MeshNew.materials = m.materials[:] - if RBmesh2.val == 1: - MeshPos = NMesh.GetRaw() - MeshPos.materials = m.materials[:] - MeshNeg = NMesh.GetRaw() - MeshNeg.materials = m.materials[:] - # get the indices of the faces of the mesh - idx = [] - for i in range(len(m.faces)): - idx.append(i) - # if idx is not reversed, this results in a list index out of range if - # the original mesh is used (RBmesh1 == 0) - idx.reverse() - - lenface, vertglob, vertidx, vertdist, facemat = [], [], [], [], [] - - # total number of vertices - totverts = len(m.verts) - - # for every face: calculate global coordinates of the vertices - # append the vertex-index to a list - # calculate distance of vertices to cutplane in advance - - for i in idx: - fvertidx, Ve, dist = [], [], [] - fa = m.faces[i] - facemat.append(fa.mat) - lenface.append(len(fa)) - for v in fa.v: - globpos = GlobalPosition(v.co, Obj) - Ve.append(globpos) - fvertidx.append(v.index) - dist.append(Distance(globpos, PNormal, POffset)) - vertidx.append(fvertidx) - vertglob.append(Ve) - vertdist.append(dist) - - - # append the verts of the original mesh to the new mesh - if RBmesh1.val == 1: - for v in m.verts: - MeshNew.verts.append(v) - - if RBmesh2.val == 1: - idx2 = [] - dist2 = [] - for v in m.verts: - MeshPos.verts.append(v) - MeshNeg.verts.append(v) - idx2.append(v.index) - dist2.append(Distance(GlobalPosition(v.co, Obj), PNormal, POffset)) - - # remove all faces of m if the original object has to be used - - if RBmesh0.val == 1: - m.faces = [] - - newvidx, newvcoo = [], [] - testidxpos, testidxneg = [], [] - - # what its all about... - for i in idx: - fp = FacePosition(vertdist[i]) - - # no intersection - if fp > 0: - if RBmesh0.val == 1: - FaceAppend(m, vertidx[i], facemat[i]) - - elif RBmesh1.val == 1: - FaceAppend(MeshNew, vertidx[i], facemat[i]) - - elif RBmesh2.val == 1: - FaceAppend(MeshPos, vertidx[i], facemat[i]) - - if testidxpos == []: - testidxpos = vertidx[i] - elif fp < 0: - if RBmesh0.val == 1: - FaceAppend(m, vertidx[i],facemat[i]) - elif RBmesh1.val == 1: - FaceAppend(MeshNew, vertidx[i],facemat[i]) - - elif RBmesh2.val == 1: - FaceAppend(MeshNeg, vertidx[i],facemat[i]) - - if testidxneg == []: - testidxneg = vertidx[i] - - # intersected faces - else: - # make new mesh - if RBmesh1.val == 1: - vlp, vln, newvidx, newvcoo = Split(Obj, MeshNew, MeshNew, vertglob[i], vertidx[i], PNormal, POffset, newvidx, newvcoo, totverts, vertdist[i]) - - if vlp != 0 and vln != 0: - FaceMake(MeshNew, vlp, facemat[i]) - FaceMake(MeshNew, vln, facemat[i] ) - # two new meshes - elif RBmesh2.val == 1: - vlp, vln, newvidx, newvcoo = Split(Obj, MeshPos, MeshNeg, vertglob[i], vertidx[i], PNormal, POffset, newvidx, newvcoo, totverts, vertdist[i]) - - if vlp != 0 and vln != 0: - FaceMake(MeshPos, vlp, facemat[i]) - FaceMake(MeshNeg, vln, facemat[i]) - - # use old mesh - elif RBmesh0.val == 1: - - vlp, vln, newvidx, newvcoo = Split(Obj, m, m, vertglob[i], vertidx[i], PNormal, POffset, newvidx, newvcoo, totverts, vertdist[i]) - - if vlp != 0 and vln != 0: - FaceMake(m, vlp, facemat[i]) - FaceMake(m, vln, facemat[i]) - - if RBmesh1.val == 1: - - ObOne = NMesh.PutRaw(MeshNew) - - ObOne.LocX, ObOne.LocY, ObOne.LocZ = Obj.LocX, Obj.LocY, Obj.LocZ - ObOne.RotX, ObOne.RotY, ObOne.RotZ = Obj.RotX, Obj.RotY, Obj.RotZ - ObOne.SizeX, ObOne.SizeY, ObOne.SizeZ = Obj.SizeX, Obj.SizeY, Obj.SizeZ - - elif RBmesh2.val == 1: - - # remove verts that do not belong to a face - idx2.reverse() - dist2.reverse() - - for i in range(len(idx2)): - if dist2[i] < 0: - v = MeshPos.verts[idx2[i]] - MeshPos.verts.remove(v) - if dist2[i] > 0: - v = MeshNeg.verts[idx2[i]] - MeshNeg.verts.remove(v) - - ObPos = NMesh.PutRaw(MeshPos) - - ObPos.LocX, ObPos.LocY, ObPos.LocZ = Obj.LocX, Obj.LocY, Obj.LocZ - ObPos.RotX, ObPos.RotY, ObPos.RotZ = Obj.RotX, Obj.RotY, Obj.RotZ - ObPos.SizeX, ObPos.SizeY, ObPos.SizeZ = Obj.SizeX, Obj.SizeY, Obj.SizeZ - - ObNeg = NMesh.PutRaw(MeshNeg) - - ObNeg.LocX, ObNeg.LocY, ObNeg.LocZ = Obj.LocX, Obj.LocY, Obj.LocZ - ObNeg.RotX, ObNeg.RotY, ObNeg.RotZ = Obj.RotX, Obj.RotY, Obj.RotZ - ObNeg.SizeX, ObNeg.SizeY, ObNeg.SizeZ = Obj.SizeX, Obj.SizeY, Obj.SizeZ - - elif RBmesh0.val == 1: - m.update() - - - #if timport == 1: - #end = time.clock() - #total = end - start - #print "mesh(es) cut in", total, "seconds" - - end = time() - total = end - start - print "mesh(es) cut in", total, "seconds" - -############################################################# -# Graphics # -############################################################# -def Warn(): - BGL.glRasterPos2d(115, 23) - Blender.Window.Redraw(Blender.Window.Const.TEXT) - -def draw(): - global msg - global RBmesh0,RBmesh1,RBmesh2 - global VERSION - - BGL.glClearColor(0.5, 0.5, 0.5, 0.0) - BGL.glClear(BGL.GL_COLOR_BUFFER_BIT) - BGL.glColor3f(0, 0, 0) # Black - BGL.glRectf(2, 2, 482, 220) - BGL.glColor3f(0.48, 0.4, 0.57) # Light Purple - BGL.glRectf(4, 179, 480, 210) - BGL.glRectf(4, 34, 480, 150) - BGL.glColor3f(0.3, 0.27, 0.35) # Dark purple - BGL.glRectf(4, 151,480, 178) - BGL.glRectf(4, 4, 480, 33) - - - BGL.glColor3f(1, 1, 1) - BGL.glRasterPos2d(8, 200) - Draw.Text("Blender Knife Tool - V. 0.0.8b - 13 May 2006") - BGL.glRasterPos2d(8, 185) - Draw.Text("by Wim <tuinbels> Van Hoydonck & Stefano <S68> Selleri (+ <jms> ) ") - Draw.Button("Exit", 1, 430, 185, 40, 20) - - RBmesh0 = Draw.Toggle("Edit Object", 10,10,157,153,18,RBmesh0.val, "The knife creates new vertices in the selected object."); - RBmesh1 = Draw.Toggle("New Object", 11,165,157,153,18,RBmesh1.val, "The knife duplicates the object and creates new vertices in the new object."); - RBmesh2 = Draw.Toggle("Two New Objects",12,320,157,153,18,RBmesh2.val, "The knife creates two new separate objects."); - - BGL.glRasterPos2d(8, 128) - Draw.Text("1 - Draw a Mesh Plane defining the Cut Plane") - BGL.glRasterPos2d(8, 108) - Draw.Text("2 - Select the Meshes to be Cut and the Cut Plane") - BGL.glRasterPos2d(8, 88) - Draw.Text(" (Meshes Dark Purple, Plane Light Purple)") - BGL.glRasterPos2d(8, 68) - Draw.Text("3 - Choose the Edit Method (Radio Buttons above)") - BGL.glRasterPos2d(8, 48) - Draw.Text("4 - Push the 'CUT' button (below)") - #Create Buttons - Draw.Button("CUT", 4, 10, 10, 465, 18, "Cut the selected mesh along the plane") - - - BGL.glRasterPos2d(10, 223) - BGL.glColor3f(1,0,0) - Draw.Text(msg) - msg = '' - -def event(evt, val): - if (evt == Draw.QKEY or evt == Draw.ESCKEY) and not val: - Draw.Exit() - if evt == Draw.CKEY and not val: - CutMesh() - Draw.Redraw() - -def bevent(evt): - global RBmesh0,RBmesh1,RBmesh2 - - if evt == 1: - Draw.Exit() - elif evt == 4: - CutMesh() - Draw.Redraw() - elif evt == 10: - RBmesh0.val = 1 - RBmesh1.val = 0 - RBmesh2.val = 0 - Draw.Redraw() - elif evt == 11: - RBmesh0.val = 0 - RBmesh1.val = 1 - RBmesh2.val = 0 - Draw.Redraw() - elif evt == 12: - RBmesh0.val = 0 - RBmesh1.val = 0 - RBmesh2.val = 1 - Draw.Redraw() - -Draw.Register(draw, event, bevent) diff --git a/release/scripts/uvpaint.py b/release/scripts/uvpaint.py deleted file mode 100644 index ac8c8062ceb..00000000000 --- a/release/scripts/uvpaint.py +++ /dev/null @@ -1,690 +0,0 @@ -#!BPY - -""" Registration info for Blender menus: <- these words are ignored -Name: 'UVpainter' -Blender: 232 -Group: 'UV' -Tip: 'Use vertex paint color value to fill uvmapping' -""" - -__author__ = "Jean-Michel Soler (jms)" -__url__ = ("blender", "elysiun", -"Script's homepage, http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_uvpainting.htm", -"Communicate problems and errors, http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender") -__version__ = "0.8 08/2005" - -__bpydoc__ = """\ -This script "paints" uv-mappings with the model's vertex colors. - -Usage: - -With this script you can export uv-maps filled with vertex colors to TARGA -(.tga) images. To use it the mesh must have proper uv coordinates assigned -in UV Face Select Mode. And to fill the projected faces with color, the mesh -can also have material(s) and vertex colors painted on it. - -The script has a GUI with a preview of the results and options like drawing -lines or not, defining size, etc. You can paint vertex colors in the mesh and -see the uv-map updated in the script's window. - -Notes:<br> - Material's rgb color is also used to fill the uv-map;<br> - If there are no vertex colors or texture faces in the mesh and you press -the "Make" VColors button in the edit mesh buttons win, the current light setup -is saved as vertex colors for the model;<br> - Check the script's homepage for example images. - -Short keys Documentation - -KEYS -M : dipslay GUI Menu -D : Set/Unset Documentation -S : Save current window content - in a tga file -Q or ESC : Exit -T : Set/Unset Transparency -L : Set/Unset lines -E : Set/Unset outline -B : Set lines color to Black -W : Set lines color to white -ARROW : displace model on - UP/DOWN/LEFT/RIGHT side -PADPLUS : increase ZOOM -PADMINUS : decrease ZOOM -HOME : cancel display modifs - -Mouse button -RIGHTMOUSE : same as arrows - -""" - -# $Id$ -# -#---------------------------------------------- -# uvpainter script (c) 04/2004 jean-michel soler -# http://jmsoler.free.fr/util/blenderfile/py/UVpaint05.zip -# this script is released under GPL licence -# for the Blender 2.33 scripts distribution -#---------------------------------------------- -# Official page : -# http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_uvpainting.htm -# Communicate problems and errors on: -# http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender -#---------------------------------------------- -# Page officielle : -# http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_uvpainting.htm -# Communiquer les problemes et erreurs sur: -# http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender -#--------------------------------------------- -# ce script est proposé sous licence GPL pour etre associe -# a la distribution de Blender 2.33 et suivant -# -------------------------------------------------------------------------- -# this script is released under GPL licence -# for the Blender 2.33 scripts package -# -------------------------------------------------------------------------- -# ***** BEGIN GPL LICENSE BLOCK ***** -# -# Script copyright (C) 2003, 2004: Jean-Michel Soler -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# ***** END GPL LICENCE BLOCK ***** -# -------------------------------------------------------------------------- - -import Blender -from Blender.Draw import * -from Blender.BGL import * -from Blender.NMesh import * - -try: - import nt - os=nt -except: - import posix - os=posix - -def exist(path): - try: - pth=os.stat(Blender.sys.dirname(path)) - except: - return 0 - return 1 - -loc0= Blender.Get ("filename").replace('\\','/') -loc0=loc0[:loc0.rfind('/')] - -loc2=loc0+'/'+'test00.tga' - - -mouse_x,mouse_y=0,0 -mouse_xr=1 -mouse_yr=1 -POS=[0,0] -ANC=[0,0] -XY=[0,0] -size=[] -sel=0 -X,Y=0,0 -TRANSP,EMPTY,DOCU=0,0,0 -MENU, SAVE =1,0 - -glCr=glRasterPos2d -glCl3=glColor3f -glCl4=glColor4f -glRct=glRectf - -LC=1.0 - -xlimit=0 -selmatlist=[] -LIM=[0.0,0.0,0.0,0.0] -NOLIM=1 -if not NOLIM : LIM=[-1.0,1.0,-1.0,1.0] - -TR=0.8 - -def Doc(size): - S0,S1=40,50 - - a=[S0,size[3]-S1, .8,.8,.8] - b=[S0*7,size[3]-S1, .8,0.8,0.8] - c=[S0*7,size[3]-S1*7, 0.8,0.8,0.8] - d=[S0,size[3]-S1*7, 0.8,0.8,0.8] - Tcarre(a,b,c,d,0.8) - Lcarre(a,b,c,d,0.0) - DOC=[' ', -'Documentation', -' ', -'KEYS ', -'M : dipslay GUI Menu', -'D : Set/Unset Documentation', -'S : Save current window content', -' in a tga file', -'Q or ESC : Exit', -'T : Set/Unset Transparency', -'L : Set/Unset lines', -'E : Set/Unset outline', -'B : Set lines color to Black ', -'W : Set lines color to white', -'ARROW : displace model on ', -' UP/DOWN/LEFT/RIGHT side' , -'PADPLUS : increase ZOOM ', -'PADMINUS : decrease ZOOM ', -'HOME : cancel display modifs', -' ', -'Mouse button', -'RIGHTMOUSE : same as arrows', -] - glColor3f(0.0,0.0,0.0) - for D in DOC : - glRasterPos2f(S0+8, size[3]-S1-13*DOC.index(D)) - Text(D) - -def Ttriangle(a,b,c): - glBegin(GL_TRIANGLES); - glColor4f(a[2],a[3],a[4],TR) - glVertex2f(a[0],a[1]); - glColor4f(b[2],b[3],b[4],TR) - glVertex2f(b[0],b[1]); - glColor4f(c[2],c[3],c[4],TR) - glVertex2f(c[0],c[1]); - glEnd(); - -def Ftriangle(a,b,c): - glBegin(GL_TRIANGLES); - glColor3f(a[2],a[3],a[4]) - glVertex2f(a[0],a[1]); - glColor3f(b[2],b[3],b[4]) - glVertex2f(b[0],b[1]); - glColor3f(c[2],c[3],c[4]) - glVertex2f(c[0],c[1]); - glEnd(); - -def Ltriangle(a,b,c,LC=0.5): - TL=[a,b,c,a] - for v in [0,1,2] : - glBegin(GL_LINES); - glColor4f(LC,LC,LC,TR+0.2) - glVertex2f(TL[v][0],TL[v][1]); - glVertex2f(TL[v+1][0],TL[v+1][1]); - glEnd(); - - -def Tcarre(a,b,c,d,LC=1.0): - Ttriangle(a,b,c) - Ttriangle(a,c,d) - -def Fcarre(a,b,c,d,LC=1.0): - Ftriangle(a,b,c) - Ftriangle(a,c,d) - -def Lcarre(a,b,c,d,LC=0.5): - TL=[a,b,c,d,a] - for v in [0,1,2,3] : - glBegin(GL_LINES); - glColor4f(LC,LC,LC,TR+0.2) - glVertex2f(TL[v][0],TL[v][1]); - glVertex2f(TL[v+1][0],TL[v+1][1]); - glEnd(); - - -def transface(f,x,y,u=0.0, v=0.0): - global xlimit, LIM - global mouse_xr,sel, ANC, X,Y - global mouse_yr, POS, XY,size - global mouse_x, mouse_y - - mouse_x=mouse_xr-size[0] - mouse_y=mouse_yr-size[1] - - if sel==1: - POS=[mouse_x-ANC[0],mouse_y-ANC[1]] - u,v=POS - - a=[0,0,0.0, 0.0,0.0,0.0] - b=[0,0,0.0, 0.0,0.0,0.0] - c=[0,0,0.0, 0.0,0.0,0.0] - d=[0,0,0.0, 0.0,0.0,0.0] - - if len(f.v)>=3: - a[0]=int((f.uv[0][0]-LIM[1])*x+u) - a[1]=int((f.uv[0][1]-LIM[3])*y+v) - - if a[0]>xlimit: - xlimit=a[0] - - if f.col : - a[2]=f.col[0].r/255.0 - a[3]=f.col[0].g/255.0 - a[4]=f.col[0].b/255.0 - - else : - a[2],a[3],a[4]=1.0,1.0,1.0 - - c[0]=int((f.uv[2][0]-LIM[1])*x+u) - c[1]=int((f.uv[2][1]-LIM[3])*y+v) - - if c[0]>xlimit: - xlimit=c[0] - - if f.col : - c[2]=f.col[2].r/255.0 - c[3]=f.col[2].g/255.0 - c[4]=f.col[2].b/255.0 - else : - c[2],c[3],c[4]=1.0,1.0,1.0 - - b[0]=int((f.uv[1][0]-LIM[1])*x+u) - b[1]=int((f.uv[1][1]-LIM[3])*y+v) - - if b[0]>xlimit: - xlimit=b[0] - - if f.col : - b[2]=f.col[1].r/255.0 - b[3]=f.col[1].g/255.0 - b[4]=f.col[1].b/255.0 - else : - b[2],b[3],b[4]=1.0,1.0,1.0 - - if len(f.v)==4: - d[0]=int((f.uv[3][0]-LIM[1])*x+u) - d[1]=int((f.uv[3][1]-LIM[3])*y+v) - - if d[0]>xlimit: - xlimit=d[0] - if f.col : - d[2]=f.col[3].r/255.0 - d[3]=f.col[3].g/255.0 - d[4]=f.col[3].b/255.0 - else : - d[2],d[3],d[4]=1.0,1.0,1.0 - else: - d=0 - - #print a,b,c - return a,b,c,d - - -def extract_faces(me,MENU): - global TMATList, selmatlist - if MENU==2: - listf=[] - for f in me.faces: - if f.mat in selmatlist: - listf.append(f) - return listf - -def affiche_mesh(ME,x,y): - global LINE,xlimit,MMENU,XLIMIT,xwin,xlimit,LC - global LIM, EMPTY,TRANSP - if not NOLIM : LIM=[-1.0,1.0,-1.0,1.0] - - if ME.getType()=='Mesh' and ME.getData().hasFaceUV(): - me=ME.getData() - if MMENU.val==1: - se=me.faces - elif MMENU.val==3: - se=[s for s in me.faces if s in me.getSelectedFaces() or s.sel] - elif MMENU.val==2: - se=extract_faces(me,2) - if not NOLIM : - for s in se: - for u in s.uv: - if u[0] >LIM[0] : LIM[0]=u[0] - if u[0] <LIM[1] : LIM[1]=u[0] - if u[1] >LIM[2] : LIM[2]=u[1] - if u[1] <LIM[3] : LIM[3]=u[1] - xlimit=0 - for f in se: - a,b,c,d=transface(f,x,y) - if not EMPTY and not TRANSP: - if len(f.v)==4: - Ftriangle(a,b,c) - Ftriangle(a,c,d) - elif len(f.v)==3: - Ftriangle(a,b,c) - elif not EMPTY : - if len(f.v)==4: - Ttriangle(a,b,c) - Ttriangle(a,c,d) - elif len(f.v)==3: - Ttriangle(a,b,c) - - if LINE.val==1 or EMPTY: - for f in se: - a,b,c,d=transface(f,x,y) - if len(f.v)==4: - Lcarre(a,b,c,d,LC) - elif len(f.v)==3: - Ltriangle(a,b,c,LC) - if XLIMIT.val==0: - Lcarre([1,1],[1,y-2],[xlimit+2,y-2],[xlimit+2,1]) - else: - Lcarre([1,1],[1,y-2],[xwin-2,y-2],[xwin-2,1]) - - -def write_tgafile(loc2,bitmap,width,height,profondeur): - - f=open(loc2,'wb') - Origine_en_haut_a_gauche=32 - Origine_en_bas_a_gauche=0 - Data_Type_2=2 - RVB=profondeur*8 - RVBA=32 - entete0=[] - for t in range(18): - entete0.append(chr(0)) - - entete0[2]=chr(Data_Type_2) - entete0[13]=chr(width/256) - entete0[12]=chr(width % 256) - entete0[15]=chr(height/256) - entete0[14]=chr(height % 256) - entete0[16]=chr(RVB) - entete0[17]=chr(Origine_en_bas_a_gauche) - - #Origine_en_haut_a_gauche - - for t in entete0: - f.write(t) - - for t in bitmap: - - for c in [2,1,0,3]: - #print t[c]%256 - f.write(chr(t[c]*2)) - f.close() - - -def save(x0,y0,dx,dy): - global SAVE - im = Buffer(GL_BYTE,[dx*(dy+1),4]) - glReadPixels(x0,y0,dx,dy,GL_RGBA, GL_BYTE,im); - print len(im), dx*dy, dx, dy, len(im)/dy - write_tgafile(loc2,im,dx,dy+1,4) - SAVE=0 - Blender.Redraw() - -def DOCMat_list(TMATList,ME): - me=Blender.NMesh.GetRaw(ME.getData(name_only=1)) - if len(me.materials)!=0: - n=0 - for mat in me.materials: - TMATList[1][n][0]=mat.R - TMATList[1][n][1]=mat.G - TMATList[1][n][2]=mat.B - n+=1 - TMATList[0]=n - else: - TMATList[0]=0 - return TMATList - -def SELMat_list(): - global TMATList,selmatlist - Me=Blender.Object.GetSelected() - if Me!=[]: - if Me[0].getType()=='Mesh': - TMATList=DOCMat_list(TMATList,Me[0]) - selmatlist=[] - for TMat in TMATList[2]: - if TMat.val==1.0: - selmatlist.append(TMATList[2].index(TMat)) - ERROR=0 - else: - ERROR=1 - TextERROR='Selected Object is not a mesh.' - else: - ERROR=1 - TextERROR='No Selected Object.' - -def DOCBONEMENU(TBONEMENU): - pass - -# ---------- -# uvpaint1 -# ---------- -NSIZE=Create(1.0) -# ---------- -# uvpaint2 -# ---------- -LINE=Create(0) -# ---------- -# uvpaint3 -# ---------- -TEXT=Create(loc2) -# ---------- -# uvpaint4 -# ---------- -TMENU="MODE MENU %t|All %x1|Material %x2|Selected %x3" -# ---------- -# uvpaint4 -# ---------- -# coming soon : "|vertex group %x4", perhaps in uvpainter v0.5 -LCOLOR= Create(64) -SAVE=0 - -MMENU=Create(3) -TDOCMat = Create(0) -# ---------- -TMATList= [0,[],[]] -for t in range(16): - TMATList[1].append([0.0,0.0,0.0]) - TMATList[2].append(Create(0)) -# ---------- -TDOCMat = Create(1) -# ---------- -TBONEMENU= Create(1) -# ---------- - -XLIMIT=Create(0) - -y=0 -x=0 -x0=0 -y0=0 -xwin=0 - -n0=32 - -def draw(): - global NSIZE,LINE,x0,y0,y,x,TEXT,MMENU,TDOCMat - global XLIMIT,selmatlist,xwin, LCOLOR, SAVE - global mouse_xr,sel, ANC, X,Y, TRANSP, DOCU - global mouse_yr, POS, XY,size, TRANSP,EMPTY - global MENU, SAVE - - size=Buffer(GL_FLOAT, 4) - glGetFloatv(GL_SCISSOR_BOX, size) - size=[int(s) for s in size ] - - n0=32 - x0=size[0] - y0=size[1] - - x=size[2] - y=size[3] - - xwin=x - ywin=y - - - glClear(GL_COLOR_BUFFER_BIT) - glShadeModel(GL_SMOOTH) - #transparence - if TRANSP : - glEnable(GL_BLEND) - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) - - SelecMESH=Blender.Object.GetSelected() - if SelecMESH!=[] and SelecMESH[0].getType()=='Mesh': - affiche_mesh(SelecMESH[0],int(y*NSIZE.val),int(y*NSIZE.val-2)) - - if MENU: - glColor3f(0.0,0.0,0.0) - glRectf(4,size[3],555,size[3]-32 ) - glColor3f(1.0,1.0,1.0) - - glRasterPos2f(8, size[3]-13) - Text("uvpainter v0.8") - - glRasterPos2f(8, size[3]-28) - Text("Jm Soler, 08/2005") - - Button("ReDraw" ,16 ,290-118+61 ,size[3]-30 ,60 ,13) - Button("Exit" ,1 ,250-122+63 ,size[3]-30 ,38 ,13) - Button("Save" ,6 ,250-16+61 ,size[3]-30 ,40 ,13) - - NSIZE= Slider("Sc:",4 ,290-118+61 ,size[3]-15 , 102, 13, NSIZE.val, 0.1,5.0,0,"SIZE.") - LINE=Toggle("line", 5 ,250-122+63 ,size[3]-15 , 38, 13, LINE.val, "Draw lines") - - glRasterPos2f(250-130 ,size[3]-13,) - Text("Mode") - - LCOLOR=Number("", 50, 250-77,size[3]-15,18,13,LCOLOR.val,1,64,'Line color, 64-lighter, 1-darker.') - - MMENU= Menu(TMENU ,2 ,250-130, size[3]-30, 63, 13, MMENU.val, "MODE menu.") - - if MMENU.val==1 or MMENU.val==3: - glRasterPos2f( 250-16+61+42+80,size[3]-13) - if XLIMIT.val: - xl=xwin - else: - xl=xlimit - - Text("x :"+"%d"%(xl+2)) - - glRasterPos2f(250-16+61+42+65*2,size[3]-13) - Text("y :"+"%d"%(y-n0+1)) - - TEXT=String("to:", 7 , 278+61 ,size[3]-28 , 213, 13, TEXT.val, 256, "Draw lines") - if XLIMIT.val==1: - limit='winlimit' - else: - limit='maxXlimit' - XLIMIT=Toggle(limit, 9 , 250-16+61+42 ,size[3]-15 , 60, 13, XLIMIT.val, "to save picture from x max uv limit, or x window max limit") - - if MMENU.val==2: - TDOCMat=Toggle("doc" ,24,250-130+35 ,size[3]-13 , 28, 13, TDOCMat.val) - if TDOCMat.val==1: - SELMat_list() - for t in range(TMATList[0]): - glCl3(TMATList[1][t][0], - TMATList[1][t][1], - TMATList[1][t][2]) - glRct((293-16+61)+t*20, - size[3]-13, - (293-16+61)+t*20+20, - size[3]-30,) - TMATList[2][t]=Toggle("%s"%t , 32+t ,(293-16+61)+t*20 ,size[3]-13 ,20 , 13,TMATList[2][t].val) - - #else: - # save() - - if DOCU: - Doc(size) - -def event(evt, val): - global mouse_x, x, mouse_y, y, LC - global LCOLOR, DOCU, MENU, SAVE - global mouse_xr,sel, ANC, X,Y ,NSIZE - global mouse_yr, POS, XY,size, TRANSP,EMPTY - - if (evt== QKEY or evt== ESCKEY and not val): - Exit() - elif (evt== TKEY and not val): - TRANSP=abs(TRANSP-1) - elif (evt== EKEY and not val): - EMPTY=abs(EMPTY-1) - elif (evt== MKEY and not val): - MENU=abs(MENU-1) - elif (evt== SKEY and not val): - SAVE=abs(MENU-1) - elif (evt== WKEY and not val): - LC=1.0 - LCOLOR.val=64 - elif (evt== BKEY and not val): - LC=0.0 - LCOLOR.val=1 - elif (evt==LEFTARROWKEY and not val) : - POS[0]-=10 - elif (evt==RIGHTARROWKEY and not val) : - POS[0]+=10 - elif (evt==UPARROWKEY and not val) : - POS[1]+=10 - elif (evt==DOWNARROWKEY and not val) : - POS[1]-=10 - elif (evt==PADMINUS and not val) : - NSIZE.val-=0.1 - elif (evt==PADPLUSKEY and not val) : - NSIZE.val+=0.1 - elif (evt==LKEY and not val) : - LINE.val=abs(LINE.val-1) - elif (evt==HOMEKEY and not val) : - NSIZE.val=1.0 - POS=[0,0] - elif (evt==DKEY and not val) : - DOCU=abs(DOCU-1) - elif (evt == MOUSEX): mouse_xr = val - elif (evt == MOUSEY): mouse_yr = val - - elif (evt == RIGHTMOUSE and val): - if (sel==0 ) : - ANC=[(mouse_xr-size[0])-POS[0],(mouse_yr-size[1])-POS[1]] - sel=1 - elif (evt == RIGHTMOUSE and not val): - sel=0 - ANC=0,0 - Redraw(1) - - -def bevent(evt): - global LINE,NSIZE,n0,x0,y0,y,TEXT, loc2 - global TMATList, selmatlist, TDOCMat,XLIMIT - global xlimit,LCOLOR,LC,SAVE - - if (evt== 1): - Exit() - - elif (evt== 16): - pass - - elif (evt== 4): - ng=NSIZE.val - - elif (evt== 6): - if XLIMIT.val==1: - xi=xwin - save(x0,y0,xi+2,int(y-n0)) - else: - xi=xlimit - save(x0,y0,xi+2,int(y*NSIZE.val)-n0) - - elif (evt== 7): - if exist(TEXT.val): - loc2=TEXT.val - else: - TEXT.val=loc2 - - elif (evt== 24) or (evt in [32,33,34,35,36,37,38,39,40,41,42,43,44]): - SELMat_list() - - elif (evt== 50): - LC=float(LCOLOR.val)/64.0 - - - Blender.Redraw() - -Register(draw, event, bevent)
\ No newline at end of file |