|
10 | 10 | #include "Engine/LatentActionManager.h" |
11 | 11 |
|
12 | 12 | void UAssetConstructor::CreateMeshFromMeshDataOnProceduralMeshComponent( |
13 | | - const UObject* WorldContextObject, FLatentActionInfo LatentActionInfo, |
14 | | - const FLoadedMeshData& MeshData, |
15 | | - UMaterialInterface* ParentMaterialInterface, |
16 | | - UProceduralMeshComponent* TargetProceduralMeshComponent) { |
17 | | - // check to WorldContextObject is properly set |
18 | | - check(WorldContextObject != nullptr); |
19 | | - |
20 | | - // check to ParentMaterialInterface is properly set |
21 | | - check(ParentMaterialInterface != nullptr); |
22 | | - |
23 | | - // check to TargetProceduralMeshComponent is properly set |
24 | | - check(TargetProceduralMeshComponent != nullptr); |
25 | | - |
26 | | - const auto World = GEngine->GetWorldFromContextObject( |
27 | | - WorldContextObject, EGetWorldErrorMode::Assert); |
28 | | - check(World != nullptr); |
29 | | - |
30 | | - FLatentActionManager& LatentActionManager = World->GetLatentActionManager(); |
31 | | - |
32 | | - LatentActionManager.AddNewAction( |
33 | | - LatentActionInfo.CallbackTarget, LatentActionInfo.UUID, |
34 | | - new FCreateMeshFromMeshDataOnProceduralMeshComponentLatentAction( |
35 | | - LatentActionInfo, MeshData, *ParentMaterialInterface, |
36 | | - *TargetProceduralMeshComponent)); |
| 13 | + const UObject *WorldContextObject, FLatentActionInfo LatentActionInfo, const FLoadedMeshData &MeshData, |
| 14 | + UMaterialInterface *ParentMaterialInterface, UProceduralMeshComponent *TargetProceduralMeshComponent) |
| 15 | +{ |
| 16 | + // check to WorldContextObject is properly set |
| 17 | + check(WorldContextObject != nullptr); |
| 18 | + |
| 19 | + // check to ParentMaterialInterface is properly set |
| 20 | + check(ParentMaterialInterface != nullptr); |
| 21 | + |
| 22 | + // check to TargetProceduralMeshComponent is properly set |
| 23 | + check(TargetProceduralMeshComponent != nullptr); |
| 24 | + |
| 25 | + const auto World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::Assert); |
| 26 | + check(World != nullptr); |
| 27 | + |
| 28 | + FLatentActionManager &LatentActionManager = World->GetLatentActionManager(); |
| 29 | + |
| 30 | + LatentActionManager.AddNewAction( |
| 31 | + LatentActionInfo.CallbackTarget, LatentActionInfo.UUID, |
| 32 | + new FCreateMeshFromMeshDataOnProceduralMeshComponentLatentAction( |
| 33 | + LatentActionInfo, MeshData, *ParentMaterialInterface, *TargetProceduralMeshComponent)); |
37 | 34 | } |
38 | 35 |
|
39 | | -UProceduralMeshComponent* |
40 | | - UAssetConstructor::ConstructProceduralMeshComponentFromMeshData( |
41 | | - const FLoadedMeshData& MeshData, |
42 | | - UMaterialInterface* ParentMaterialInterface, AActor* const Owner, |
43 | | - const bool ShouldRegisterComponentToOwner) { |
44 | | - // check to ParentMaterialInterface is properly set |
45 | | - check(ParentMaterialInterface != nullptr); |
| 36 | +UProceduralMeshComponent *UAssetConstructor::ConstructProceduralMeshComponentFromMeshData( |
| 37 | + const FLoadedMeshData &MeshData, UMaterialInterface *ParentMaterialInterface, AActor *const Owner, |
| 38 | + const bool ShouldRegisterComponentToOwner) |
| 39 | +{ |
| 40 | + // check to ParentMaterialInterface is properly set |
| 41 | + check(ParentMaterialInterface != nullptr); |
46 | 42 |
|
47 | | - // check to Owner is properly set |
48 | | - check(Owner != nullptr); |
| 43 | + // check to Owner is properly set |
| 44 | + check(Owner != nullptr); |
49 | 45 |
|
50 | | - return ConstructMeshComponentFromMeshData<UProceduralMeshComponent>( |
51 | | - MeshData, ParentMaterialInterface, Owner, ShouldRegisterComponentToOwner); |
| 46 | + return ConstructMeshComponentFromMeshData<UProceduralMeshComponent>(MeshData, ParentMaterialInterface, Owner, |
| 47 | + ShouldRegisterComponentToOwner); |
52 | 48 | } |
53 | 49 |
|
54 | | -UStaticMeshComponent* |
55 | | - UAssetConstructor::ConstructStaticMeshComponentFromMeshData( |
56 | | - const FLoadedMeshData& MeshData, |
57 | | - UMaterialInterface* ParentMaterialInterface, AActor* const Owner, |
58 | | - const bool ShouldRegisterComponentToOwner) { |
59 | | - // check to ParentMaterialInterface is properly set |
60 | | - check(ParentMaterialInterface != nullptr); |
| 50 | +UStaticMeshComponent *UAssetConstructor::ConstructStaticMeshComponentFromMeshData( |
| 51 | + const FLoadedMeshData &MeshData, UMaterialInterface *ParentMaterialInterface, AActor *const Owner, |
| 52 | + const bool ShouldRegisterComponentToOwner) |
| 53 | +{ |
| 54 | + // check to ParentMaterialInterface is properly set |
| 55 | + check(ParentMaterialInterface != nullptr); |
61 | 56 |
|
62 | | - // check to Owner is properly set |
63 | | - check(Owner != nullptr); |
| 57 | + // check to Owner is properly set |
| 58 | + check(Owner != nullptr); |
64 | 59 |
|
65 | | - return ConstructMeshComponentFromMeshData<UStaticMeshComponent>( |
66 | | - MeshData, ParentMaterialInterface, Owner, ShouldRegisterComponentToOwner); |
| 60 | + return ConstructMeshComponentFromMeshData<UStaticMeshComponent>(MeshData, ParentMaterialInterface, Owner, |
| 61 | + ShouldRegisterComponentToOwner); |
67 | 62 | } |
68 | 63 |
|
69 | | -UDynamicMeshComponent* |
70 | | - UAssetConstructor::ConstructDynamicMeshComponentFromMeshData( |
71 | | - const FLoadedMeshData& MeshData, |
72 | | - UMaterialInterface* ParentMaterialInterface, AActor* const Owner, |
73 | | - const bool ShouldRegisterComponentToOwner) { |
74 | | - // check to ParentMaterialInterface is properly set |
75 | | - check(ParentMaterialInterface != nullptr); |
| 64 | +UDynamicMeshComponent *UAssetConstructor::ConstructDynamicMeshComponentFromMeshData( |
| 65 | + const FLoadedMeshData &MeshData, UMaterialInterface *ParentMaterialInterface, AActor *const Owner, |
| 66 | + const bool ShouldRegisterComponentToOwner) |
| 67 | +{ |
| 68 | + // check to ParentMaterialInterface is properly set |
| 69 | + check(ParentMaterialInterface != nullptr); |
76 | 70 |
|
77 | | - // check to Owner is properly set |
78 | | - check(Owner != nullptr); |
| 71 | + // check to Owner is properly set |
| 72 | + check(Owner != nullptr); |
79 | 73 |
|
80 | | - return ConstructMeshComponentFromMeshData<UDynamicMeshComponent>( |
81 | | - MeshData, ParentMaterialInterface, Owner, ShouldRegisterComponentToOwner); |
| 74 | + return ConstructMeshComponentFromMeshData<UDynamicMeshComponent>(MeshData, ParentMaterialInterface, Owner, |
| 75 | + ShouldRegisterComponentToOwner); |
82 | 76 | } |
83 | 77 |
|
84 | | -UProceduralMeshComponent* |
85 | | - UAssetConstructor::ConstructProceduralMeshComponentFromAssetFile( |
86 | | - const FString& FilePath, |
87 | | - UMaterialInterface* const ParentMaterialInterface, AActor* const Owner, |
88 | | - EConstructProceduralMeshComponentFromAssetFileResult& |
89 | | - ConstructProceduralMeshComponentFromAssetFileResult, |
90 | | - const bool ShouldRegisterComponentToOwner) { |
91 | | - // check to ParentMaterialInterface is properly set |
92 | | - check(ParentMaterialInterface != nullptr); |
93 | | - |
94 | | - // check to Owner is properly set |
95 | | - check(Owner != nullptr); |
96 | | - |
97 | | - // load mesh from asset file(path: FilePath) |
98 | | - ELoadMeshFromAssetFileResult LoadMeshFromAssetFileResult; |
99 | | - const auto& LoadedMeshData = UAssetLoader::LoadMeshFromAssetFile( |
100 | | - FilePath, LoadMeshFromAssetFileResult); |
101 | | - |
102 | | - // check load result |
103 | | - if (ELoadMeshFromAssetFileResult::Failure == LoadMeshFromAssetFileResult) { |
104 | | - ConstructProceduralMeshComponentFromAssetFileResult = |
105 | | - EConstructProceduralMeshComponentFromAssetFileResult::Failure; |
106 | | - return nullptr; |
107 | | - } |
108 | | - |
109 | | - // assume the result is success |
110 | | - ConstructProceduralMeshComponentFromAssetFileResult = |
111 | | - EConstructProceduralMeshComponentFromAssetFileResult::Success; |
112 | | - |
113 | | - // construct from loaded mesh data |
114 | | - return ConstructProceduralMeshComponentFromMeshData( |
115 | | - LoadedMeshData, ParentMaterialInterface, Owner, |
116 | | - ShouldRegisterComponentToOwner); |
| 78 | +UProceduralMeshComponent *UAssetConstructor::ConstructProceduralMeshComponentFromAssetFile( |
| 79 | + const FString &FilePath, UMaterialInterface *const ParentMaterialInterface, AActor *const Owner, |
| 80 | + EConstructProceduralMeshComponentFromAssetFileResult &ConstructProceduralMeshComponentFromAssetFileResult, |
| 81 | + const bool ShouldRegisterComponentToOwner) |
| 82 | +{ |
| 83 | + // check to ParentMaterialInterface is properly set |
| 84 | + check(ParentMaterialInterface != nullptr); |
| 85 | + |
| 86 | + // check to Owner is properly set |
| 87 | + check(Owner != nullptr); |
| 88 | + |
| 89 | + // load mesh from asset file(path: FilePath) |
| 90 | + ELoadMeshFromAssetFileResult LoadMeshFromAssetFileResult; |
| 91 | + const auto &LoadedMeshData = UAssetLoader::LoadMeshFromAssetFile(FilePath, LoadMeshFromAssetFileResult); |
| 92 | + |
| 93 | + // check load result |
| 94 | + if (ELoadMeshFromAssetFileResult::Failure == LoadMeshFromAssetFileResult) |
| 95 | + { |
| 96 | + ConstructProceduralMeshComponentFromAssetFileResult = |
| 97 | + EConstructProceduralMeshComponentFromAssetFileResult::Failure; |
| 98 | + return nullptr; |
| 99 | + } |
| 100 | + |
| 101 | + // assume the result is success |
| 102 | + ConstructProceduralMeshComponentFromAssetFileResult = EConstructProceduralMeshComponentFromAssetFileResult::Success; |
| 103 | + |
| 104 | + // construct from loaded mesh data |
| 105 | + return ConstructProceduralMeshComponentFromMeshData(LoadedMeshData, ParentMaterialInterface, Owner, |
| 106 | + ShouldRegisterComponentToOwner); |
117 | 107 | } |
118 | 108 |
|
119 | | -UStaticMeshComponent* |
120 | | - UAssetConstructor::ConstructStaticMeshComponentFromAssetFile( |
121 | | - const FString& FilePath, UMaterialInterface* ParentMaterialInterface, |
122 | | - AActor* Owner, |
123 | | - EConstructStaticMeshComponentFromAssetFileResult& |
124 | | - ConstructStaticMeshComponentFromAssetFileResult, |
125 | | - bool ShouldRegisterComponentToOwner) { |
126 | | - // check to ParentMaterialInterface is properly set |
127 | | - check(ParentMaterialInterface != nullptr); |
128 | | - |
129 | | - // check to Owner is properly set |
130 | | - check(Owner != nullptr); |
131 | | - |
132 | | - // load mesh from asset file(path: FilePath) |
133 | | - ELoadMeshFromAssetFileResult LoadMeshFromAssetFileResult; |
134 | | - const auto& LoadedMeshData = UAssetLoader::LoadMeshFromAssetFile( |
135 | | - FilePath, LoadMeshFromAssetFileResult); |
136 | | - |
137 | | - // check load result |
138 | | - if (ELoadMeshFromAssetFileResult::Failure == LoadMeshFromAssetFileResult) { |
139 | | - ConstructStaticMeshComponentFromAssetFileResult = |
140 | | - EConstructStaticMeshComponentFromAssetFileResult::Failure; |
141 | | - return nullptr; |
142 | | - } |
143 | | - |
144 | | - // assume the result is success |
145 | | - ConstructStaticMeshComponentFromAssetFileResult = |
146 | | - EConstructStaticMeshComponentFromAssetFileResult::Success; |
147 | | - |
148 | | - // construct from loaded mesh data |
149 | | - return ConstructStaticMeshComponentFromMeshData( |
150 | | - LoadedMeshData, ParentMaterialInterface, Owner, |
151 | | - ShouldRegisterComponentToOwner); |
| 109 | +UStaticMeshComponent *UAssetConstructor::ConstructStaticMeshComponentFromAssetFile( |
| 110 | + const FString &FilePath, UMaterialInterface *ParentMaterialInterface, AActor *Owner, |
| 111 | + EConstructStaticMeshComponentFromAssetFileResult &ConstructStaticMeshComponentFromAssetFileResult, |
| 112 | + bool ShouldRegisterComponentToOwner) |
| 113 | +{ |
| 114 | + // check to ParentMaterialInterface is properly set |
| 115 | + check(ParentMaterialInterface != nullptr); |
| 116 | + |
| 117 | + // check to Owner is properly set |
| 118 | + check(Owner != nullptr); |
| 119 | + |
| 120 | + // load mesh from asset file(path: FilePath) |
| 121 | + ELoadMeshFromAssetFileResult LoadMeshFromAssetFileResult; |
| 122 | + const auto &LoadedMeshData = UAssetLoader::LoadMeshFromAssetFile(FilePath, LoadMeshFromAssetFileResult); |
| 123 | + |
| 124 | + // check load result |
| 125 | + if (ELoadMeshFromAssetFileResult::Failure == LoadMeshFromAssetFileResult) |
| 126 | + { |
| 127 | + ConstructStaticMeshComponentFromAssetFileResult = EConstructStaticMeshComponentFromAssetFileResult::Failure; |
| 128 | + return nullptr; |
| 129 | + } |
| 130 | + |
| 131 | + // assume the result is success |
| 132 | + ConstructStaticMeshComponentFromAssetFileResult = EConstructStaticMeshComponentFromAssetFileResult::Success; |
| 133 | + |
| 134 | + // construct from loaded mesh data |
| 135 | + return ConstructStaticMeshComponentFromMeshData(LoadedMeshData, ParentMaterialInterface, Owner, |
| 136 | + ShouldRegisterComponentToOwner); |
152 | 137 | } |
153 | 138 |
|
154 | | -UDynamicMeshComponent* |
155 | | - UAssetConstructor::ConstructDynamicMeshComponentFromAssetFile( |
156 | | - const FString& FilePath, UMaterialInterface* ParentMaterialInterface, |
157 | | - AActor* Owner, |
158 | | - EConstructDynamicMeshComponentFromAssetFileResult& |
159 | | - ConstructDynamicMeshComponentFromAssetFileResult, |
160 | | - bool ShouldRegisterComponentToOwner) { |
161 | | - // check to ParentMaterialInterface is properly set |
162 | | - check(ParentMaterialInterface != nullptr); |
163 | | - |
164 | | - // check to Owner is properly set |
165 | | - check(Owner != nullptr); |
166 | | - |
167 | | - // load mesh from asset file(path: FilePath) |
168 | | - ELoadMeshFromAssetFileResult LoadMeshFromAssetFileResult; |
169 | | - const auto& LoadedMeshData = UAssetLoader::LoadMeshFromAssetFile( |
170 | | - FilePath, LoadMeshFromAssetFileResult); |
171 | | - |
172 | | - // check load result |
173 | | - if (ELoadMeshFromAssetFileResult::Failure == LoadMeshFromAssetFileResult) { |
174 | | - ConstructDynamicMeshComponentFromAssetFileResult = |
175 | | - EConstructDynamicMeshComponentFromAssetFileResult::Failure; |
176 | | - return nullptr; |
177 | | - } |
178 | | - |
179 | | - // assume the result is success |
180 | | - ConstructDynamicMeshComponentFromAssetFileResult = |
181 | | - EConstructDynamicMeshComponentFromAssetFileResult::Success; |
182 | | - |
183 | | - // construct from loaded mesh data |
184 | | - return ConstructDynamicMeshComponentFromMeshData( |
185 | | - LoadedMeshData, ParentMaterialInterface, Owner, |
186 | | - ShouldRegisterComponentToOwner); |
| 139 | +UDynamicMeshComponent *UAssetConstructor::ConstructDynamicMeshComponentFromAssetFile( |
| 140 | + const FString &FilePath, UMaterialInterface *ParentMaterialInterface, AActor *Owner, |
| 141 | + EConstructDynamicMeshComponentFromAssetFileResult &ConstructDynamicMeshComponentFromAssetFileResult, |
| 142 | + bool ShouldRegisterComponentToOwner) |
| 143 | +{ |
| 144 | + // check to ParentMaterialInterface is properly set |
| 145 | + check(ParentMaterialInterface != nullptr); |
| 146 | + |
| 147 | + // check to Owner is properly set |
| 148 | + check(Owner != nullptr); |
| 149 | + |
| 150 | + // load mesh from asset file(path: FilePath) |
| 151 | + ELoadMeshFromAssetFileResult LoadMeshFromAssetFileResult; |
| 152 | + const auto &LoadedMeshData = UAssetLoader::LoadMeshFromAssetFile(FilePath, LoadMeshFromAssetFileResult); |
| 153 | + |
| 154 | + // check load result |
| 155 | + if (ELoadMeshFromAssetFileResult::Failure == LoadMeshFromAssetFileResult) |
| 156 | + { |
| 157 | + ConstructDynamicMeshComponentFromAssetFileResult = EConstructDynamicMeshComponentFromAssetFileResult::Failure; |
| 158 | + return nullptr; |
| 159 | + } |
| 160 | + |
| 161 | + // assume the result is success |
| 162 | + ConstructDynamicMeshComponentFromAssetFileResult = EConstructDynamicMeshComponentFromAssetFileResult::Success; |
| 163 | + |
| 164 | + // construct from loaded mesh data |
| 165 | + return ConstructDynamicMeshComponentFromMeshData(LoadedMeshData, ParentMaterialInterface, Owner, |
| 166 | + ShouldRegisterComponentToOwner); |
187 | 167 | } |
0 commit comments