CARLA
StaticMeshCollection.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017 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 
7 #include "Carla.h"
8 #include "StaticMeshCollection.h"
9 
10 #include "Components/InstancedStaticMeshComponent.h"
11 #include "Engine/StaticMesh.h"
12 
14  const FObjectInitializer& ObjectInitializer) :
15  Super(ObjectInitializer)
16 {
17  PrimaryActorTick.bCanEverTick = false;
18  RootComponent =
19  ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, TEXT("SceneComponent"));
20  RootComponent->SetMobility(EComponentMobility::Static);
21 }
22 
24 {
25  auto Instantiator = NewObject<UInstancedStaticMeshComponent>(this);
26  check(Instantiator != nullptr);
27  Instantiator->SetMobility(EComponentMobility::Static);
28  Instantiator->SetupAttachment(RootComponent);
29  Instantiator->SetStaticMesh(Mesh);
30  Instantiator->RegisterComponent();
31  MeshInstantiators.Add(Instantiator);
32 }
33 
34 void AStaticMeshCollection::SetStaticMesh(uint32 i, UStaticMesh *Mesh)
35 {
36  if ((GetNumberOfInstantiators() > i) && (MeshInstantiators[i] != nullptr)) {
37  MeshInstantiators[i]->SetStaticMesh(Mesh);
38  }
39 }
40 
41 void AStaticMeshCollection::AddInstance(uint32 i, const FTransform &Transform)
42 {
43  if ((GetNumberOfInstantiators() > i) && (MeshInstantiators[i] != nullptr)) {
44  MeshInstantiators[i]->AddInstance(Transform);
45  }
46 }
47 
49 {
50  for (auto *Instantiator : MeshInstantiators) {
51  if (Instantiator != nullptr) {
52  Instantiator->ClearInstances();
53  }
54  }
55 }
56 
58 {
60  MeshInstantiators.Empty();
61 }
AStaticMeshCollection(const FObjectInitializer &ObjectInitializer)
TArray< UInstancedStaticMeshComponent * > MeshInstantiators
void ClearInstantiators()
Clear the instances too.
void PushBackInstantiator(UStaticMesh *Mesh)
uint32 GetNumberOfInstantiators() const
void SetStaticMesh(uint32 i, UStaticMesh *Mesh)
void AddInstance(uint32 i, const FTransform &Transform)
geom::Transform Transform
Definition: rpc/Transform.h:16