#!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:
Material's rgb color is also used to fill the uv-map;
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;
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] a[2]=f.col[0].r/255.0 a[3]=f.col[0].g/255.0 a[4]=f.col[0].b/255.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] c[2]=f.col[2].r/255.0 c[3]=f.col[2].g/255.0 c[4]=f.col[2].b/255.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] b[2]=f.col[1].r/255.0 b[3]=f.col[1].g/255.0 b[4]=f.col[1].b/255.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] 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=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': 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[2] : LIM[2]=u[1] if u[1]