Crocotile3D, glTF and Hemispheric Lighting

Hello again! I’m sorry I’m so bad at this stuff, it’s all very overwhelming. This is going to be a mish-mash of thoughts because I don’t really know where to go from here.

I created a fence post model in crocotile3d and exported it as glTF (also have the option of obj and glb, just fyi). I’m having a heck of a time getting the ambient light to affect the mesh. I’ve searched the forums and only found 1 post that was similar to my issue, but it didn’t really help me. Someone mentioned that maybe because the coordinates were flipped, it broke the lighting. I’ve also read that ambient lighting doesn’t work on glTF (and I assume also glb).

Another person said to use PBR materials on the model and set the light falloff to glTF. This is over my head and I don’t know how to switch the material on an imported glTF file that has an embedded texture. So I didn’t bother even trying that.

Why is this so difficult? Shouldn’t I be able to just import a model and have the lighting system work on it?

Why does the model import as 2 separate meshes, one with the id “root” and one with the id “node0”? I noticed “node0” is parented to “root” and “node0” contains things like the normals information while the “root” does not.

So many questions and the deeper I dig the more confused and overwhelmed I get. Any advice would be appreciated.

Is it possible to give us a playground, so we can take a look on your model? You can use Dropbox for example Using External Assets In the Playground | Babylon.js Documentation (use .glb format for simplicity) and customise this playground (according to the doc I’ve just linked): Babylon.js Playground

Also, what happens if you drop your files into the sandbox?

Let’s begin with the files first, or maybe you even could create a PG?
I don’t know how crocotile3D is making files.
As for lighting - you may find lights from GLTF model like here - How can I import lights if I use SceneLoader.ImportMesh - #2 by kvasss

Here is my playground. Hope it helps.

https://playground.babylonjs.com/#LA840W#6

edit: changed to arc rotate camera instead

So, it works, right?

It loads, but the intensity of the hemispheric light doesn’t effect the model like it does anything created with the mesh builder.

Ah ok I see, it’s just that your material is exported as unlit, so it’s totally normal that lighting does’nt affect it.

Just put it to false https://playground.babylonjs.com/#LA840W#7

3 Likes

Oh my god. That’s so simple. Thank you soooooooooooooooooooooooooooooo much.

1 Like

@Vinc3r
Do you know if there is a way to access a meshes material from the mesh itself using typescript?
_materials is private and since I have no control over the material name, if I import multiple meshes, won’t using scene.getMeshByName() cause problems?

Edit: Nevermind… I guess I can access the material from the mesh but there is no unlit property when using typescript. Odd.

I’m not using Typescript so can’t help, but with Javascript I just call scene.getMeshByName("node0").material.

if I import multiple meshes, won’t using scene.getMeshByName() cause problems?

With a nice naming convention it’s not an issue. You have to check if Crocodile3D allows to name meshes & export theses names in the gltf file.

2 Likes

That’s probably because your material is seen as an instance of Material by typescript, not as PBRMaterial: mesh.material is a Material, not a PBRMaterial.

1 Like

You’re right. I wasn’t even aware it imported as a PBR. I was able to access it by using material[“unlit”] = false;
Kinda hacky, but whatever. I appreciate everyone’s help!

In typescript, you can do (mesh.material as PBRMaterial).unlit = false;

2 Likes