-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8_perspective_animation.py
220 lines (168 loc) · 7.59 KB
/
8_perspective_animation.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
"""
**Project Name:** MakeHuman
**Product Home Page:** http://www.makehuman.org/
**Code Home Page:** https://bitbucket.org/MakeHuman/makehuman/
**Authors:** Jonas Hauquier, punkduck
**Copyright(c):** MakeHuman Team 2001-2017
**Licensing:** AGPL3 (http://www.makehuman.org/doc/node/the_makehuman_application.html)
This file is part of MakeHuman (www.makehuman.org).
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**Coding Standards:** See http://www.makehuman.org/node/165
Abstract
--------
Experimental plugin based on 3_library_animation.py, which allows to show bvh files
frame by frame and is able to switch between orthogonal and perspective view.
"""
import mh
import gui
import gui3d
import log
from collections import OrderedDict
from core import G
import filechooser as fc
import skeleton
import getpath
import numpy as np
import os
class PerspectiveTaskView(gui3d.TaskView):
def __init__(self, category):
gui3d.TaskView.__init__(self, category, 'Perspective')
self.human = gui3d.app.selectedHuman
self.humanPos = [0.0, 0.0, 0.0]
self.currentframe = 0
self.framesloaded = 0
animbox = self.addLeftWidget(gui.GroupBox('Frames'))
self.avFramesText = animbox.addWidget(gui.TextView('Available frames: 0'))
self.playbackSlider = animbox.addWidget(gui.Slider(label=['Current frame', ': %d']))
self.playbackSlider.setMin(0)
@self.playbackSlider.mhEvent
def onChange(value):
self.currentframe = int(value)
self.updateFrame()
self.nextframeButton = animbox.addWidget(gui.Button('Next frame'))
@self.nextframeButton.mhEvent
def onClicked(event):
anim = self.human.getActiveAnimation()
if anim:
if self.currentframe >= anim.nFrames-1:
self.currentframe = 0
else:
self.currentframe += 1
self.updateFrame()
self.playbackSlider.setValue(self.currentframe)
self.prevframeButton = animbox.addWidget(gui.Button('Previous frame'))
@self.prevframeButton.mhEvent
def onClicked(event):
anim = self.human.getActiveAnimation()
if anim:
if self.currentframe <= 0:
self.currentframe = anim.nFrames-1
else:
self.currentframe -= 1
self.updateFrame()
self.playbackSlider.setValue(self.currentframe)
projbox = self.addLeftWidget(gui.GroupBox('Projection'))
self.projRadioButtonGroup = []
self.persButton = projbox.addWidget(gui.RadioButton(self.projRadioButtonGroup, 'Perspective',selected=G.app.modelCamera.projection))
@self.persButton.mhEvent
def onClicked(event):
G.app.guiCamera.projection = True
G.app.guiCamera.fixedRadius = True
G.app.modelCamera.projection = True
G.app.modelCamera.fixedRadius = True
if G.app.backgroundGradient:
G.app.removeObject(G.app.backgroundGradient)
G.app.backgroundGradient = None
# G.app.modelCamera.updateCamera()
self.orthButton = projbox.addWidget(gui.RadioButton(self.projRadioButtonGroup, 'Orthogonal',selected=not G.app.modelCamera.projection))
@self.orthButton.mhEvent
def onClicked(event):
G.app.guiCamera.projection = False
G.app.guiCamera.fixedRadius = False
G.app.modelCamera.projection = False
G.app.modelCamera.fixedRadius = False
G.app.loadBackgroundGradient()
# G.app.modelCamera.updateCamera()
self.fovslider = projbox.addWidget(gui.Slider(label=['Camera focus', '= %.2f'], min=25.0, max=130.0, value=90.0))
@self.fovslider.mhEvent
def onChange(value):
G.app.modelCamera.setFovAngle(value)
G.app.guiCamera.setFovAngle(value)
#G.app.modelCamera.updateCamera()
G.app.redraw()
posbox = self.addLeftWidget(gui.GroupBox('Position'))
self.xposslider = posbox.addWidget(gui.Slider(label=['X-position', '= %.2f'], min=-10.0, max=10.0, value=0.0))
@self.xposslider.mhEvent
def onChange(value):
self.humanPos[0] = value
G.app.selectedHuman.setPosition(self.humanPos)
self.updateFrame()
self.yposslider = posbox.addWidget(gui.Slider(label=['Y-position', '= %.2f'], min=-10.0, max=10.0, value=0.0))
@self.yposslider.mhEvent
def onChange(value):
self.humanPos[1] = value
G.app.selectedHuman.setPosition(self.humanPos)
self.updateFrame()
self.zposslider = posbox.addWidget(gui.Slider(label=['Z-position', '= %.2f'], min=-10.0, max=10.0, value=0.0))
@self.zposslider.mhEvent
def onChange(value):
self.humanPos[2] = value
G.app.selectedHuman.setPosition(self.humanPos)
self.updateFrame()
self.resetButton = posbox.addWidget(gui.Button('Reset position'))
@self.resetButton.mhEvent
def onClicked(event):
self.humanPos = [0.0, 0.0, 0.0]
self.xposslider.setValue (0.0)
self.yposslider.setValue (0.0)
self.zposslider.setValue (0.0)
G.app.selectedHuman.setPosition(self.humanPos)
self.updateFrame()
def updateFrame(self):
self.human.setToFrame(self.currentframe)
self.human.refreshPose()
def onShow(self, event):
self.currentframe = 0
gui3d.TaskView.onShow(self, event)
if gui3d.app.getSetting('cameraAutoZoom'):
gui3d.app.setGlobalCamera()
self.playbackSlider.setEnabled(False)
self.prevframeButton.setEnabled(False)
self.nextframeButton.setEnabled(False)
if self.human.getSkeleton():
if self.human.getActiveAnimation():
maxframes = self.human.getActiveAnimation().nFrames
if maxframes > 1:
self.avFramesText.setText('Available frames: ' + str(maxframes))
self.playbackSlider.setEnabled(True)
self.playbackSlider.setMax(maxframes -1)
self.prevframeButton.setEnabled(True)
self.nextframeButton.setEnabled(True)
self.playbackSlider.setValue(self.currentframe)
self.updateFrame()
elif maxframes == 1:
self.avFramesText.setText('Available frames: 1')
def onHide(self, event):
gui3d.TaskView.onHide(self, event)
def onHumanChanged(self, event):
human = event.human
if event.change == 'reset':
if self.isShown():
# Refresh onShow status
self.onShow(event)
def load(app):
category = app.getCategory('Community')
taskview = category.addTask(PerspectiveTaskView(category))
def unload(app):
pass