-
Notifications
You must be signed in to change notification settings - Fork 12
Description
(Happy to help on this one)
There are two approaches, as far as I can tell, but you can conveniently use the same C++ code to do both. Here are the two lua functions:
This first one requires that the caller be in a frame action, but blocks that particular action while the spinning takes place until loading is complete.
hugemodel = function(fn)
local modelLoader = vrjLua.ModelLoader(fn)
-- Attach your spinny thing to some convenient place here - note that you'd have to do
-- this arbitrarily (RelativeTo.Room or something)
while not modelLoader.finished do
Actions.waitForRedraw()
end
-- remove your spinny here
return modelLoader.node
endThe second one does a swap behind the scenes: it returns a group node immediately, which initially has the spinner attached. It launches its own frame action to watch the model loader and replaces the spinner with the model when it's done.
backgroundModel = function(fn)
local modelLoader = vrjLua.ModelLoader(fn)
local temp = osg.Group()
local mySpinner = CreateSpinner()
temp:addChild(mySpinner)
Actions.createFrameAction(
function()
while not modelLoader.finished do
Actions.waitForRedraw()
end
temp:removeChild(mySpinner)
temp:addChild(modelLoader.node)
end
)
return temp
endInterface for vrjLua.ModelLoaderThread:
This would be a C++ class that starts a thread (vpr::Thread - pass a functor) and has two main members: an osg node and a bool (might be redundant?). The object owns the thread, and has appropriate thread-safety around the two members. The thread would load the file passing ReaderWriter::Options that result in the complete, blocking loading of the model - making this the thread that blocks instead of the draw thread. Upon completion, the thread would pass the node back to the model loader, set the flag (which might be redundant - a non-null pointer might work, although the load method returns a null pointer in case of failure), and exits.