|
|
|
|
|
|
|
|
""" Registration info for Blender menus
|
|
|
Name: 'Shape Key Transfer'
|
|
|
Blender: 246
|
|
|
Group: 'Animation'
|
|
|
Tooltip: 'Transfer selected point positions inside of the same mesh from shape key to aother shape key'
|
|
|
"""
|
|
|
|
|
|
__author__ = "Nate Nesler"
|
|
|
__url__ = ("http://www.blender.org")
|
|
|
__version__ = "v07-27-2008"
|
|
|
|
|
|
__bpydoc__ = """\
|
|
|
***** 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 *****
|
|
|
--------------------------------------------------------------------------
|
|
|
|
|
|
This script allows you to align selected vertex points of a mesh from one shape to another of the same object.
|
|
|
"""
|
|
|
|
|
|
|
|
|
import Blender
|
|
|
from Blender.Draw import *
|
|
|
from Blender.BGL import *
|
|
|
from Blender.Types import *
|
|
|
from Blender.NMesh import *
|
|
|
from Blender.Mesh import *
|
|
|
from Blender.Window import *
|
|
|
|
|
|
transVert = []
|
|
|
captureVert = []
|
|
|
|
|
|
transStr = "transfer points: empty"
|
|
|
captureStr = "capture points: empty"
|
|
|
|
|
|
selectedMesh = 0
|
|
|
failur = ""
|
|
|
|
|
|
def typeCheck(obj_list):
|
|
|
global failur
|
|
|
ret = 0
|
|
|
if len(obj_list) == 0:
|
|
|
failur = "ERROR: Select a Meshobject first!!"
|
|
|
ret = 1
|
|
|
elif type(obj_list[0].getData()) != NMeshType:
|
|
|
failur = "ERROR: Select a Meshobject first!!"
|
|
|
ret = 1
|
|
|
else: failur = ""
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def captureSelectedVerts(vertList):
|
|
|
ret = 0
|
|
|
try:
|
|
|
|
|
|
outfile = open('./.blender/scripts/captureshapepoints/capture_shape_points.txt', 'w')
|
|
|
for i in range(0, len(vertList)):
|
|
|
if vertList[i].sel == 1:
|
|
|
ret+=1
|
|
|
|
|
|
outfile.write( '%d '%vertList[i].index )
|
|
|
outfile.write( '%f '%vertList[i].co.x )
|
|
|
outfile.write( '%f '%vertList[i].co.y )
|
|
|
outfile.write( '%f \n'%vertList[i].co.z )
|
|
|
outfile.close()
|
|
|
except:
|
|
|
print 'Check your file permissions to make sure you can write files.\n'
|
|
|
else:
|
|
|
if outfile: outfile.close()
|
|
|
print 'done writing'
|
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getSelectedVerts(vertList):
|
|
|
ret = []
|
|
|
for i in range(0, len(vertList)):
|
|
|
if vertList[i].sel == 1:
|
|
|
ret.append(vertList[i])
|
|
|
print "Index: %d \n"%vertList[i].index
|
|
|
print "Selected: %d \n"%vertList[i].sel
|
|
|
|
|
|
for count in [0,1,2]:
|
|
|
print "Coordinate XYZ: [%f] \n"%vertList[i].co[count]
|
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def movePointsTransfer(trans):
|
|
|
capturedPoints=[]
|
|
|
indexCoords=[]
|
|
|
numTemp=""
|
|
|
|
|
|
|
|
|
try:
|
|
|
infile = open('./.blender/scripts/captureshapepoints/capture_shape_points.txt', 'r')
|
|
|
captureFile = infile.readlines()
|
|
|
except:
|
|
|
print 'Error reading file'
|
|
|
else:
|
|
|
infile.close()
|
|
|
print 'done'
|
|
|
|
|
|
for line in captureFile:
|
|
|
indexCoords=[]
|
|
|
countSet=0
|
|
|
print "line = "+line+"\n"
|
|
|
for char in line:
|
|
|
print "char = "+char+"\n"
|
|
|
if char != " ":
|
|
|
numTemp+=char
|
|
|
elif char == " ":
|
|
|
print "Num Temp = "+numTemp+"\n"
|
|
|
countSet+=1
|
|
|
print "Count Set: %d \n"%countSet
|
|
|
if countSet == 1:
|
|
|
indexCoords.append(int(numTemp))
|
|
|
elif countSet > 1:
|
|
|
indexCoords.append(float(numTemp))
|
|
|
|
|
|
numTemp=""
|
|
|
capturedPoints.append(indexCoords)
|
|
|
|
|
|
for count1 in range(0, len(capturedPoints)):
|
|
|
indexCoords=capturedPoints[count1]
|
|
|
print "captured points = %d \n"%indexCoords[0]
|
|
|
for count2 in [1,2,3]:
|
|
|
print "captured points = %f"%indexCoords[count2]
|
|
|
for count2 in range(0, len(trans)):
|
|
|
if indexCoords[0] == trans[count2].index:
|
|
|
print "Index Coords = %d "%indexCoords[0]
|
|
|
print "Trans Index = %d \n"%trans[count2].index
|
|
|
for count3 in [1,2,3]:
|
|
|
print "Before: Index Coords Co = %f "%indexCoords[count3]
|
|
|
print "Before: Trans Co = %f \n"%trans[count2].co[(count3-1)]
|
|
|
trans[count2].co[(count3-1)] = indexCoords[count3]
|
|
|
print "After: Index Coords Co = %f "%indexCoords[count3]
|
|
|
print "After: Trans Co = %f \n"%trans[count2].co[(count3-1)]
|
|
|
count2 = len(trans)
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def BEvent(evt):
|
|
|
global transVert,targetVert,selectedMesh
|
|
|
global failur, captureStr, transStr
|
|
|
print "Event number: %d"%evt
|
|
|
|
|
|
if evt == 8:
|
|
|
editMode = EditMode()
|
|
|
if EditMode(): EditMode(0)
|
|
|
objList = Blender.Object.GetSelected()
|
|
|
if typeCheck(Blender.Object.GetSelected()) == 0:
|
|
|
selectedMesh = objList[0].getData(False, True)
|
|
|
capturePointNum = captureSelectedVerts(selectedMesh.verts)
|
|
|
if capturePointNum > 0:
|
|
|
if capturePointNum == 1:
|
|
|
captureStr = "capture point: ok (vertex: %d)"%capturePointNum
|
|
|
Blender.Redraw()
|
|
|
else:
|
|
|
captureStr = "capture points: ok (vertices: %d)"%capturePointNum
|
|
|
else:
|
|
|
captureStr = "capture points: empty"
|
|
|
if editMode: EditMode(0)
|
|
|
|
|
|
elif evt == 9:
|
|
|
editMode = EditMode()
|
|
|
if EditMode(): EditMode(0)
|
|
|
objList = Blender.Object.GetSelected()
|
|
|
if typeCheck(Blender.Object.GetSelected()) == 0:
|
|
|
selectedMesh = objList[0].getData(False, True)
|
|
|
transVert = getSelectedVerts(selectedMesh.verts)
|
|
|
print "Selected Mesh Verts Transfer Number: %d\n"%len(selectedMesh.verts)
|
|
|
if len(transVert) > 0:
|
|
|
movePointsTransfer(transVert)
|
|
|
else:
|
|
|
failur = "The target point is empty!"
|
|
|
|
|
|
if failur == "Warning: check console":
|
|
|
print "----------------------------------------------------"
|
|
|
if editMode: EditMode(0)
|
|
|
|
|
|
elif evt == 10:
|
|
|
print "----------------------------------------------------"
|
|
|
Exit()
|
|
|
return
|
|
|
|
|
|
Blender.Redraw()
|
|
|
|
|
|
def Event(evt, val):
|
|
|
if evt == QKEY:
|
|
|
Exit()
|
|
|
return
|
|
|
|
|
|
def GUI ():
|
|
|
global captureStr, transStr, failur
|
|
|
|
|
|
glColor3f(0.7, 0.7, 0.7)
|
|
|
glRecti(15, 35, 320, 110)
|
|
|
glColor3f(0.9, 0.9, 0.9)
|
|
|
glRecti(15, 15, 320, 35)
|
|
|
glColor3f(0.65, 0.65, 0.65)
|
|
|
glRecti(15, 110, 320, 130)
|
|
|
glColor3f(0.0, 0.0, 0.0)
|
|
|
glRecti(15, 54, 320, 56)
|
|
|
|
|
|
glRasterPos2f(20,117)
|
|
|
Text("Shape Key Transfer")
|
|
|
|
|
|
btnSelectTarget = Button("Capture Points", 8, 20, 85, 90, 20, "target point of alignment, This is the shape you want the other shape key to become.")
|
|
|
btnTransfer = Button("Transfer", 9, 20, 60, 90, 20, "Transfer points in the shape key that you want to change.")
|
|
|
btnQuit = Button("Quit", 10, 255, 60, 60, 20, "quit the script")
|
|
|
|
|
|
glColor3f(0.15,0.15,0.15)
|
|
|
|
|
|
glRasterPos2f(20,41)
|
|
|
Text(transStr, "small")
|
|
|
|
|
|
glRasterPos2f(170,41)
|
|
|
Text(captureStr, "small")
|
|
|
|
|
|
glRasterPos2f(35,5)
|
|
|
Text("created by Nate Nesler) (v07-27-2008)", "tiny")
|
|
|
glColor3f(1, 0.0, 0.0)
|
|
|
glRasterPos2f(20,20)
|
|
|
Text(failur)
|
|
|
|
|
|
Register(GUI, Event, BEvent)
|
|
|
Blender.Redraw(1) |