Hi all,

I still have problems with this. I modify the code of cookbook like this:


Code:

class RenderThread : public QThread
{
public:
    RenderThread() : QThread(), viewerPtr(0), _done(false)
        {
        }
    
    virtual ~RenderThread()
    { 
                if (viewerPtr) 
                        viewerPtr->setDone(true); 
                _done = true;
                wait(); 
        }

        QMutex* getMutex() { return &mutex; }
    
    osgViewer::Viewer* viewerPtr;
        bool _done;
        QWaitCondition condition;
        Qt::HANDLE id;

protected:
    virtual void run()
    { 
                id = QThread::currentThreadId();

                yieldCurrentThread();
                
                while( !_done ) 
                {
                        if(mutex.tryLock()){
                                if (viewerPtr)
                                        viewerPtr->frame();
                                mutex.unlock();
                                condition.wakeAll();
                        }
                        Sleep(10);
                }

                viewerPtr->setDone(true);
        }

        QMutex  mutex;
};

class ViewerWidget : public QWidget
{
public:
    ViewerWidget( osg::Camera* camera, osg::Node* scene )
    : QWidget()
    {
        _viewer.setCamera( camera );
        _viewer.setSceneData( scene );
       // _viewer.addEventHandler( new osgViewer::StatsHandler );
       // _viewer.setCameraManipulator( new osgGA::TrackballManipulator );
        _viewer.setThreadingModel( osgViewer::Viewer::SingleThreaded );
        
        osgQt::GraphicsWindowQt* gw = dynamic_cast<osgQt::GraphicsWindowQt*>( 
camera->getGraphicsContext() );
        if ( gw )
        {
            QVBoxLayout* layout = new QVBoxLayout;
            layout->addWidget( gw->getGLWidget() );
            setLayout( layout );
        }
        
        _thread.viewerPtr = &_viewer;
        _thread.start();
    }
        void stopRendering() { _thread._done = true; }
        bool isRendering() { return _thread.isRunning(); }
        osg::Matrix getCameraMatrix()
        {
                osg::Matrix mat;
                if( _thread.id != QThread::currentThreadId()){
            QMutexLocker locker( _thread.getMutex() );
        }
                mat = _viewer.getCamera()->getViewMatrix();

                return mat;
        }
        void setCameraMatrix(osg::Matrix mat)
        {
                if( _thread.id != QThread::currentThreadId()){
            QMutexLocker locker( _thread.getMutex() );
        }
                _viewer.getCamera()->setViewMatrix(mat);
        }

protected:
    osgViewer::Viewer _viewer;
    RenderThread _thread;
};




My intention is to load an animated model (mesh with skeleton) in the scene and 
rotate their bones from the main thread:

Code:

in the constructor
...
//osg layout render thread
osg::Camera* camera = createCamera( 0, 0, 640, 480 );
m_qtOsgViewer = new ViewerWidget(camera, _sceneGroup);

_sceneGroup->setUpdateCallback( this ); 
...

void MyOSGSceneManager::loadScene()
{
        model = new 
AvatarE::AnimatedModel("../../../extras/data/models/hand.fbx");
        _sceneGroup->addChild(model->getRootGroup());
        setActiveCamera(m_activeCameraID);
}

void MyOSGSceneManager::operator()(  osg::Node * node , osg::NodeVisitor * 
nodeVisitor )
{
        //update cameras
        if(m_cameraController->isCamMoving()){
                m_cameraController->updateCamera();
                
m_qtOsgViewer->setCameraMatrix(m_cameraController->getCameraMatrix());
        }
}



All is loaded correctly and the camera is moved without problems. 
But when I call a bone manipulator function, 

Code:

m_osgSceneManager->getAnimatedModel()->getAnimationManager()->manualBonesRotate(
                
"radio_dcho",osg::Matrix::rotate(osg::Quat(1.0,0.0,0.0,osg::DegreesToRadians(30.0))),"proba");



Nothing happens. This does not happen if the entire application works in the 
same thread.

Any suggestions?

Thank you!

Cheers,
Aitor

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=53073#53073





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to