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

Center/Radius algorithm #69

Open
ttl269 opened this issue Jul 7, 2014 · 5 comments
Open

Center/Radius algorithm #69

ttl269 opened this issue Jul 7, 2014 · 5 comments

Comments

@ttl269
Copy link
Member

ttl269 commented Jul 7, 2014

NifSkope has two algorithms for computing the Center and Radius values of NiTriShapeData/NiTriStripsData blocks. One algorithm computes the center of the data's bounding box, and one uses another method (some kind of vertex average?).

In NifSkope mesh.cpp#L618 the algorithm chosen depends on the NIF version or if Consistency Flags is set to CT_VOLATILE. See: mesh.cpp#L634. (That condition was surely written before Skyrim.)

I have checked several Skyrim NIFs and found that their Center and Radius values are precisely like using the bounding box algorithm but instead have their Consistency Flags set to CT_STATIC. So, in NifSkope when Mesh > Update Center/Radius function is used on Skyrim NIFs, it produces different Center/Radius values because it chooses the second method.

I think that the condition should be changed such that in the case that Consistency Flags is set to CT_STATIC, the first method (Bounding box) is used instead.

@neomonkeus
Copy link
Member

neomonkeus commented Jul 8, 2014

Nothing for @niftools/blender-plugin-reviewer
This may need to be investigated in the Blender Nif Plugin.

@hexabits hexabits changed the title Choose of Center/Radius algorithm Center/Radius algorithm Aug 4, 2014
@hexabits
Copy link
Member

hexabits commented Aug 4, 2014

@ttl269 @neomonkeus

Did CT_STATIC exist before Skyrim? If so does CT_STATIC need to use the second algorithm in the case that the NIF version < Skyrim? For example, assuming that CT_STATIC did exist in Oblivion, obviously the condition that it be CT_VOLATILE is saying that only that algorithm is good for that one Consistency Flags value.

Does this mean that every Skyrim NIF ever saved by NifSkope has an incorrect Center/Radius if the data is CT_STATIC and the Mesh > Update Center/Radius function has been used?

I saw the basis of this ticket in the forums, and it had to do with an object showing up in the wrong position in the inventory, no? Can someone test running Mesh > Update Center/Radius on some Skyrim NIFs and see if some, all, or none of them shift their position in game? Not specifically in the inventory, but out in the world. I will also try to test this thoroughly when I can.

Also, the Center/Radius appears to have no bearing on the position in NifSkope, and I am guessing if these values actually matter somehow, that these should be taken into account..

My guess is that the objects will not move out in the world because they use the actual origins of the meshes, and that for whatever reason they use the center/radius when positioning the object on screen for display in the inventory.

Should FO3/NV also be taken into account here? I assume they either act like Oblivion or act like Skyrim for the algorithm choice, but nowhere is Fallout covered in the conditions for that function.


Side note: I need to audit CT_VOLATILE vs CT_STATIC in general, because this isn't the first issue brought up with it. The first had something to do with the defaults for that value in Fallout 3 vs other versions. I believe Hana reported it, and the use case was switching the NIF file's version to something else temporarily (e.g. Skyrim > Fallout), but when setting the NIF version back (e.g. Fallout > Skyrim) the value for that field is "erased" i.e. reverted back to the default value in the previous NIF version. (I think this may have already been resolved in nif.xml, or there is still a ticket for it)

@ttl269
Copy link
Member Author

ttl269 commented Nov 2, 2014

I have tested some files in Skyrim and Fallout3.
Skyrim:
It seems that if consistency flags is set to CS_STATIC, the values in Center/Radius are ignored. Game probably computes own values and everything is ok.

  • if consistency flags is set to CS_MUTABLE or CS_VOLATILE:
    • game use Center and Radius in nif file for showing the item in inventory,
    • game use Center in nif file for placing the object into world when dropped from inventory
    • if Radius is set to 0
      • item is not showed in invetory
      • item dropped into world from inventory is invisible (its 3D is not rendered, havok is ok) and probably placed on some wrong place, because after a while it is placed on its editor coordinates but still invisible - its 3D is not rendered, havok is ok
    • if values in Center are wrong
      • item in the world can be invisible from certain angles (its 3D is not rendered, havok is ok)
      • item's initial position when dropped from inventory is shifted
      • item's position in invetory is shifted, rotating it by mouse can move it out of the screen

Fallout3:
It seems that game always use Center/Radius values in nif file for placing the object into world when dropped from inventory, regardless of setting of consistency flags.

  • if consistency flags is set to CS_STATIC:
    • wrong values in Center can shift object's initial world position after dropped from inventory
    • wrong values in Center has no influence on item rendering in world
    • it seems that non-zero values in Radius has no influence
    • if Radius se set to 0, item dropped into world from inventory is invisible (its 3D is not rendered, havok is ok) and probably placed on some wrong place, because after a while it is placed on its editor coordinates and become normally visible
  • if consistency flags is set to CS_MUTABLE or CS_VOLATILE:
    • wrong values in Center can shift object's initial world position after dropped from inventory
    • wrong values in Center can cause that item in the world can be invisible from certain angles (its 3D is not rendered, havok is ok)
    • it seems that non-zero values in Radius has no influence
    • if Radius se set to 0, item dropped into world from inventory is invisible (its 3D is not rendered, havok is ok) and probably placed on some wrong place, because after a while it is placed on its editor coordinates but still invisible - its 3D is not rendered, havok is ok

So, for Skyrim is best solution to set consistency flags to CT_STATIC - this is important namely for nif export plug-ins. Then the values in Center/Radius are ignored. And for nifskope would be good to always use first algorithm of computing Center/Radius (in recent code marked as is a Oblivion mesh!) producing same values as in vanilla nifs.
For Fallout would be also good to set consistency flags to CT_STATIC and also choose first algorithm - it also produces same values as in vanilla nifs.

It would be good to find if exists any Fallout3 or Skyrim vanilla nif with consistency flags set to CS_MUTABLE or CS_VOLATILE.
For that time I have found CS_MUTABLE:

  • in Fallout3 NiPSysData blocks, for example meshes\effects\ashpile01.nif.
  • in Fallout3 meshes in directory meshes\characters\hair which represents parts of character. Accessories like glasses or eyepatch uses CS_STATIC.

@Ghostwalker71
Copy link

All 3 values are used in all of the mentioned games depending on item types. currently the plugin has a custom to store imported setting for this and defaults to static if setting in not found on export.
NiParticleSystem data objects use ct_mutable

@neomonkeus
Copy link
Member

This is something that needs to be added as general documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants