modular-avatar
modular-avatar copied to clipboard
MA Mesh Settings: Add "update when off screen" checkbox to apply to all mesh children
The "update when off screen" option in the skinnedmeshrenderer component computes the bounding box, without regard for the root bone or defined center and extent, by automatically drawing the rectangular bounding box within which the mesh occupies at every frame.
Not all mesh systems are set up properly, and sometimes it's tricky and/or tedious to do so. This option will reduce the number of problems with meshes disappearing in plain sight due to misplaced bounding boxes not encapsulating the entire mesh.
Suggested implementation: add as checkbox in the Set menu for bounds override configuration.
Computing a precise bounding box can result in inconsistent lighting in some situations, so it's not always a good idea to have this set. Why is the existing bounding box override insufficient?
The current implementation of bounding box configuration changes the root bone, which not all skinnedmeshrenderer objects ignore. If the skinnedmeshrenderer exists but does not have its own armature, the gameobject itself is the renderer's origin and setting a root bone will set the object's transform to the root bone, which can prove to be undesirable if the renderers are linked via constraints or are part of other hierarchies under the same circumstance. Blender is required to fix this issue.
As for lighting, as far as I know (but I'm confident in my experience), the anchor (skinnedmeshrenderer>Probes>Anchor Override) changes the light receiving position from the gameobject to the new object. The root bone changes the bounding box origin, and the object transform is zeroed to the root bone if it's not linked to a bone via the preferred mesh editor.
I usually add the MA Mesh Settings component to my avatar to produce consistent lighting results (e.g. anchor override to Chest so everything lights up in unison), but I currently can't safely set the bounding box without overriding the root bone (which is usually just Hips 0,0,0,2,2,2 for me). I just think that adding this checkbox will make the bounding box setup process easier since it's always done for you.
Okay, so the issue is primarily unskinned meshes that are displayed using the Skinned Mesh Renderer component? I could potentially correct those by generating bone data for them (ie - fix the issue like you would in Blender).
As for lighting, I've done some experimentation and for vertex lights specifically unity seems to use dynamic bounds (even if that check is off, interestingly)
Okay, so the issue is primarily unskinned meshes that are displayed using the Skinned Mesh Renderer component?
I think so, yeah. But sometimes it uses blendshapes which Mesh Renderers can't manipulate, and converting MRs to SMRs usually yield the red warning that says it may not render in player. I don't know the circumstances for which it wouldn't though, but I like avoiding this warning.
As for lighting, I've done some experimentation and for vertex lights specifically unity seems to use dynamic bounds (even if that check is off, interestingly)
In VRChat, I've found that in a dark room with light sources, the light intensity that reaches the meshes depends on the anchor set by the SMR and its proximity with said light sources. The bounds only determines when the mesh should be rendered, the viewing camera must have line of sight with the bounds to appear. Also, I've found that "update when offscreen" is semi-independent from the bounds, it ignores the orientation of the object it's hooked to (whether itself or rootbone) and creates a box that the mesh occupies, but center and extent can still be defined.
In the case of meshes that have multiple bones, sometimes the mesh is translated outside of the static bounds that is set for it, which leads to the disappearing meshes at the edges of a screen, whether in VR or desktop. This is where update when offscreen comes in. It sets the box automatically based on what space the mesh takes up, which can change drastically. I just do this for all SMRs in my project, albeit manually.
Here is an example in practice. The first picture depicts the mesh with the root bone specified to Hips and a center and extent defined to roughly fit the mesh in edit mode.
Update when offscreen OFF:
Update when offscreen ON: