Going back and forth between production AR and working on our templates has the problem that objects are often moved and cameras set to some pretty weird values from camera tracking. so that when we want to go and work in layout mode on our projects, we have to keep resetting cameras and object positions in order to bring them into the viewport.
Since UX puts the scene we likely want to work on online on layer 0 on framebuffer 0, I wrote a script that attempts to get a a non-copy, actual reference to a template and set up the defined "StaticCamera" and "position" objects to give a reasonable default view.
'
' For non-production (debugging, building) work, takes the scene
' online on fb 0, layer 0, and sets the static camera and object
' position to make things visible.
'
dim ref as xpScene
dim scene as xpScene
dim camera as xpCameraObject
dim obj as xpBaseObject
dim fb as xpOutputFramebuffer
Engine.DebugMessage("Hello World.", MessageType.mt_Notify)
' Get the current online scene
if Engine.getOuptFrameBuffer(0, fb) then
if fb.getSceneOnLayer(0, ref) then
' Ok, now we have a REFERENCE to the scene, not the raw scene, so
' now ask for the real, non-copy scene from the engine
if Engine.getSceneByName(ref.Name, scene, False) then
' Get the object position and set it to zeros.
if scene.getObjectByName("position", obj) then
obj.setPosRotXYZ(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
obj.setScaleXYZ(1.0, 1.0, 1.0)
else
Engine.DebugMessage("Unable to get position object.", MessageType.mt_Error)
end if
' Get the camera object and set it back a little, and give it
' some other reasonable values.
if scene.getObjectByName("StaticCamera", camera) then
camera.useGlobalCamera = False
camera.setPosRotXYZ(0.0, 12.0, 36.0, 0.0, 0.0, 0.0)
camera.setCCDOffsets(0.0, 0.0)
camera.setCCDSize(0.0, 0.0)
camera.FOV = 45.0
scene.SetActiveCamera(camera)
else
Engine.DebugMessage("Unable to get static camera in this scene.", MessageType.mt_Error)
end if
else
Engine.DebugMessage("Unable to get actual non-copy scene.", MessageType.mt_Error)
end if
else
Engine.DebugMessage("Unable to get scene on layer 0.", MessageType.mt_Error)
end if
else
Engine.DebugMessage("Unable to get output FrameBuffer.", MessageType.mt_Error)
end if
Not knowing if I'm getting the scene from the framebuffer is giving me a copy or not, I explicitly request the same scene from the engine and request a non-copy (actual) reference to the scene.
So I know the script executes when I trigger the hot-key because the debug monitor shows "Hello World," but the rest doesn't seem to do anything - and it does NOT print any other messages, so the method functions calls must be returning "True."
EDIT: is there a way to figure out what template is active in layout mode? That would be much better.