Need help with texture replacemnt.

I’ve been digging through the manual and all of the forum posts concerning the topic of Texture Replacement, but nothing I have found will works.

I’m new to Panda3D, but I have basic programing skills.

I’ve created a Trilon in blender and baked the texture. It Shows up fine in Panda. I then Opened the Texture file and altered it in and saved it as another png file.

Here is my working code.

from direct.showbase.ShowBase import ShowBase

class MyApp(ShowBase):
    def __init__(self):
        # Load the environment model.
        self.Trilon = loader.loadModel("models/Trilon.egg")
		# Reparent the model to render.
        # Apply scale and position transforms on the model.
        self.Trilon.setPosHpr(0,15,0, 0,0,0)

app = MyApp()

I’ve tried adding from panda3d.core import Texture and doing the loader.loadTexture / .setTexture(texture,1) examples I’ve found. I just don’t know what I’m missing. Right now I am just trying to override the baked texture from the get go. Will eventually implement it to be triggered.

Thanks for any help.

Have you seen this post? It seems to indicate that the missing step might be finding the texture stage associated with the texture specified in the model-file. (The same post includes some illustrative code, I believe.)

Yes, I saw that post, but since my object doesn’t have specific names for the UVs I did not attempt it. If I remember correctly, either that post or in another, someone stated that you shouldn’t have to mess with the textureStage.

I did try the example at the bottom of the post that you linked (the one with the smiley), and I couldn’t even get it to run. I assumed that I was missing an import or something. Like I said, I’m new to Panda and to Python.

I will give textureStage a try, though, when I get a chance.


Something that I failed to mention, now that I think of it, is whenever I tried using the loader.loadtexture and setTexture commands, my simple script would not even run. I’m sure that I am missing something, but I cannot figure out what it is. I even went through the sample script for Swapping Textures and could not figure it out.

Ah! Are you getting any error messages, then? Perhaps the texture is failing to load for some reason.

(If you’re running it in a way that doesn’t produce output, try running in from the command-line; I forget offhand whether the SDK produces log files. ^^; )

As far as error messages, I don’t know if it is giving me anything in the python command window or not. The command windows initializes and closes too quickly. I would have thought that the texture would have been fine since I only slightly modified the texture that is baked in (and then saved it under another name).

Really shooting in the dark here. I’m used to programming in VB. This is a new realm altogether for me.

Hmm… What IDE are you using? I would expect it to display the console output a little more usefully than that.

However, short of changing IDEs, I really do suggest running your program via the command-line. Quite how you get there depends on which OS you use, I believe: under Windows, I seem to recall that it’s a program named “cmd” that you execute via the “run” option in the start menu; under Linux, it’s the “terminal” program.

When you have a command-line open, navigate to the directory in which your Python file is located and run your program as follows (if I recall correctly): “python .py”, where “” is the name of, well, your Python file. This should result in your program’s output being printed in the console window, and thus available for you to read.

I’m using Notepad++ to code in. And I will give it a try running it from the CMD window. I had created a shortcut that linked my code to the Python app (just like they did in the samples folder.

Thanks for all of your suggestions.

you can try :

ts =  mymodel.findTextureStage("default")
tx1 = mymodel.findTexture(ts)
pi = PNMImage("path/to/my/texture")

it seems a little complicated, but i didnt find the simpler way

I got it to work, guys. Thanks for the advice.

I have no idea what I was going wrong but I took another crack at using loader.loadTexture & setTexture and it works just like it was supposed to. Maybe I had sat too long at the computer the other day and was just missing something simple.

Here is the code:

from direct.showbase.ShowBase import ShowBase

class MyApp(ShowBase):

def __init__(self):

self.Trilon = loader.loadModel("models/Trilon.egg")
    self.TrilonTex = loader.loadTexture("models/textures/Cube_diffuse2.png")
self.Trilon.setTexture(self.TrilonTex, 1)
     #Apply scale and position transforms on the model.
    self.Trilon.setPosHpr(0,15,0, -90,0,0)

app = MyApp()