Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for imported models rendering solid black #89

Closed
jojoofu opened this issue Aug 25, 2016 · 6 comments
Closed

Fix for imported models rendering solid black #89

jojoofu opened this issue Aug 25, 2016 · 6 comments

Comments

@jojoofu
Copy link

jojoofu commented Aug 25, 2016

I'm not sure if this was fixed yet but I found a solution to the problem with the models showing all black after importing. It seems to be coming from the material option. I found running the code block below on my scene fixes the issue 100% of the time.

public void clearMaterialOptions(){
gameManager.node.depthFirstTraversal(new SceneGraphVisitor() {
public void visit(Spatial spatial) {
if (spatial instanceof Geometry){
Geometry geo = (Geometry)(spatial);
geo.getMaterial().setBoolean("UseVertexColor", false);
geo.getMaterial().setBoolean("UseMaterialColors", true);
geo.getMaterial().setBoolean("VertexLighting", true);
}
}
});
}

It looks like importing blender models and certain wave front files leaves only the vertex color option on and disables everything else.

@MeFisto94
Copy link
Member

I have to check that it really sets MaterialColors to false. Maybe they are disabled in Blender as well?
Anyway it's usual that the backside is darkish since the sun shines from the front, could that be?
What happens when you add a Light from the back?

@jojoofu
Copy link
Author

jojoofu commented Aug 26, 2016

Adding a light via the scene editor only affects certain objects in my scene. Many of the meshes render solid black while the ones affected by the light only absorb low levels of the light. I found you can over come this by creating a new custom material which is a hassle to do this for every object when you have scenes like that contains hundred to thousands of meshes. I found running the above code block fixes it then I save the node after correcting the material settings.

I think it has something to do with the way blender exports materials it leaves certain settings blank. I also had this problem with a few wave front files but only a very few. Blender files have this problem often.

@MeFisto94
Copy link
Member

I have to see what a core member is saying to this. Whether it's okay to "simply" overwrite what were blender settings (Maybe you can also figure those out?).
MaterialColors is valid, though but do we need VertexLighting?

@MeFisto94
Copy link
Member

Sorry for the Delay, but:
a) I have to reject this, since it's no valid sledgehammer approach because those Parameters depend on what you want to achieve with your model, etc
b) I'll keep it a bit arround so you can see if it works using XBuf (Which means it would be a blender-importer bug) or at least how you have to change things in blender for it to work.

That's the keypoint here, it seems to me that this requires the correct setup on the blender side.
I'll now add a few Quotes about those Parameters:

"VertexColor" toggles the lighting calculation in the vertex shader instead of in the frag shader.
you have less accurate lighting with it, but it's faster.
I don't think it's the issue here. IMO the issue comes from the first 2 params

So that to the VertexColor.

If your model uses a diffusemap/specularmap etc, it won't use materialcolors

You use a DiffuseMap (aka Texture) I guess?

you should not assume that it's being used everytime. the loader should set it to true, if a diffuse color / specular color / ambient color is set

This might be a good hint. I've always had problems since my Ambient Color was set to Black. That way it wasn't effected by Ambient-Lighting.

the thing is...
if you have a diffuse color and a diffuse map and that useMaterialColor is set to true, the diffuse color is multiplied with the diffusemap color
so people may want to use this.

It could be that you've set the DiffuseColor to black in Blender or something?

@jojoofu
Copy link
Author

jojoofu commented Aug 30, 2016

I was doing some fiddling around with this and I found if you create a custom texture with the SDK that the only parameter checked is "UseVertexColor". Unchecking the vertex color fixes it. This represents a problem because it means I would have to add the custom material to every object manually.

I also imported an individual wave front file directly using the SDK and the materials rendered correctly. Blender is zeroing out certain parameters such as ambient and specular plus doing some other unknown functions to the file.

I also noted the wave front files will import with out being triangulated but the same file saved in blender format must be triangulated to import properly.

I'm currently using Blender 2.77a. It could be a backwards compatibility issue. The method I mentioned while not perfect makes a quick fix for the issue. Maybe one day we can find a Blender wizard who can make a .j3o exporter and all of our problems will solved :>

@MeFisto94
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants