How to change texture of image to other texture. Example a wall texture change with texure

Change the texture of image with given texture

Have you looked at this manual page?

There are some potential complications (some of which might have been encountered previously be others, and so turn up in a forum search), but let’s first see if the simple approach is applicable!

hello i was go through the manual page. But i didn’t get the my result.
I was confused in two things:

  1. I have an image which i want use as a texture. How to deal with it.
  2. I have a 360 image of apartment. In that apartment i want to change the texture of wall with my new image texture.
    Please guide me with best approach.
    Thanks in advance

You can load a texture from a file via the “loader.loadTexture” method–something like this:

myTexture = loader.loadTexture(pathToTextureFile)

So, do I understand correctly that you want to load an image (the image of the apartment), and then replace part of that image with another image?

If so, then the best way might vary depending on the specifics of your requirements. You could perhaps use the PNMImage interface. (Note the PNMPainter and PNMBrush classes, too.) This allows one to copy an image or part of an image into another image–much as you seem to be intending to do.

This approach does have limitations, but again, let’s look at the relatively-simple solution first.

No i want to change the texture of wall in the apartment image.

But… Is that not the same thing? An image is just an image–a set of pixels. So to change part of that image, you would overwrite those pixels.

How i can resolve the issue. Convert image to model?

As I said, the PNMImage class and its associated classes provide one fairly simple way of replacing part of an image.

If I may ask, how are you defining the section of wall to be replaced?

I don’t know how to define the part of wall. Is there any way?
My requirement is when i click on wall it will change all wall texture with my saved texture.

Ah. In that case, I suggest doing some research on the broader internet–there will be resources describing methods of doing this, I think.

(If your wall is just a flat colour–no shading or texture–then you could perhaps use a flood-fill technique to detect the pixels that belong to the wall, and thus which pixels to replace.)

Thanks i have research more into it.

1 Like

I need some help.

  1. i have a texture and i loaded it using :
    myTexture = loader.loadTexture(“mytexture.png”)
  2. What is the use of “setTexture” please share some example code.

Thanks you so much. I’m able to load a model and change the texture of model (full texture change).
How i can save the new texture model in local system.

1 Like

I’m glad to read it! :slight_smile:

(I presume that your preceding question about “setTexture” has been resolved, then?)

I think that this can be done by loading the texture into a PNMImage, and then having that image-object write to file, as PNMImage provides a method to do so. Check the API-pages of both Texture and PNMImage for the relevant methods.

Can we change a specific texture (my model having multiple texture) with given texture?

Indeed. This approach operates on the textures, not the models to which they’re applied, I believe.

replaceTexture function is not working.
model.replaceTexture(oldTexture, myTexture)
I want to change a particular texture from model.

Ah, sorry, I misread you–I thought that you were still talking about saving a texture to file! ^^;

I’m afraid that I haven’t really used “replaceTexture”, that I recall, so I don’t know much about its use. Perhaps someone else will have more information!

okay thanks to help me

1 Like

i have an image i want to change texture of that image. Is it possible?