[SOLVED] Capture image of a node


photo

Recommended Posts

Hello World !

I am asking for help to capture an image of a node.

Here is what I need to do :

  1. Have the screenshot saved
  2. See the camera view in the screenshot
  3. See the node in the screenshot

And here is what happens:

  1. Screenshot is saved - OK
  2. We can see the camera view - OK
  3. The node is not in the screenshot - NOT OK

What I do (after checking the sample "Screenshot") :

  • In WorldLogic.init():
    • Load a node in my world with World::loadnode();
    • Place the camera in order to see the node (player->setWorldTransform)
    •     PlayerSpectatorPtr player = PlayerSpectator::create();
          Game::setPlayer(player);
          NodePtr node = World::loadNode("test.node");
          BoundBox bb = node->getBoundBox();
          player->setWorldPosition(Vec3(bb.getMax()) * 10);
          player->worldLookAt(node->getWorldPosition());
  • In WorldLogic.update():
    • Create my TexturePtr if it does not exist and set its size to the size of the app
    •     if(!_screenTexture){
              _screenTexture = Texture::create();
              _screenTexture->create2D(App::getWidth(), App::getHeight(), Texture::FORMAT_RGBA8, Texture::FILTER_POINT | Texture::USAGE_RENDER);
          }
  • In WorldLogic.beforeSwap():
    • if (_screenTexture)
              _screenTexture->copy2D();
  • In WorldLogic.swap():
    • Check if the screenshot was already taken
    • if no Take the screenshot and save it.
    •     if(_takeScreenshot)
          {
              // Screenshot de l'objet
              ImagePtr image = Image::create();
              _screenTexture->getImage(image);
              if (!Render::isFlipped())
                  image->flipY();
              image->convertToFormat(Image::FORMAT_RGB8);
              
              image->save("Resources/Test.png");
       
              _takeScreenshot = false;
          }

 

At the moment I have tried to use World::updateSpatial(); after loading the node but it does not change anything.

The next step is to load a list of nodes and take a screenshot of each one bye one, but if I can't even have the first one...

My main loop looks like that

 

AppSystemLogic system_logic;
    AppWorldLogic world_logic;
    AppEditorLogic editor_logic;
 
    // init engine
    Unigine::EnginePtr engine(UNIGINE_VERSION, argc, argv);
    
    engine->addSystemLogic(&system_logic);
    engine->addWorldLogic(&world_logic);
 
    world_logic.init();
 
    while (!engine->isDone())
    {
        engine->update();
        engine->render();
        
        world_logic.beforeSwap();
 
        engine->swap();
    }

How can I manage to see my node in the screenshot ? Are there steps that I missed ?

And if I want to do that for a list of 10 nodes. Is there something else to do like waiting for the nodes to render ?

Tell me if you need any more information. 

Thanks for your time,

Best regards.

Antoine

Link to post
  • silent changed the title to [SOLVED] Capture image of a node