From f3c966796f53587a579d4721a27c87175c0dad62 Mon Sep 17 00:00:00 2001 From: Tom Erez Date: Mon, 16 Jan 2023 02:58:25 -0800 Subject: [PATCH] Allow models without numerical suffixes. This is important for MJPC, where some element special names (e.g., a site called "trace0", or different custom numeric fields) are used. PiperOrigin-RevId: 502338391 Change-Id: I632b5d633c92b82b60160daeeb169693225640a3 --- unity/Runtime/Components/MjGlobalSettings.cs | 3 +++ unity/Runtime/Tools/MjcfGenerationContext.cs | 16 ++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/unity/Runtime/Components/MjGlobalSettings.cs b/unity/Runtime/Components/MjGlobalSettings.cs index 618555e9..ad8b7e0f 100644 --- a/unity/Runtime/Components/MjGlobalSettings.cs +++ b/unity/Runtime/Components/MjGlobalSettings.cs @@ -327,6 +327,9 @@ public class MjGlobalSettings : MonoBehaviour { [Tooltip("Scales the force applied by the mouse spring.")] public float MouseSpringStiffness = 100; + [Tooltip("If false, numerical suffixes will be aded to ensure name uniqueness.")] + public bool UseRawGameObjectNames; + public MjOptionStruct GlobalOptions = MjOptionStruct.Default; public MjSizeStruct GlobalSizes = MjSizeStruct.Default; diff --git a/unity/Runtime/Tools/MjcfGenerationContext.cs b/unity/Runtime/Tools/MjcfGenerationContext.cs index 6269bc84..c2ff59d8 100644 --- a/unity/Runtime/Tools/MjcfGenerationContext.cs +++ b/unity/Runtime/Tools/MjcfGenerationContext.cs @@ -51,15 +51,15 @@ public class MjcfGenerationContext { return _meshAssets[mesh]; } - // Generates a Unique name for the specified component. - // Uniqueness of names is required for every type independently. - // The per-type uniqueness will be guaranteed by the combination of information used: - // - name of the host GameObject. - // - number of names that have been generated to date. public string GenerateName(Component comp) { - var name = $"{comp.gameObject.name}_{_numGeneratedNames}"; - _numGeneratedNames++; - return name; + var settings = MjGlobalSettings.Instance; + if (settings?.UseRawGameObjectNames ?? false) { + return comp.gameObject.name; + } else { + var name = $"{comp.gameObject.name}_{_numGeneratedNames}"; + _numGeneratedNames++; + return name; + } } private void GenerateConfigurationMjcf(XmlElement mjcf) {