2010-09-01 02:48:23 +00:00
|
|
|
# ##### BEGIN GPL LICENSE BLOCK #####
|
2010-02-24 11:03:22 +00:00
|
|
|
#
|
2010-09-01 02:48:23 +00:00
|
|
|
# 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.
|
2010-02-24 11:03:22 +00:00
|
|
|
#
|
2010-09-01 02:48:23 +00:00
|
|
|
# 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.
|
2010-02-24 11:03:22 +00:00
|
|
|
#
|
2010-09-01 02:48:23 +00:00
|
|
|
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-02-24 11:03:22 +00:00
|
|
|
#
|
2010-09-01 02:48:23 +00:00
|
|
|
# ##### END GPL LICENSE BLOCK #####
|
2010-02-24 11:03:22 +00:00
|
|
|
|
|
|
|
# <pep8 compliant>
|
|
|
|
|
|
|
|
# mdd importer by Bill L.Nieuwendorp
|
|
|
|
# conversion to blender 2.5: Ivo Grigull (loolarge)
|
|
|
|
#
|
|
|
|
# Warning if the vertex order or vertex count differs from the
|
|
|
|
# origonal model the mdd was Baked out from their will be Strange
|
|
|
|
# behavior
|
|
|
|
#
|
2010-03-06 01:40:29 +00:00
|
|
|
# vertex animation to ShapeKeys with ipo and gives the frame a value of 1.0
|
2010-02-24 11:03:22 +00:00
|
|
|
# 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
|
|
|
|
|
|
|
|
import bpy
|
|
|
|
from struct import unpack
|
|
|
|
|
|
|
|
|
2010-09-01 12:11:34 +00:00
|
|
|
def load(operator, context, filepath, frame_start=0, frame_step=1):
|
|
|
|
|
|
|
|
scene = context.scene
|
|
|
|
obj = context.object
|
|
|
|
|
|
|
|
print('\n\nimporting mdd %r' % filepath)
|
2010-03-06 01:40:29 +00:00
|
|
|
|
2010-09-01 12:11:34 +00:00
|
|
|
if bpy.ops.object.mode_set.poll():
|
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
2010-02-24 11:03:22 +00:00
|
|
|
|
|
|
|
file = open(filepath, 'rb')
|
|
|
|
frames, points = unpack(">2i", file.read(8))
|
|
|
|
time = unpack((">%df" % frames), file.read(frames * 4))
|
2010-03-06 01:40:29 +00:00
|
|
|
|
2010-04-04 14:52:15 +00:00
|
|
|
print('\tpoints:%d frames:%d' % (points, frames))
|
2010-02-24 11:03:22 +00:00
|
|
|
|
|
|
|
# If target object doesn't have Basis shape key, create it.
|
|
|
|
try:
|
2010-09-01 12:11:34 +00:00
|
|
|
num_keys = len(obj.data.shape_keys.keys)
|
2010-02-24 11:03:22 +00:00
|
|
|
except:
|
2010-09-01 12:11:34 +00:00
|
|
|
basis = obj.add_shape_key()
|
2010-02-24 11:03:22 +00:00
|
|
|
basis.name = "Basis"
|
2010-09-01 12:11:34 +00:00
|
|
|
obj.data.update()
|
2010-02-24 11:03:22 +00:00
|
|
|
|
2010-09-01 12:11:34 +00:00
|
|
|
scene.frame_current = frame_start
|
2010-02-24 11:03:22 +00:00
|
|
|
|
|
|
|
def UpdateMesh(ob, fr):
|
2010-03-06 01:40:29 +00:00
|
|
|
|
2010-02-24 11:03:22 +00:00
|
|
|
# Insert new shape key
|
2010-09-01 12:11:34 +00:00
|
|
|
new_shapekey = obj.add_shape_key()
|
2010-02-24 11:03:22 +00:00
|
|
|
new_shapekey.name = ("frame_%.4d" % fr)
|
|
|
|
new_shapekey_name = new_shapekey.name
|
2010-03-06 01:40:29 +00:00
|
|
|
|
2010-09-01 12:11:34 +00:00
|
|
|
obj.active_shape_key_index = len(obj.data.shape_keys.keys)-1
|
|
|
|
index = len(obj.data.shape_keys.keys)-1
|
2010-10-27 22:15:55 +00:00
|
|
|
obj.show_only_shape_key = True
|
2010-03-06 01:40:29 +00:00
|
|
|
|
2010-09-01 12:11:34 +00:00
|
|
|
verts = obj.data.shape_keys.keys[len(obj.data.shape_keys.keys)-1].data
|
2010-03-06 01:40:29 +00:00
|
|
|
|
2010-02-24 11:03:22 +00:00
|
|
|
|
2010-04-04 14:52:15 +00:00
|
|
|
for v in verts: # 12 is the size of 3 floats
|
|
|
|
v.co[:] = unpack('>3f', file.read(12))
|
2010-02-24 11:03:22 +00:00
|
|
|
#me.update()
|
2010-10-27 22:15:55 +00:00
|
|
|
obj.show_only_shape_key = False
|
2010-03-06 01:40:29 +00:00
|
|
|
|
2010-02-24 11:03:22 +00:00
|
|
|
|
|
|
|
# insert keyframes
|
2010-09-01 12:11:34 +00:00
|
|
|
shape_keys = obj.data.shape_keys
|
2010-02-24 11:03:22 +00:00
|
|
|
|
2010-04-01 21:44:56 +00:00
|
|
|
scene.frame_current -= 1
|
2010-09-01 12:11:34 +00:00
|
|
|
obj.data.shape_keys.keys[index].value = 0.0
|
|
|
|
shape_keys.keys[len(obj.data.shape_keys.keys)-1].keyframe_insert("value")
|
2010-02-24 11:03:22 +00:00
|
|
|
|
2010-04-01 21:44:56 +00:00
|
|
|
scene.frame_current += 1
|
2010-09-01 12:11:34 +00:00
|
|
|
obj.data.shape_keys.keys[index].value = 1.0
|
|
|
|
shape_keys.keys[len(obj.data.shape_keys.keys)-1].keyframe_insert("value")
|
2010-02-24 11:03:22 +00:00
|
|
|
|
2010-04-01 21:44:56 +00:00
|
|
|
scene.frame_current += 1
|
2010-09-01 12:11:34 +00:00
|
|
|
obj.data.shape_keys.keys[index].value = 0.0
|
|
|
|
shape_keys.keys[len(obj.data.shape_keys.keys)-1].keyframe_insert("value")
|
2010-02-24 11:03:22 +00:00
|
|
|
|
2010-09-01 12:11:34 +00:00
|
|
|
obj.data.update()
|
2010-02-24 11:03:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
for i in range(frames):
|
2010-09-01 12:11:34 +00:00
|
|
|
UpdateMesh(obj, i)
|
2010-02-24 11:03:22 +00:00
|
|
|
|
2010-09-01 12:11:34 +00:00
|
|
|
return {'FINISHED'}
|