Phong13 / BulletSharpUnity3d

A fork of the BulletSharp project to make the Bullet Physics Engine usable from C# code in Unity3d
Other
549 stars 145 forks source link

Soft body example scenes are broken since 2019.1.1f1 #67

Open R2RT opened 5 years ago

R2RT commented 5 years ago

Hi, I wanted to make use of your package for soft bodies simulation and I found out that something must have changed between 2018 and 2019 Unity releases. See attached image for meaning of "broken": image image

Skinned mesh triangles seems to be quite randomized. I've tested it with current master commit and Unity Package's imported one.

2018.4.6f1 is the last release where soft skinned mesh behaves for me correctly. Checked on Windows only.

I could not find any related change in changelog... https://unity3d.com/unity/whats-new/2019.1.0

Phong13 commented 5 years ago

Hi R2RT, I think the problem is that 2019.1 serializes scene data differently than 2018 and 2018- scenes don't always upgrade properly. Some of the example scenes have Meshes generated in the editor in 2017 and these are mangled in 2019.1. They work if you click the button to re-generate the meshes.

For the SoftBody scenes I think you need to click the "Bind Bones To Soft Body & Nodes To Anchor". I think it is the binding data that is corrupt.

I am not sure how to deal with this issue since I don't want to have a branch with duplicate scenes.

R2RT commented 5 years ago

Hey, thanks, rebinding anchors solved the issue.

Maybe adding metadata about Editor version which created the soft body with custom serializer (ISerializationCallbackReceiver) could be used here? Which emits warning that you should manually rebind using "Bind Bones To Soft Body & Nodes To Anchor" button if version differs "too much" (i.e. pre-2019 vs 2019).

Also, I've noticed that rebinding the bones does not set object as "dirty", so in order to save the scene you have to change some normal property on and off. UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(sb.gameObject.scene); right after sb.BindBonesToSoftBodyAndNodesToAnchors(); line fixes it. I may issue independent PR for this.