Skip to content

Instantly share code, notes, and snippets.

@smakhtin
Created June 15, 2012 16:16
Show Gist options
  • Save smakhtin/2937350 to your computer and use it in GitHub Desktop.
Save smakhtin/2937350 to your computer and use it in GitHub Desktop.
DFusion Scene Controller Fixed
-- Test
-- Tracking variables
local trackingIndex = -1
trackingKeyFrameIndex = -1
trackingStatus = 0
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 = {101, 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 = {}
secuences[i] = textures
CreateTextures(textures, "./sequences/" .. 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(folder .. "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
Setup()
function TrackMarkers()
for i=1,6 do
errorStatus, trackingStatus = MLTPlugin:getTargetStatus(trackingIndex, i - 1)
errorStatus, trackingKeyFrameIndex = MLTPlugin:getRecognizedKeyFrameIndex(trackingIndex, i - 1)
if(trackingStatus == 1) then
--debugText:setText("MarkerFound")
currentTrackingObject = i
return
end
end
currentTrackingObject = -1
end
function PlaySequence()
debugText:setText("Sequence Started")
local currentTime = scene:getTime()
if (sequenceStartTime < 0) then sequenceStartTime = currentTime end
local currentFrame = math.floor((currentTime - sequenceStartTime) / timeForFrame) + 1
if(currentFrame > texturesCount[currentTrackingObject]) then
debugText:setText("Sequence finished")
return
end
debugText:setText(currentFrame)
videoMaterial:setTexture(secuences[currentTrackingObject][currentFrame])
debugText:setText(secuences[currentTrackingObject][currentFrame]:getWidth())
end
--Update data
function Update()
TrackMarkers()
debugText:setText("No Markers")
if(currentTrackingObject < 0) then return end
debugText:setText(currentTrackingObject)
MLTPlugin:getTargetPos(trackingIndex, currentTrackingObject - 1, trackingPosition, trackingOrientation)
local animatedObject = Scenette(animatedObjects[currentTrackingObject])
local objectAnimation = animatedObject:getAnimation(0)
if not objectAnimation:isPlaying() then
objectAnimation:play(0)
--objectAnimation:setLoop(true)
end
debugText:setText(objectAnimation:getTimePosition())
local trackingObject = Object3D(scene:getObjectByName("Tracking_Object" .. currentTrackingObject))
--debugText:setText(trackingObject:getName())
trackingObject:setPosition(trackingPosition, camera)
trackingObject:setOrientation(trackingOrientation, camera)
if not trackingObject:getVisible() then trackingObject:setVisible(true) end
if not animatedObject:getVisible() then animatedObject:setVisible(true) end
if objectAnimation: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