I have been trying to use the DrawCylinder function but am just unable to draw a cylinder during runtime. I am able to use the DrawLine and DrawWireBox function and render those shapes during runtime. Does anyone have any idea why I’m unable to see a cylinder in the world at runtime?
This is my code -
FPrimitiveSceneProxy* UCustomComponent::CreateSceneProxy()
{
class FCustomSceneProxy : public FPrimitiveSceneProxy
{
public:
FCustomSceneProxy (const UCustomComponent* InComponent)
: FPrimitiveSceneProxy(InComponent)
, CapsuleRadius(InComponent->CapsuleRadius)
, CapsuleHalfHeight(InComponent->CapsuleHalfHeight)
, AxisMaterialX(InComponent->GetMatInstance())
{
bWillEverBeLit = false;
}
virtual void GetDynamicMeshElements(const TArray<const FSceneView*>& Views, const FSceneViewFamily& ViewFamily, uint32 VisibilityMap, FMeshElementCollector& Collector) const override
{
QUICK_SCOPE_CYCLE_COUNTER(STAT_GetDynamicMeshElements_DrawDynamicElements);
const FMatrix& LocalToWorld = GetLocalToWorld();
const int32 CapsuleSides = FMath::Clamp<int32>(CapsuleRadius / 4.f, 16, 64);
const float AxisLength = 35.f;
const float HalfHeight = AxisLength / 2.0f;
const float CylinderRadius = 1.2f;
const FVector Offset(0, 0, HalfHeight);
FMatrix WidgetMatrix = CustomCoordSystem * FTranslationMatrix(FVector(0.f, 0.f, 200.f));
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
{
if (VisibilityMap & (1 << ViewIndex))
{
const FSceneView* View = Views[ViewIndex];
auto Color = FLinearColor::Blue;
FPrimitiveDrawInterface* PDI = Collector.GetPDI(ViewIndex);
DrawCylinder(PDI, FVector(0, 0, 30.f), FVector(0, 0, 70.f), 20.f, 16, AxisMaterialX->GetRenderProxy(false), SDPG_Foreground);
//DrawSphere(PDI, FVector(0, 0, 50.f), FVector(0, 0, 30.f), 8, 6, AxisMaterialX->GetRenderProxy(false), SDPG_Foreground);
PDI->DrawLine(FVector(0.f, 0.f, 0.f), FVector(0.f, 0.f, 50.f), FColor::Red, SDPG_Foreground, 2.f, 0, false);
auto Box = FBox{ GetActorPosition() - FVector(1.f, 1.f, 1.f) * 50.f, GetActorPosition() + FVector(1.f, 1.f, 1.f) * 50.f };
DrawWireBox(PDI, Box, Color, SDPG_Foreground, 2.f, 0.f, false);
}
}
}
virtual FPrimitiveViewRelevance GetViewRelevance(const FSceneView* View) const override
{
FPrimitiveViewRelevance Result;
Result.bDrawRelevance = IsShown(View);
Result.bShadowRelevance = IsShadowCast(View);
Result.bDynamicRelevance = true;
return Result;
}
virtual bool CanBeOccluded() const override
{
return false;
}
virtual uint32 GetMemoryFootprint(void) const override { return(sizeof(*this) + GetAllocatedSize()); }
uint32 GetAllocatedSize(void) const { return(FPrimitiveSceneProxy::GetAllocatedSize()); }
private:
//const uint32 bDrawOnlyIfSelected : 1;
const float CapsuleRadius;
const float CapsuleHalfHeight;
const FColor CurrentColor;
const UMaterialInstanceDynamic* AxisMaterialX;
};
return new FCustomSceneProxy (this);
}