-
Notifications
You must be signed in to change notification settings - Fork 0
/
transitionEffects.lua
101 lines (84 loc) · 2.88 KB
/
transitionEffects.lua
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
Transition_Effects = {
shrink = function(node,duration)
local duration = duration or 4
if duration <= 0 then duration = 4 end
local scaleRate = 1 / duration
Actions.addFrameAction(
function()
while duration > 0 do
local scale = duration * scaleRate
node:setScale(osg.Vec3d(scale,scale,scale))
duration = duration - Actions.waitForRedraw()
end
end
)
end,
unshrink = function(node,duration,endsize)
local duration = duration or 4
if duration <= 0 then duration = 4 end
local scaleRate = 1 / duration
Actions.addFrameAction(
function()
while duration > 0 do
local scale = 1-(duration * scaleRate)
node:setScale(osg.Vec3d(scale,scale,scale))
duration = duration - Actions.waitForRedraw()
end
end
)
end,
fadein = function(node,duration)
local CONSTANT_ALPHA = 0x8003
local ONE_MINUS_CONSTANT_ALPHA = 0x8004
local duration = duration or 4
if duration <= 0 then duration = 4 end
local state = node:getOrCreateStateSet()
state:setRenderingHint(2) -- transparent bin
local bf = osg.BlendFunc()
bf:setFunction(CONSTANT_ALPHA, ONE_MINUS_CONSTANT_ALPHA)
state:setAttributeAndModes(bf)
local transparencyRate = 1 / duration
local bc = osg.BlendColor(osg.Vec4(1.0, 1.0, 1.0, 1.0))
state:setAttributeAndModes(bc)
--this one is a frame action (its own thread action) because the node is already showing (switch) - visible
Actions.addFrameAction(
function()
while duration > 0 do
bc:setConstantColor(osg.Vec4(1.0, 1.0, 1.0, 1-(duration * transparencyRate)))
state:setAttributeAndModes(bc)
duration = duration - Actions.waitForRedraw()
end
state:setAttributeAndModes(osg.BlendFunc())
end
)
end,
fadeout = function(node,duration)
local CONSTANT_ALPHA = 0x8003
local ONE_MINUS_CONSTANT_ALPHA = 0x8004
local duration = duration or 4
if duration <= 0 then duration = 4 end
local state = node:getOrCreateStateSet()
state:setRenderingHint(2) -- transparent bin
local bf = osg.BlendFunc()
bf:setFunction(CONSTANT_ALPHA, ONE_MINUS_CONSTANT_ALPHA)
state:setAttributeAndModes(bf)
local transparencyRate = 1 / duration
local bc = osg.BlendColor(osg.Vec4(1.0, 1.0, 1.0, 1.0))
state:setAttributeAndModes(bc)
--not adding as frame action above - we need this one to wait (not start its own thread action)
while duration > 0 do
bc:setConstantColor(osg.Vec4(1.0, 1.0, 1.0, duration * transparencyRate))
state:setAttributeAndModes(bc)
duration = duration - Actions.waitForRedraw()
end
--state:setAttributeAndModes(osg.BlendFunc())
end,
fadeAllOut = function(xform)
Transition_Effects.shrink(xform,.5)
Transition_Effects.fadeout(xform,.25)
end,
fadeAllIn = function(xform)
Transition_Effects.fadein(xform,.5)
Transition_Effects.unshrink(xform,.25)
end,
}