2006-04-25 07:25:22 +00:00
|
|
|
#!BPY
|
|
|
|
|
|
|
|
""" Registration info for Blender menus: <- these words are ignored
|
|
|
|
Name: 'Lightwave Motion (.mot)...'
|
|
|
|
Blender: 241
|
|
|
|
Group: 'Export'
|
|
|
|
Tip: 'Export Loc Rot Size chanels to a Lightwave .mot file'
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = "Daniel Salazar (ZanQdo)"
|
2008-04-23 14:04:05 +00:00
|
|
|
__url__ = ("blender", "blenderartists.org",
|
2006-04-25 07:25:22 +00:00
|
|
|
"e-mail: zanqdo@gmail.com")
|
2008-04-16 20:03:59 +00:00
|
|
|
__version__ = "16/04/08"
|
2006-04-25 07:25:22 +00:00
|
|
|
|
|
|
|
__bpydoc__ = """\
|
2008-04-16 20:03:59 +00:00
|
|
|
This script exports the selected object's motion channels to Lightwave
|
|
|
|
motion files (.mot).
|
2006-04-25 07:25:22 +00:00
|
|
|
|
|
|
|
Usage:
|
|
|
|
Run the script with one or more objects selected (any kind), frames exported
|
|
|
|
are between Start and End frames in Render buttons.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
#
|
|
|
|
# Copyright (C) 2003, 2004: A Vanpoucke
|
|
|
|
#
|
|
|
|
# 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 as B
|
2008-04-16 20:03:59 +00:00
|
|
|
import math as M
|
2006-04-25 07:25:22 +00:00
|
|
|
#------------------------------------
|
|
|
|
#Declarados:
|
|
|
|
TotalCanales = 9
|
|
|
|
#------------------------------------
|
|
|
|
|
|
|
|
def FuncionPrincipal (Dir):
|
|
|
|
B.Window.WaitCursor(1)
|
2007-01-27 02:15:14 +00:00
|
|
|
ObjSelect = B.Object.GetSelected()
|
|
|
|
|
|
|
|
if not ObjSelect:
|
|
|
|
B.Draw.PupMenu('Select 1 or more objects, aborting.')
|
|
|
|
return
|
|
|
|
|
|
|
|
if not Dir.lower().endswith('.mot'):
|
|
|
|
Dir += '.mot'
|
|
|
|
|
|
|
|
|
|
|
|
SC = B.Scene.GetCurrent()
|
|
|
|
SCR = SC.getRenderingContext()
|
|
|
|
|
2006-04-27 12:51:09 +00:00
|
|
|
for ob in ObjSelect:
|
|
|
|
origName= NombreObjeto= ob.name
|
2006-04-25 07:25:22 +00:00
|
|
|
print '----\nExporting Object "%s" motion file...' % origName
|
|
|
|
|
|
|
|
FrameA = B.Get('curframe')
|
|
|
|
FrameP = B.Get('staframe')
|
|
|
|
FrameF = B.Get('endframe')
|
|
|
|
|
|
|
|
FrameRate = float(SCR.framesPerSec())
|
|
|
|
|
|
|
|
#---------------------------------------------
|
|
|
|
|
|
|
|
# Replace danger characters by '_'
|
|
|
|
for ch in ' /\\~!@#$%^&*()+=[];\':",./<>?\t\r\n':
|
|
|
|
NombreObjeto = NombreObjeto.replace(ch, '_')
|
|
|
|
|
|
|
|
# Check for file path extension
|
2007-01-27 02:15:14 +00:00
|
|
|
if len(ObjSelect) > 1:
|
2006-04-25 07:25:22 +00:00
|
|
|
DirN= '%s_%s.mot' % (Dir[:-4], NombreObjeto)
|
|
|
|
else:
|
2007-01-27 02:15:14 +00:00
|
|
|
DirN= Dir
|
|
|
|
|
2006-04-25 07:25:22 +00:00
|
|
|
# Open the file
|
|
|
|
File = open(DirN,'w')
|
|
|
|
File.write ('LWMO\n3\n\n') # 3 is the version number.
|
|
|
|
|
|
|
|
# number of channels
|
|
|
|
File.write ('NumChannels %i\n' % TotalCanales)
|
|
|
|
|
|
|
|
# ----------------------------
|
|
|
|
# Main Cycle
|
|
|
|
|
|
|
|
def CicloPrimario(NumCanal):
|
|
|
|
B.Set('curframe', FrameP)
|
|
|
|
|
2007-01-27 02:15:14 +00:00
|
|
|
File.write ('Channel %i\n{ Envelope\n %i\n' % (NumCanal, (FrameF - FrameP + 1)))
|
2006-04-25 07:25:22 +00:00
|
|
|
|
|
|
|
FrameA = FrameP
|
|
|
|
while FrameA < (FrameF + 1):
|
|
|
|
|
|
|
|
B.Set('curframe', FrameA)
|
2006-04-27 12:51:09 +00:00
|
|
|
|
|
|
|
mat= ob.mat # Worldspace matrix
|
|
|
|
|
2006-04-25 07:25:22 +00:00
|
|
|
if NumCanal == 0:
|
2006-04-27 12:51:09 +00:00
|
|
|
Val = mat.translationPart().x
|
2006-04-25 07:25:22 +00:00
|
|
|
elif NumCanal == 1:
|
2006-04-27 12:51:09 +00:00
|
|
|
Val = mat.translationPart().z
|
2006-04-25 07:25:22 +00:00
|
|
|
elif NumCanal == 2:
|
2006-04-27 12:51:09 +00:00
|
|
|
Val = mat.translationPart().y
|
2006-04-25 07:25:22 +00:00
|
|
|
elif NumCanal == 3:
|
2008-04-16 20:03:59 +00:00
|
|
|
Val = M.radians (-mat.toEuler().z)
|
2006-04-25 07:25:22 +00:00
|
|
|
elif NumCanal == 4:
|
2008-04-16 20:03:59 +00:00
|
|
|
Val = M.radians (-mat.toEuler().x)
|
2006-04-25 07:25:22 +00:00
|
|
|
elif NumCanal == 5:
|
2008-04-16 20:03:59 +00:00
|
|
|
Val = M.radians (-mat.toEuler().y)
|
2006-04-25 07:25:22 +00:00
|
|
|
elif NumCanal == 6:
|
2006-04-27 12:51:09 +00:00
|
|
|
Val = mat.scalePart().x
|
2006-04-25 07:25:22 +00:00
|
|
|
elif NumCanal == 7:
|
2006-04-27 12:51:09 +00:00
|
|
|
Val = mat.scalePart().z
|
2006-04-25 07:25:22 +00:00
|
|
|
elif NumCanal == 8:
|
2006-04-27 12:51:09 +00:00
|
|
|
Val = mat.scalePart().y
|
2007-01-27 02:15:14 +00:00
|
|
|
File.write (' Key %f %f 3 0 0 0 0 0 0\n' % (Val, (FrameA/FrameRate)))
|
2006-04-25 07:25:22 +00:00
|
|
|
|
|
|
|
FrameA += 1
|
|
|
|
# Ending Stuff
|
|
|
|
File.write (' Behaviors 1 1\n}\n')
|
|
|
|
|
|
|
|
NumObjetoActual = len(ObjSelect)
|
|
|
|
Iteraciones = 0
|
|
|
|
ProgBarVal = 0.0
|
|
|
|
while Iteraciones < TotalCanales:
|
|
|
|
CicloPrimario(Iteraciones)
|
|
|
|
|
|
|
|
# Start Progress Bar
|
|
|
|
B.Window.DrawProgressBar(ProgBarVal, origName)
|
|
|
|
ProgBarVal = (float(Iteraciones) / TotalCanales) * 0.98
|
|
|
|
Iteraciones += 1
|
|
|
|
|
|
|
|
B.Window.DrawProgressBar(1.0, '') # Done
|
|
|
|
print '\nDone, %s motion file location is:\n%s\n' % (origName, DirN)
|
2007-01-27 02:15:14 +00:00
|
|
|
B.Window.WaitCursor(0)
|
2006-04-25 07:25:22 +00:00
|
|
|
|
|
|
|
# Check if there are selected objects
|
|
|
|
def main():
|
2007-01-27 02:15:14 +00:00
|
|
|
B.Window.FileSelector(FuncionPrincipal, "Write .mot File", B.sys.makename(ext='.mot'))
|
2006-04-25 07:25:22 +00:00
|
|
|
|
|
|
|
if __name__=='__main__':
|
2008-04-16 20:03:59 +00:00
|
|
|
main()
|