-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
[3.x] Add vertex color support to OBJ importer #76671
Conversation
I wouldn't necessarily call it a bug that we can't handle OBJ files that don't follow this format, but I'd suggest opening a bug for this for 4.x as it's not tracked anywhere as I can see |
Reading the code, I thought the last component was the vertex color's alpha channel? What is the 7th component exported by TreeIt or SpeedTree? |
@Calinou I actually have no idea. I tested both options for color, I mean components 4-6 versus 5-7, and the former resulted in green vertices for the exported trees, so I would assume this version is correct :-) I do not think it's alpha, though. Why would SpeedTree export alpha values for leaves, if they're supposed to be alpha blended/alpha cut through the albedo texture anyway? Both apps are closed source and there seems to be no documentation, so I could not check the implementation, unfortunately. The imported meshes seem fine - tree trunks are of singular color for both SpeedTree and TreeIt, so leaf shaders should work correctly. |
It was mentioned that this diverges from 4.0? We typically merge to master before backporting enhancements. |
I wonder if the reason there are 7 components is because speed tree is exporting in xyzwrgb format instead of xyzrgb as we currently assume. It is valid for a .obj file to have xyz or xyzw. Color is a weird extension that everyone seems to support, but isn't technically specified anywhere. It is just tacked onto the end of the vertex line. So in theory, it should be possible to have 6 or 7 components for each vertex. That being said, you mention that using 456 for color looks more correct than 567, so perhaps speedtree is storing something else per vertex edit: Speedtree seems to indicate it is only passing 3-channel colors https://docs8.speedtree.com/modeler/doku.php?id=vertex_colors Edit2: Its out of date, but this UE3 post references the alpha value from a SpeedTree vertex color https://docs.unrealengine.com/udk/Three/SpeedTree.html |
Below you'll find the vertex color view from TreeIt and on the right Godot with vertex color as albedo with this PR enabled (components 4-6). So, it seems this is correct. As for the SpeedTree I apologize, but I must have mistaken one of my TreeIt trees for a SpeedTree tree, because I just checked all OBJ export presets in SpeedTree and none of them include vertex colors. It's just for FBX, it seems. So, if one needs OBJ from SpeedTree, they can only depend on having a separate material for leaves to animate them with a shader. |
Ah okay. Thanks for updating. I took a look at TreeIt and it seems to use 456 for color and 7 for baked ambient occlusion. So for now it seems like using 456 and ignoring 7 is the way to go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Could you also make a PR targeting master changing the check to v.size() >= 7
so that 4.0 can work with TreeIt assets as well?
@clayjohn sure, I will. Thank you for finding my first contribution useful 😃 |
Bump :) I'd like to get the change merged in |
PR for |
Thanks! |
Backport of #71033 to
3.x
, with one notable difference.I believe the original PR is implemented correctly, according to the specification, but does not actually work with programs like TreeIt or SpeedTree. This is because they output seven components after
v
, instead of six, like the original implementation assumes. Therefore, the4.x
version does not import the colors from OBJs created in the above applications, while my3.x
version does. The rest of the code is the same (only changes necessary for 4 -> 3 Godot version).