Blender => glb => p3d

Hello P3d Community,

I’m new to using p3d. I cannot load a .glb model with multiple textures, only diffuse color is shown, and I don’t seem to be able to assign later normal and roughness maps to my earth model. I attach the .glb which displays fine in https://sandbox.babylonjs.com.

I had a look to the forum but most of the info I could find concerns old versions of panda3d using the egg format.

Earth.008.glb (1.3 MB)

from direct.showbase.ShowBase import ShowBase
from panda3d.core import PointLight
from panda3d.core import TextureStage

class MyApp(ShowBase):
	def __init__(self):
		ShowBase.__init__(self)

		self.earth = self.loader.loadModel("Earth.008.glb")
		self.earth.reparentTo(self.render)

		diffuse_map = loader.loadTexture('Earth_diffuse_4096x2048.jpg')
		diffuse_map_ts = TextureStage('diffuse_map')
		self.earth.setTexture(diffuse_map_ts, diffuse_map)

		normal_map = loader.loadTexture('Earth_normal_4096x2048.jpg')
		normal_map_ts = TextureStage('normal_map')
		normal_map_ts.setMode(TextureStage.MNormal)
		self.earth.setTexture(normal_map_ts, normal_map)

		rough_map = loader.loadTexture('Earth_roughness_4096x2048.jpg')
		rough_map_ts = TextureStage('rough_map')
		rough_map_ts.setMode(TextureStage.MGloss)
		self.earth.setTexture(rough_map_ts, rough_map)

		pointLight = PointLight('PointLight')
		pointLight.setMaxDistance(100.0)
		self.pointLight = self.render.attachNewNode(pointLight)
		self.pointLight.node().setColor((1.0, 1.0, 1.0, 1))
		self.earth.setLight(self.pointLight)

		self.earth.setPos(0, 0, 0)
		self.cam.setPos(0,-5,0)
		self.cam.lookAt(0,0,0)
		self.pointLight.setPos(5.0,-5,0)
		self.pointLight.lookAt(0,0,0)

app = MyApp()

app.run()

Any advice?

Cheers, dvsdata

I read about setShaderAuto and tried it out but this time the earth turns black.

Are you using panda3d-gltf to load the model? Is there a reason you are trying to load the textures manually instead of loading them through the glb file? If the glb loader is setting these textures (panda3d-gltf creates fallback textures if the glb/gltf file does not have them) then you will need to override them when calling set_texture() as discussed here. For example:

		normal_map = loader.loadTexture('Earth_normal_4096x2048.jpg')
		normal_map_ts = TextureStage('normal_map')
		normal_map_ts.setMode(TextureStage.MNormal)
		self.earth.setTexture(normal_map_ts, normal_map, 1)

EDIT: Also, if you want a PBR shader to use with glb/glTF files (which use PBR materials), then checkout panda3d-simplepbr.

Hi Moguri, Thank you for answering. I’ve tried your suggestions. The PBR shader is indeed better than the default one. Still I can see neither bump nor glossy maps applied to my model when I Ioad the glb file with panda3d-gltf. Nor the override (with ,1) appears to produce any visible effect. As before setShaderAuto blackens the model out.

I was in same situation for a while trying to load image textured models from blender, and finally get into a way to make it work:

  1. In Blender use glb/gltf exporter, and make sure you have selected the model, and check “selected objects” in “include” section. And check “tangents” in “geometry” section if you are using normal maps.

  1. in Panda3d use panda3d-simplepbr AND panda3d-gltf with the gltf.patch_loader(self.loader) sentence in ShowBase init as documentation says.

something like:

import simplepbr
import gltf

