cmbasnett / io_scene_rsw

Blender plugin for importing assets from Ragnarok Online
MIT License
12 stars 8 forks source link

Fix RSM node transform issues #7

Open cmbasnett opened 5 years ago

cmbasnett commented 5 years ago

https://gitlab.com/open-ragnarok/open-ragnarok/blob/master/roint/rsm.cc

The node transformations, especially for the root transform appear to be way off. The location value seems to be pretty consistently correct, while the "parent" node transforms are a bit more of a mystery. A way to test code and visually confirm results for multiple models at once would be useful compared to testing against single models where the validity of the results is less clear.

Some way to compare imported models against what the "ground truth" should be (re: offset from origin etc.) would be indispensable in sorting out these issues.

cmbasnett commented 5 years ago

I found source code for an old RSM viewer that, while incomplete (it skims over certain data in later versions) appears to have some sort of way to conditionally translate the root parent node into the correct position (I'm actually just assuming it's doing it right, but at first glance appears consistent with the odd results I've been seeing from the import script).

Their code appears to be applying certain translations to nodes depending on whether or not the node is the "root" (or "main") node, and if it's the "only" node (if the mesh count is 1). It also seems to calculate some kind of bounding box and uses that for translations as well, though it could be for something specific to their viewer rendering (centering the model infront of the camera, for example)

Here is the relevant code block:

if (!main)
  glTranslatef(transf.todo[12], transf.todo[13], transf.todo[14]);

if (!nframes)
  glRotatef(transf.todo[15] * 180.0 / 3.14159,
            transf.todo[16], transf.todo[17], transf.todo[18]);
else
  glMultMatrixf(Ori);

glPushMatrix();

if (main && only)
  glTranslatef(-box->range[0], -box->range[1], -box->range[2]);

if (!main || !only)
  glTranslatef(transf.todo[9], transf.todo[10], transf.todo[11]);

Take aways:

if (!main)
  glTranslatef(transf.todo[12], transf.todo[13], transf.todo[14]);

This appears to be applying the raw translation (but only if it's not the root node).

if (!main || !only)
  glTranslatef(transf.todo[9], transf.todo[10], transf.todo[11]);

This appears to be applying the node transform, but only if it's not the main node or if it's not the only node. Very strange. Will experiment implementing this stuff soon.

cmbasnett commented 5 years ago

I did some playing around with Browedit. For many of the models I tested, It seems like it is almost always treating the "bottom center" of the bounding box as the origin. More investigation is needed to see if this is actually a generalizable rule in regards to how it's placed within the RSW-space.

I don't really trust Bromedit as it's rendering of what the origin seems somehow dubious. Not to self: try placing the Morroco railing and seeing if it's origin is identical to what is seen in Bromedit.

rdw-software commented 4 years ago

Yes, it appears the client simply casts from float to int:

r = (int)(r / LEVEL_COUNT) * LEVEL_COUNT
g = (int)(g / LEVEL_COUNT) * LEVEL_COUNT
b = (int)(b / LEVEL_COUNT) * LEVEL_COUNT
In RO, LEVEL_COUNT is 16.

(Source: rathena forums)

The actual texture doesn't have any artifacts, as can be seen in this comparison: Actual RGB values vs truncated RGB values and again, original colors vs posterized colors

As for the RSM issue:

I haven't spent much work on the RSM format yet, but have you looked at some other working implementations? These should all be capable of rendering models:

I don't really know what to look for, but I noticed something weird with the positions of the light sources stored in the RSW file: Original positioning and my best attempt, still somewhat off. Not sure if they use the same coordinate system as RSM nodes, though.

I could probably add a RSM loader to my app and see if I can determine what the problem is with relatively little effort once I understand the format better. This way, adding visualizations would be trivial, although you might be able to do the same with any of the other projects listed above?

cmbasnett commented 4 years ago

Thanks for the links to all those other projects, this should help. I've only looked at BrowEdit, but its documentation leaves much to be desired. I will eventually circle back to this and sort out what the issue is, hopefully.

rdw-software commented 4 years ago

Unfortunately I haven't had time to look into RSM files further yet, but if you have an example of this problem I can probably do that soon. I've mostly just models and effect files left, and my framework is now flexible enough to start working on the rest :)