~ubuntu-branches/ubuntu/intrepid/blender/intrepid-updates

« back to all changes in this revision

Viewing changes to release/scripts/animation_trajectory.py

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-08-08 02:45:40 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080808024540-kkjp7ekfivzhuw3l
Tags: 2.46+dfsg-4
* Fix python syntax warning in import_dxf.py, which led to nasty output
  in installation/upgrade logs during byte-compilation, using a patch
  provided by the script author (Closes: #492280):
   - debian/patches/45_fix_python_syntax_warning

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: 'Trajectory'
5
 
Blender: 242
6
 
Group: 'Animation'
7
 
Tip: 'See Trajectory of selected object'
8
 
"""
9
 
 
10
 
__author__ = '3R - R3gis'
11
 
__version__ = '2.42'
12
 
__url__ = ["Script's site , http://blenderfrance.free.fr/python/Trajectory_en.htm","Author's site , http://cybercreator.free.fr", "French Blender support forum, http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender"]
13
 
__email__=["3R, r3gis@free.fr"]
14
 
 
15
 
 
16
 
__bpydoc__ = """
17
 
 
18
 
Usage:
19
 
 
20
 
* Launch with alt+P (or put it in .script folder)
21
 
 
22
 
Allow to see in real time trajectory of selected object.
23
 
 
24
 
On first run, it ask you
25
 
- If you want that actually selected object have they trajectory always shown
26
 
- If you want to use Space Handler or a Scriptlink in Redraw mode
27
 
- Future and Past : it is the frame in past and future
28
 
of the beggining and the end of the path
29
 
- Width of line that represent the trajectory
30
 
 
31
 
Then the object's trajectory will be shown in all 3D areas.
32
 
When trajectory is red, you can modifiy it by moving object.
33
 
When trajectory is blue and you want to be able to modify it, inser a Key (I-Key)
34
 
 
35
 
Points appears on trajectory :
36
 
- Left Clic to modify position
37
 
- Right Clic to go to the frame it represents
38
 
 
39
 
Notes:<br>
40
 
In scriptlink mode, it create one script link so make sure that 'Enable Script Link' toogle is on
41
 
In SpaceHandler mode, you have to go in View>>SpaceHandlerScript menu to activate Trajectory
42
 
 
43
 
 
44
 
"""
45
 
 
46
 
 
47
 
# --------------------------------------------------------------------------
48
 
# ***** BEGIN GPL LICENSE BLOCK *****
49
 
#
50
 
# Copyright (C) 2004-2006: Regis Montoya
51
 
#
52
 
# This program is free software; you can redistribute it and/or
53
 
# modify it under the terms of the GNU General Public License
54
 
# as published by the Free Software Foundation; either version 2
55
 
# of the License, or (at your option) any later version.
56
 
#
57
 
# This program is distributed in the hope that it will be useful,
58
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
59
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
60
 
# GNU General Public License for more details.
61
 
#
62
 
# You should have received a copy of the GNU General Public License
63
 
# along with this program; if not, write to the Free Software Foundation,
64
 
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
65
 
#
66
 
# ***** END GPL LICENCE BLOCK *****
67
 
# --------------------------------------------------------------------------
68
 
#################################
69
 
# by 3R - 26/08/05
70
 
# for any problem :
71
 
#       r3gis@free.fr
72
 
#       ou sur le newsgroup:
73
 
# http://zoo-logique.org/3D.Blender/
74
 
#################################
75
 
#Many thanks to cambo for his fixes
76
 
#################################
77
 
 
78
 
 
79
 
 
80
 
import Blender
81
 
 
82
 
 
83
 
scene= Blender.Scene.GetCurrent()
84
 
 
85
 
        
86
 
#Writing
87
 
def write_script(name, script):
88
 
        global scene
89
 
        #List texts and their name
90
 
        #write : type of writing : 1->New, 2->Overwrite
91
 
        scripting= None
92
 
        for text in Blender.Text.Get():
93
 
                if text.name==name and text.asLines()[1] != "#"+str(__version__):
94
 
                        scripting= Blender.Text.Get(name)
95
 
                        scripting.write(script)
96
 
                        break
97
 
        
98
 
        if not scripting:
99
 
                scripting= Blender.Text.New(name)
100
 
                scripting.write(script)
101
 
 
102
 
 
103
 
#Linking                        
104
 
def link_script(name, type):
105
 
        global scene
106
 
        try:
107
 
                scene.getScriptLinks(type).index(name) # Does nothing. just fails of the script isnt there.
108
 
        except:
109
 
                scene.addScriptLink(name, type)
110
 
 
111
 
 
112
 
#Deleting of a text
113
 
def text_remove(name):
114
 
        global scene
115
 
        #try to delete text if already linked
116
 
        try:
117
 
                text= Blender.Text.Get(name)
118
 
                # Texte.clear()
119
 
                scene.clearScriptLinks([name])
120
 
                Blender.Text.unlink(text)
121
 
        except:
122
 
                print('---Initialisation of Trajectory_'+str(__version__)+'.py---')
123
 
 
124
 
#Whether is already running, also check if it's the last version of the script : second line contain the version fo the script
125
 
ask_modif= 0 # Default
126
 
for text in Blender.Text.Get():
127
 
        if text.name == 'Trajectory' and text.asLines()[1] == "#"+str(__version__):
128
 
                #We ask if script modify his seetings, keep it or stop script
129
 
                ask_modif= Blender.Draw.PupMenu("Script already launch %t|Modify settings%x0|Keep settings%x1|Stop script%x2|")
130
 
                if ask_modif==-1: # user canceled.
131
 
                        ask_modif= 1 
132
 
                break
133
 
 
134
 
selection_mode= 0
135
 
future= 35
136
 
past= 20
137
 
width= 2
138
 
 
139
 
#In modify case
140
 
if ask_modif==0:
141
 
        handle_mode= Blender.Draw.Create(0)
142
 
        selection_mode= Blender.Draw.Create(0)
143
 
        future= Blender.Draw.Create(35)
144
 
        past= Blender.Draw.Create(20)
145
 
        width= Blender.Draw.Create(2)
146
 
 
147
 
        block= []
148
 
        block.append(("Use Space Handlers", handle_mode, "You have to activate for each area by View>>SpaceHandler")) #You can delete this option...
149
 
        block.append(("Always draw for sel.", selection_mode, "Selected object will have their trajectory always shown"))
150
 
        block.append(("Past :", past, 1, 900))
151
 
        block.append(("Futur:", future, 1, 900))
152
 
        block.append(("Width:", width, 1,5))
153
 
        
 
1
#!BPY
 
2
 
 
3
""" Registration info for Blender menus: <- these words are ignored
 
4
Name: 'Trajectory'
 
5
Blender: 243
 
6
Group: 'Animation'
 
7
Tip: 'See Trajectory of selected object'
 
8
"""
 
9
 
 
10
__author__ = '3R - R3gis'
 
11
__version__ = '2.43'
 
12
__url__ = ["Script's site , http://blenderfrance.free.fr/python/Trajectory_en.htm","Author's site , http://cybercreator.free.fr", "French Blender support forum, http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender"]
 
13
__email__=["3R, r3gis@free.fr"]
 
14
 
 
15
 
 
16
__bpydoc__ = """
 
17
 
 
18
Usage:
 
19
 
 
20
* Launch with alt+P (or put it in .script folder)
 
21
 
 
22
Allow to see in real time trajectory of selected object.
 
23
 
 
24
On first run, it ask you
 
25
- If you want that actually selected object have they trajectory always shown
 
26
- If you want to use Space Handler or a Scriptlink in Redraw mode
 
27
- Future and Past : it is the frame in past and future
 
28
of the beggining and the end of the path
 
29
- Width of line that represent the trajectory
 
30
 
 
31
Then the object's trajectory will be shown in all 3D areas.
 
32
When trajectory is red, you can modifiy it by moving object.
 
33
When trajectory is blue and you want to be able to modify it, inser a Key (I-Key)
 
34
 
 
35
Points appears on trajectory :
 
36
- Left Clic to modify position
 
37
- Right Clic to go to the frame it represents
 
38
 
 
39
Notes:<br>
 
40
In scriptlink mode, it create one script link so make sure that 'Enable Script Link' toogle is on
 
41
In SpaceHandler mode, you have to go in View>>SpaceHandlerScript menu to activate Trajectory
 
42
 
 
43
 
 
44
"""
 
45
 
 
46
 
 
47
# --------------------------------------------------------------------------
 
48
# ***** BEGIN GPL LICENSE BLOCK *****
 
49
#
 
50
# Copyright (C) 2004-2006: Regis Montoya
 
51
#
 
52
# This program is free software; you can redistribute it and/or
 
53
# modify it under the terms of the GNU General Public License
 
54
# as published by the Free Software Foundation; either version 2
 
55
# of the License, or (at your option) any later version.
 
56
#
 
57
# This program is distributed in the hope that it will be useful,
 
58
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
59
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
60
# GNU General Public License for more details.
 
61
#
 
62
# You should have received a copy of the GNU General Public License
 
63
# along with this program; if not, write to the Free Software Foundation,
 
64
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
65
#
 
66
# ***** END GPL LICENCE BLOCK *****
 
67
# --------------------------------------------------------------------------
 
68
#################################
 
69
# by 3R - 26/08/05
 
70
# for any problem :
 
71
#       r3gis@free.fr
 
72
#       ou sur le newsgroup:
 
73
# http://zoo-logique.org/3D.Blender/
 
74
#################################
 
75
#Many thanks to cambo for his fixes
 
76
#################################
 
77
 
 
78
 
 
79
 
 
80
import Blender
 
81
 
 
82
 
 
83
scene= Blender.Scene.GetCurrent()
 
84
 
 
85
        
 
86
#Writing
 
87
def write_script(name, script):
 
88
        global scene
 
89
        #List texts and their name
 
90
        #write : type of writing : 1->New, 2->Overwrite
 
91
        scripting= None
 
92
        for text in Blender.Text.Get():
 
93
                if text.name==name and text.asLines()[1] != "#"+str(__version__):
 
94
                        scripting = text
 
95
                        scripting.clear()
 
96
                        scripting.write(script)
 
97
                        break
 
98
        
 
99
        if not scripting:
 
100
                scripting= Blender.Text.New(name)
 
101
                scripting.write(script)
 
102
 
 
103
def link_script(name, type):
 
104
        global scene
 
105
        scriptlinks = scene.getScriptLinks(type) # none or list
 
106
        if not scriptlinks or name not in scriptlinks:
 
107
                scene.addScriptLink(name, type)
 
108
 
 
109
 
 
110
#Deleting of a text
 
111
def text_remove(name):
 
112
        global scene
 
113
        #try to delete text if already linked
 
114
        try:
 
115
                text= Blender.Text.Get(name)
 
116
                # Texte.clear()
 
117
                scene.clearScriptLinks([name])
 
118
                Blender.Text.unlink(text)
 
119
        except:
 
120
                print('---Initialisation of Trajectory_'+str(__version__)+'.py---')
 
121
 
 
122
#Whether is already running, also check if it's the last version of the script : second line contain the version fo the script
 
123
ask_modif= 0 # Default
 
124
for text in Blender.Text.Get():
 
125
        if text.name == 'Trajectory' and text.asLines()[1] == "#"+str(__version__):
 
126
                #We ask if script modify his seetings, keep it or stop script
 
127
                ask_modif= Blender.Draw.PupMenu("Script already launch %t|Modify settings%x0|Keep settings%x1|Stop script%x2|")
 
128
                if ask_modif==-1: # user canceled.
 
129
                        ask_modif= 1 
 
130
                break
 
131
 
 
132
selection_mode= 0
 
133
future= 35
 
134
past= 20
 
135
width= 2
 
136
 
 
137
#In modify case
 
138
if ask_modif==0:
 
139
        handle_mode= Blender.Draw.Create(0)
 
140
        selection_mode= Blender.Draw.Create(0)
 
141
        future= Blender.Draw.Create(35)
 
142
        past= Blender.Draw.Create(20)
 
143
        width= Blender.Draw.Create(2)
 
144
 
 
145
        block= []
 
146
        block.append(("Space Handlers", handle_mode, "You have to activate for each area by View>>SpaceHandler")) #You can delete this option...
 
147
        block.append(("Always Draw", selection_mode, "Selected object will have their trajectory always shown"))
 
148
        block.append(("Past :", past, 1, 900))
 
149
        block.append(("Futur:", future, 1, 900))
 
150
        block.append(("Width:", width, 1,5))
 
151
        
154
152
        if not Blender.Draw.PupBlock("Trajectory seetings", block):
155
 
                ask_modif=1
156
 
        
157
 
        handle_mode= handle_mode.val
158
 
        selection_mode= selection_mode.val
159
 
        future= future.val
160
 
        past= past.val
161
 
        width= width.val
162
 
 
163
 
 
164
 
#put names of selected objects in objects_select if option choosen by user
165
 
if selection_mode==1:
166
 
        objects_select= [ob.name for ob in Blender.Object.GetSelected()]
167
 
else:
168
 
        objects_select= []
169
 
        
170
 
 
171
 
try:
172
 
        if handle_mode==1:
173
 
                DrawPart="#SPACEHANDLER.VIEW3D.DRAW\n"
174
 
        else:
175
 
                DrawPart="#!BPY\n"
176
 
except:DrawPart="#BadlyMade"
177
 
        
178
 
 
179
 
#Here is the script to write in Blender and to link, options are also written now
180
 
DrawPart=DrawPart+"#"+str(__version__)+"""
181
 
#This script is a part of Trajectory.py and have to be linked to the scene in Redraw if not in HANDLER mode.
182
 
#Author : 3R - Regis Montoya
183
 
#It's better to use the Trajectory_"version_number".py
184
 
#You can modify the two following value to change the path settings
185
 
future="""+str(future)+"""
186
 
past="""+str(past)+"""
187
 
object_init_names="""+str(objects_select)+"""
188
 
 
189
 
 
190
 
import Blender, math
191
 
from Blender import BGL, Draw, Ipo
192
 
from Blender.BGL import *
193
 
from Blender.Draw import *
194
 
from math import *
195
 
 
196
 
from Blender.Mathutils import Vector
197
 
 
198
 
#take actual frame
199
 
frameC=Blender.Get('curframe')
200
 
render_context=Blender.Scene.getCurrent().getRenderingContext()
201
 
#ajust number of frames with NewMap and OldMapvalue values
202
 
k=1.00*render_context.oldMapValue()/render_context.newMapValue()
203
 
if k<1:
204
 
        tr=-1*int(log(k*0.1, 10))
205
 
else:
206
 
        tr=-1*int(log(k, 10))
207
 
#The real and integer frame to compare to ipos keys frames
208
 
frameCtr=round(frameC*k, tr)
209
 
frameCr=frameC*k
210
 
frameC=int(round(frameC*k, 0))
211
 
 
212
 
 
213
 
#List objects that we have to show trajectory in $objects
214
 
# In this case, using a dict for unique objects is the fastest way.
215
 
object_dict= dict([(ob.name, ob) for ob in Blender.Object.GetSelected()])
216
 
for obname in object_init_names:
217
 
        try: # checking if its alredy there.
218
 
                object_dict[obname] 
219
 
        except: # Object is not there.
220
 
                try: # Object may be removed.
221
 
                        object_dict[obname]= Blender.Object.Get(obname)
222
 
                except:
223
 
                        pass # object was removed.
224
 
 
225
 
#This fonction give the resulting matrix of all parents at a given frame
226
 
#parent_list is the list of all parents [object, matrix, locX_ipo, locY, Z, rotX, Y, Z, sizeX, Y, Z] of current object
227
 
def matrixForTraj(frame, parent_list):
228
 
        DecMatC=Blender.Mathutils.Matrix([1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1])
229
 
 
230
 
        for parent_data in parent_list:
231
 
                parent_ob=      parent_data[0]
232
 
                
233
 
                try:    X=      parent_data[5].evaluate(frame)*pi/18
234
 
                except: X=      parent_ob.RotX
235
 
                try:    Y=      parent_data[6].evaluate(frame)*pi/18
236
 
                except: Y=      parent_ob.RotY
237
 
                try:    Z=      parent_data[7].evaluate(frame)*pi/18
238
 
                except: Z=      parent_ob.RotZ
239
 
                try:    LX=     parent_data[2].evaluate(frame)
240
 
                except: LX=     parent_ob.LocX
241
 
                try:    LY=     parent_data[3].evaluate(frame)
242
 
                except: LY=     parent_ob.LocY
243
 
                try:    LZ=     parent_data[4].evaluate(frame)
244
 
                except: LZ=     parent_ob.LocZ
245
 
                try:    SX=     parent_data[8].evaluate(frame)
246
 
                except: SX=     parent_ob.SizeX
247
 
                try:    SY=     parent_data[9].evaluate(frame)
248
 
                except: SY=     parent_ob.SizeY
249
 
                try:    SZ=     parent_data[10].evaluate(frame)
250
 
                except: SZ=     parent_ob.SizeZ
251
 
 
252
 
                NMat=Blender.Mathutils.Matrix([cos(Y)*cos(Z)*SX,SX*cos(Y)*sin(Z),-SX*sin(Y),0],
253
 
                [(-cos(X)*sin(Z)+sin(Y)*sin(X)*cos(Z))*SY,(sin(X)*sin(Y)*sin(Z)+cos(X)*cos(Z))*SY,sin(X)*cos(Y)*SY,0],
254
 
                [(cos(X)*sin(Y)*cos(Z)+sin(X)*sin(Z))*SZ,(cos(X)*sin(Y)*sin(Z)-sin(X)*cos(Z))*SZ,SZ*cos(X)*cos(Y),0],
255
 
                [LX,LY,LZ,1])
256
 
                DecMatC=DecMatC*parent_data[1]*NMat
257
 
        return DecMatC
258
 
 
259
 
#####
260
 
TestLIST=[]
261
 
matview=Blender.Window.GetPerspMatrix()
262
 
###########
263
 
#Fonction to draw trajectories
264
 
###########
265
 
 
266
 
def Trace_Traj(ob):
267
 
                global TestLIST, matview
268
 
                #we draw trajectories for all objects in list
269
 
        
270
 
                LocX=[]
271
 
                LocY=[]
272
 
                LocZ=[]
273
 
                #List with trajectories' vertexs
274
 
                vertexX=[]
275
 
                
276
 
                contextIpo= ob.ipo
277
 
                if contextIpo:
278
 
                        ipoLocX=contextIpo[Ipo.OB_LOCX]
279
 
                        ipoLocY=contextIpo[Ipo.OB_LOCY]
280
 
                        ipoLocZ=contextIpo[Ipo.OB_LOCZ]
281
 
                        ipoTime=contextIpo[Ipo.OB_TIME]
282
 
                else: # only do if there is no IPO (if no ipo curves : return None object and don't go in this except)
283
 
                        ipoLocX= ipoLocY= ipoLocZ= ipoTime= None
284
 
                
285
 
                if ipoTime:
286
 
                        return 0
287
 
                
288
 
                #Get all parents of ob
289
 
                parent=ob.parent
290
 
                backup_ob= ob
291
 
                child= ob
292
 
                parent_list= []
293
 
                
294
 
                #Get parents's infos :
295
 
                #list of [name, initial matrix at make parent, ipo in X,Y,Z,rotX,rotY,rotZ,sizeX,Y,Z]
296
 
                while parent:
297
 
                        Init_Mat=Blender.Mathutils.Matrix(child.getMatrix('worldspace')) #must be done like it (it isn't a matrix otherwise)
298
 
                        Init_Mat.invert()
299
 
                        Init_Mat=Init_Mat*child.getMatrix('localspace')
300
 
                        Init_Mat=parent.getMatrix()*Init_Mat
301
 
                        Init_Mat.invert()
302
 
        
303
 
                        contextIpo= parent.ipo # None or IPO
304
 
                        if contextIpo:
305
 
                                ipo_Parent_LocX=contextIpo[Ipo.OB_LOCX]
306
 
                                ipo_Parent_LocY=contextIpo[Ipo.OB_LOCY]
307
 
                                ipo_Parent_LocZ=contextIpo[Ipo.OB_LOCZ]
308
 
                                ipo_Parent_RotX=contextIpo[Ipo.OB_ROTX]
309
 
                                ipo_Parent_RotY=contextIpo[Ipo.OB_ROTY]
310
 
                                ipo_Parent_RotZ=contextIpo[Ipo.OB_ROTZ]
311
 
                                ipo_Parent_SizeX=contextIpo[Ipo.OB_SIZEX]
312
 
                                ipo_Parent_SizeY=contextIpo[Ipo.OB_SIZEY]
313
 
                                ipo_Parent_SizeZ=contextIpo[Ipo.OB_SIZEZ]
314
 
                        else:
315
 
                                ipo_Parent_LocX=ipo_Parent_LocY=ipo_Parent_LocZ=\
316
 
                                ipo_Parent_RotX=ipo_Parent_RotY=ipo_Parent_RotZ=\
317
 
                                ipo_Parent_SizeX=ipo_Parent_SizeY=ipo_Parent_SizeZ= None
318
 
                        
319
 
                        parent_list.append([parent, Init_Mat, ipo_Parent_LocX, ipo_Parent_LocY, ipo_Parent_LocZ, ipo_Parent_RotX, ipo_Parent_RotY, ipo_Parent_RotZ, ipo_Parent_SizeX, ipo_Parent_SizeY, ipo_Parent_SizeZ])
320
 
        
321
 
                        child=parent
322
 
                        parent=parent.parent
323
 
                        
324
 
                #security : if one of parents object are a path>>follow : trajectory don't work properly so it have to draw nothing
325
 
                for parent in parent_list:
326
 
                        # getData() is slow especialy with NMesh.
327
 
                        # check its a curve. 
328
 
                        if parent[0].getType() == 'Curve':
329
 
                                if parent[0].data.flag & 1<<4: # Follow path, 4th bit
330
 
                                        return 1
331
 
                
332
 
                #ob >> re-assign obj and not parent
333
 
                ob= backup_ob
334
 
                
335
 
                
336
 
                if ipoLocX: LXC= ipoLocX.evaluate(frameC)
337
 
                else:           LXC= ob.LocX
338
 
                if ipoLocY:     LYC= ipoLocY.evaluate(frameC)
339
 
                else:           LYC= ob.LocY
340
 
                if ipoLocZ:     LZC= ipoLocZ.evaluate(frameC)
341
 
                else:           LZC= ob.LocZ
342
 
 
343
 
                vect= Vector([ob.LocX, ob.LocY, ob.LocZ, 1])
344
 
                color=[0, 1]    
345
 
        
346
 
                #If trajectory is being modified and we are at a frame where a ipo key already exist
347
 
                if round(ob.LocX, 5)!=round(LXC, 5):
348
 
                        for bez in ipoLocX.bezierPoints:
349
 
                                if round(bez.getPoints()[0], tr)==frameCtr:
350
 
                                        bez.setPoints((frameCr, vect[0]))
351
 
                        ipoLocX.recalc()
352
 
                if round(ob.LocY, 5)!=round(LYC, 5):
353
 
                        for bez in ipoLocY.bezierPoints:
354
 
                                if round(bez.getPoints()[0], tr)==frameCtr:
355
 
                                        bez.setPoints((frameCr, vect[1]))
356
 
                        ipoLocY.recalc()
357
 
                if round(ob.LocZ, 5)!=round(LZC, 5):
358
 
                        for bez in ipoLocZ.bezierPoints:
359
 
                                if round(bez.getPoints()[0], tr)==frameCtr:
360
 
                                        bez.setPoints((frameCr, vect[2]))
361
 
                        ipoLocZ.recalc()
362
 
                
363
 
                #change trajectory color if at an ipoKey
364
 
                VertexFrame=[]
365
 
                bezier_Coord=0
366
 
                if ipoLocX: # FIXED like others it was just in case ipoLocX==None
367
 
                        for bez in ipoLocX.bezierPoints:
368
 
                                bezier_Coord=round(bez.getPoints()[0], tr)
369
 
                                if bezier_Coord not in VertexFrame:
370
 
                                        VertexFrame.append(bezier_Coord)
371
 
                                if bezier_Coord==frameCtr:
372
 
                                                color=[1, color[1]-0.3]
373
 
                if ipoLocY: # FIXED
374
 
                        for bez in ipoLocY.bezierPoints:
375
 
                                bezier_Coord=round(bez.getPoints()[0], tr)
376
 
                                if bezier_Coord not in VertexFrame:
377
 
                                        VertexFrame.append(bezier_Coord)
378
 
                                if round(bez.getPoints()[0], tr)==frameCtr:
379
 
                                                color=[1, color[1]-0.3]
380
 
                if ipoLocZ: # FIXED
381
 
                        for bez in ipoLocZ.bezierPoints:
382
 
                                bezier_Coord=round(bez.getPoints()[0], tr)
383
 
                                if bezier_Coord not in VertexFrame:
384
 
                                        VertexFrame.append(bezier_Coord)
385
 
                                if round(bez.getPoints()[0], tr)==frameCtr:
386
 
                                                color=[1, color[1]-0.3]
387
 
                
388
 
        
389
 
                #put in LocX, LocY and LocZ all points of trajectory
390
 
                for frame in xrange(frameC-past, frameC+future):
391
 
                        DecMat=matrixForTraj(frame, parent_list)
392
 
 
393
 
                        if ipoLocX: LX= ipoLocX.evaluate(frame)
394
 
                        else:           LX= ob.LocX
395
 
                        if ipoLocY:     LY= ipoLocY.evaluate(frame)
396
 
                        else:           LY= ob.LocY
397
 
                        if ipoLocZ:     LZ= ipoLocZ.evaluate(frame)
398
 
                        else:           LZ= ob.LocZ
399
 
                        
400
 
                        vect= Vector([LX, LY, LZ, 1])
401
 
                        vect=vect*DecMat
402
 
                        LocX.append(vect[0])
403
 
                        LocY.append(vect[1])
404
 
                        LocZ.append(vect[2])
405
 
        
406
 
                
407
 
                #draw part : get current view
408
 
                MatPreBuff= [matview[i][j] for i in xrange(4) for j in xrange(4)]
409
 
                        
410
 
                MatBuff=BGL.Buffer(GL_FLOAT, 16, MatPreBuff)
411
 
                
412
 
                glLoadIdentity()
413
 
                glMatrixMode(GL_PROJECTION)
414
 
                glPushMatrix()
415
 
                glLoadMatrixf(MatBuff)
416
 
                
417
 
                #draw trajectory line
418
 
                glLineWidth("""+str(width)+""")
419
 
                
420
 
                glBegin(GL_LINE_STRIP)
421
 
                for i in xrange(len(LocX)):
422
 
                        glColor3f((i+1)*1.00/len(LocX)*color[0], 0, (i+1)*1.00/len(LocX)*color[1])
423
 
                        glVertex3f(LocX[i], LocY[i], LocZ[i])
424
 
                
425
 
                glEnd() 
426
 
                
427
 
                #draw trajectory's "vertexs"
428
 
                if not Blender.Window.EditMode():
429
 
                        glPointSize(5)
430
 
                        glBegin(GL_POINTS)
431
 
                        TestPOINTS=[]
432
 
                        TestFRAME=[]
433
 
                        i=0
434
 
                        for frame in VertexFrame:
435
 
                                ix=int(frame)-frameC+past
436
 
                                if ix>=0 and ix<len(LocX):
437
 
                                        glColor3f(1, 0.7, 0.2)
438
 
                                        glVertex3f(LocX[ix], LocY[ix], LocZ[ix])
439
 
                                        TestPOINTS.append(Vector([LocX[ix], LocY[ix], LocZ[ix], 1]))
440
 
                                        TestFRAME.append(int(frame))
441
 
                                        i+=1
442
 
                        glEnd()
443
 
                        #this list contains info about where to check if we click over a "vertex" in 3D view
444
 
                        TestLIST.append((ob, TestPOINTS, TestFRAME))
445
 
                
446
 
                glLineWidth(1)
447
 
                return 0
448
 
 
449
 
 
450
 
for ob in object_dict.itervalues():
451
 
        Trace_Traj(ob)
452
 
 
453
 
###########
454
 
#Fonction to handle trajectories
455
 
###########
456
 
 
457
 
def Manip():
458
 
        #use TestLIST and matview defined by Trace_Traj
459
 
        global TestLIST, matview
460
 
        for screen in Blender.Window.GetScreenInfo(Blender.Window.Types.VIEW3D):
461
 
                if screen['id']==Blender.Window.GetAreaID():
462
 
                        x0, y0, x1, y1= screen['vertices']
463
 
                        break
464
 
        
465
 
        #Projection of GL matrix in 3D view
466
 
        glPushMatrix()
467
 
        glMatrixMode(GL_PROJECTION)
468
 
        glPushMatrix()
469
 
        glLoadIdentity()
470
 
        #Global coordinates' matrix
471
 
        glOrtho(x0, x1, y0, y1, -1, 0)
472
 
        glMatrixMode(GL_MODELVIEW)
473
 
        glLoadIdentity()
474
 
        #Test mouse clics and other events
475
 
        
476
 
        
477
 
        if Blender.Window.QTest():
478
 
                evt, val= Blender.Window.QRead()
479
 
                if (evt==LEFTMOUSE or evt==RIGHTMOUSE) and not Blender.Window.EditMode():
480
 
                        mouse_co=Blender.Window.GetMouseCoords()
481
 
                        #if click on trajectory "vertexs"...
482
 
                        for ob, TestPOINTS, TestFRAME in TestLIST: # ob is now used, line 552 to know what object it had to select
483
 
                                for k, Vect in enumerate(TestPOINTS):
484
 
                                        proj=Vect*matview
485
 
                                        
486
 
                                        pt=[(proj[0]/proj[3])*(x1-x0)/2+(x1+x0)/2, (proj[1]/proj[3])*(y1-y0)/2+(y1+y0)/2]
487
 
 
488
 
                                        if mouse_co[0]<pt[0]+4 and mouse_co[0]>pt[0]-4 and mouse_co[1]>pt[1]-4 and mouse_co[1]<pt[1]+4:
489
 
                                                if evt==LEFTMOUSE:
490
 
                                                        #remember current selected object
491
 
                                                        object_names=[obj.name for obj in Blender.Object.GetSelected()]
492
 
                                                        #this script allow to simulate a GKey, but I have to write a script
493
 
                                                        #another way would made a infinit redraw or don't allow to move object
494
 
                                                        #it auto unlink and delete itself
495
 
                                                        script=\"\"\"
496
 
import Blender
497
 
from Blender import Draw, Window
498
 
from Blender.Window import *
499
 
from Blender.Draw import *
500
 
 
501
 
from Blender.Mathutils import Vector
502
 
 
503
 
# The following code is a bit of a hack, it allows clicking on the points and dragging directly
504
 
#It simulate user press GKey 
505
 
#It also set the cursor position at center (because user have previously clic on area and moved the cursor): 
506
 
#And I can't get previous cursor position : redraw appear after it has been moved
507
 
#If there is no better way you can remove this comments
508
 
f= GetAreaID()
509
 
SetCursorPos(0,0,0)
510
 
#SetKeyQualifiers(1) #FIXED : the bug in older versions seems to have been fixed
511
 
SetKeyQualifiers(0)
512
 
QAdd(f, Blender.Draw.GKEY, 1, 0)
513
 
QHandle(f)
514
 
Blender.Redraw()
515
 
done=0
516
 
while not done:
517
 
        while Blender.Window.QTest():
518
 
                ev=Blender.Window.QRead()[0]
519
 
                if ev not in (4, 5, 18, 112, 213): #all event needed to move object
520
 
                        #SetKeyQualifiers(1) #FIXED too, same reason that above
521
 
                        #SetKeyQualifiers(0)
522
 
                        SetKeyQualifiers(Blender.Window.GetKeyQualifiers())
523
 
                        QAdd(f, ev, 1, 0)
524
 
                        QHandle(f)
525
 
                        Blender.Redraw()
526
 
                if ev in (RIGHTMOUSE, LEFTMOUSE, ESCKEY):
527
 
                        done=1
528
 
Blender.Set('curframe',\"\"\"+str(Blender.Get('curframe'))+\"\"\")
529
 
Blender.Object.GetSelected()[0].sel= False
530
 
for obname in \"\"\"+str(object_names)+\"\"\":
531
 
        ob=Blender.Object.Get(obname)
532
 
        ob.sel= True
533
 
SetCursorPos(0,0,0)
534
 
scripting=Blender.Text.Get('Edit_Trajectory')
535
 
scripting.clear()
536
 
Blender.Text.unlink(scripting)
537
 
                                                \"\"\"
538
 
                                                        
539
 
                                                        #FIXED Edit_Trajectory was longer : all SetKeyQualifiers removed
540
 
                                                        scene=Blender.Scene.GetCurrent()
541
 
                                                        try:
542
 
                                                                scripting=Blender.Text.Get('Edit_Trajectory')
543
 
                                                                scripting.clear()
544
 
                                                        except:
545
 
                                                                scripting=Blender.Text.New('Edit_Trajectory')
546
 
                                                        
547
 
                                                        scripting.write(script)
548
 
                                                        #script= scripting #FIXED seems not needed anymore
549
 
                                                        
550
 
                                                        #Go to frame that correspond to selected "vertex"
551
 
                                                        Blender.Set('curframe', TestFRAME[k])
552
 
                                                        
553
 
                                                        #un select all objects
554
 
                                                        for _ob in Blender.Object.GetSelected():
555
 
                                                                _ob.sel= False
556
 
                                                        #FIXED TestLIST[j][0].sel=0, but no j. So ob.sel and above variable changed in obj
557
 
                                                        ob.sel= True
558
 
                                                        Blender.Run('Edit_Trajectory')
559
 
                                                
560
 
                                                #work well now !!!
561
 
                                                if evt==RIGHTMOUSE :
562
 
                                                        Blender.Set('curframe', TestFRAME[k])
563
 
 
564
 
Manip()
565
 
#retrieve a normal matrix
566
 
glPopMatrix()
567
 
glMatrixMode(GL_PROJECTION)
568
 
glPopMatrix()
569
 
glMatrixMode(GL_MODELVIEW)
570
 
"""
571
 
 
572
 
if ask_modif==0:
573
 
        text_remove('Trajectory')
574
 
        write_script('Trajectory', DrawPart)
575
 
        if handle_mode==1:
576
 
                Blender.UpdateMenus()
577
 
        else:
578
 
                link_script('Trajectory', 'Redraw')
579
 
if ask_modif==2:
580
 
        text_remove('Trajectory')
581
 
        print("---End of Trajectory_"+str(__version__)+".py---\n---   Thanks for use   ---")
 
 
b'\\ No newline at end of file'
 
153
                ask_modif=1
 
154
        
 
155
        handle_mode= handle_mode.val
 
156
        selection_mode= selection_mode.val
 
157
        future= future.val
 
158
        past= past.val
 
159
        width= width.val
 
160
 
 
161
 
 
162
#put names of selected objects in objects_select if option choosen by user
 
163
if selection_mode==1:
 
164
        objects_select= [ob.name for ob in scene.objects.context]
 
165
else:
 
166
        objects_select= []
 
167
        
 
168
 
 
169
try:
 
170
        if handle_mode==1:
 
171
                DrawPart="#SPACEHANDLER.VIEW3D.DRAW\n"
 
172
        else:
 
173
                DrawPart="#!BPY\n"
 
174
except:DrawPart="#BadlyMade"
 
175
        
 
176
 
 
177
#Here is the script to write in Blender and to link, options are also written now
 
178
DrawPart=DrawPart+"#"+str(__version__)+"""
 
179
#This script is a part of Trajectory.py and have to be linked to the scene in Redraw if not in HANDLER mode.
 
180
#Author : 3R - Regis Montoya
 
181
#It's better to use the Trajectory_"version_number".py
 
182
#You can modify the two following value to change the path settings
 
183
future="""+str(future)+"""
 
184
past="""+str(past)+"""
 
185
object_init_names="""+str(objects_select)+"""
 
186
 
 
187
 
 
188
import Blender, math
 
189
from Blender import BGL, Draw, Ipo
 
190
from Blender.BGL import *
 
191
from Blender.Draw import *
 
192
from math import *
 
193
 
 
194
from Blender.Mathutils import Vector
 
195
 
 
196
#take actual frame
 
197
frameC=Blender.Get('curframe')
 
198
scene = Blender.Scene.GetCurrent()
 
199
render_context=scene.getRenderingContext()
 
200
#ajust number of frames with NewMap and OldMapvalue values
 
201
k=1.00*render_context.oldMapValue()/render_context.newMapValue()
 
202
if k<1:
 
203
        tr=-1*int(log(k*0.1, 10))
 
204
else:
 
205
        tr=-1*int(log(k, 10))
 
206
#The real and integer frame to compare to ipos keys frames
 
207
frameCtr=round(frameC*k, tr)
 
208
frameCr=frameC*k
 
209
frameC=int(round(frameC*k, 0))
 
210
 
 
211
 
 
212
#List objects that we have to show trajectory in $objects
 
213
# In this case, using a dict for unique objects is the fastest way.
 
214
object_dict= dict([(ob.name, ob) for ob in scene.objects.context])
 
215
for obname in object_init_names:
 
216
        if not object_dict.has_key(obname):
 
217
                try: # Object may be removed.
 
218
                        object_dict[obname]= Blender.Object.Get(obname)
 
219
                except:
 
220
                        pass # object was removed.
 
221
 
 
222
#This fonction give the resulting matrix of all parents at a given frame
 
223
#parent_list is the list of all parents [object, matrix, locX_ipo, locY, Z, rotX, Y, Z, sizeX, Y, Z] of current object
 
224
def matrixForTraj(frame, parent_list):
 
225
        DecMatC=Blender.Mathutils.Matrix([1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1])
 
226
 
 
227
        for parent_data in parent_list:
 
228
                parent_ob=      parent_data[0]
 
229
                
 
230
                try:    X=      parent_data[5][frame]*pi/18
 
231
                except: X=      parent_ob.RotX
 
232
                try:    Y=      parent_data[6][frame]*pi/18
 
233
                except: Y=      parent_ob.RotY
 
234
                try:    Z=      parent_data[7][frame]*pi/18
 
235
                except: Z=      parent_ob.RotZ
 
236
                try:    LX=     parent_data[2][frame]
 
237
                except: LX=     parent_ob.LocX
 
238
                try:    LY=     parent_data[3][frame]
 
239
                except: LY=     parent_ob.LocY
 
240
                try:    LZ=     parent_data[4][frame]
 
241
                except: LZ=     parent_ob.LocZ
 
242
                try:    SX=     parent_data[8][frame]
 
243
                except: SX=     parent_ob.SizeX
 
244
                try:    SY=     parent_data[9][frame]
 
245
                except: SY=     parent_ob.SizeY
 
246
                try:    SZ=     parent_data[10][frame]
 
247
                except: SZ=     parent_ob.SizeZ
 
248
 
 
249
                NMat=Blender.Mathutils.Matrix([cos(Y)*cos(Z)*SX,SX*cos(Y)*sin(Z),-SX*sin(Y),0],
 
250
                [(-cos(X)*sin(Z)+sin(Y)*sin(X)*cos(Z))*SY,(sin(X)*sin(Y)*sin(Z)+cos(X)*cos(Z))*SY,sin(X)*cos(Y)*SY,0],
 
251
                [(cos(X)*sin(Y)*cos(Z)+sin(X)*sin(Z))*SZ,(cos(X)*sin(Y)*sin(Z)-sin(X)*cos(Z))*SZ,SZ*cos(X)*cos(Y),0],
 
252
                [LX,LY,LZ,1])
 
253
                DecMatC=DecMatC*parent_data[1]*NMat
 
254
        return DecMatC
 
255
 
 
256
#####
 
257
TestLIST=[]
 
258
matview=Blender.Window.GetPerspMatrix()
 
259
###########
 
260
#Fonction to draw trajectories
 
261
###########
 
262
 
 
263
def Trace_Traj(ob):
 
264
                global TestLIST, matview
 
265
                #we draw trajectories for all objects in list
 
266
        
 
267
                LocX=[]
 
268
                LocY=[]
 
269
                LocZ=[]
 
270
                #List with trajectories' vertexs
 
271
                vertexX=[]
 
272
                
 
273
                contextIpo= ob.ipo
 
274
                if contextIpo:
 
275
                        ipoLocX=contextIpo[Ipo.OB_LOCX]
 
276
                        ipoLocY=contextIpo[Ipo.OB_LOCY]
 
277
                        ipoLocZ=contextIpo[Ipo.OB_LOCZ]
 
278
                        ipoTime=contextIpo[Ipo.OB_TIME]
 
279
                else: # only do if there is no IPO (if no ipo curves : return None object and don't go in this except)
 
280
                        ipoLocX= ipoLocY= ipoLocZ= ipoTime= None
 
281
                
 
282
                if ipoTime:
 
283
                        return 0
 
284
                
 
285
                #Get all parents of ob
 
286
                parent=ob.parent
 
287
                backup_ob= ob
 
288
                child= ob
 
289
                parent_list= []
 
290
                
 
291
                #Get parents's infos :
 
292
                #list of [name, initial matrix at make parent, ipo in X,Y,Z,rotX,rotY,rotZ,sizeX,Y,Z]
 
293
                while parent:
 
294
                        Init_Mat=Blender.Mathutils.Matrix(child.getMatrix('worldspace')) #must be done like it (it isn't a matrix otherwise)
 
295
                        Init_Mat.invert()
 
296
                        Init_Mat=Init_Mat*child.getMatrix('localspace')
 
297
                        Init_Mat=parent.getMatrix()*Init_Mat
 
298
                        Init_Mat.invert()
 
299
        
 
300
                        contextIpo= parent.ipo # None or IPO
 
301
                        if contextIpo:
 
302
                                ipo_Parent_LocX=contextIpo[Ipo.OB_LOCX]
 
303
                                ipo_Parent_LocY=contextIpo[Ipo.OB_LOCY]
 
304
                                ipo_Parent_LocZ=contextIpo[Ipo.OB_LOCZ]
 
305
                                ipo_Parent_RotX=contextIpo[Ipo.OB_ROTX]
 
306
                                ipo_Parent_RotY=contextIpo[Ipo.OB_ROTY]
 
307
                                ipo_Parent_RotZ=contextIpo[Ipo.OB_ROTZ]
 
308
                                ipo_Parent_SizeX=contextIpo[Ipo.OB_SIZEX]
 
309
                                ipo_Parent_SizeY=contextIpo[Ipo.OB_SIZEY]
 
310
                                ipo_Parent_SizeZ=contextIpo[Ipo.OB_SIZEZ]
 
311
                        else:
 
312
                                ipo_Parent_LocX=ipo_Parent_LocY=ipo_Parent_LocZ=\
 
313
                                ipo_Parent_RotX=ipo_Parent_RotY=ipo_Parent_RotZ=\
 
314
                                ipo_Parent_SizeX=ipo_Parent_SizeY=ipo_Parent_SizeZ= None
 
315
                        
 
316
                        parent_list.append([parent, Init_Mat, ipo_Parent_LocX, ipo_Parent_LocY, ipo_Parent_LocZ, ipo_Parent_RotX, ipo_Parent_RotY, ipo_Parent_RotZ, ipo_Parent_SizeX, ipo_Parent_SizeY, ipo_Parent_SizeZ])
 
317
        
 
318
                        child=parent
 
319
                        parent=parent.parent
 
320
                        
 
321
                #security : if one of parents object are a path>>follow : trajectory don't work properly so it have to draw nothing
 
322
                for parent in parent_list:
 
323
                        if parent[0].type == 'Curve':
 
324
                                if parent[0].data.flag & 1<<4: # Follow path, 4th bit
 
325
                                        return 1
 
326
                
 
327
                #ob >> re-assign obj and not parent
 
328
                ob= backup_ob
 
329
                ob= backup_ob
 
330
                
 
331
                
 
332
                if ipoLocX: LXC= ipoLocX[frameC]
 
333
                else:           LXC= ob.LocX
 
334
                if ipoLocY:     LYC= ipoLocY[frameC]
 
335
                else:           LYC= ob.LocY
 
336
                if ipoLocZ:     LZC= ipoLocZ[frameC]
 
337
                else:           LZC= ob.LocZ
 
338
 
 
339
                vect= Vector([ob.LocX, ob.LocY, ob.LocZ, 1])
 
340
                color=[0, 1]    
 
341
        
 
342
                #If trajectory is being modified and we are at a frame where a ipo key already exist
 
343
                if round(ob.LocX, 5)!=round(LXC, 5):
 
344
                        for bez in ipoLocX.bezierPoints:
 
345
                                if round(bez.pt[0], tr)==frameCtr:
 
346
                                        bez.pt = [frameCr, vect[0]]
 
347
                        ipoLocX.recalc()
 
348
                if round(ob.LocY, 5)!=round(LYC, 5):
 
349
                        for bez in ipoLocY.bezierPoints:
 
350
                                if round(bez.pt[0], tr)==frameCtr:
 
351
                                        bez.pt = [frameCr, vect[1]]
 
352
                        ipoLocY.recalc()
 
353
                if round(ob.LocZ, 5)!=round(LZC, 5):
 
354
                        for bez in ipoLocZ.bezierPoints:
 
355
                                if round(bez.pt[0], tr)==frameCtr:
 
356
                                        bez.pt = [frameCr, vect[2]]
 
357
                        ipoLocZ.recalc()
 
358
                
 
359
                #change trajectory color if at an ipoKey
 
360
                VertexFrame=[]
 
361
                bezier_Coord=0
 
362
                if ipoLocX: # FIXED like others it was just in case ipoLocX==None
 
363
                        for bez in ipoLocX.bezierPoints:
 
364
                                bezier_Coord=round(bez.pt[0], tr)
 
365
                                if bezier_Coord not in VertexFrame:
 
366
                                        VertexFrame.append(bezier_Coord)
 
367
                                if bezier_Coord==frameCtr:
 
368
                                                color=[1, color[1]-0.3]
 
369
                if ipoLocY: # FIXED
 
370
                        for bez in ipoLocY.bezierPoints:
 
371
                                bezier_Coord=round(bez.pt[0], tr)
 
372
                                if bezier_Coord not in VertexFrame:
 
373
                                        VertexFrame.append(bezier_Coord)
 
374
                                if round(bez.pt[0], tr)==frameCtr:
 
375
                                                color=[1, color[1]-0.3]
 
376
                if ipoLocZ: # FIXED
 
377
                        for bez in ipoLocZ.bezierPoints:
 
378
                                bezier_Coord=round(bez.pt[0], tr)
 
379
                                if bezier_Coord not in VertexFrame:
 
380
                                        VertexFrame.append(bezier_Coord)
 
381
                                if round(bez.pt[0], tr)==frameCtr:
 
382
                                                color=[1, color[1]-0.3]
 
383
                
 
384
        
 
385
                #put in LocX, LocY and LocZ all points of trajectory
 
386
                for frame in xrange(frameC-past, frameC+future):
 
387
                        DecMat=matrixForTraj(frame, parent_list)
 
388
 
 
389
                        if ipoLocX: LX= ipoLocX[frame]
 
390
                        else:           LX= ob.LocX
 
391
                        if ipoLocY:     LY= ipoLocY[frame]
 
392
                        else:           LY= ob.LocY
 
393
                        if ipoLocZ:     LZ= ipoLocZ[frame]
 
394
                        else:           LZ= ob.LocZ
 
395
                        
 
396
                        vect=Vector(LX, LY, LZ)*DecMat
 
397
                        LocX.append(vect[0])
 
398
                        LocY.append(vect[1])
 
399
                        LocZ.append(vect[2])
 
400
        
 
401
                
 
402
                #draw part : get current view
 
403
                MatPreBuff= [matview[i][j] for i in xrange(4) for j in xrange(4)]
 
404
                        
 
405
                MatBuff=BGL.Buffer(GL_FLOAT, 16, MatPreBuff)
 
406
                
 
407
                glLoadIdentity()
 
408
                glMatrixMode(GL_PROJECTION)
 
409
                glPushMatrix()
 
410
                glLoadMatrixf(MatBuff)
 
411
                
 
412
                #draw trajectory line
 
413
                glLineWidth("""+str(width)+""")
 
414
                
 
415
                glBegin(GL_LINE_STRIP)
 
416
                for i in xrange(len(LocX)):
 
417
                        glColor3f((i+1)*1.00/len(LocX)*color[0], 0, (i+1)*1.00/len(LocX)*color[1])
 
418
                        glVertex3f(LocX[i], LocY[i], LocZ[i])
 
419
                
 
420
                glEnd() 
 
421
                
 
422
                #draw trajectory's "vertexs"
 
423
                if not Blender.Window.EditMode():
 
424
                        glPointSize(5)
 
425
                        glBegin(GL_POINTS)
 
426
                        TestPOINTS=[]
 
427
                        TestFRAME=[]
 
428
                        i=0
 
429
                        for frame in VertexFrame:
 
430
                                ix=int(frame)-frameC+past
 
431
                                if ix>=0 and ix<len(LocX):
 
432
                                        glColor3f(1, 0.7, 0.2)
 
433
                                        glVertex3f(LocX[ix], LocY[ix], LocZ[ix])
 
434
                                        TestPOINTS.append(Vector([LocX[ix], LocY[ix], LocZ[ix], 1]))
 
435
                                        TestFRAME.append(int(frame))
 
436
                                        i+=1
 
437
                        glEnd()
 
438
                        #this list contains info about where to check if we click over a "vertex" in 3D view
 
439
                        TestLIST.append((ob, TestPOINTS, TestFRAME))
 
440
                
 
441
                glLineWidth(1)
 
442
                return 0
 
443
 
 
444
 
 
445
for ob in object_dict.itervalues():
 
446
        Trace_Traj(ob)
 
447
 
 
448
###########
 
449
#Fonction to handle trajectories
 
450
###########
 
451
 
 
452
def Manip():
 
453
        #use TestLIST and matview defined by Trace_Traj
 
454
        global TestLIST, matview
 
455
        for screen in Blender.Window.GetScreenInfo(Blender.Window.Types.VIEW3D):
 
456
                if screen['id']==Blender.Window.GetAreaID():
 
457
                        x0, y0, x1, y1= screen['vertices']
 
458
                        break
 
459
        
 
460
        #Projection of GL matrix in 3D view
 
461
        glPushMatrix()
 
462
        glMatrixMode(GL_PROJECTION)
 
463
        glPushMatrix()
 
464
        glLoadIdentity()
 
465
        #Global coordinates' matrix
 
466
        glOrtho(x0, x1, y0, y1, -1, 0)
 
467
        glMatrixMode(GL_MODELVIEW)
 
468
        glLoadIdentity()
 
469
        #Test mouse clics and other events
 
470
        
 
471
        
 
472
        if Blender.Window.QTest():
 
473
                evt, val= Blender.Window.QRead()
 
474
                if (evt==LEFTMOUSE or evt==RIGHTMOUSE) and not Blender.Window.EditMode():
 
475
                        mouse_co=Blender.Window.GetMouseCoords()
 
476
                        #if click on trajectory "vertexs"...
 
477
                        for ob, TestPOINTS, TestFRAME in TestLIST: # ob is now used, line 552 to know what object it had to select
 
478
                                for k, Vect in enumerate(TestPOINTS):
 
479
                                        proj=Vect*matview
 
480
                                        
 
481
                                        pt=[(proj[0]/proj[3])*(x1-x0)/2+(x1+x0)/2, (proj[1]/proj[3])*(y1-y0)/2+(y1+y0)/2]
 
482
 
 
483
                                        if mouse_co[0]<pt[0]+4 and mouse_co[0]>pt[0]-4 and mouse_co[1]>pt[1]-4 and mouse_co[1]<pt[1]+4:
 
484
                                                if evt==LEFTMOUSE:
 
485
                                                        #remember current selected object
 
486
                                                        object_names=[obj.name for obj in Blender.Object.GetSelected()]
 
487
                                                        #this script allow to simulate a GKey, but I have to write a script
 
488
                                                        #another way would made a infinit redraw or don't allow to move object
 
489
                                                        #it auto unlink and delete itself
 
490
                                                        script=\"\"\"
 
491
import Blender
 
492
from Blender import Draw, Window
 
493
from Blender.Window import *
 
494
from Blender.Draw import *
 
495
 
 
496
from Blender.Mathutils import Vector
 
497
 
 
498
# The following code is a bit of a hack, it allows clicking on the points and dragging directly
 
499
#It simulate user press GKey 
 
500
#It also set the cursor position at center (because user have previously clic on area and moved the cursor): 
 
501
#And I can't get previous cursor position : redraw appear after it has been moved
 
502
#If there is no better way you can remove this comments
 
503
f= GetAreaID()
 
504
SetCursorPos(0,0,0)
 
505
#SetKeyQualifiers(1) #FIXED : the bug in older versions seems to have been fixed
 
506
SetKeyQualifiers(0)
 
507
QAdd(f, Blender.Draw.GKEY, 1, 0)
 
508
QHandle(f)
 
509
Blender.Redraw()
 
510
done=0
 
511
while not done:
 
512
        while Blender.Window.QTest():
 
513
                ev=Blender.Window.QRead()[0]
 
514
                if ev not in (4, 5, 18, 112, 213): #all event needed to move object
 
515
                        #SetKeyQualifiers(1) #FIXED too, same reason that above
 
516
                        #SetKeyQualifiers(0)
 
517
                        SetKeyQualifiers(Blender.Window.GetKeyQualifiers())
 
518
                        QAdd(f, ev, 1, 0)
 
519
                        QHandle(f)
 
520
                        Blender.Redraw()
 
521
                if ev in (RIGHTMOUSE, LEFTMOUSE, ESCKEY):
 
522
                        done=1
 
523
Blender.Set('curframe',\"\"\"+str(Blender.Get('curframe'))+\"\"\")
 
524
Blender.Object.GetSelected()[0].sel= False
 
525
for obname in \"\"\"+str(object_names)+\"\"\":
 
526
        ob=Blender.Object.Get(obname)
 
527
        ob.sel= True
 
528
SetCursorPos(0,0,0)
 
529
scripting=Blender.Text.Get('Edit_Trajectory')
 
530
scripting.clear()
 
531
Blender.Text.unlink(scripting)
 
532
                                                \"\"\"
 
533
                                                        
 
534
                                                        #FIXED Edit_Trajectory was longer : all SetKeyQualifiers removed
 
535
                                                        scene=Blender.Scene.GetCurrent()
 
536
                                                        try:
 
537
                                                                scripting=Blender.Text.Get('Edit_Trajectory')
 
538
                                                                scripting.clear()
 
539
                                                        except:
 
540
                                                                scripting=Blender.Text.New('Edit_Trajectory')
 
541
                                                        
 
542
                                                        scripting.write(script)
 
543
                                                        #script= scripting #FIXED seems not needed anymore
 
544
                                                        
 
545
                                                        #Go to frame that correspond to selected "vertex"
 
546
                                                        Blender.Set('curframe', TestFRAME[k])
 
547
                                                        
 
548
                                                        scene.objects.selected = [] #un select all objects
 
549
                                                        
 
550
                                                        #FIXED TestLIST[j][0].sel=0, but no j. So ob.sel and above variable changed in obj
 
551
                                                        ob.sel= True
 
552
                                                        Blender.Run('Edit_Trajectory')
 
553
                                                
 
554
                                                #work well now !!!
 
555
                                                if evt==RIGHTMOUSE :
 
556
                                                        Blender.Set('curframe', TestFRAME[k])
 
557
 
 
558
Manip()
 
559
#retrieve a normal matrix
 
560
glPopMatrix()
 
561
glMatrixMode(GL_PROJECTION)
 
562
glPopMatrix()
 
563
glMatrixMode(GL_MODELVIEW)
 
564
"""
 
565
 
 
566
if ask_modif==0:
 
567
        text_remove('Trajectory')
 
568
        write_script('Trajectory', DrawPart)
 
569
        if handle_mode==1:
 
570
                Blender.UpdateMenus()
 
571
        else:
 
572
                link_script('Trajectory', 'Redraw')
 
573
if ask_modif==2:
 
574
        text_remove('Trajectory')
 
575
        print("---End of Trajectory_"+str(__version__)+".py---\n---   Thanks for use   ---")