I’m trying to create BP spline and the can’t get the mesh to act properly. its always deformed. But the landscape spline is able to render it perfectly with default topology.
If i simplify the mesh (using unreal modeling tool) blueprint spline it looks good but the curves are not smooth.
Anyone know what’s happening here. I wanna understand what magic is Landscape spline doing. And any link to the source code?
My spline logic at the bottom
The default Mesh wireframe
Simplified mesh with spline
void ARoadSplineActor::UpdateSplineMeshes() {
for (USplineMeshComponent* Comp : SplineMeshComponents) {
if (Comp) {
Comp->DestroyComponent();
}
}
SplineMeshComponents.Empty();
if (!SplineMesh) return;
float SplineLen = SplineComponent->GetSplineLength();
float MeshLen = MeshLength;
if (MeshLen <= 0.0f) {
FBoxSphereBounds Bounds = SplineMesh->GetBounds();
MeshLen = Bounds.BoxExtent.X * 2.0f;
}
float CurrentDistance = 0.0f;
while (CurrentDistance < SplineLen) {
float Start = CurrentDistance;
float End = FMath::Min(Start + MeshLen, SplineLen);
const FVector StartPos = SplineComponent->GetLocationAtDistanceAlongSpline(
Start, ESplineCoordinateSpace::Local) + FVector(0, 0, 10);
const FVector EndPos = SplineComponent->GetLocationAtDistanceAlongSpline(
End, ESplineCoordinateSpace::Local) + FVector(0, 0, 10);
const FVector StartTangent = SplineComponent->GetTangentAtDistanceAlongSpline(
Start, ESplineCoordinateSpace::Local);
const FVector EndTangent = SplineComponent->GetTangentAtDistanceAlongSpline(
End, ESplineCoordinateSpace::Local);
USplineMeshComponent* SplineMeshComp = NewObject<USplineMeshComponent>(this);
SplineMeshComp->SetStaticMesh(SplineMesh);
SplineMeshComp->SetMobility(SplineComponent->Mobility);
SplineMeshComp->RegisterComponentWithWorld(GetWorld());
SplineMeshComp->AttachToComponent(SplineComponent,
FAttachmentTransformRules::KeepRelativeTransform);
SplineMeshComp->SetStartAndEnd(StartPos, StartTangent, EndPos, EndTangent);
SplineMeshComp->SetStartScale(FVector2D(1.0f, 1.0f));
SplineMeshComp->SetEndScale(FVector2D(1.0f, 1.0f));
SplineMeshComponents.Add(SplineMeshComp);
CurrentDistance += MeshLen + MeshOffset;
}
}