bool testApp::loadDefaultScene(){
    ofxXmlSettings settings;
    if(settings.loadFile("RGBDSimpleSceneDefaults.xml")){
        if(!loadScene(settings.getValue("defaultScene", ""))){
            return loadNewScene();
        }
        return true;
    }
    return loadNewScene();
}
//--------------------------------------------------------------
void testApp::update(){
    if(loadNew){
        loadNewScene();
    }
    
    cam.applyRotation = cam.applyTranslation = meshRect.inside(mouseX, mouseY) || triangulatedRect.inside(mouseX, mouseY);
    
    //copy any GUI changes into the mesh builder
    if(meshBuilder.shift.x != xshift || meshBuilder.shift.y != yshift || meshBuilder.farClip != farClip){
        meshBuilder.setXYShift( ofVec2f(xshift,yshift) );
		meshBuilder.farClip = farClip;
        meshBuilder.updateMesh(player.getDepthPixels());
    }
    
    //update the mesh if there is a new depth frame in the player
    player.update();
    if(player.isFrameNew()){
        meshBuilder.updateMesh(player.getDepthPixels());
    }
    
    if(renderMode){
//        if(!player.getVideoPlayer().isPlaying()){
//            player.getVideoPlayer().play();
//            player.getVideoPlayer().setSpeed(0);
//        }

        player.getVideoPlayer().setFrame( player.getVideoPlayer().getCurrentFrame() + 1);
        player.update();
	    createTriangulation();
    }
}
void RenderServerRenderer::onNewRenderCommandInQueue()
{
    while(true)
    {
        // Process queued up events/slots, in case we quit
        QCoreApplication::processEvents();

        if(m_quit)
        {
            return;
        }

        // If queue is empty, we wait until we get a new request
        if(m_queue.size() == 0)
        {
            m_waitCondition.wait(&m_waitConditionMutex);
            continue;
        }
        // Process the next RenderServerRenderRequest

        RenderServerRenderRequest renderRequest = m_queue.dequeue();
        QString iterationNumbersInPacketString = "";

        for(int i = 0; i < renderRequest.getNumIterations(); i++)
        {
            // If the packet we are working has become old during this rendering for-loop, then break out of this loop
            if(m_currentSequenceNumber != renderRequest.getSequenceNumber())
            {
                break;
            }
            // Else we'll render this frame
            else
            {
                // This renderRequest has a new scene name, so we'll load the new scene
                if(m_scene == NULL || m_scene->getSceneName() != renderRequest.getDetails().getSceneName())
                {
                    loadNewScene(renderRequest.getDetails().getSceneName());
                }

                // Render the frame with local iteration number going from 0 to renderRequestsCurrentPacket.size()
                // We only need to create the output buffer for the last iteration of the packet
                bool createOutputBuffer = i == renderRequest.getNumIterations() - 1;
                renderFrame(renderRequest.getIterationNumbers().at(i), i, renderRequest.getPPMRadii().at(i), createOutputBuffer, renderRequest.getDetails());
                iterationNumbersInPacketString += " " + QString::number(renderRequest.getIterationNumbers().at(i));
            }
        }

        // If the packet we have just rendered is old (m_currentSequenceNumber is newer)
        // then we drop this packet. This can happen if we have started on a RenderServerRenderRequest but later found out about
        // a new sequence, in which case we have break-ed out of the loop above.

        if(renderRequest.getSequenceNumber() == m_currentSequenceNumber)
        {
            RenderResultPacket result = createRenderResultPacket(renderRequest);
            QString logString = QString("TRANSFERRING packet (%1 iteration:%2) in sequence %3 to client.")
                                .arg(result.getNumIterationsInPacket())
                                .arg(iterationNumbersInPacketString)
                                .arg(result.getSequenceNumber());
            emit newLogString(logString);
            emit newRenderResultPacket(result);
        }
        else
        {
            QString logString = QString("IGNORED package with %1 iterations since sequence %3 != %4.")
                                .arg(renderRequest.getNumIterations())
                                .arg(renderRequest.getSequenceNumber())
                                .arg(m_currentSequenceNumber);
            emit newLogString(logString);
        }
    }
}