-
Notifications
You must be signed in to change notification settings - Fork 78
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
Draft for a course model extractor #438
base: master
Are you sure you want to change the base?
Conversation
This PR is very work-in-progress, leaving it up as a draft for commentary purposes |
Looks good to me! |
Updated to also fetch face data from the base ROM. So now the It should be possible to get texture coordinates in there too but that'll take some extra processing. Need to convert the given integers into floats in the 0.0 to 1.0 range. Somehow. Vertex normals need extra processing too since the |
The N64's UV coordinate format uses 16-bit fixed point from -1024 to +1023. You need 11 bits for that, so 5 are left over, thus simply dividing each texture coordinate by 32, and then by the relevant texture size minus one (width for U, height for V) should do the trick. (Minus 1 because a U coordinate of 1024 already shows the next pixel) Converting them back without introducing UV artifacting is a little tricky unless you do not care about generating vertex data that is accurate to the source material. My SM64 level converter tool takes the middle point of the UV triangle, and then moves all the points such that fmod(centerPointCoord, 1) == newCenterPointCoord. |
That works for regular Vtx structs, my confusion has to do with converting the S/T values of the
These non-standard vertices eventually get straight copied (ignoring how |
I have found that leaving the texture coordinates as they are after the expected divide by 32, divide by texture width/height, even if that leaves them outside of the 0 to 1 range, is fine. I don't know if Blender is doing something in the background or if the OBJ file spec is lying. |
The texture list stuff for each course is going to be a pain in the ass. I think I know what we need to do to get that stuff properly linked though. I'll work on that sometime soon(tm). |
No. Actually it's a perfectly fine texture coordinate. In order for the texture to repeat several times you must obviously go beyond the [0, 1) bounds. |
d08ae79
to
da3ce97
Compare
I'm done messing with this for the moment. Its in a mostly good state, although some courses have some very noticeable flaws when the OBJ file is imported into Blender. The short version is that several courses make use of the texture clamping feature which Blender does not support. This is most noticeable for Moo Moo Farm. where the starting/finish line texture is clamped to create both the race course and the grassy out-of-bounds area. A similar issue is observed in Rainbow Road and Mario Raceway road (albeit less dramatically) and the ocean in Koopa Troopa Beach (not 100% what's going on there really). In some cases a tunnel (like the pipe in Mario Raceway) has its entrance/exit covered with a texture which obviously doesn't happen in practice. I'm not sure what's going on there. OBJ files don't support vertex colors and Blender doesn't support texture mapping and vertex coloring simultaneously so some courses aren't fully detailed. Things like the Mario/Luigi hats (in their respective courses) and the rainbow ring in Rainbow Road are left uncolored since they're supposed to handled by vertex colors. Finally, any textures that are meant to be mirrored aren't designated as such (I don't think OBJ files can handle it) so some courses like Royal Raceway are extremely close to be correct, but the road texture will be slightly off due to it repeating/wrapping/tiling instead of mirroring. In the future exporting the courses in either COLLADA or glTF2 would likely be best, but those formats are far more complicated than OBJ (simplicity is its only asset). glTF2 appears to support repeating/mirroring/clamping in the U and V directions independently, which is nice since the N64 has that capability too. I have had trouble finding good examples of how to use those formats however and I really don't feel like dragging this PR out any longer. |
} | ||
return (char *)base; | ||
} | ||
// char *basename(const char *name) |
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.
Is this intentional? I'm fine with it. But it's part of a utils.c just wanna check this won't mess anything up.
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.
Yeah, it seems like the basename
definition here is conflicting with something in C++'s STL (I think?). It goes unused in all our tools so commenting it out shouldn't hurt anything.
Please add how to use the tool to your PR desc. Or does it just work when you build the repo? |
Usage: |
Should be able to extract arbitrary vtx lists with a little adjustment Signed-off-by: Taggerung <tyler.taggerung@email.com>
course.vtx is the file to be #included in course_vertices.inc.c course.obj is, as named, an OBJ file with the vertex and face lists for the given course Signed-off-by: Taggerung <tyler.taggerung@email.com>
Signed-off-by: Taggerung <tyler.taggerung@email.com>
This mostly works, although you have to generate the mtl file yourself and even then there's some stuff that's horribly messed up. Signed-off-by: Taggerung <tyler.taggerung@email.com>
Signed-off-by: Taggerung <tyler.taggerung@email.com>
Also made the master material file for all course. The paths in that file are relative so if it or the target png's move there will have to be a lot of other changes made Signed-off-by: Taggerung <tyler.taggerung@email.com>
Signed-off-by: Taggerung <tyler.taggerung@email.com>
|
||
CPPFLAGS := -fpermissive | ||
|
||
vtx_extract: vtx_extract.cpp libmio0.c libmio0.h utils.c utils.h |
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.
If this doesn't build when you run make
can we instead integrate this into the normal tools makefile.
Ie. I think the program should be built by default. But only ran if the user desires to do so.
Honestly, it's probably fine if it runs automatically. I'll leave that decision up to you.
Should be able to extract arbitrary vtx lists with a little
adjustment