Antoine.YVAN Posted January 22, 2021 Share Posted January 22, 2021 Hello World ! I am asking for help to capture an image of a node. Here is what I need to do : Have the screenshot saved See the camera view in the screenshot See the node in the screenshot And here is what happens: Screenshot is saved - OK We can see the camera view - OK 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 comment
silent Posted January 22, 2021 Share Posted January 22, 2021 Hi Antoine, Have you tried to set the streaming mode to force via Render::setStreamingMode(Render::STREAMING_FORCE). That in theory should help to avoid any issues when you do the single frame captures. Thanks! 1 How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
Antoine.YVAN Posted January 22, 2021 Author Share Posted January 22, 2021 Hi Silent, It works as expected ! Thanks a lot. 1 Link to comment
Recommended Posts