when i using the model 'untitled.gltf', textures and shadow works. but when i use my model 'abstractroom.gltf' it renders black.
link of my code:
https://we.tl/t-DknvFjZtod
links of from where i take the sample code:
https://discourse.panda3d.org/t/directional-lighting-not-working-when-imported-with-panda3d-gltf-but-does-when-imported-with-assimp/29524/69
https://discourse.panda3d.org/uploads/short-url/qFDbB7lYnydnJBIU4GImz5vrKnf.zip
Greetings, and welcome to the forum! I hope that you find your time here to be positive!
As to your question… I’ll confess that I’m hesitant to follow a link to a site that I’m not familiar with, to an arbitrary file…
(You could post your code here, within code-tags.)
That said, I doubt that the code is at fault, given that it works with one of the models. It seems to me more likely that there’s a problem with the model that isn’t being rendered as expected.
So, let me ask: How was the “untitled.gltf” model made, and how was it exported?
Here I can’t able to upload attachments. Thats why i uploaded to external site.
I take the code from here and i used my model to load:
No, I mean, copy-paste the code into code-tags.
If there’s so much of it that doing so is a problem, then there’s probably a bit much for us to want to comb through all of it, I feel, and either a short snippet or–preferably–a short, separate test-program might be useful.
But, more to the point, I’m less interested in your code right now than your models.
Is “untitled.gltf” a model that you made yourself? If so, what program did you use to make it, how did you apply your textures, and are you loading it directly into your Panda-program or did you export to a different format?
And the same for “abstractroom.gltf”–is it a model that you made? If so, how (if at all) did your making of it differ from that of “untitled.gltf”?
Main.py
from fix_gltf_bam import render_stage_convert
from panda3d.core import AmbientLight, DirectionalLight, NodePath
from direct.showbase.ShowBase import ShowBase
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
#model = loader.load_model("untitled.gltf")
model = loader.load_model("abstractroom.gltf")
render_stage_convert(model)
model.reparent_to(render)
sun = DirectionalLight("sun")
sun.set_color((0.8, 0.8, 0.8, 1))
sun_np = NodePath(sun)
sun_np.reparent_to(render)
sun_np.set_z(50)
sun_np.set_x(40)
sun_np.set_y(-40)
sun_np.set_p(-40)
sun_np.set_h(45)
sun_np.node().set_shadow_caster(True, 1024, 1024)
sun_np.node().get_lens().set_film_size(20, 20)
#sun_np.node().get_lens().setNearFar(10, 100)
#sun_np.setDepthOffset(1)
#sun_np.node().get_lens().setFov(40)
sun_np.node().show_frustum()
render.set_light(sun_np)
ambient = AmbientLight('alight')
ambient.set_color((0.5, 0.5, 0.5, 1))
ambient_np = NodePath(ambient)
ambient_np.reparent_to(render)
render.set_light(ambient_np)
render.set_shader_auto()
app = MyApp()
app.run()
fix_gltf_bam.py
from panda3d.core import TextureAttrib, MaterialAttrib, TextureStage
def render_stage_convert(node, modulate = True, normal = True, selector = True, emission = True):
for node_path in node.find_all_matches(‘**/+GeomNode’):
geom_node = node_path.node()
for index_geom in range(geom_node.get_num_geoms()):
render_state = geom_node.get_geom_state(index_geom)
new_render_state = render_state.remove_attrib(TextureAttrib)
if render_state.has_attrib(MaterialAttrib):
material = render_state.get_attrib(MaterialAttrib).get_material()
#print('material_1',material)
material.set_twoside(False)
material.clear_metallic()
new_render_state = new_render_state.add_attrib(MaterialAttrib.make(material))
if render_state.has_attrib(TextureAttrib):
new_texture_attrib = TextureAttrib.make_default()
texture_attrib = render_state.get_attrib(TextureAttrib)
count_stages = texture_attrib.get_num_on_stages()
for index_texture_stage in range(count_stages):
texture_stage = texture_attrib.get_on_stage(index_texture_stage)
texture = render_state.get_attrib(TextureAttrib).get_on_texture(texture_stage)
sampler = render_state.get_attrib(TextureAttrib).get_on_sampler(texture_stage)
if modulate:
if texture_stage.get_mode() == TextureStage.M_modulate:
if texture.get_ram_image_size() > 100:
new_texture_attrib = new_texture_attrib.add_on_stage(texture_stage, texture, sampler)
if normal:
if texture_stage.get_mode() == TextureStage.M_normal:
if texture.get_ram_image_size() > 100:
new_texture_attrib = new_texture_attrib.add_on_stage(texture_stage, texture, sampler)
if selector:
if texture_stage.get_mode() == TextureStage.M_selector:
if texture.get_ram_image_size() > 100:
new_texture_attrib = new_texture_attrib.add_on_stage(texture_stage, texture, sampler)
if emission:
if texture_stage.get_mode() == TextureStage.M_emission:
if texture.get_ram_image_size() > 100:
new_texture_attrib = new_texture_attrib.add_on_stage(texture_stage, texture, sampler)
if new_texture_attrib.get_num_on_stages() > 0:
new_render_state = new_render_state.add_attrib(new_texture_attrib)
geom_node.set_geom_state(index_geom, new_render_state)
‘Untitled.gltf’ model is from another thread which i mentioned above.
‘Abstractroom.gltf’ is from:
From panda3d official sample code ‘bump-mapping’, i get the model ‘abstractroom.egg’
And i converted it to gltf using blender 4.2
code.zip (1014.1 KB)
This is full code with models
First of all, thank you for posting the details regarding the model, and the code.
Aah! Okay, I think that I may see the problem:
Re-converting your “abstractroom.gltf” back to an egg-file and examining that, I see that it doesn’t appear to have tangents or binormals–and as a result, standard shader-based lighting likely won’t work with it.
(Indeed, if you load the model into PView, you should find that it appears as expected when viewed without lighting, or with lighting but not per-pixel (i.e. shader-based) lighting–but that as soon as per-pixel lighting is activated it goes black.)
Compare with the original “abstractroom.egg”, which does have tangent- and binormal- vectors.
I’d suggest trying to convert it to gltf again, and looking specifically for options to enable tangent- and binormal- vectors.
Thanks for the answer.
As you suggest, i tried the followings. but problem not solved.
- i set the ‘tangent’ option checked when exporting model to gltf. it displays below warning in console
WARNING: polySurface2: Could not calculate tangents. Please try to triangulate the mesh first.
- i apply triangulate modifier in blender and export the model with ‘apply modifiers’,‘normals’,‘tangents’ options checked.
Now warning disappears. model saved. But textures not appear.
am i missing anything.
Hmm… I’m not sure! And I still use an old version of Blender, so I don’t think that I can even check.
Hm… It might be worth looking at the manual page that more-broadly covers converting models from Blender. That includes quite a bit of information on the various options available–and how to use them–I believe. See the link below:
https://docs.panda3d.org/1.10/python/pipeline/converting-from-blender