CARLA
Loading...
Searching...
No Matches
StaticMeshCollection.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
8#include "Carla.h"
9
10#include <util/ue-header-guard-begin.h>
11#include "Components/InstancedStaticMeshComponent.h"
12#include "Engine/StaticMesh.h"
13#include <util/ue-header-guard-end.h>
14
16 const FObjectInitializer& ObjectInitializer) :
17 Super(ObjectInitializer)
18{
19 PrimaryActorTick.bCanEverTick = false;
20 RootComponent =
21 ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, TEXT("SceneComponent"));
22 RootComponent->SetMobility(EComponentMobility::Static);
23}
24
26{
27 auto Instantiator = NewObject<UInstancedStaticMeshComponent>(this);
28 check(Instantiator != nullptr);
29 Instantiator->SetMobility(EComponentMobility::Static);
30 Instantiator->SetupAttachment(RootComponent);
31 Instantiator->SetStaticMesh(Mesh);
32 Instantiator->RegisterComponent();
33 MeshInstantiators.Add(Instantiator);
34}
35
36void AStaticMeshCollection::SetStaticMesh(uint32 i, UStaticMesh *Mesh)
37{
38 if ((GetNumberOfInstantiators() > i) && (MeshInstantiators[i] != nullptr)) {
39 MeshInstantiators[i]->SetStaticMesh(Mesh);
40 }
41}
42
43void AStaticMeshCollection::AddInstance(uint32 i, const FTransform &Transform)
44{
45 if ((GetNumberOfInstantiators() > i) && (MeshInstantiators[i] != nullptr)) {
46 MeshInstantiators[i]->AddInstance(Transform);
47 }
48}
49
51{
52 for (auto *Instantiator : MeshInstantiators) {
53 if (Instantiator != nullptr) {
54 Instantiator->ClearInstances();
55 }
56 }
57}
58
TArray< UInstancedStaticMeshComponent * > MeshInstantiators
void PushBackInstantiator(UStaticMesh *Mesh)
uint32 GetNumberOfInstantiators() const
void ClearInstantiators()
Clear the instances too.
AStaticMeshCollection(const FObjectInitializer &ObjectInitializer)
void AddInstance(uint32 i, const FTransform &Transform)
void SetStaticMesh(uint32 i, UStaticMesh *Mesh)
A rigid transform in CARLA's / Unreal's left-handed frame: x forward, y right, z up,...