|
本帖最后由 wangxiao358 于 2011-4-6 16:54 编辑
osg 运行中按下某个键,添加一个节点
_root->addChild(osgDB::readNodeFile("dx.IVE"));
这个ive 比较大 动动鼠标窗口就 没有响应 了。我又写了个线程还是卡那哦 各位帮我看看哈 。
class TestThread : public OpenThreads::Thread
{
public:
TestThread(osg::Group* root) : _done(false), _count(0),_root(root) {}
~TestThread() { cancel(); }
void block() { _operator.block(); }
virtual int cancel()
{
_operator.release();
_done = true;
while( isRunning() )
OpenThreads::Thread::YieldCurrentThread();
return 0;
}
virtual void run()
{
_root->addChild(osgDB::readNodeFile("[url=]dx.IVE[/url]"));
_operator.release();
_operator.reset();
_operator.block();
}
protected:
bool _done;
unsigned long _count;
OpenThreads::Block _operator;
osg::Group* _root;
};
//事件响应
class InsertModel : public osgGA::GUIEventHandler
{
public:
InsertModel(){}
~InsertModel(void){}
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
{
switch(ea.getEventType())
{
case(osgGA::GUIEventAdapter::KEYDOWN):
{
osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
if (!viewer)
{
return false;
}
osg::Group* root = dynamic_cast<osg::Group*>(viewer->getSceneData());
if(!root) return false;
TestThread ttread(root);
ttread.start();
ttread.block();
}
return false;
default:
return false;
}
}
}; |
|