Page MenuHome

RVK_Shape_Manager.py

RVK_Shape_Manager.py

This document is not UTF8. It was detected as ISO-8859-1 (Latin 1) and converted to UTF8 for display.
#!BPY
""" Registration info for Blender menus:
Name: '_Shape Manager'
Blender: 248
Group: 'Animation'
Tip: 'Utilities for managing shapes'
"""
__author__ = "Carlos López (klopes)"
__url__ = ("http://wiki.blender.org/index.php/Scripts/Manual/Animation/RVK_Shape_Manager", "Imathon Limited, http://www.imathon.com","Author's web page, http://klopes.tk",
"Script's homepage, http://www.iespana.es/klopes/enchufes-guiri.htm",
"Thread on Blenderartists with links to English and Spanish webpage and pdf docs,\
http://www.elysiun.com/forum/viewtopic.php?t=25736"
"Third Wish Software, http://www.thirdwishsoftware.com/")
__version__ = "1.243"
__bpydoc__ = """\
This script helps you to work with shapes (RVKs) as you would do with other more \
expensive softwares. The proposal of its development was ordered by Ruben Martinez, \
from Imathon Ltd., in order to cover some necessities that Blender didn't directly \
provide. Actually, the program has been revised and updated for running under Blender 2.34 \
and being usable for the new shapes system.
Usage: Run the script from "File->Animation" menu.
Available utilities are:
* Remove All Shapes: Deletes all shapes defined on a selected mesh.
*Shape Transport: Copies relative vertices displacements. Used to transport shapes \
from the mesh of the active object, to every selected meshes.
* Object Sequence: Creates automatically shapes for the active object mesh, from the \
other selected objects with the same number of vertices.
* Read XML code: (either from a file, or copied text to a buffer). Importing utility \
from Third Wish Software's Magpie Pro XML buffer data.
"""
# --------------------------------------------------------------------------
# SHAPE Manager by Carlos López (klopes) for Imathon
# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# Copyright (C) 2007: Carlos López, http://klopes.tk
#
# 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 NMesh,BGL
from Blender.Draw import *
Buf=Create(1)
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")
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)
lin=''
iponames=[]
while '</xsheet>' not in lin:
lin=f.next()
if lin.count('<morphcurve'):
lin=lin.split(' ')
for variab in filter(lambda x:'='in x,lin):
if variab.startswith('actor'):
nombreact = variab.split('"')[1]
print "\nProcessing actor:",nombreact
m=Blender.NMesh.GetRaw(nombreact)
if not m:
PupMenu("%tERROR|%xActor Mesh \""+nombreact+"\" not found")
return
key = m.key
if not key:
m.insertKey()
key = m.key
ipo = key.ipo
if not ipo:
ipo = Blender.Ipo.New('Key',nombreact)
m.key.ipo = ipo
for x in m.key.blocks:
if not ipo.getCurve(x.name):
curva=ipo.addCurve(x.name)
elif variab.startswith('pose'):
nombrepose=variab.split('"')[1]
print "\tProcessing pose:",nombrepose
curva = ipo.getCurve(nombrepose)
lista_bloques = map(lambda x:x.name, m.key.blocks)
print lista_bloques
if nombrepose not in lista_bloques:
PupMenu("ERROR: Actor \""+nombreact+"\" hasn't shapekey \""+nombrepose+"\"")
break
while '</morphcurve>' not in lin:
lin=f.next()
if '<x>' in lin:
x=float(lin[lin.index('<x>')+3:lin.index('</x>')])
lin=f.next()
y=float(lin[lin.index('<y>')+3:lin.index('</y>')])
curva.addBezier((x,y))
iponames.append(nombrepose)
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=160
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,75,0.,0.5,0.7)
rectang(0,75,long,113,0.7,0.7,0.5)
rectang(long,75,long*2,113,0.7,0.6,0.3)
rectang(0,113,long*2,150,0.3,0.6,0.5)
BGL.glColor3f(0,0,0)
BGL.glRasterPos2i(int(long*.05), 140)
Text("RVK manager","normal")
BGL.glRasterPos2i(int(long*.05), 127)
Text("by Klopes, for Ruben Martinez","tiny")
BGL.glRasterPos2i(int(long*.05), 116)
Text("Copyright 2005 - Carlos Lopez Yrigaray","tiny")
Button("Remove all shapes", 6, int(long*1.1), 117, int(long*0.8), 28,"Remove RVKs (blue lines) on selected object")
Button("Shape transport", 1, int(long*0.1), 80, int(long*0.8), 28,"Create RVKs as they are in other mesh (copies diferences)")
Button("Object Sequence", 2, int(long*1.1), 80, 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)
Button("Import XML", 3, int(long*0.1), 40, int(long*0.7), 28,"Read .XML file pasted from Magpie")
Button("Read XML Blender buffer", 4, int(long*.9), 40, int(long), 28,"Read .XML buffer pasted from Magpie")
Buf=Menu("Select buffer%t"+TexBuf(),98,int(long*.9),20,int(long),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:
warn=0
m=os[0].getData()
print "Creating shapes from selected meshes on mesh \"%s\"" % m.name
if not m.key: m.insertKey()
quenom=PupMenu("%tShape names are...|len(shape)Object names|Mesh names")
for o in filter(lambda x:x.type=='Mesh',os[1:]):
sh = o.getData()
print quenom
nombre=[o.name,sh.name][quenom-1]
print "\tShape "+nombre+"...",
nombres = map(lambda x:x.name,m.key.blocks)
if nombre in nombres:
print "WARNING: exists. ",
warn=1
print "Creating...",
shape=sh.verts
Lv=len(shape)
if Lv==len(m.verts):
for j in range(Lv):
Blender.Window.drawProgressBar(j*1./len(shape),nombre)
for c in range(3):
m.verts[j][c]=shape[j][c]
m.update()
m.insertKey()
block=m.key.blocks[-1]
block.name=nombre
m.update()
print "OK"
else:
print "WARNING: Wrong vertex num., ignored"
if warn:
PupMenu("%tWARNING:|Read console")
def CopyRVKs(os):
if len(os)<2:
PupMenu("%tPlease, select at least 2 objects|First TARGET source object(s), then the SOURCE one (active)")
return
m0 = os[0].getData()
for o in filter(lambda x:x.type=='Mesh',os[1:]):
m = o.getData()
warn=0
print "Transporting shapes from mesh \"%s\" on mesh \"%s\"" % (m0.name,m.name)
if not m.key: m.insertKey()
for blk in m0.key.blocks[1:]:
nombre = blk.name
print "\tShape "+nombre+"...",
nombres = map(lambda x:x.name,m.key.blocks)
if nombre in nombres:
print "WARNING: exists.",
warn=1
print "transporting...",
transport(m0.key.blocks[0].data,blk.data, m, blk.name)
if warn:
PupMenu("%tWARNING:|Shape names duplicated, read console")
def transport(m0basis,m0shape, m, nam):
for j in range(len(m0shape)):
Blender.Window.drawProgressBar(j*1./len(m0shape),nam)
l = m0shape[j].co - m0basis[j].co
for c in range(3):
m.verts[j][c] = m.key.blocks[0].data[j][c] + l[c]
m.update()
m.insertKey()
block=m.key.blocks[-1]
block.name=nam
m.update()
print "OK"
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)

File Metadata

Mime Type
text/x-python
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
95/69/554234954f9e43cc6d5fb74b6aac

Event Timeline