-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapt curve resolution for existing curves on scene open
This is added in order to prevent Unity performance degradation when there are large curves with too high resolution.
- Loading branch information
Showing
4 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public static class BezierCurveUpgrade | ||
{ | ||
public static void Upgrade(BezierCurve curve) | ||
{ | ||
// resolution logic change - adapt old serialized resolution value to new behavior | ||
if (curve.version < 2) | ||
{ | ||
Debug.Log(string.Format("[BezierCurve upgrade] adapting curve resolution value for '{0}'", curve.name), curve); | ||
|
||
// will use maximum resolution that matches old curve interpolation density | ||
float shortestSegmentLength = float.MaxValue; | ||
for (int i = 0; i < curve.pointCount - 1; i++) | ||
{ | ||
float length = BezierCurve.ApproximateLength(curve[i], curve[i + 1], numPoints: 5); | ||
if (length < shortestSegmentLength) shortestSegmentLength = length; | ||
} | ||
float newRes = curve.resolution / shortestSegmentLength; | ||
Debug.Log(string.Format("Old resolution: {0}, new resolution: {1}", curve.resolution, newRes), curve); | ||
|
||
curve.resolution = newRes; | ||
curve.version = 2; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters