Vertex colouring
Opened this issue · 13 comments
Hi! Firstly, great package you have here. The control/scene system is really good and solves a lot of problems I've been having with other packages.
So I was just wondering if you had any plans to implement vertex colouring for obj files? (Or if it's already there and I haven't found it?)
If you aren't aware, there is a flavour of obj that allows for vertex definitions like:
v 1220.094482 -572.500000 177.713943 0.984314 0.764706 1.000000
where the last three parameters are RGB.
It's not part of the official specification, but there are some applications (in my case, a Unity exporter plugin) that export in this format.
@alexobviously Thank you, I'm happy you liked the package.
I'd love to add this feature, but sadly I don't know how to. I got the core of this code from a Flutter demonstration from @gskinner and adapted it into a library format, adding the controllers, etc. This means that I don't actually have any experience with parsing obj files, so I wouldn't know how to implement this. But if you'd like to give it a try, I'd be happy to help! You just gotta see if Flutter also supports rendering vertices with colors in the canvas (although I think it does).
@alexobviously there currently isn't any support for that flavor of specifying colors in the object file. However there is support for multiple materials which can be used to color sets of vertices independently.
@alexobviously Thank you, I'm happy you liked the package.
I'd love to add this feature, but sadly I don't know how to. I got the core of this code from a Flutter demonstration from @gskinner and adapted it into a library format, adding the controllers, etc. This means that I don't actually have any experience with parsing obj files, so I wouldn't know how to implement this. But if you'd like to give it a try, I'd be happy to help! You just gotta see if Flutter also supports rendering vertices with colors in the canvas (although I think it does).
Hey, thanks for replying so quickly and sorry it took me a while to get back to you, I was working on another project. I've had a look at the parsing code for vertex and I'm sure I can easily add the ability to parse vertex colours without affecting the normal behaviour at all.
For rendering, I'm not 100% sure that it will be trivial, but I see that the Vertices class in flutter has this definition:
Vertices(
VertexMode mode,
List<Offset> positions, {
List<Offset>? textureCoordinates,
List<Color>? colors,
List<int>? indices,
})
so I'm fairly sure it'll be possible.
@alexobviously there currently isn't any support for that flavor of specifying colors in the object file. However there is support for multiple materials which can be used to color sets of vertices independently.
Yeah, in the official .obj definition it doesn't exist, and I'd maybe even also say it's not a very good way to do it, but it is relatively common (there is even support by default in OSX quicklook). In my case, I'm working with a long and complicated tool chain starting with 3D cameras that generate these vertices with colour in that way by default.
@alexobviously it should be pretty easy to implement the parsing as you mentioned as long as I can keep compatibility with the spec unambiguously. I have some time this week, I'll try to submit a PR if that's okay with you @nythrox.
I've tried to implement this here: https://github.com/alexobviously/vertex
It sort of works - colours are getting parsed and assigned but they're not the right colours. The actual colours should be quite dark but I'm getting very bright whites and blues, and it looks like only some of the faces are being rendered. I replaced the movable star in example01 with a vertex coloured model.
If either of you can figure out what's going wrong here I'd appreciate the help 👍
@alexobviously I think there is a base lighting added to the vertices, maybe it could be that?
Here in this block of code https://github.com/alexobviously/vertex/blob/master/lib/mesh.dart#L151
Seems like it adds some lighting, maybe this is what is causing it. Maybe you can change this to only be activated when there is no colors being applied?
Here in this block of code https://github.com/alexobviously/vertex/blob/master/lib/mesh.dart#L151
Seems like it adds some lighting, maybe this is what is causing it. Maybe you can change this to only be activated when there is no colors being applied?
Lighting sounds like about the right thing here, but I'm not sure that anything in that bit of code would affect it?
The 'xn' variable isn't referenced after it's assigned (so actually normals aren't used at all for colouring?) and b is just fixed at 1.0, so the colours should be just passed through as far as I can see.
I've updated my version of the repository with an 'example03' to make it simpler to compare. This is what I get at the moment.
There seems to be two problems. Firstly, some of the faces seem to be invisible. I'm not sure what's going on there. Can either of you see anything wrong?
The other problem is that actually the colours are backwards! When I set red to 0, for example, I get a totally red model. (This is also useful for seeing how some of the faces are not getting drawn).
@alexobviously sorry man... I really have no idea what could be causing the problem, maybe you could try reaching out to the gskinner team but it's a long shot
Are the faces in your mesh triangulated? It's not just the colors that are off from what I can tell in your screen shots, the geometry is also incorrect. Currently the obj loader only supported triangulated faces.