Convert prefab to temp spawnable assets (#6179)
* Convert prefab to temp in-memory spawnable assets Signed-off-by: chiyenteng <82238204+chiyenteng@users.noreply.github.com>
This commit is contained in:
+40
-4
@@ -8,14 +8,16 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import azlmbr.areasystem as areasystem
|
||||
import azlmbr.asset as asset
|
||||
import azlmbr.bus as bus
|
||||
import azlmbr.components as components
|
||||
import azlmbr.math as math
|
||||
import azlmbr.vegetation as vegetation
|
||||
import azlmbr.areasystem as areasystem
|
||||
import azlmbr.paths
|
||||
import azlmbr.prefab as prefab
|
||||
import azlmbr.vegetation as vegetation
|
||||
|
||||
sys.path.append(os.path.join(azlmbr.paths.projectroot, 'Gem', 'PythonTests'))
|
||||
import editor_python_test_tools.hydra_editor_utils as hydra
|
||||
@@ -91,7 +93,7 @@ def create_mesh_surface_entity_with_slopes(name, center_point, uniform_scale):
|
||||
return surface_entity
|
||||
|
||||
|
||||
def create_vegetation_area(name, center_point, box_size_x, box_size_y, box_size_z, dynamic_slice_asset_path):
|
||||
def create_dynamic_slice_vegetation_area(name, center_point, box_size_x, box_size_y, box_size_z, dynamic_slice_asset_path):
|
||||
# Create a vegetation area entity to use as our test vegetation spawner
|
||||
spawner_entity = hydra.Entity(name)
|
||||
spawner_entity.create_entity(
|
||||
@@ -104,14 +106,48 @@ def create_vegetation_area(name, center_point, box_size_x, box_size_y, box_size_
|
||||
box_size_z))
|
||||
|
||||
# Set the vegetation area to a Dynamic Slice spawner with a specific slice asset selected
|
||||
descriptor = hydra.get_component_property_value(spawner_entity.components[2], 'Configuration|Embedded Assets|[0]')
|
||||
dynamic_slice_spawner = vegetation.DynamicSliceInstanceSpawner()
|
||||
dynamic_slice_spawner.SetSliceAssetPath(dynamic_slice_asset_path)
|
||||
descriptor = hydra.get_component_property_value(spawner_entity.components[2], 'Configuration|Embedded Assets|[0]')
|
||||
descriptor.spawner = dynamic_slice_spawner
|
||||
spawner_entity.get_set_test(2, "Configuration|Embedded Assets|[0]", descriptor)
|
||||
return spawner_entity
|
||||
|
||||
|
||||
def create_prefab_vegetation_area(name, center_point, box_size_x, box_size_y, box_size_z, target_prefab):
|
||||
# Create a vegetation area entity to use as our test vegetation spawner
|
||||
spawner_entity = hydra.Entity(name)
|
||||
spawner_entity.create_entity(
|
||||
center_point,
|
||||
["Vegetation Layer Spawner", "Box Shape", "Vegetation Asset List"]
|
||||
)
|
||||
if spawner_entity.id.IsValid():
|
||||
print(f"'{spawner_entity.name}' created")
|
||||
spawner_entity.get_set_test(1, "Box Shape|Box Configuration|Dimensions", math.Vector3(box_size_x, box_size_y,
|
||||
box_size_z))
|
||||
# Get the in-memory spawnable asset id if exists
|
||||
spawnable_name = Path(target_prefab.file_path).stem
|
||||
spawnable_asset_id = prefab.PrefabPublicRequestBus(bus.Broadcast, 'GetInMemorySpawnableAssetId',
|
||||
spawnable_name)
|
||||
|
||||
# Create the in-memory spawnable asset from given prefab if the spawnable does not exist
|
||||
if not spawnable_asset_id.is_valid():
|
||||
create_spawnable_result = prefab.PrefabPublicRequestBus(bus.Broadcast, 'CreateInMemorySpawnableAsset',
|
||||
target_prefab.file_path,
|
||||
spawnable_name)
|
||||
assert create_spawnable_result.IsSuccess(), \
|
||||
f"Prefab operation 'CreateInMemorySpawnableAssets' failed. Error: {create_spawnable_result.GetError()}"
|
||||
spawnable_asset_id = create_spawnable_result.GetValue()
|
||||
|
||||
# Set the vegetation area to a prefab instance spawner with a specific prefab asset selected
|
||||
descriptor = hydra.get_component_property_value(spawner_entity.components[2], 'Configuration|Embedded Assets|[0]')
|
||||
prefab_spawner = vegetation.PrefabInstanceSpawner()
|
||||
prefab_spawner.SetPrefabAssetId(spawnable_asset_id)
|
||||
descriptor.spawner = prefab_spawner
|
||||
spawner_entity.get_set_test(2, "Configuration|Embedded Assets|[0]", descriptor)
|
||||
return spawner_entity
|
||||
|
||||
|
||||
def create_blocker_area(name, center_point, box_size_x, box_size_y, box_size_z):
|
||||
# Create a Vegetation Layer Blocker area
|
||||
blocker_entity = hydra.Entity(name)
|
||||
|
||||
Reference in New Issue
Block a user