Welcome to mirror list, hosted at ThFree Co, Russian Federation.

export_lightwave_motion.py « scripts « release - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cabc4cf5fc6ccbe16472e95bbc9b9a8ac6b4b1c4 (plain)
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
#!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)"
__url__ = ("blender", "elysiun",
"e-mail: zanqdo@gmail.com")
__version__ = "24/03/06"

__bpydoc__ = """\
This script exports the selected object's motion channels to a Lightwave
motion file (.mot).

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
#------------------------------------
#Declarados:
TotalCanales = 9
#------------------------------------

def FuncionPrincipal (Dir):
	B.Window.WaitCursor(1)
	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()
	
	for ob in ObjSelect:
		origName= NombreObjeto= ob.name
		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
		if len(ObjSelect) > 1:
			DirN= '%s_%s.mot' % (Dir[:-4], NombreObjeto)
		else:
			DirN= Dir
		
		# 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)

			File.write ('Channel %i\n{ Envelope\n  %i\n' % (NumCanal, (FrameF - FrameP + 1)))

			FrameA = FrameP
			while FrameA < (FrameF + 1):

				B.Set('curframe', FrameA)
				
				mat= ob.mat # Worldspace matrix
				
				if NumCanal == 0:
					Val = mat.translationPart().x
				elif NumCanal == 1:
					Val = mat.translationPart().z
				elif NumCanal == 2:
					Val = mat.translationPart().y
				elif NumCanal == 3:
					Val = -mat.toEuler().z
				elif NumCanal == 4:
					Val = -mat.toEuler().x
				elif NumCanal == 5:
					Val = -mat.toEuler().y
				elif NumCanal == 6:
					Val = mat.scalePart().x
				elif NumCanal == 7:
					Val = mat.scalePart().z
				elif NumCanal == 8:
					Val = mat.scalePart().y
				File.write ('  Key %f %f 3 0 0 0 0 0 0\n' % (Val, (FrameA/FrameRate)))

				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)
	B.Window.WaitCursor(0)

# Check if there are selected objects
def main():
	B.Window.FileSelector(FuncionPrincipal, "Write .mot File", B.sys.makename(ext='.mot'))

if __name__=='__main__':
	main()