aka3301 Posted May 14, 2020 Share Posted May 14, 2020 (edited) While I changing Albedo texture at runtime, I got wrong projected image. But it was correct in Editor. Could anyone give advice? Thanks in advance. Here is my sample code Unigine SDK2.7.3 / 2.8.0 int AppWorldLogic::init() { // Write here code to be called on world initialization: initialize resources for your world scene during the world start. ImagePtr img = Image::create(); img->load("image/cat.png"); //img->save("image/test__4.png"); // save to file is ok Unigine::DecalOrthoPtr projector = DecalOrtho::cast(Editor::get()->getNodeByName("DecalOrtho")); MaterialPtr mat0 = projector->getMaterial(); TexturePtr frame_texture = Texture::create(); //img->convertToFormat(Image::FORMAT_RGB8); //frame_texture->create2D(img->getWidth(), img->getHeight(), Texture::FORMAT_RGBA8); frame_texture->create(img); int num = mat0->findTexture("albedo"); if (num != -1) mat0->setTexture(num, frame_texture); PlayerSpectatorPtr g_camera = Unigine::PlayerSpectator::cast(Unigine::Game::get()->getPlayer()); g_camera->setPosition(Vec3(1.0, 0, 100)); return 1; } Edited May 14, 2020 by unisol3 Link to comment
silent Posted May 14, 2020 Share Posted May 14, 2020 I believe you can simply do the following: ImagePtr image = Image::create("image/cat.png"); MaterialPtr mat0 = projector->getMaterial(); int num = mat0->findTexture("albedo"); if (num != -1) mat0->setTextureImage(num, image); 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
aka3301 Posted May 15, 2020 Author Share Posted May 15, 2020 Thanks a lot. Simple and concise. . Link to comment
Recommended Posts