{lyn7251} Add material component example in Python (#4724)
* {lyn7251} Add material component example in Python
adds a AZ::Render::EditorMaterialComponent as an example of how to
override the default material from the scene building pipeline
Signed-off-by: jackalbe <23512001+jackalbe@users.noreply.github.com>
* Only set the cube to a gray material
Skip loading the asset, instead just set the outPrefabAssetPath for the Prefab system to load
Signed-off-by: jackalbe <23512001+jackalbe@users.noreply.github.com>
* stablizing the sub-id of procedural prefab groups
Signed-off-by: jackalbe <23512001+jackalbe@users.noreply.github.com>
This commit is contained in:
@@ -54,6 +54,30 @@ def get_mesh_node_names(sceneGraph):
|
||||
|
||||
return meshDataList, paths
|
||||
|
||||
def add_material_component(entity_id):
|
||||
# Create an override AZ::Render::EditorMaterialComponent
|
||||
editor_material_component = azlmbr.entity.EntityUtilityBus(
|
||||
azlmbr.bus.Broadcast,
|
||||
"GetOrAddComponentByTypeName",
|
||||
entity_id,
|
||||
"EditorMaterialComponent")
|
||||
|
||||
# this fills out the material asset to a known product AZMaterial asset relative path
|
||||
json_update = json.dumps({
|
||||
"Controller": { "Configuration": { "materials": [
|
||||
{
|
||||
"Key": {},
|
||||
"Value": { "MaterialAsset":{
|
||||
"assetHint": "materials/basic_grey.azmaterial"
|
||||
}}
|
||||
}]
|
||||
}}
|
||||
});
|
||||
result = azlmbr.entity.EntityUtilityBus(azlmbr.bus.Broadcast, "UpdateComponentForEntity", entity_id, editor_material_component, json_update)
|
||||
|
||||
if not result:
|
||||
raise RuntimeError("UpdateComponentForEntity for editor_material_component failed")
|
||||
|
||||
def update_manifest(scene):
|
||||
import json
|
||||
import uuid, os
|
||||
@@ -75,6 +99,7 @@ def update_manifest(scene):
|
||||
|
||||
created_entities = []
|
||||
previous_entity_id = azlmbr.entity.InvalidEntityId
|
||||
first_mesh = True
|
||||
|
||||
# Loop every mesh node in the scene
|
||||
for activeMeshIndex in range(len(mesh_name_list)):
|
||||
@@ -112,6 +137,11 @@ def update_manifest(scene):
|
||||
if not result:
|
||||
raise RuntimeError("UpdateComponentForEntity failed for Mesh component")
|
||||
|
||||
# an example of adding a material component to override the default material
|
||||
if previous_entity_id is not None and first_mesh:
|
||||
first_mesh = False
|
||||
add_material_component(entity_id)
|
||||
|
||||
# Get the transform component
|
||||
transform_component = azlmbr.entity.EntityUtilityBus(azlmbr.bus.Broadcast, "GetOrAddComponentByTypeName", entity_id, "27F1E1A1-8D9D-4C3B-BD3A-AFB9762449C0")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user