{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>
monroegm-disable-blank-issue-2
Allen Jackson 4 years ago committed by GitHub
parent 7f10b5d1b9
commit fbedd8126d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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")

@ -766,15 +766,8 @@ namespace AzToolsFramework
{
return false;
}
outPrefabAssetPath = product->GetRelativePath();
auto asset = AZ::Data::AssetManager::Instance().GetAsset(
product->GetAssetId(),
azrtti_typeid<AZ::Prefab::ProceduralPrefabAsset>(),
AZ::Data::AssetLoadBehavior::Default);
return asset.BlockUntilLoadComplete() != AZ::Data::AssetData::AssetStatus::Error;
return true;
}
void PrefabIntegrationManager::WarnUserOfError(AZStd::string_view title, AZStd::string_view message)

@ -174,7 +174,7 @@ namespace AZ::SceneAPI::Behaviors
const auto bytesWritten = fileStream.Write(sb.GetSize(), sb.GetString());
if (bytesWritten > 1)
{
AZ::u32 subId = AZ::Crc32(filePath.c_str());
AZ::u32 subId = AZ::Crc32(assetPath.c_str());
context.GetProductList().AddProduct(
filePath,
context.GetScene().GetSourceGuid(),

Loading…
Cancel
Save