I need to change the texture of a plane in a 3D scene. In the BackEnd class in C++ I make a new QImage for setting it on a texture. I want to send it as a signal to my QML and there assign it to the planes material property.
But it looks like TextureMaterial etc. can only use a URL path to a texture file. I cant't save my Images to my hard drive to use them as a URL path. It will be too long. I need to change my texture 20+ times in a second and there are other things which this program should to do in the same time.
Is there any way to do this?
You can have a look at my implementation of a background image in Qt3D .
The way I achieved what you are looking for is by using the classes QTextureMaterial
, QTexture2D
and QPaintedTextureImage
. I had to flip the image before drawing it that's why I subclassed QPaintedTextureImage
but this might also just be what you need. Instead of loading the texture from disk, like I did, you could set the QImage
on your subclass as an attribute. You only need to make the C++ class available to QML and set it on your plane (maybe you could even use PaintedTextureImage
directly and write the image painting in their JavaScript-style language).
You can add your QPaintedTextureIage
to the QTexture2D
and then set the result as the texture on the QTextureMaterial
. I'm not sure if this yields the best performance, though.
You could also try to follow these steps but they seem to be a bit more involved. This would mean you have to implement your own version of QAbstractTextureImage
and return the appropriate QTextureImageDataGeneratorPtr
. You can checkout the sources to gain a better understanding.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.