You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
localmodelLoader=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)whilenotmodelLoader.finisheddoActions.waitForRedraw()
end-- remove your spinny herereturnmodelLoader.nodeend
The 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.
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.
The text was updated successfully, but these errors were encountered:
This is one rough approximation of how the modelloader might look. Not 100% sure that the semaphore trick I do is valid - plain old mutexes and a flag is probably safer.
classModelLoader;
namespace {
classModelLoadFunctor {
public:ModelLoadFunctor(std::string const& fn, ModelLoader & l) : _fn(fn), _loader(l) {}
voidoperator()() {
osg::ref_ptr<osg::Object> obj = osgDB::readObjectFile( bla bla bla make it fully load here)
if (obj) {
l.reportSuccess(obj);
} else {
l.reportFailure();
}
}
private:
std::string _fn;
ModelLoader & l;
};
} // end of namespaceclassModelLoader {
public:ModelLoader(std::string const& fn)
: _objProtection(0) // start with resource "unavailable", aka initially held by the functor
, _obj() {
// Spawn and run thread
thread.reset(newvpr::Thread(ModelLoadFunctor(fn, *this)));
}
/// bind this oneboolisFinished() {
vpr::Guard<vpr::Semaphore> myGuard(_objProtection, false/*don't block */);
// If we got it, then the thread is done.return myGuard.locked();
}
/// bind this one too
osg::ref_ptr<osg::Object> getObject() {
vpr::Guard<vpr::Semaphore> myGuard(_objProtection, false/*don't block */);
// If we got it, then the thread is done.if (myGuard.locked()) {
return _obj;
}
// return null pointer if thread isn't donereturn osg::ref_ptr<osg::Object>();
}
private:friendclassModelLoadFunctor;
voidreportSuccess(osg::ref_ptr<osg::Object> o) {
_obj = o;
_objProtection.release();
}
voidreportFailure() {
_objProtection.release();
}
vpr::Semaphore _objProtection;
osg::ref_ptr<osg::Object> _obj;
};
(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.
The 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.
Interface 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.
The text was updated successfully, but these errors were encountered: