3
3
*
4
4
* This source code is protected under international copyright law. All rights
5
5
* reserved and protected by the copyright holders.
6
- * This file is confidential and only available to authorized individuals with the
7
- * permission of the copyright holders. If you encounter this file and do not have
8
- * permission, please contact the copyright holders and delete this file.
6
+ * This file is confidential and only available to authorized individuals with
7
+ * the permission of the copyright holders. If you encounter this file and do
8
+ * not have permission, please contact the copyright holders and delete this
9
+ * file.
9
10
*/
10
11
11
12
#include " CsvSpawnerUtils.h"
13
+
14
+ #include " AzFramework/Physics/CollisionBus.h"
15
+
12
16
#include < AzCore/Asset/AssetSerializer.h>
13
17
#include < AzCore/Serialization/EditContext.h>
14
18
#include < AzCore/Serialization/SerializeContext.h>
@@ -49,7 +53,8 @@ namespace CsvSpawner::CsvSpawnerUtils
49
53
->Field (" PositionStdDev" , &CsvSpawnableAssetConfiguration::m_positionStdDev)
50
54
->Field (" RotationStdDev" , &CsvSpawnableAssetConfiguration::m_rotationStdDev)
51
55
->Field (" ScaleStdDev" , &CsvSpawnableAssetConfiguration::m_scaleStdDev)
52
- ->Field (" PlaceOnTerrain" , &CsvSpawnableAssetConfiguration::m_placeOnTerrain);
56
+ ->Field (" PlaceOnTerrain" , &CsvSpawnableAssetConfiguration::m_placeOnTerrain)
57
+ ->Field (" CollisionGroup" , &CsvSpawnableAssetConfiguration::m_selectedCollisionGroup);
53
58
54
59
if (auto * editContext = serializeContext->GetEditContext ())
55
60
{
@@ -78,15 +83,32 @@ namespace CsvSpawner::CsvSpawnerUtils
78
83
&CsvSpawnableAssetConfiguration::m_placeOnTerrain,
79
84
" Place on Terrain" ,
80
85
" Perform scene query raytrace to place on terrain" )
86
+ ->Attribute (AZ::Edit::Attributes::ChangeNotify, &CsvSpawnableAssetConfiguration::OnPlaceOnTerrainChanged)
81
87
->DataElement (
82
88
AZ::Edit::UIHandlers::Default,
83
89
&CsvSpawnableAssetConfiguration::m_scaleStdDev,
84
90
" Scale Std. Dev." ,
85
- " Scale standard deviation, in meters" );
91
+ " Scale standard deviation, in meters" )
92
+ ->DataElement (
93
+ AZ::Edit::UIHandlers::Default,
94
+ &CsvSpawnableAssetConfiguration::m_selectedCollisionGroup,
95
+ " Collision Group" ,
96
+ " To which collision group this target will be attached" )
97
+ ->Attribute (AZ::Edit::Attributes::ReadOnly, &CsvSpawnableAssetConfiguration::IsCollisionLayerEnabled);
86
98
}
87
99
}
88
100
}
89
101
102
+ bool CsvSpawnableAssetConfiguration::IsCollisionLayerEnabled () const
103
+ {
104
+ return !m_placeOnTerrain;
105
+ }
106
+
107
+ AZ::Crc32 CsvSpawnableAssetConfiguration::OnPlaceOnTerrainChanged ()
108
+ {
109
+ return AZ::Edit::PropertyRefreshLevels::EntireTree;
110
+ }
111
+
90
112
AZStd::unordered_map<AZStd::string, CsvSpawnableAssetConfiguration> GetSpawnableAssetFromVector (
91
113
AZStd::vector<CsvSpawnableAssetConfiguration> spawnableAssetConfigurations)
92
114
{
@@ -127,10 +149,15 @@ namespace CsvSpawner::CsvSpawnerUtils
127
149
}
128
150
129
151
AZStd::optional<AZ::Vector3> RaytraceTerrain (
130
- const AZ::Vector3& location, const AzPhysics::SceneHandle sceneHandle, const AZ::Vector3& gravityDirection, float maxDistance)
152
+ const AZ::Vector3& location,
153
+ const AzPhysics::SceneHandle sceneHandle,
154
+ const AZ::Vector3& gravityDirection,
155
+ float maxDistance,
156
+ const AzPhysics::CollisionGroup& collisionGroup)
131
157
{
132
158
AZStd::optional<AZ::Vector3> hitPosition = AZStd::nullopt ;
133
159
160
+ AZ_Assert (sceneHandle == AzPhysics::InvalidSceneHandle, " Unable to get scene handle" );
134
161
if (sceneHandle == AzPhysics::InvalidSceneHandle)
135
162
{
136
163
return hitPosition;
@@ -150,6 +177,7 @@ namespace CsvSpawner::CsvSpawnerUtils
150
177
request.m_start = location;
151
178
request.m_direction = gravityDirection;
152
179
request.m_distance = maxDistance;
180
+ request.m_collisionGroup = collisionGroup;
153
181
154
182
AzPhysics::SceneQueryHits result = sceneInterface->QueryScene (sceneHandle, &request);
155
183
@@ -211,21 +239,29 @@ namespace CsvSpawner::CsvSpawnerUtils
211
239
212
240
if (spawnConfig.m_placeOnTerrain )
213
241
{
242
+ // Get collision group chosen from editor
243
+ AzPhysics::CollisionGroup collisionGroup;
244
+ Physics::CollisionRequestBus::BroadcastResult (
245
+ collisionGroup, &Physics::CollisionRequests::GetCollisionGroupById, spawnConfig.m_selectedCollisionGroup );
246
+
214
247
const AZStd::optional<AZ::Vector3> hitPosition =
215
- RaytraceTerrain (transform.GetTranslation (), sceneHandle, -AZ::Vector3::CreateAxisZ (), 1000 .0f );
248
+ RaytraceTerrain (transform.GetTranslation (), sceneHandle, -AZ::Vector3::CreateAxisZ (), 1000 .0f , collisionGroup);
249
+
216
250
if (hitPosition.has_value ())
217
251
{
218
252
transform.SetTranslation (hitPosition.value ());
219
253
}
220
254
else
221
255
{
222
- continue ; // Skip this entity if we can't find a valid position and place on terrain is enabled.
256
+ continue ; // Skip this entity if we can't find a valid position and
257
+ // place on terrain is enabled.
223
258
}
224
259
}
225
260
AZ_Assert (spawner, " Unable to get spawnable entities definition" );
226
261
AzFramework::SpawnAllEntitiesOptionalArgs optionalArgs;
227
262
AzFramework::EntitySpawnTicket ticket (spawnable);
228
- // Set the pre-spawn callback to set the name of the root entity to the name of the spawnable
263
+ // Set the pre-spawn callback to set the name of the root entity to the name
264
+ // of the spawnable
229
265
optionalArgs.m_preInsertionCallback = [transform](auto id, auto view)
230
266
{
231
267
if (view.empty ())
0 commit comments