#!BPY """ Registration info for Blender menus: Name: 'RVK manager' Blender: 236 Group: 'Animation' Tip: '' -------------------------------------------------------------------------- # ***** BEGIN GPL LICENSE BLOCK ***** # # Copyright (C) 2005: Carlos López Yrigaray (aka Klopes) and Imathon Limited, http://www.imathon.com # # 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. # # 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 ***** # -------------------------------------------------------------------------- # Official Site: # http://www.imathon.com/?q=RVK_Manager_script # -------------------------- Script written in Python language version 2.3, interpreted by Blender version 2.36 The script transfers up to 64 relative vertex keys (rvk) from an active  Blender Object in a given .blend file to another alien Object imported into the .blend file. The alien Object has to have the same number of geometric vertices as the active one. The alien Object keeps the uvmapping after importing the rvks from the active Object. The script can also link different Meshes into a single Object. The former become all linked to the original single Mesh as rvks. Each rvk may be a mesh or texture relative morph of the object. The rvks can also be deleted. The script also imports the exposure sheet of an animation program in an xml format by assigning an IPO to each rvk with the same animation keyframes and interpolation curves. The layout of the script is a window in the Blender GUI with buttons for each of the actions described above. """ import Blender from Blender import NMesh,BGL from Blender.Draw import * separ=Create(".") Buf=Create(1) maxframes=Create(64) def makeTempIPO(): ipo=Blender.Ipo.New('Key','$$$') for key in range(63): c=ipo.addCurve("Key "+str(key+1)) c.addBezier((key+.5,0)) c.addBezier((key+1,1)) c.addBezier((key+1.5,0)) print dir(ipo) PupMenu("%tOk|temp IPO created (name: "+ipo.getName()+"\")") def readfile(fname): f=open(fname) XML2blend(f.readlines()) def XML2blend(texto): if not texto[0].count('xml'): PupMenu("%tERROR|%xBuffer hasn't .XML format") return f=iter(texto) i=0 lin='' iponames=[] while '' not in lin: lin=f.next() if lin.count('' not in lin: lin=f.next() if '' in lin: x=float(lin[lin.index('')+3:lin.index('')]) lin=f.next() y=float(lin[lin.index('')+3:lin.index('')]) curva.addBezier((x,y)) iponames2="" for i in iponames: iponames2+="|"+i PupMenu("%tOk, mesh IPOs created:"+iponames2) def rectang(x,y,l,h,r,g,b): BGL.glColor3f(r,g,b) BGL.glBegin(BGL.GL_POLYGON) BGL.glVertex2i(x, y) BGL.glVertex2i(l, y) BGL.glVertex2i(l, h) BGL.glVertex2i(x, h) BGL.glEnd() def TexBuf(): menuText,i='',0 for t in Blender.Text.Get(): i+=1 menuText+='|'+t.name+'%x'+str(i) return menuText def draw(): global separ,Buf,maxframes long=200 BGL.glClearColor(0.5, 0.5, 0.6, 1) BGL.glColor3f(1.,1.,1.) BGL.glClear(BGL.GL_COLOR_BUFFER_BIT) rectang(0,0,long*2,200,0.,0.5,0.7) rectang(0,100,long,200,0.7,0.7,0.5) rectang(long,100,long*2,200,0.7,0.6,0.3) rectang(0,200,long*2,250,0.3,0.6,0.5) BGL.glColor3f(0,0,0) BGL.glRasterPos2i(int(long*.05), 235) Text("RVK manager","normal") BGL.glRasterPos2i(int(long*.05), 220) Text("by Klopes, for Ruben Martinez","tiny") BGL.glRasterPos2i(int(long*.05), 210) Text("Copyright 2005 - Carlos Lopez Yrigaray","tiny") Button("Remove all RVKs", 6, int(long*1.1), 210, int(long*0.8), 28,"Remove RVKs (blue lines) on selected object") Button("Object RVK copy", 1, int(long*0.1), 150, int(long*0.8), 28,"Create RVKs as they are in other mesh (copies diferences)") maxframes=Number("Max. RVKs:",98,int(long*0.1),120,int(long*0.6),18,maxframes.val,1,64,"Max. number of RVKs to consider") Button("Object Sequence", 2, int(long*1.1), 150, int(long*0.8), 28,"Create RVKs on active object, from the selected ones") BGL.glColor3f(1.,1.,1.) BGL.glRasterPos2i(int(long*1.1), 115) Text("Name Separator") separ=String("",98,int(long*1.7),110,int(long*0.2),18,separ.val,4,"Character(s) before the sequence numbers") Button("Import XML", 3, int(long*0.1), 50, int(long*0.8), 28,"Read .XML file pasted from Magpie") Button("Read XML Blender buffer", 4, int(long*1.1), 50, int(long*.8), 28,"Read .XML buffer pasted from Magpie") Buf=Menu("Select buffer%t"+TexBuf(),98,int(long*1.1),30,int(long*.8),18,Buf.val) Button("Exit (Q)",99,10,7,50,22,"Exits script. Key: Q") def getRVKsFromSelec(os): if not os: PupMenu("%tPlease|%xSelect OBJECT sequence, then the TARGET one (active)") return else: act=os[0] m0=act.getData() try: for i in range(maxframes.val): o=filter(lambda x:i+1==int(x.name.split(separ.val)[-1]), os[1:]) l=len(o) if l>1: men=str(l)+" objects has the suffix: <"+str(i)+">" PupMenu("%tERROR|%x"+men) return elif l==0: men="Process finished at Key "+str(i) PupMenu("%tOk|%x"+men) return else: m=Blender.NMesh.GetRawFromObject(o[0].name) for v0 in m0.verts: j= m0.verts.index(v0) v1=m.verts[j] for c in range(3): v0.co[c]=v1.co[c] m0.update() m0.insertKey(i+1,'relative') m0.update() act.makeDisplayList() print "RVK from %s added to %s "%(o[0].name,act.name) except ValueError: PupMenu("%tERROR|%xSelection contains objects with no sequence suffix") return def CopyRVKs(os): if len(os)!=2: a=PupMenu("%tPlease, select only 2 objects|First RVKs source object, then the TARGET one (active)") return a=PupMenu("%tREMEMBER|First RVKs source object, then the TARGET one (active)|%l|Remember to link manually IPO named \"$$$\" to the source one|Press HERE to create the temp IPO|Press HERE to proceed") if a==4: makeTempIPO() elif a==5: for i in range(maxframes.val): Blender.Set('curframe',i) m=Blender.NMesh.GetRawFromObject(os[1].name) m0=os[0].getData() if i==0: m1base=m m0base=m0 Blender.Redraw() Blender.Window.drawProgressBar(i/64.,"Key "+str(i)) for v0 in m0.verts: j= m0.verts.index(v0) v1=m.verts[j] v0base=m0base.verts[j] v1base=m1base.verts[j] for c in range(3): v0.co[c]=v0base.co[c] + v1.co[c] - v1base.co[c] m0.update() m0.insertKey(i+1,'relative') m0.update() os[0].makeDisplayList() print "RVK added created for %s as they're in %s "%(os[0].name,os[1].name) else: a=PupMenu("%xTask Canceled") def event(evt,val): if evt==QKEY: Exit() return def bevent(evt): os= Blender.Object.GetSelected() if evt==1: CopyRVKs(os) if evt==2: getRVKsFromSelec(os) if evt==3: Blender.Window.FileSelector(readfile, "Import Magpie .XML") if evt==4: texto=Blender.Text.Get()[Buf.val-1].asLines() XML2blend(texto) if evt==6: for o in os: o.getData().removeAllKeys() if evt==99: Exit() Blender.Redraw() Register(draw,event,bevent)