I am looking for functionality that is similar to Unity’s WWW.texture
// Get the latest webcam shot from outside "Friday's" in Times Square
var url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
function Start () {
// Start a download of the given URL
var www : WWW = new WWW (url);
// Wait for download to complete
yield www;
// assign texture
renderer.material.mainTexture = www.texture;
}
Yes you could do that, however you would have to write in the functionality to obtain the image from a webserver, and to parse the BMP/JPG, then you can create a UTexture2D (Using the CreateTransient static function). Lock it and fill it with data, I am doing something similar to this for runtime textures, although I am using DDS and reading from the HDD.
This is great!
Do you mind sharing some of the code you use to read from the drive, use the function and create a texture object? If you could share any part of this code, it would really help. I am very new to C++ but used to program in other languages. Thank you for your time.
I used FDDSLoadHelper to actually parse the file, which is a built in UE4 helper class. The code was too big to paste in here, so below is a link to the snippet.
Hi there, I am also interested in this topic. So far I get image data from an URL and save the response as TArray imageDataArray = response->GetContent();
When trying to create a texture from this TArray I fail miserably. I considered using libpng/libjpeg for this purpose but I guess I am not skilled enough.
It would be great if you could share your solution or at least give a hint on how to create a texture to use it on runtime. Thanks!
thank you very much, this works great. I have one final error. I hope you can assist. When I assign the texture to a StaticMesh, the texture falsely appears white. I got:
...
// HTTP respone; image
TArray<uint8> imageDataArray = response->GetContent();
if (ImageWrapper.IsValid() && ImageWrapper->SetCompressed(imageDataArray.GetData(), imageDataArray.Num()))
{
const TArray<uint8>* uncompressedBGRA = NULL;
if (ImageWrapper->GetRaw(ERGBFormat::BGRA, 8, uncompressedBGRA))
{
// TODO get actual image dimensions
imageTexture = UTexture2D::CreateTransient(100, 100, PF_B8G8R8A8);
imageTexture->MipGenSettings = TMGS_NoMipmaps;
..
// change appropriate texture parameter
matInst->SetTextureParameterValue(FName("webTexture"), imageTexture);
UncompressedBGRA correctly holds all the color values. Do I have to call something else after CreateTransient(...)?
perfect! thanks again. I thought I do not have to care about mips because I have a non power of two image and therefore there are no mipmaps. The basic mip has to be created anyways… great help
and I don’t need this texture anymore. Will setting mytex to nullptr will be enaught and GarbageCollector will do the job? Do I have to run UTexture::ReleaseResource() or UObject::ConditionalBeginDestroy() ? Simply deleting mytex cause crash, so I thing the engine has to clean it it’s ways.
Hi. I don’t know if any of you are still watching this thread, but in my case, using 4.9 (I don’t use 4.10+ yet) the garbage collector is running amok on this texture and calls UTexture2D::BeginDestroy() after a few seconds. I only use it directly on to the HUD, plotting it at every tick, so it’s not dependent on another object being destroyed. Any thought on what might happen here ?
I’m trying to set material onto object at run-time from texture, normal map, displacement map etc. located in the hard disk. To achieve this i need to create dynamic material instance and set the parameter to the material by loading the image file at run-time.
I’m creating material from texture & displacement map image file. These image files are loading from folder using Victory Plugin’s “Victory Load Texture 2D from File” Node.
I’m creating the material instance dynamic of the “test material”. Now I’m setting the texture and displacement parameter as shown in figure 4.
After creating material instance dynamic, I’m setting this material to the object.
figure[1] test material:
figure[2] texture:
figure[3] displacement map:
figure[4] Method:
Now here is the problem.
When I directly create material in material editor from texture and displacement map and set it onto object. It doesn’t generate** moiré pattern.**
But when I run-time set the material onto object using figure [4]. It will generate moiré pattern.
I think the “Load Texture 2D from File” nodes is not calculating the Mip Map correctly.
I tried with following nodes but the result is same.
1> “Victory Load Texture 2D from File” (Created by rama)
2> “Load Texture 2D from File by Extension” (Created by you)
3> “Victory Load Texture 2D from File Pixels” (Created by rama)
I hope you will take this request into consideration. I would like to thank you in advance for your time and attention in this matter.
Should you have any further questions or concerns, please do not hesitate to contact me.