From c65410a92d22758245bd5fca451e1b137619ee83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Hodossy?= Date: Sun, 18 Feb 2024 14:45:54 +0000 Subject: [PATCH] Preliminary support for plugins. Load all plugins in plugin folder. --- unity/Editor/Importer/MjImporterWithAssets.cs | 1 + unity/Runtime/Importer/MjcfImporter.cs | 5 +++++ unity/Runtime/Plugins.meta | 8 ++++++++ unity/Runtime/Tools/MjEngineTool.cs | 10 ++++++++++ 4 files changed, 24 insertions(+) create mode 100644 unity/Runtime/Plugins.meta diff --git a/unity/Editor/Importer/MjImporterWithAssets.cs b/unity/Editor/Importer/MjImporterWithAssets.cs index 6f3f8c61..4713a9f8 100644 --- a/unity/Editor/Importer/MjImporterWithAssets.cs +++ b/unity/Editor/Importer/MjImporterWithAssets.cs @@ -50,6 +50,7 @@ public class MjImporterWithAssets : MjcfImporter { // mjcfString. var name = Path.GetFileNameWithoutExtension(filePath) + $"{UnityEngine.Random.Range(0,999)}"; string newPath = Path.Combine(Application.temporaryCachePath, $"{name}.xml"); + MjEngineTool.LoadPlugins(); _mjModel = MjEngineTool.LoadModelFromFile(filePath); MjEngineTool.SaveModelToFile(newPath, _mjModel); Debug.Log($"Imported MJCF loaded, saved to {newPath}"); diff --git a/unity/Runtime/Importer/MjcfImporter.cs b/unity/Runtime/Importer/MjcfImporter.cs index 3442de0b..72181007 100644 --- a/unity/Runtime/Importer/MjcfImporter.cs +++ b/unity/Runtime/Importer/MjcfImporter.cs @@ -284,6 +284,11 @@ public class MjcfImporter { CreateGameObjectWithCamera(parentObject, child); break; } + case "plugin": { + Debug.Log($"Plugin elements are only partially supported."); + break; + } + default: { Debug.Log($"The importer does not yet support tags <{child.Name}>."); break; diff --git a/unity/Runtime/Plugins.meta b/unity/Runtime/Plugins.meta new file mode 100644 index 00000000..5b2808be --- /dev/null +++ b/unity/Runtime/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1135ed488170c0444b32c18cc61fb9ef +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/unity/Runtime/Tools/MjEngineTool.cs b/unity/Runtime/Tools/MjEngineTool.cs index bc07258e..1cac32e6 100644 --- a/unity/Runtime/Tools/MjEngineTool.cs +++ b/unity/Runtime/Tools/MjEngineTool.cs @@ -368,6 +368,16 @@ public static class MjEngineTool { } } } + + public static void LoadPlugins() { + if(!Directory.Exists("Packages/org.mujoco/Runtime/Plugins/")) return; + + foreach (string pluginPath in Directory.GetFiles("Packages/org.mujoco/Runtime/Plugins/")) { + MujocoLib.mj_loadPluginLibrary(pluginPath); + } + + } + } public static class MjSceneImportSettings {