Skip to content

Instantly share code, notes, and snippets.

@smakhtin
Created June 14, 2012 15:45
Show Gist options
  • Save smakhtin/2931072 to your computer and use it in GitHub Desktop.
Save smakhtin/2931072 to your computer and use it in GitHub Desktop.
DFusion scene controller
-- Test
-- Tracking variables
local trackingIndex = -1
local trackingKeyFrameIndex = -1
local MLTPlugin = getMLTPluginManager()
local errorStatus = eOk
--Core variables
local scene = getCurrentScene()
local camera = Camera(scene:getCurrentCamera())
local videoCapture_live = VideoCapture(scene:getObjectByName("videocapture_live"))
local videoMaterial = getMaterial("ti_plan/plan_mat")
local trackingPosition = Vector3()
local trackingOrientation = Quaternion()
local animatedObjects = {}
local secuences = {}
local texturesCount = {2, 4, 6, 8, 25, 16}
local timeForFrame = 1 / 30
local sequenceStartTime = -1;
local currentTrackingObject = -1;
local debugText = Text2D(scene:getObjectByName("DebugText"))
debugText:setVisible(true)
function FillSecuences()
for i=1,6 do
local textures = {}
CreateTextures(textures, "./sequence" .. i .. "/", texturesCount[i])
end
end
function CreateTextures(array, folder, count)
for i=1,count do
array[i] = Texture(scene:createObject(CID_TEXTURE))
array[i]:setResource("./MoyBank/image_" .. i .. ".png")
end
end
function GetAllObjects()
for i=1,6 do
animatedObjects[i] = Scenette(scene:getObjectByName("AnimatedObject" .. i))
end
end
-- Setup
function Setup()
GetAllObjects()
FillSecuences()
end
function TrackMarkers()
for i=1,6 do
local trackingStatus = 0
errorStatus, trackingStatus = MLTPlugin:getTargetStatus(trackingIndex, i - 1)
errorStatus, trackingKeyFrameIndex = MLTPlugin:getRecognizedKeyFrameIndex(trackingIndex, i - 1)
if(trackingStatus == 1) then
currentTrackingObject = i
break
end
end
currentTrackingObject = -1
end
function PlaySequence()
local currentTime = scene:getTime()
if (sequenceStartTime < 0) then sequenceStartTime = currentTime end
local currentFrame = (currentTime - sequenceStartTime) / timeForFrame + 1
videoMaterial:setTexture(secuences[currentTrackingObject][currentFrame])
end
--Update data
function Update()
TrackMarkers()
if(currentTrackingObject < 0) then return end
MLTPlugin:getTargetPos(trackingIndex, currentTrackingObject - 1, trackingPosition, trackingOrientation)
local trackingObject = Scenette(animatedObjects[currentTrackingObject])
trackingObject:setPosition(trackingPosition, camera)
trackingObject:setOrientation(trackingOrientation, camera)
local animation = trackingObject:getAmimation(0)
animation:play(0)
if not trackingObject:getVisible() then trackingObject:setVisible(true) end
if animation:hasEnded() then PlaySequence() end
end
errorStatus, trackingIndex = MLTPlugin:startTracking("tracking/tracker.xml", videoCapture_live:getVidCapID(), camera)
if errorStatus == eOk then
-- Main Loop
repeat
Update()
until coroutine.yield()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment