Skip to content

Commit c582bbf

Browse files
authored
Use TransformComponent API instead of buses (o3de#594)
Signed-off-by: Michał Pełka <[email protected]>
1 parent 707f431 commit c582bbf

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

Gems/ROS2/Code/Source/RobotImporter/URDF/VisualsMaker.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -202,34 +202,30 @@ namespace ROS2
202202
}
203203

204204
AZ::Entity* entity = AzToolsFramework::GetEntityById(entityId);
205-
auto editorMeshComponent = entity->CreateComponent(AZ::Render::EditorMeshComponentTypeId);
206205

207-
// Prepare scale
208206
bool isUniformScale = AZ::IsClose(scale.GetMaxElement(), scale.GetMinElement(), AZ::Constants::FloatEpsilon);
209-
if (!isUniformScale)
207+
if (isUniformScale)
210208
{
211-
entity->CreateComponent<AzToolsFramework::Components::EditorNonUniformScaleComponent>();
209+
auto* transformComponent = entity->FindComponent(AZ::EditorTransformComponentTypeId);
210+
AZ_Assert(transformComponent, "Entity doesn't have a transform component.");
211+
auto* transformInterface = azrtti_cast<AZ::TransformInterface*>(transformComponent);
212+
AZ_Assert(transformInterface, "Found component has no transformInterface");
213+
transformInterface->SetLocalUniformScale(scale.GetX());
214+
}
215+
else
216+
{
217+
auto component = entity->CreateComponent<AzToolsFramework::Components::EditorNonUniformScaleComponent>();
218+
AZ_Assert(component, "EditorNonUniformScaleComponent was not created");
219+
component->SetScale(scale);
212220
}
213221

222+
auto editorMeshComponent = entity->CreateComponent(AZ::Render::EditorMeshComponentTypeId);
214223
if (editorMeshComponent)
215224
{
216225
auto editorBaseComponent = azrtti_cast<AzToolsFramework::Components::EditorComponentBase*>(editorMeshComponent);
217226
AZ_Assert(editorBaseComponent, "EditorMeshComponent didn't derive from EditorComponentBase.");
218227
editorBaseComponent->SetPrimaryAsset(assetId);
219228
}
220-
221-
entity->Activate();
222-
223-
// Set scale, uniform or non-uniform
224-
if (isUniformScale)
225-
{
226-
AZ::TransformBus::Event(entityId, &AZ::TransformBus::Events::SetLocalUniformScale, scale.GetX());
227-
}
228-
else
229-
{
230-
AZ::NonUniformScaleRequestBus::Event(entityId, &AZ::NonUniformScaleRequests::SetScale, scale);
231-
}
232-
entity->Deactivate();
233229
}
234230

235231
static void OverrideScriptMaterial(const sdf::Material* material, AZ::Render::MaterialAssignmentMap& overrides)

0 commit comments

Comments
 (0)