class ElEnvBase(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        gltf.patch_loader(self.loader)
        pbr = simplepbr.init()
        ...

you need to play a while with pbr keywords, this worked for me:

        pbr.use_hardware_skinning = True
        pbr.msaa_samples = 8
        pbr.enable_shadows = True
        pbr.use_330 = True # export MESA_GL_VERSION_OVERRIDE="3.00 ES"
        pbr.use_normal_maps = True
        pbr.use_emission_maps = True
        pbr.use_occlusion_maps = True
        pbr.enable_fog = True

but for 330, for example, needed to set MESA_GL_VERSION_OVERRIDE=“3.00 ES” in environment variables to get it work propperly (I am using Debian GNU/Linux 11 and Intel i915 video card). Add one keyword at a time, and check results each.

Finally, be aware of lightning, use only Ambient and Directional, so Point has some issues with some mappings.

Hope it helps.

(xcuse my English if you notice any mistake or typo)

Hi Octaviotron,

Thank you for the info. I see I was missing the part of tweaking the pbr config patameters… I will try that tonight and see if I can make it work on my win10 laptop. I also notice that you do not use setShaderAuto which I reckon gets replaced by the pbr shader. Wrt the point lights, it would be a big limitation for what I intend to do with p3d if I could not use them. I nead at least one.

In general, I’m progressing fast with my animation project in p3d! Thank you to the developers and the maintainers of this great piece of sw!

Cheers,

Hi All, I have tried the pbr settings suggested by Octaviotron with no success. I have also update my video card drivers (should support opengl 4.5) with no success. There must be some configuration still missing. Maybe I should have said it before, p3d gives me this error when running my test:-

:display:gsg:glgsg(error): An error occurred while compiling GLSL fragment shader created-shader:
ERROR: created-shader:56: '' : illegal recursive expansion of macro p3d_TextureNormal
ERROR: created-shader:56: 'p3d_TextureNormal' : failed to expand macro
ERROR: created-shader:57: '' : illegal recursive expansion of macro p3d_TextureEmission
ERROR: created-shader:57: 'p3d_TextureEmission' : failed to expand macro
ERROR: created-shader:121: '' : illegal recursive expansion of macro p3d_TextureNormal
ERROR: created-shader:121: 'p3d_TextureNormal' : failed to expand macro
ERROR: created-shader:134: '' : illegal recursive expansion of macro p3d_TextureEmission
ERROR: created-shader:134: 'p3d_TextureEmission' : failed to expand macro

Cheers

Side note - there’s also blend2bam, which will handle most of the import settings for you.

1 Like

Hi CM, I have tried the .bam route but I have the same situation: I cannot see any normal/gloss mapping and I get those messages from the shader compiler. I have tried the shader-terrain sample and I’ve noticed that I can see the elevation of the terrain whereas the skybox (which is a .bam model) is not displayed. I have tried also other samples, like ball-in-maze and bump-mapping: they both appear to be working fine (the ball is nicely textured and glossy and the bricks are correctly showing the normal map effect). These two samples (and all the others) don’t use .bam/.glb/gltf but .egg/.egg.pz. If I interpret all this correctly then my problem is not with OpenGL (which does its job in building the terrain glsl shader for example), nor it is with the preparation of the models (the .bam shipped with the sample project should be fine), but it is rather with the displaying of .bam/.glb/.gltf. What do you thing? I would be ok using the egg format as well, but are still there converters that generate .egg files from blender 2.9+? Cheers,

Seen PRPEE, I’ll try it out!

@dvsdata

I strongly recommend that you don’t.

PRPEE, I believe, was not made for general usage, but rather towards the specific purposes of its creator. As a result, it doesn’t always produce the expected results.

We’ve had quite a few threads pop up as a result of people finding PRPEE, having trouble with it, and so coming here for help, as I recall.

If you want to export to egg/bam, I’d suggest trying Maxwell175’s port of YABEE instead.

But more generally, I have an “exporting from Blender” quick-reference thread, which may give you some leads to investigate (including the above-mentioned port by Maxwell175)–you should find it here:

Hi Thaumaturge, thank you for the pointers. I have tried both PRPEE and YABEE but the results aren’t very encouraging. I have also tried to reuse the untextured egg models of the solar-system example (veeery low-poly) with my textures instead of the original. Something happens when I apply these textures, but now I am not sure of what I’m seeing… Maybe my normal/gloss maps simply aren’t fit for the job. I’ll have to live without those effects for the moment. Cheers,

Unfortunately, I have very little experience with glTF files (let alone “glb” files) and PBR rendering–and on top of that, I use an older version of Blender. Thus I have little more to offer right now, I fear.

However, perhaps someone else on the forum will have an idea as to what might be going wrong!

Remember this when exporting GLFT/GLB from blender.

Also, get once problem at a time:

  • Export a single mesh, with only base color defined, unset all “use_xxx_maps” in pbr init and verify you can load your model.
  • Next, add a image texture and try again
  • and so on…

You can also try results when force the GL version in operating system when using or not 330 option in pbr.

I use GNU/Linux, if you dont check it out how to set this environment variable in your operating system.

Hello @dvsdata,

More than a year after the last message, I want to answer your post regarding the following errors you experienced because I experience the same exact errors:

:display:gsg:glgsg(error): An error occurred while compiling GLSL fragment shader created-shader:
ERROR: created-shader:56: '' : illegal recursive expansion of macro p3d_TextureNormal
ERROR: created-shader:56: 'p3d_TextureNormal' : failed to expand macro
ERROR: created-shader:57: '' : illegal recursive expansion of macro p3d_TextureEmission
ERROR: created-shader:57: 'p3d_TextureEmission' : failed to expand macro
ERROR: created-shader:121: '' : illegal recursive expansion of macro p3d_TextureNormal
ERROR: created-shader:121: 'p3d_TextureNormal' : failed to expand macro
ERROR: created-shader:134: '' : illegal recursive expansion of macro p3d_TextureEmission
ERROR: created-shader:134: 'p3d_TextureEmission' : failed to expand macro

I got a project which runs perfectly fine on my desktop computer which has a decent hardware configuration. But when I try to run it on my Microsoft Surface, I have the same errors as you above. This is the same exact lines of code with the same versions of packages, dependencies, …

So my guess is, your laptop’s hardware is the culprit here : your laptop doesn’t have the graphical resources to run your project. If somebody have more information feel free to share your knowledge ! :smile:

Cheer.

This looks like an issue in panda3d-simplepbr, are you sure you have updated it to the latest version?

I copied all my project folder and dependencies in python’s sites-package from my desktop computer to a flash USB to test on a Surface, so I guess everything is the same.

Not sure if I clean the pycache folders, I could try this!