applying normalmap by code?

Normal maps specified in an egg file work, but not by code:

import direct.directbase.DirectStart
from panda3d.core import *

# model
panda = loader.loadModel('panda')
panda.reparentTo(render)
panda.setShaderAuto()

# light
dlight = NodePath(DirectionalLight('dlight'))
panda.setLight(dlight)

# normalmap
normalmap = loader.loadTexture('layingrock-n.jpg')
ts = TextureStage('normal_map')
ts.setMode(TextureStage.MNormal)
panda.setTexture(ts, normalmap)

run()

The panda that ships with Panda has no tangent/binormals. Normal mapping can’t work without them.

As far as I know binormals are not made, they’re just generated like normals. Are you saying Panda doesn’t have a function for generating binormals? I thought it would silently do it itself when loading a normal map anyway. I mean I’m using a 3d format which doesn’t store that information. Seems like a common scenario.

You can use “egg-trans -tbnall” to generate this information.

Like I said my models are not in egg.
Maybe we could have a NodePath method which does that, by reusing the code from egg-trans?

Why not convert your models to .egg, then? If you use another file format, they are in most cases internally converted to .egg anyway before they are loaded.

What if format not supported by Panda natively (no converter)? Well OK, I guess this isn’t a very common scenario then.
But still what if the person has 200 models in the format? Converting all of them will take a lot of time. Not to mention if they are using a 3d modeller which doesn’t have an exporter for egg, each time they will need to go that extra step. And then there are people who generate their models procedurally, a C++ panda3d method would be nicer/faster than generating it by hand.

The only formats Panda supports natively are .egg and .bam, at the moment. Any other formats will be converted using a converter first.

You could easily write a script that converts all of your models to .egg format and invokes the egg-trans command on them.

People who generate their models procedurally should generate correct binormals and tangents on these models in the first place.