forked from JMG1/ExplodedAssembly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCameraAnimation.py
110 lines (99 loc) · 5.3 KB
/
CameraAnimation.py
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
# -*- coding: utf-8 -*-
# Exploded Assembly Animation workbench for FreeCAD
# (c) 2016 Javier Martínez García
#***************************************************************************
#* (c) Javier Martínez García 2016 *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU General Public License (GPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* 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 Lesser General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with FreeCAD; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************/
from __future__ import division
import os
import time
import FreeCAD
import Part
from pivy import coin
"""
class AnimationCamera:
def __init__(self, obj):
obj.addProperty('App::PropertyBool', 'Enable')
obj.addProperty('App::PropertyString', 'RunFrom', 'Interval')
obj.addProperty('App::PropertyString', 'RunTo', 'Interval')
# edge trajectory
obj.addProperty('App::PropertyBool', 'EdgeTrajectory', 'Follow Edge')
obj.addProperty('App::PropertyString','ShapeName', 'Follow Edge')
obj.addProperty('App::PropertyFloat', 'EdgeNumber', 'Follow Edge')
# Manual trajectory
obj.addProperty('App::PropertyBool', 'ManualTrajectory', 'Manual trajectory')
obj.addProperty('App::PropertyVector', 'InitialCameraBase', 'Manual trajectory')
obj.addProperty('App::PropertyVector', 'InitialCameraLookPoint', 'Manual trajectory')
obj.addProperty('App::PropertyVector', 'FinalCameraBase', 'Manual trajectory')
obj.addProperty('App::PropertyVector', 'FinalCameraLookPoint', 'Manual trajectory')
obj.addProperty('App::PropertyStringList', 'TransitionMode', 'Manual trajectory').TransitionMode = 'Frame', 'Smooth'
# Attached trajectory
obj.addPropertyd
"""
class ManualAnimationCamera:
def __init__(self, obj):
obj.addProperty('App::PropertyBool', 'Enable', 'Enable Camera')
obj.addProperty('App::PropertyString', 'RunFrom', 'Interval')
obj.addProperty('App::PropertyString', 'RunTo', 'Interval')
obj.addProperty('App::PropertyVector', 'InitialCameraBase', 'Camera Position')
obj.addProperty('App::PropertyVector', 'FinalCameraBase', 'Camera Position')
obj.addProperty('App::PropertyVector', 'InitialCameraLookPoint', 'Camera Position')
obj.addProperty('App::PropertyVector', 'FinalCameraLookPoint', 'Camera Position')
obj.addProperty('App::PropertyEnumeration', 'Transition', 'Camera Transition').Transition = ['Sudden', 'Linear']
class ManualAnimationCameraViewProvider:
def __init__(self, obj):
obj.Proxy = self
def getIcon(self):
__dir__ = os.path.dirname(__file__)
return __dir__ + '/icons/AnimationCameraManual.svg'
def createManualCamera():
# retrieve selection
initial_obj = FreeCAD.Gui.Selection.getSelectionEx()[0].Object.Name
final_obj = FreeCAD.Gui.Selection.getSelectionEx()[1].Object.Name
EAFolder = FreeCAD.ActiveDocument.ExplodedAssembly
MCObj = FreeCAD.ActiveDocument.addObject('App::FeaturePython', 'ManualCamera')
ManualAnimationCamera(MCObj)
ManualAnimationCameraViewProvider(MCObj.ViewObject)
EAFolder.addObject(MCObj)
# add selection to camera from-to
MCObj.RunFrom = initial_obj
MCObj.RunTo = final_obj
# organize inside folder
FreeCAD.Gui.Selection.clearSelection()
FreeCAD.Gui.Selection.addSelection(MCObj)
FreeCAD.Gui.Selection.addSelection(EAFolder.Group[0])
from ExplodedAssembly import placeBeforeSelectedTrajectory
placeBeforeSelectedTrajectory()
FreeCAD.Console.PrintMessage('\nManual camera created\n')
"""from FreeCAD import Base
cam = FreeCADGui.ActiveDocument.ActiveView.getCameraNode()
trajectory = Gui.Selection.getSelectionEx()[0].Object.Shape.Edges
for edge in trajectory:
startPoint = edge.valueAt( 0.0 )
endPoint = edge.valueAt( edge.Length )
dirVector = ( endPoint - startPoint ).normalize()
currentPoint = startPoint
while (currentPoint - startPoint).Length < edge.Length:
currentPoint = currentPoint + dirVector
cam.position.setValue(currentPoint + Base.Vector( 0,0, 10) )
cam.pointAt( coin.SbVec3f( endPoint[0], endPoint[1], endPoint[2]+10) , coin.SbVec3f( 0, 0, 1 ) )
Gui.updateGui()
time.sleep(0.005)
"""