Subdivision Step Sampler diff 5.8 / 5.7

बनाया गया Diff कभी समाप्त नहीं होता
0 हटाए गए
87 लाइनें
3 जोड़े गए
87 लाइनें
virtual void Step(FSamplerResult& OutResult) override
virtual void Step(FSamplerResult& OutResult) override
{
{
const int PreviousSegmentIndex = (CurrentSegmentIndex > 0 ? CurrentSegmentIndex : NumSegments) - 1;
const int PreviousSegmentIndex = (CurrentSegmentIndex > 0 ? CurrentSegmentIndex : NumSegments) - 1;


// To capture the last key point on the spline, we sample the point at the end of the previous segment.
// To capture the last key point on the spline, we sample the point at the end of the previous segment.
const bool bLastKeyPoint = CurrentSegmentIndex == LineData->GetNumSegments();
const bool bLastKeyPoint = CurrentSegmentIndex == LineData->GetNumSegments();
const int SegmentIndex = bLastKeyPoint ? PreviousSegmentIndex : CurrentSegmentIndex;
const int SegmentIndex = bLastKeyPoint ? PreviousSegmentIndex : CurrentSegmentIndex;


const FVector::FReal SegmentLength = LineData->GetSegmentLength(SegmentIndex);
const FVector::FReal SegmentLength = LineData->GetSegmentLength(SegmentIndex);
const FVector::FReal SegmentStep = SegmentLength / (SubdivisionsPerSegment + 1);
const FVector::FReal SegmentStep = SegmentLength / (SubdivisionsPerSegment + 1);
const FVector::FReal DistanceAlongSegment = bLastKeyPoint ? SegmentLength : SubpointIndex * SegmentStep;
const FVector::FReal DistanceAlongSegment = bLastKeyPoint ? SegmentLength : SubpointIndex * SegmentStep;


FBox& OutBox = OutResult.Box;
FBox& OutBox = OutResult.Box;
FTransform& OutTransform = OutResult.LocalTransform;
FTransform& OutTransform = OutResult.LocalTransform;
OutTransform = LineData->GetTransformAtDistance(SegmentIndex, DistanceAlongSegment, /*bWorldSpace=*/false, &OutBox);
OutTransform = LineData->GetTransformAtDistance(SegmentIndex, DistanceAlongSegment, /*bWorldSpace=*/false, &OutBox);
OutResult.SampleIndex = SampleIndex++;
OutResult.SampleIndex = SampleIndex++;
OutResult.SegmentIndex = LineData->IsClosed() ? CurrentSegmentIndex : SegmentIndex;
OutResult.SegmentIndex = LineData->IsClosed() ? CurrentSegmentIndex : SegmentIndex;
OutResult.SubsegmentIndex = SubpointIndex;
OutResult.SubsegmentIndex = SubpointIndex;
OutResult.InputKey = LineData->GetInputKeyAtDistance(SegmentIndex, DistanceAlongSegment);
OutResult.InputKey = LineData->GetInputKeyAtDistance(SegmentIndex, DistanceAlongSegment);


if (bComputeCurvature)
if (bComputeCurvature)
{
{
OutResult.Curvature = LineData->GetCurvatureAtDistance(SegmentIndex, DistanceAlongSegment);
OutResult.Curvature = LineData->GetCurvatureAtDistance(SegmentIndex, DistanceAlongSegment);
}
}


if (bComputeTangents)
if (bComputeTangents)
{
{
// Control points have actual Arrive and Leave tangents
// Control points have actual Arrive and Leave tangents
if (SubpointIndex == 0)
if (SubpointIndex == 0)
{
{
LineData->GetTangentsAtSegmentStart(CurrentSegmentIndex, OutResult.ArriveTangent, OutResult.LeaveTangent);
LineData->GetTangentsAtSegmentStart(CurrentSegmentIndex, OutResult.ArriveTangent, OutResult.LeaveTangent);
}
}
else
else
{
{
// For a non-control-point, we can get the normalized tangent at least.
// For a non-control-point, we can get the normalized tangent at least.
const FVector Forward = OutTransform.GetRotation().GetForwardVector();
const FVector Forward = OutTransform.GetRotation().GetForwardVector();
OutResult.ArriveTangent = Forward;
OutResult.ArriveTangent = Forward;
OutResult.LeaveTangent = Forward;
OutResult.LeaveTangent = Forward;
}
}
}
}


if (bComputeAlpha)
if (bComputeAlpha)
{
{
OutResult.Alpha = LineData->GetAlphaAtDistance(SegmentIndex, DistanceAlongSegment);
OutResult.Alpha = LineData->GetAlphaAtDistance(SegmentIndex, DistanceAlongSegment);
}
}


if (bComputeDistance)
if (bComputeDistance)
{
{
// When we step onto a new segment, add the length of the previous segment onto the distance to our current segment.
// When we step onto a new segment, add the length of the previous segment onto the distance to our current segment.
if (SegmentIndex > 0 && !bLastKeyPoint && SubpointIndex == 0)
if (SegmentIndex > 0 && !bLastKeyPoint && SubpointIndex == 0)
{
{
DistanceToCurrentSegment += LineData->GetSegmentLength(SegmentIndex - 1);
DistanceToCurrentSegment += LineData->GetSegmentLength(SegmentIndex - 1);
}
}


OutResult.Distance = DistanceToCurrentSegment + DistanceAlongSegment;
OutResult.Distance = DistanceToCurrentSegment + DistanceAlongSegment;
}
}


const double ScaleFactor = 0.5 * SegmentStep / (FMath::IsNearlyZero(OutTransform.GetScale3D().X) ? UE_DOUBLE_SMALL_NUMBER : OutTransform.GetScale3D().X);
const double ScaleFactor = 0.5 * SegmentStep / (FMath::IsNearlyZero(OutTransform.GetScale3D().X) ? UE_DOUBLE_SMALL_NUMBER : OutTransform.GetScale3D().X);


if (SubpointIndex == 0)
if (SubpointIndex == 0)
{
{
const FVector::FReal PreviousSegmentLength = LineData->GetSegmentLength(PreviousSegmentIndex);
const FVector::FReal PreviousSegmentLength = LineData->GetSegmentLength(PreviousSegmentIndex);
FTransform PreviousSegmentEndTransform = LineData->GetTransformAtDistance(PreviousSegmentIndex, PreviousSegmentLength, /*bWorldSpace=*/false);
FTransform PreviousSegmentEndTransform = LineData->GetTransformAtDistance(PreviousSegmentIndex, PreviousSegmentLength, /*bWorldSpace=*/false);


if ((PreviousSegmentEndTransform.GetLocation() - OutTransform.GetLocation()).Length() <= KINDA_SMALL_NUMBER)
if ((PreviousSegmentEndTransform.GetLocation() - OutTransform.GetLocation()).Length() <= KINDA_SMALL_NUMBER)
{
{
OutBox.Min.X *= 0.5 * PreviousSegmentLength / ((FMath::IsNearlyZero(PreviousSegmentEndTransform.GetScale3D().X) ? UE_DOUBLE_SMALL_NUMBER : PreviousSegmentEndTransform.GetScale3D().X) * (SubdivisionsPerSegment + 1));
OutBox.Min.X *= 0.5 * PreviousSegmentLength / ((FMath::IsNearlyZero(PreviousSegmentEndTransform.GetScale3D().X) ? UE_DOUBLE_SMALL_NUMBER : PreviousSegmentEndTransform.GetScale3D().X) * (SubdivisionsPerSegment + 1));
}
}
else
else
{
{
OutBox.Min.X *= ScaleFactor;
OutBox.Min.X *= 0.5 * SegmentStep / ScaleFactor;
}
}
}
}
else
else
{
{
OutBox.Min.X *= ScaleFactor;
OutBox.Min.X *= 0.5 * SegmentStep / ScaleFactor;
}
}


OutBox.Max.X *= ScaleFactor;
OutBox.Max.X *= 0.5 * SegmentStep / ScaleFactor;


++SubpointIndex;
++SubpointIndex;
if (SubpointIndex > SubdivisionsPerSegment || bLastKeyPoint)
if (SubpointIndex > SubdivisionsPerSegment || bLastKeyPoint)
{
{
SubpointIndex = 0;
SubpointIndex = 0;
++CurrentSegmentIndex;
++CurrentSegmentIndex;
}
}
}
}