void AThirdPersonCppCharacter::TestFoliageMeshInSideSphere()
{
ULevel* Level = GetLevel();
// フォリッジアクターを取得
AInstancedFoliageActor* IFA = AInstancedFoliageActor::GetInstancedFoliageActorForLevel(Level);
FVector vPos = GetActorLocation();
float fRadius = 10000.0f; // 100m
FSphere SearchSphere(vPos, fRadius);
// 球を描画
DrawDebugSphere(GWorld, vPos, fRadius, 8, FColor::White, false, 5.0f);
// TMap<UFoliageType*, TUniqueObj<FFoliageMeshInfo>> FoliageMeshes;
for (auto It = IFA->FoliageMeshes.CreateConstIterator(); It; ++It)
{
UFoliageType* Key = It.Key();
//FFoliageMeshInfo& Value = It.Value();
FFoliageMeshInfo const* MeshInfo = &*It.Value();
if (MeshInfo && MeshInfo->Component)
{
UHierarchicalInstancedStaticMeshComponent* HISMComponent = MeshInfo->Component;
for(int32 i = 0; i < HISMComponent->PerInstanceSMData.Num(); i++)
{
FVector MeshPos = HISMComponent->PerInstanceSMData[i].Transform.GetOrigin();
bool bInside = SearchSphere.IsInside(MeshPos);
FColor color = FColor::Red;
if(bInside)
{
color = FColor::Green;
}
DrawDebugLine(GWorld, MeshPos, MeshPos + FVector(0, 0, 10000.0f), color, false, 5.0f);
}
}
}
}
|