修改线渲染逻辑
This commit is contained in:
@@ -44,11 +44,6 @@ namespace NBF
|
||||
[SerializeField] private int stableFramesBeforeSleep = 4;
|
||||
[Min(0f)]
|
||||
[SerializeField] private float wakeDistanceThreshold = 0.001f;
|
||||
[Min(0f)]
|
||||
[SerializeField] private float tautSegmentThreshold = 0.002f;
|
||||
[Min(0.001f)]
|
||||
[SerializeField] private float tautTransitionRange = 0.03f;
|
||||
|
||||
[Header("Corner Smoothing")]
|
||||
[SerializeField] private bool smoothCorners = true;
|
||||
[Range(0f, 180f)]
|
||||
@@ -257,7 +252,8 @@ namespace NBF
|
||||
|
||||
ApplyWaterSurfaceConstraint(stepDelta);
|
||||
SolveDistanceConstraints(points, restLengths);
|
||||
StraightenTautLogicalSegments(points, restLengths);
|
||||
// Keep a final pure distance solve so the render chain settles back to its rest-length budget
|
||||
// without reintroducing the old forced-straightening behavior.
|
||||
SolveDistanceConstraints(points, restLengths);
|
||||
PinLogicalPoints(points);
|
||||
ApplySleep();
|
||||
@@ -334,89 +330,6 @@ namespace NBF
|
||||
positions[segmentIndex + 1] -= correction;
|
||||
}
|
||||
|
||||
private void StraightenTautLogicalSegments(
|
||||
IReadOnlyList<FishingLineSolver.ChainPoint> points,
|
||||
IReadOnlyList<float> restLengths)
|
||||
{
|
||||
if (points.Count < 2 || restLengths.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var segmentStartIndex = 0;
|
||||
while (segmentStartIndex < points.Count - 1)
|
||||
{
|
||||
if (!points[segmentStartIndex].IsLogical)
|
||||
{
|
||||
segmentStartIndex++;
|
||||
continue;
|
||||
}
|
||||
|
||||
var segmentEndIndex = segmentStartIndex + 1;
|
||||
while (segmentEndIndex < points.Count && !points[segmentEndIndex].IsLogical)
|
||||
{
|
||||
segmentEndIndex++;
|
||||
}
|
||||
|
||||
if (segmentEndIndex >= points.Count)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
ProjectLogicalSegmentIfTaut(segmentStartIndex, segmentEndIndex, restLengths);
|
||||
segmentStartIndex = segmentEndIndex;
|
||||
}
|
||||
}
|
||||
|
||||
private void ProjectLogicalSegmentIfTaut(
|
||||
int startIndex,
|
||||
int endIndex,
|
||||
IReadOnlyList<float> restLengths)
|
||||
{
|
||||
if (endIndex - startIndex <= 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var segmentRestLength = 0f;
|
||||
for (var i = startIndex; i < endIndex; i++)
|
||||
{
|
||||
segmentRestLength += restLengths[i];
|
||||
}
|
||||
|
||||
var start = positions[startIndex];
|
||||
var end = positions[endIndex];
|
||||
var delta = end - start;
|
||||
var endpointDistance = delta.magnitude;
|
||||
if (endpointDistance <= 0.0001f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var fullTautDistance = Mathf.Max(0f, segmentRestLength - tautSegmentThreshold);
|
||||
var blendStartDistance = Mathf.Max(0f, fullTautDistance - tautTransitionRange);
|
||||
if (endpointDistance < blendStartDistance)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var straightenBlend = blendStartDistance >= fullTautDistance
|
||||
? 1f
|
||||
: Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(blendStartDistance, fullTautDistance, endpointDistance));
|
||||
|
||||
var direction = delta / endpointDistance;
|
||||
var accumulatedDistance = 0f;
|
||||
for (var pointIndex = startIndex + 1; pointIndex < endIndex; pointIndex++)
|
||||
{
|
||||
accumulatedDistance += restLengths[pointIndex - 1];
|
||||
var projectedPosition = start + direction * accumulatedDistance;
|
||||
var currentPosition = positions[pointIndex];
|
||||
var blendedPosition = Vector3.Lerp(currentPosition, projectedPosition, straightenBlend);
|
||||
positions[pointIndex] = blendedPosition;
|
||||
previousPositions[pointIndex] = Vector3.Lerp(previousPositions[pointIndex], blendedPosition, straightenBlend);
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyWaterSurfaceConstraint(float stepDelta)
|
||||
{
|
||||
if (!constrainToWaterSurface || positions.Count == 0)
|
||||
|
||||
@@ -47,6 +47,8 @@ namespace NBF
|
||||
|
||||
[SerializeField] public LineType LineType;
|
||||
|
||||
public JointPinchController PinchController;
|
||||
|
||||
[Header("References")] [SerializeField]
|
||||
private Transform anchorTransform;
|
||||
|
||||
|
||||
@@ -101,10 +101,10 @@ namespace NBF
|
||||
var handItemView = Player.HandItem.GetComponent<PlayerItemView>();
|
||||
if (handItemView != null && handItemView.Rod != null)
|
||||
{
|
||||
// if (handItemView.Rod.Line.PinchController != null)
|
||||
// {
|
||||
// handItemView.Rod.Line.PinchController.StartPinch(view.Unity.ModelAsset.Pinch);
|
||||
// }
|
||||
if (handItemView.Rod.Line.PinchController != null)
|
||||
{
|
||||
handItemView.Rod.Line.PinchController.StartPinch(view.Unity.ModelAsset.Pinch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,10 +118,10 @@ namespace NBF
|
||||
var handItemView = Player.HandItem.GetComponent<PlayerItemView>();
|
||||
if (handItemView != null && handItemView.Rod != null)
|
||||
{
|
||||
// if (handItemView.Rod.Line.PinchController != null)
|
||||
// {
|
||||
// handItemView.Rod.Line.PinchController.ReleasePinch();
|
||||
// }
|
||||
if (handItemView.Rod.Line.PinchController != null)
|
||||
{
|
||||
handItemView.Rod.Line.PinchController.ReleasePinch();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user