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

Vertex colors not loaded in Gltf models #1871

Closed
ghost opened this issue Nov 28, 2022 · 11 comments · Fixed by #1873
Closed

Vertex colors not loaded in Gltf models #1871

ghost opened this issue Nov 28, 2022 · 11 comments · Fixed by #1873
Assignees
Labels
bug Something that is supposed to work, but doesn't. More severe than a "defect".

Comments

@ghost
Copy link

ghost commented Nov 28, 2022

Models coloured through vertex colours are not properly rendered in the application; various attempts in altering the formats and materials have resulted in null results. If a material isn't specified, the model is wholly white. Using the lighting material, even with "UseVertexColor" it's wholly black without details.

The following code is without utilizing any material, but it may be altered to set the 'Lighting.j3md' material. "UseVertexColor" does not appear to function as intended.

Light directionalLight = new DirectionalLight(new Vector3f(-10, -5, -10));
Light ambientLight = new AmbientLight();
Material material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
material.setBoolean("UseVertexColor", true);
Spatial playerModel = assetManager.loadModel("models/TestGirl.glb");
playerModel.setLocalScale(0.5f);
playerModel.setLocalTranslation(new Vector3f(-4,-7.1f,0));

rootNode.attachChild(playerModel);
rootNode.addLight(directionalLight);
rootNode.addLight(ambientLight);

The model file is available here, for testing:
TestModel.zip

@zzuegg
Copy link
Member

zzuegg commented Nov 28, 2022

at least with prb material you have to set BaseColor to vec4(1,1,1,1) if you want vertex color only.

not at the pc so i cant test. looked at the shader code

//add: seems should be 1,1,1,1 by default.

@Ali-RS
Copy link
Member

Ali-RS commented Nov 28, 2022

I can confirm it is not working.

Tried it with Unsahded, Lighting and PBRLighting materials but could not get vertex colors to work in any of them. I can confirm mesh has a color buffer on it. VertexBuffer[fmt=Float, type=Color, usage=Dynamic, elements=7268]

for unshaded material I used

Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md" );
mat.setBoolean("VertexColor", true);
mat.setColor("Color", ColorRGBA.White);

for lighting material I used:

Material mat = new Material(assetManager, Materials.LIGHTING);
mat.setFloat("Shininess", 64f);
mat.setBoolean("UseVertexColor", true);
mat.setBoolean("UseMaterialColors", true);
mat.setColor("Ambient", ColorRGBA.White);
mat.setColor("Diffuse", ColorRGBA.White);
mat.setColor("Specular", ColorRGBA.White);
mat.setBoolean("VertexLighting", true);

@pspeed42
Copy link
Contributor

GLTF issues aside, I can assure you 100% that vertex colors work in the engine, definitely for Unshaded.j3md because I use that one all the time (unless it was broken very recently). So to whomever is looking at this, it would be worth checking what's in the color buffer.

@ghost
Copy link
Author

ghost commented Nov 28, 2022

What's a colour buffer, and where would I find 'Unshaded.j3md'?

@Ali-RS
Copy link
Member

Ali-RS commented Nov 28, 2022

it would be worth checking what's in the color buffer.

Yeah, looks like buffer is corrupted. All of them are set to:

Color[-0.0017700465, 0.0012359808, 0.0018616007, 1.2207218E-4]

The gltf file can be viewed correctly without error on online viewers, so probably an issue with GltfLoader!

@Ali-RS
Copy link
Member

Ali-RS commented Nov 28, 2022

I figured this change in gltf blender addon broked GltfLoader.

KhronosGroup/glTF-Blender-IO#1169

If I revert that change I can successfully load vertex colors in JME.

Screenshot_2022-11-28_18-44-40

@pspeed42
Copy link
Contributor

Lovely. Is there something in the GLTF that indicates the bad version versus the good version? Or are we stuck having to do some odd detection to find these cases?

Either way, nice of them to break this for everyone. (Or maybe JME is reading these values in a dumb way. 50/50 chance.)

@Ali-RS
Copy link
Member

Ali-RS commented Nov 28, 2022

Well, I guess it is detectable based on buffer type.

In the old one, the vertex data was exported as a float buffer

        {
            "bufferView" : 3,
            "componentType" : 5126,
            "count" : 24,
            "type" : "VEC4"
        },

case 5126:
return VertexBuffer.Format.Float;

after the change, it is now exported as unsigned short buffer

        {
            "bufferView" : 3,
            "componentType" : 5123,
            "count" : 24,
            "normalized" : true,
            "type" : "VEC4"
        },

case 5123:
return VertexBuffer.Format.UnsignedShort;

there is already a check in GltfLoader to unpack short back to a float buffer but it seems something goes wrong down the road.

if (normalized) {
// Some float data can be packed into short buffers,
// "normalized" means they have to be unpacked.
// In that case the buffer is a FloatBuffer
format = VertexBuffer.Format.Float;
}

@tonihele tonihele self-assigned this Nov 28, 2022
@tonihele
Copy link
Contributor

I got this fixed, I'll submit a PR shortly.

@pspeed42
Copy link
Contributor

pspeed42 commented Nov 28, 2022

re: "Or maybe JME is reading these values in a dumb way. 50/50 chance."
...turns out I was 50/50 right. :)

Edit: (and seems like it was probably a copy-pasta issue.)

@tonihele tonihele added the bug Something that is supposed to work, but doesn't. More severe than a "defect". label Nov 28, 2022
@Ali-RS Ali-RS changed the title Vertex Colours Do Not Render Vertex colors not loaded in Gltf models Nov 28, 2022
tonihele added a commit that referenced this issue Nov 29, 2022
Fix #1871 (vertex colors not loaded in gltf models)
@tonihele
Copy link
Contributor

Thank you @Abstrusle for taking the time to report this. GLTF pipeline is very important and as such I'd say this bug is high priority level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that is supposed to work, but doesn't. More severe than a "defect".
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants