1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
#!BPY
"""
Name: 'Load MDD to Mesh RVKs'
Blender: 242
Group: 'Import'
Tooltip: 'baked vertex animation to active mesh object.'
"""
__author__ = "Bill L.Nieuwendorp"
__bpydoc__ = """\
This script Imports Lightwaves MotionDesigner format.
The .mdd format has become quite a popular Pipeline format<br>
for moving animations from package to package.
"""
# mdd importer
#
# Warning if the vertex order or vertex count differs from the
# origonal model the mdd was Baked out from their will be Strange
# behavior
#
#
#vertex animation to ShapeKeys with ipo and gives the frame a value of 1.0
#A modifier to read mdd files would be Ideal but thats for another day :)
#
#Please send any fixes,updates,bugs to Slow67_at_Gmail.com
#Bill Niewuendorp
# ***** 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 *****
try:
from struct import unpack
except:
unpack = None
import Blender
from Blender import Mesh, Object, Scene
import BPyMessages
def mdd_import(filepath, ob, PREF_IPONAME, PREF_START_FRAME, PREF_JUMP):
print '\n\nimporting mdd "%s"' % filepath
Blender.Window.DrawProgressBar (0.0, "Importing mdd ...")
Blender.Window.EditMode(0)
Blender.Window.WaitCursor(1)
file = open(filepath, 'rb')
frames, points = unpack(">2i", file.read(8))
time = unpack((">%df" % frames), file.read(frames * 4))
print '\tpoints:%d frames:%d' % (points,frames)
scn = Scene.GetCurrent()
ctx = scn.getRenderingContext()
Blender.Set("curframe", PREF_START_FRAME)
me = ob.getData(mesh=1)
def UpdateMesh(me,fr):
for v in me.verts:
# 12 is the size of 3 floats
x,y,z= unpack('>3f', file.read(12))
v.co[:] = x,z,y
me.update()
Blender.Window.DrawProgressBar (0.4, "4 Importing mdd ...")
curfr = ctx.currentFrame()
print'\twriting mdd data...'
for i in xrange(frames):
Blender.Set("curframe", i+PREF_START_FRAME)
if len(me.verts) > 1 and (curfr >= PREF_START_FRAME) and (curfr <= PREF_START_FRAME+frames):
UpdateMesh(me, i)
ob.insertShapeKey()
Blender.Window.DrawProgressBar (0.5, "5 Importing mdd ...")
key= me.key
# Add the key of its not there
if not key:
me.insertKey(1, 'relative')
key= me.key
key.ipo = Blender.Ipo.New('Key', PREF_IPONAME)
ipo = key.ipo
# block = key.getBlocks() # not used.
all_keys = ipo.curveConsts
for i in xrange(PREF_JUMP+1, len(all_keys), PREF_JUMP):
curve = ipo.getCurve(i)
if curve == None:
curve = ipo.addCurve(all_keys[i])
curve.append((PREF_START_FRAME+i-1,1))
curve.append((PREF_START_FRAME+i- PREF_JUMP -1,0))
curve.append((PREF_START_FRAME+i+ PREF_JUMP-1,0))
curve.setInterpolation('Linear')
curve.recalc()
print 'done'
Blender.Window.WaitCursor(0)
Blender.Window.DrawProgressBar (1.0, '')
def mdd_import_ui(filepath):
if BPyMessages.Error_NoFile(filepath):
return
scn= Scene.GetCurrent()
ob_act= scn.objects.active
if ob_act == None or ob_act.type != 'Mesh':
BPyMessages.Error_NoMeshActive()
return
PREF_IPONAME = Blender.Draw.Create(filepath.split('/')[-1].split('\\')[-1].split('.')[0])
PREF_START_FRAME = Blender.Draw.Create(1)
PREF_JUMP = Blender.Draw.Create(1)
block = [\
("Ipo Name: ", PREF_IPONAME, 0, 30, "Ipo name for the new shape key"),\
("Start Frame: ", PREF_START_FRAME, 1, 3000, "Start frame for the animation"),\
("Key Skip: ", PREF_JUMP, 1, 100, "KeyReduction, Skip every Nth Frame")\
]
if not Blender.Draw.PupBlock("Import MDD", block):
return
orig_frame = Blender.Get('curframe')
mdd_import(filepath, ob_act, PREF_IPONAME.val, PREF_START_FRAME.val, PREF_JUMP.val)
Blender.Set('curframe', orig_frame)
if __name__ == '__main__':
if not unpack:
Draw.PupMenu('Error%t|This script requires a full python install')
Blender.Window.FileSelector(mdd_import_ui, 'IMPORT MDD', '*.mdd')
|