~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to release/scripts/export_lightwave_motion.py

  • Committer: Bazaar Package Importer
  • Author(s): Lukas Fittl
  • Date: 2006-09-20 01:57:27 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060920015727-gmoqlxwstx9wwqs3
Tags: 2.42a-1ubuntu1
* Merge from Debian unstable (Closes: Malone #55903). Remaining changes:
  - debian/genpot: Add python scripts from Lee June <blender@eyou.com> to
    generate a reasonable PO template from the sources. Since gettext is used
    in a highly nonstandard way, xgettext does not work for this job.
  - debian/rules: Call the scripts, generate po/blender.pot, and clean it up
    in the clean target.
  - Add a proper header to the generated PO template.
* debian/control: Build depend on libavformat-dev >= 3:0.cvs20060823-3.1,
  otherwise this package will FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!BPY
 
2
 
 
3
""" Registration info for Blender menus: <- these words are ignored
 
4
Name: 'Lightwave Motion (.mot)...'
 
5
Blender: 241
 
6
Group: 'Export'
 
7
Tip: 'Export Loc Rot Size chanels to a Lightwave .mot file'
 
8
"""
 
9
 
 
10
__author__ = "Daniel Salazar (ZanQdo)"
 
11
__url__ = ("blender", "elysiun",
 
12
"e-mail: zanqdo@gmail.com")
 
13
__version__ = "24/03/06"
 
14
 
 
15
__bpydoc__ = """\
 
16
This script exports the selected object's motion channels to a Lightwave
 
17
motion file (.mot).
 
18
 
 
19
Usage:
 
20
Run the script with one or more objects selected (any kind), frames exported
 
21
are between Start and End frames in Render buttons.
 
22
 
 
23
"""
 
24
 
 
25
# $Id: export_lightwave_motion.py,v 1.2 2006/04/27 12:51:09 campbellbarton Exp $
 
26
# --------------------------------------------------------------------------
 
27
# ***** BEGIN GPL LICENSE BLOCK *****
 
28
#
 
29
# Copyright (C) 2003, 2004: A Vanpoucke
 
30
#
 
31
# This program is free software; you can redistribute it and/or
 
32
# modify it under the terms of the GNU General Public License
 
33
# as published by the Free Software Foundation; either version 2
 
34
# of the License, or (at your option) any later version.
 
35
#
 
36
# This program is distributed in the hope that it will be useful,
 
37
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
38
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
39
# GNU General Public License for more details.
 
40
#
 
41
# You should have received a copy of the GNU General Public License
 
42
# along with this program; if not, write to the Free Software Foundation,
 
43
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
44
#
 
45
# ***** END GPL LICENCE BLOCK *****
 
46
# --------------------------------------------------------------------------
 
47
import Blender as B
 
48
#------------------------------------
 
49
#Declarados:
 
50
TotalCanales = 9
 
51
#------------------------------------
 
52
 
 
53
# Change the extension of the file path
 
54
def NuevoNombre(ext):
 
55
        return B.Get('filename')[: -len(B.Get('filename').split('.', -1)[-1]) -1 ] + ext
 
56
 
 
57
ObjSelect = B.Object.GetSelected()
 
58
 
 
59
def FuncionPrincipal (Dir):
 
60
        B.Window.WaitCursor(1)
 
61
        for ob in ObjSelect:
 
62
                origName= NombreObjeto= ob.name
 
63
                print '----\nExporting Object "%s" motion file...' % origName
 
64
 
 
65
                SC = B.Scene.getCurrent()
 
66
                SCR = SC.getRenderingContext()
 
67
 
 
68
                FrameA = B.Get('curframe')
 
69
                FrameP = B.Get('staframe')
 
70
                FrameF = B.Get('endframe')
 
71
 
 
72
                FrameRate = float(SCR.framesPerSec())
 
73
 
 
74
                #---------------------------------------------
 
75
 
 
76
                # Replace danger characters by '_'
 
77
                for ch in ' /\\~!@#$%^&*()+=[];\':",./<>?\t\r\n':
 
78
                        NombreObjeto = NombreObjeto.replace(ch, '_')
 
79
 
 
80
                # Check for file path extension
 
81
                if Dir.lower().endswith('.mot'):
 
82
                        DirN= '%s_%s.mot' % (Dir[:-4], NombreObjeto)
 
83
                else:
 
84
                        DirN= '%s_%s.mot' % (Dir, NombreObjeto)
 
85
 
 
86
                # Open the file
 
87
                File = open(DirN,'w')
 
88
                File.write ('LWMO\n3\n\n') # 3 is the version number.
 
89
 
 
90
                # number of channels
 
91
                File.write ('NumChannels %i\n' % TotalCanales)
 
92
 
 
93
                # ----------------------------
 
94
                # Main Cycle
 
95
 
 
96
                def CicloPrimario(NumCanal):
 
97
                        B.Set('curframe', FrameP)
 
98
 
 
99
                        File.write ('Channel %i\n{ Envelope\n %i\n' % (NumCanal, (FrameF - FrameP + 1)))
 
100
 
 
101
                        FrameA = FrameP
 
102
                        while FrameA < (FrameF + 1):
 
103
 
 
104
                                B.Set('curframe', FrameA)
 
105
                                
 
106
                                mat= ob.mat # Worldspace matrix
 
107
                                
 
108
                                if NumCanal == 0:
 
109
                                        Val = mat.translationPart().x
 
110
                                elif NumCanal == 1:
 
111
                                        Val = mat.translationPart().z
 
112
                                elif NumCanal == 2:
 
113
                                        Val = mat.translationPart().y
 
114
                                elif NumCanal == 3:
 
115
                                        Val = -mat.toEuler().z
 
116
                                elif NumCanal == 4:
 
117
                                        Val = -mat.toEuler().x
 
118
                                elif NumCanal == 5:
 
119
                                        Val = -mat.toEuler().y
 
120
                                elif NumCanal == 6:
 
121
                                        Val = mat.scalePart().x
 
122
                                elif NumCanal == 7:
 
123
                                        Val = mat.scalePart().z
 
124
                                elif NumCanal == 8:
 
125
                                        Val = mat.scalePart().y
 
126
 
 
127
                                File.write (' Key %f %f 3 0 0 0 0 0 0\n' % (Val, (FrameA/FrameRate)))
 
128
 
 
129
                                FrameA += 1
 
130
                        # Ending Stuff
 
131
                        File.write ('  Behaviors 1 1\n}\n')
 
132
 
 
133
                NumObjetoActual = len(ObjSelect)
 
134
                Iteraciones = 0
 
135
                ProgBarVal = 0.0
 
136
                while Iteraciones < TotalCanales:
 
137
                        CicloPrimario(Iteraciones)
 
138
 
 
139
                        # Start Progress Bar
 
140
                        B.Window.DrawProgressBar(ProgBarVal, origName)
 
141
                        ProgBarVal = (float(Iteraciones) / TotalCanales) * 0.98
 
142
                        Iteraciones += 1
 
143
                        
 
144
                B.Window.DrawProgressBar(1.0, '') # Done
 
145
                print '\nDone, %s motion file location is:\n%s\n' % (origName, DirN)
 
146
 
 
147
# Check if there are selected objects
 
148
def main():
 
149
        if len(ObjSelect) == 0:
 
150
                B.Draw.PupMenu('Select 1 or more objects, aborting.')
 
151
        else:
 
152
                # Call File Selector
 
153
                B.Window.FileSelector(FuncionPrincipal, "Write .mot File", NuevoNombre('.mot'))
 
154
 
 
155
if __name__=='__main__':
 
156
        main()
 
 
b'\\ No newline at end of file'