mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-12 14:29:42 -05:00
Feature/slide deck (#636)
* Implement basic slide deck helper and example
This commit is contained in:
committed by
Alexander Bock
parent
23a3bca304
commit
8b91c67010
@@ -0,0 +1,35 @@
|
||||
local helper = asset.require('util/slidedeck_helper')
|
||||
local deck = nil
|
||||
|
||||
asset.onInitialize(function ()
|
||||
deck = helper.createDeck("example", {
|
||||
FlatScreen = false,
|
||||
SphericalPosition = {0.0, 3.1415 / 2},
|
||||
Scale = 0.7
|
||||
})
|
||||
|
||||
helper.addSlide(deck, "${DATA}/test2.jpg")
|
||||
helper.addSlide(deck, "${DATA}/test3.jpg")
|
||||
|
||||
local interpolationDuration = 0
|
||||
|
||||
function nextSlide()
|
||||
helper.goToNextSlide(deck, interpolationDuration)
|
||||
end
|
||||
|
||||
function previousSlide()
|
||||
helper.goToPreviousSlide(deck, interpolationDuration)
|
||||
end
|
||||
|
||||
helper.setCurrentSlide(deck, 1)
|
||||
openspace.bindKey("RIGHT", "nextSlide()")
|
||||
openspace.bindKey("LEFT", "previousSlide()")
|
||||
|
||||
end)
|
||||
|
||||
|
||||
asset.onDeinitialize(function()
|
||||
openspace.clearKey("RIGHT")
|
||||
openspace.clearKey("LEFT")
|
||||
helper.removeDeck(deck)
|
||||
end)
|
||||
@@ -0,0 +1,76 @@
|
||||
local createDeck = function (identifier, defaultRenderableProperties)
|
||||
return {
|
||||
SlideIdentifiers = {},
|
||||
IdentifierPrefix = identifier,
|
||||
CurrentSlideIndex = 1,
|
||||
DefaultRenderableProperties = defaultRenderableProperties,
|
||||
}
|
||||
end
|
||||
|
||||
local removeDeck = function (deck)
|
||||
for i, identifier in pairs(deck.SlideIdentifiers) do
|
||||
openspace.removeScreenSpaceRenderable(identifier)
|
||||
end
|
||||
end
|
||||
|
||||
local addSlide = function (deck, path)
|
||||
local index = #deck.SlideIdentifiers + 1
|
||||
local identifier = deck.IdentifierPrefix .. index
|
||||
|
||||
local spec = {
|
||||
Type = "ScreenSpaceImageLocal",
|
||||
Identifier = identifier,
|
||||
Name = identifier,
|
||||
TexturePath = path
|
||||
};
|
||||
|
||||
for key, value in pairs(deck.DefaultRenderableProperties) do
|
||||
spec[key] = value
|
||||
end
|
||||
|
||||
openspace.addScreenSpaceRenderable(spec)
|
||||
|
||||
deck.SlideIdentifiers[#deck.SlideIdentifiers + 1] = identifier
|
||||
end
|
||||
|
||||
|
||||
local setCurrentSlide = function (deck, index, interpolationDuration)
|
||||
if (interpolationDuration == nil) then
|
||||
interpolationDuration = 0
|
||||
end
|
||||
|
||||
if (index < 0) then
|
||||
index = 0
|
||||
end
|
||||
|
||||
if (index > #deck.SlideIdentifiers + 1) then
|
||||
index = #deck.SlideIdentifiers + 1
|
||||
end
|
||||
|
||||
deck.CurrentSlideIndex = index
|
||||
|
||||
for i, identifier in pairs(deck.SlideIdentifiers) do
|
||||
local opacity = 0
|
||||
if (index == i) then
|
||||
opacity = 1
|
||||
end
|
||||
openspace.setPropertyValueSingle(
|
||||
"ScreenSpace." .. identifier .. ".Alpha", opacity,
|
||||
interpolationDuration)
|
||||
end
|
||||
end
|
||||
|
||||
local goToNextSlide = function (deck, interpolationDuration)
|
||||
setCurrentSlide(deck, deck.CurrentSlideIndex + 1, interpolationDuration)
|
||||
end
|
||||
|
||||
local goToPreviousSlide = function (deck, interpolationDuration)
|
||||
setCurrentSlide(deck, deck.CurrentSlideIndex - 1, interpolationDuration)
|
||||
end
|
||||
|
||||
asset.export('createDeck', createDeck)
|
||||
asset.export('removeDeck', removeDeck)
|
||||
asset.export('addSlide', addSlide)
|
||||
asset.export('setCurrentSlide', setCurrentSlide)
|
||||
asset.export('goToNextSlide', goToNextSlide)
|
||||
asset.export('goToPreviousSlide', goToPreviousSlide)
|
||||
Reference in New Issue
Block a user