CARLA
 
载入中...
搜索中...
未找到
StaticMeshCollection.cpp
浏览该文件的文档.
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"
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
34void AStaticMeshCollection::SetStaticMesh(uint32 i, UStaticMesh *Mesh)
35{
36 if ((GetNumberOfInstantiators() > i) && (MeshInstantiators[i] != nullptr)) {
37 MeshInstantiators[i]->SetStaticMesh(Mesh);
38 }
39}
40
41void 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
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)