Points uniformly spread on bézier curve should be functional.
This commit is contained in:
@@ -561,13 +561,11 @@ public class BezierCurve : MonoBehaviour {
|
|||||||
return points[points.Length - 1].position;
|
return points[points.Length - 1].position;
|
||||||
}
|
}
|
||||||
|
|
||||||
float segmentLength = length / 2;
|
|
||||||
|
|
||||||
float totalLength = 0;
|
float totalLength = 0;
|
||||||
for (int i = 0; i < points.Length - 1; i++) {
|
for (int i = 0; i < points.Length - 1; i++) {
|
||||||
var p1 = points[i];
|
var p1 = points[i];
|
||||||
var p2 = points[i + 1];
|
var p2 = points[i + 1];
|
||||||
|
|
||||||
if (p1 == null) {
|
if (p1 == null) {
|
||||||
p1 = points[points.Length - 1];
|
p1 = points[points.Length - 1];
|
||||||
p2 = points[0];
|
p2 = points[0];
|
||||||
@@ -579,15 +577,23 @@ public class BezierCurve : MonoBehaviour {
|
|||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
var curveDistance = distance - totalLength;
|
var curveDistance = distance - totalLength;
|
||||||
var segmentIndex = (float)Math.Floor(curveDistance / segmentLength);
|
|
||||||
var segmentStart = segmentIndex * segmentLength;
|
//Calculate the very first line segment
|
||||||
var segmentEnd = (segmentIndex + 1) * segmentLength;
|
Vector3 s1 = p1.position;
|
||||||
var segmentDistance = curveDistance - segmentStart;
|
Vector3 s2 = GetPoint(p1, p2, 1.0f / resolution);
|
||||||
|
float mag = (s2 - s1).magnitude;
|
||||||
|
float polylineLength = mag;
|
||||||
|
|
||||||
Vector3 s1 = GetPoint(p1, p2, segmentStart / curveLength);
|
//Keep calculating line segments until we have traveled more than curveDistance.
|
||||||
Vector3 s2 = GetPoint(p1, p2, segmentEnd / curveLength);
|
for (int segmentIndex = 2; polylineLength < curveDistance; segmentIndex++) {
|
||||||
|
s1 = s2;
|
||||||
return GetLinearPoint(s1, s2, segmentDistance / segmentLength);
|
s2 = GetPoint(p1, p2, (float)segmentIndex / resolution);
|
||||||
|
mag = (s2 - s1).magnitude;
|
||||||
|
polylineLength += mag;
|
||||||
|
}
|
||||||
|
//The desired position should be between s1 and s2.
|
||||||
|
//polylineLength should be slightly greater than curveDistance, the difference gives the 't' value.
|
||||||
|
return GetLinearPoint(s1, s2, 1 - (polylineLength - curveDistance) / mag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,14 +21,14 @@ public class WarehouseColumn : MonoBehaviour {
|
|||||||
|
|
||||||
void Update() {
|
void Update() {
|
||||||
if (Application.isPlaying) {
|
if (Application.isPlaying) {
|
||||||
//offset += Time.deltaTime;
|
//Offset += Time.deltaTime * 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Transform row in rows) {
|
foreach (Transform row in rows) {
|
||||||
var i = row.GetSiblingIndex();
|
var i = row.GetSiblingIndex();
|
||||||
var distance = (float)i / (rows.childCount) * curve.length + Offset;
|
var distance = (float)i / (rows.childCount) * curve.length + Offset;
|
||||||
distance = Mathf.Repeat(distance, curve.length);
|
distance = Mathf.Repeat(distance, curve.length);
|
||||||
var pos = curve.GetPointAtDistance(distance);
|
var pos = curve.GetUniformPointAtDistance(distance);
|
||||||
row.position = pos;
|
row.position = pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user