Whinarn / UnityMeshSimplifier

Mesh simplification for Unity.
MIT License
1.76k stars 277 forks source link

Documentation for the LOD Generator Helper #41

Closed NateDawgg closed 3 years ago

NateDawgg commented 4 years ago

Could you please provide me with some instructions for using the LOD Generator Helper? It would be very helpful to have instructions for common use. It would also be nice to have a list of do's and don'ts to reduce the occurrence of unexpected behavior and to know its limitations.

I have encountered various issues when generating LODs for vehicle models. I have roughly 21 unique vehicle models. Each vehicle model has up to 9 color variant prefabs. Each color variant prefab is a duplicate of the original model, but has a different/unique material and color applied. I am trying to generate LODs for the body of each prefab variant and then generate LOD for the wheels for each prefab variant. But my attempts have been unsuccessful due to the following issues:

Here is an example of how the vehicle color variant prefabs are named: image

Below is an example of the body and wheel groups that I need to generate LODs for. Notice that each prefab color variant has the same names for it's body and wheel groups. If the LOD Helper Component settings are copied from one wheel and applied to all 4 wheels of each color variant, would this cause a conflict? image image

Here is what the generated LOD folders look like in the Assets/UMS_LODs/ folder: image

If I add a LOD Generator Helper Component to Sporty_Hatchback_white/Wheel_FL and then set the LOD settings, copy the Component Settings, generate LODs, then open Sporty_Hatchback_silver and add a LOD Generator Helper Component to Sporty_Hatchback_silver/Wheel_FL and paste the Component Settings from Sporty_Hatchback_white/Wheel_FL, will it cause a conflict?

I figured that I would reach out for help first before listing these issues as bugs. It very well could be user error. I appreciate any help that you could provide!

Thanks, Nathan

Whinarn commented 4 years ago

Hi @NateDawgg ,

You have a lot of questions in here, so I will do my best to answer all of them.

First and foremost you should not have a hierarchy of LOD Generator Helpers, as in having one on both the parent and a child. At the moment it's not smart enough to detect that. The LOD Generator Helper will generate LODs for everything below it recursively, or at least should. So you should either have one on the prefab root, or separate for the body and each wheel if you require different settings for them.

After generating LODs for each of the 4 wheels of one of the vehicle prefabs, the LODs that are generated for the last wheel are not saved. This issue was also encountered when generating LODs for vehicle body as well.

I believe this is the bug that you reported separately and should now be resolved, if you look at my comment there.

To work-a-round the issue above, I tried regenerating the LODs for the body or wheel and manually adding the LOD Backup Component script to try to force it to save the generated LOD. Sometimes manually adding the LOD Backup Component script would cause all the other color variants of that vehicle type to loose their assigned color and they would need to be re-imported.

You should not manually add the LOD Backup Component. It's hidden in the inspector because it contains information of how to restore the object, and manually modifying it will cause unexpected issues. I have no idea why adding it would cause the problems that you experienced, because it would only affect anything if you clicked on Destroy LODs.

But the good news is that the LOD saving issue should be resolved, so you shouldn't have to work around it. I believe that manually clicking Save Project in Unity would have forced a save and be a workaround before the issue was fixed in the latest version.

I ran into another issue on occasion, where destroying LODs removes the vehicle's mesh renderer. Parts of the vehicle disappear and the original prefab must be re-imported.

This is really bad if this is true. Could you please report a separate issue for this? Preferably with a good reproduction case such as your previous one. My goal is obviously to avoid touching the original assets as much as possible, this is why I have the LOD Backup Component in attempt to restore it to its original state. But could it be due to the fact that you have manually added your own LOD Backup Component, and the wrong one gets picked up?

After generating LODs for the body and wheels of all color variant prefabs for a particular vehicle type, there were instances where the sliders for LOD switching had no affect on some of the variants but worked on others. They would switch based on the original LOD switching values instead of using the new ones.

I'm not sure I understand what this means. But if I understand you correctly, I think that it could be related to what I wrote above about not having a LOD Generator Helper on both a parent and child, since the meshes would be duplicated. If this is not it, could you provide more details or perhaps show me with screenshots or something of the problem you are experiencing?

If the LOD Helper Component settings are copied from one wheel and applied to all 4 wheels of each color variant, would this cause a conflict?

It should not cause a conflict unless the LOD meshes are saved to the same path. The default path is something like Assets/UMS_LODs/<game_object_name>/<renderer_name>/<mesh_name>.mesh but could be changed by overriding it by checking Override Save Assets Path where it would save into Assets/<path_you_provide>/<mesh_name>.mesh instead.

<game_object_name> = the name of the game object <renderer_name> = the name of the game object the renderer is attached to and details about static/skinned and sometimes the LOD level <mesh_name> = the name of the mesh generated, a combination of the original mesh name with some additional postfixes on the details of it

But as you can see you can influence this based on the naming of the game objects etc as well. Also have in mind that Copy component on the LOD Helper Component would also copy a flag about it being generated, which could cause some unexpected behavior. So I strongly recommend you to only copy it when it has not already been generated.

If I add a LOD Generator Helper Component to Sporty_Hatchback_white/Wheel_FL and then set the LOD settings, copy the Component Settings, generate LODs, then open Sporty_Hatchback_silver and add a LOD Generator Helper Component to Sporty_Hatchback_silver/Wheel_FL and paste the Component Settings from Sporty_Hatchback_white/Wheel_FL, will it cause a conflict?

This is related to above, and seeing my reply there you should see that this would result in both of them saving generated LOD meshes to the same path. It should be resolved if you only have one LOD Generator Helper on the prefab root. But if you need different settings for the wheels, I would recommend you to somehow rename the Wheel_FL game object differently between the prefabs, or override the save path as I mentioned above. Unfortunately right now you don't have so many more choices.

If you have an idea of how to configure this better, I'm open to suggestions. But you should be able to work around the issue with my suggestions above.

I hope that this answers all your questions. I look forward to your answers, and if you could open an additional issue for the bug where your orginal prefab gets broken after Destroy LODs (unless it's due to duplicated LOD Backup Component).

Best regards, Mattias

Whinarn commented 4 years ago

Also, regarding documentation, you are right. At first this was only intended for programmers, so the only documentation was explaining how to use the API. But after adding the LOD Generator Helper there is a greater need to explain how it works, what to avoid and tips and tricks.

I'll keep this issue open as a reminder and see if I can get some time for it at a later time.

Thanks!

NateDawgg commented 4 years ago

@Whinarn Thank you so much for the fix and for the great responses. The fix should help a lot. After testing more and reading your replies. I think most of the issues that I was running into were a result of user error. Specifically, I was manually copying the LOD Backup Component onto objects in an attempt to work-a-round the LODs not being saved. Before you delivered the script, I realized that If I edited the rotation of the object (after LODs were generated) and then changed the rotation back, the LODs were automatically saved correctly. That ended up being a successful work-a-round, but obviously the fix now eliminates the need to do the extra step. I will be sure to test the new version and report back.

Thanks again,

Nathan

Whinarn commented 3 years ago

Closing this issue in favor of a newly opened open, since this issue also includes other problems that have since been resolved.