From bf80ae40450cd942ee40e2c0a3a0bb29290666ec Mon Sep 17 00:00:00 2001 From: epernod Date: Wed, 27 May 2026 19:00:08 +0200 Subject: [PATCH 1/6] [src] Add SofaUtils to add static method to get paths depending on the OS --- Core/Plugins/SofaUnityAPI/SofaUtils.cs | 67 +++++++++++++++++++++ Core/Plugins/SofaUnityAPI/SofaUtils.cs.meta | 12 ++++ 2 files changed, 79 insertions(+) create mode 100644 Core/Plugins/SofaUnityAPI/SofaUtils.cs create mode 100644 Core/Plugins/SofaUnityAPI/SofaUtils.cs.meta diff --git a/Core/Plugins/SofaUnityAPI/SofaUtils.cs b/Core/Plugins/SofaUnityAPI/SofaUtils.cs new file mode 100644 index 00000000..0b0b7c6c --- /dev/null +++ b/Core/Plugins/SofaUnityAPI/SofaUtils.cs @@ -0,0 +1,67 @@ +using System.Collections; +using System.Collections.Generic; +using Unity.VisualScripting; +using UnityEngine; + +namespace SofaUnityAPI +{ + static public class SofaUtils + { + /// Application.dataPath: Unity Editor: /Assets + static public string GetPluginFullPrefixPath() + { + string pluginPath; +#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN + if (Application.isEditor) + pluginPath = "/SofaUnity/Core/Plugins/Native/Windows/x64/"; + else + pluginPath = "/Plugins/x86_64/"; +#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX + if (Application.isEditor) + pluginPath = "/SofaUnity/Core/Plugins/Native/macOS/"; + else + pluginPath = "/Plugins/x86_64/"; +#elif UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX + if (Application.isEditor) + pluginPath = "/SofaUnity/Core/Plugins/Native/Linux/x86_64/"; + else + pluginPath = "/Plugins/x86_64/"; +#elif UNITY_ANDROID + return Application.persistentDataPath; +#else +throw new PlatformNotSupportedException(); +#endif + return Application.dataPath + pluginPath; + } + + + static public string GetNativePluginPath() + { + string path; +#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN + path = "/SofaUnity/Core/Plugins/Native/Windows/x64/"; +#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX + path = "/SofaUnity/Core/Plugins/Native/macOS/"; +#elif UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX + path = "/SofaUnity/Core/Plugins/Native/Linux/x86_64/"; +#endif + return path; + } + + + static public string GetPluginFullName(string pluginName) + { + string pluginFullPath = ""; +#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN + pluginFullPath = pluginName + ".dll"; +#elif UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX || UNITY_ANDROID + pluginFullPath = "lib" + pluginName + ".so"; +#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX + pluginFullPath = "lib" + pluginName + ".dylib"; +#endif + return pluginFullPath; + } + + } +} + diff --git a/Core/Plugins/SofaUnityAPI/SofaUtils.cs.meta b/Core/Plugins/SofaUnityAPI/SofaUtils.cs.meta new file mode 100644 index 00000000..98a9eb8e --- /dev/null +++ b/Core/Plugins/SofaUnityAPI/SofaUtils.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 728efcb5a90126d47a7e4cd15747bd7e +timeCreated: 1540553792 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 474f72d0b4e61c490d6499a66b54e06fc6fd90a5 Mon Sep 17 00:00:00 2001 From: epernod Date: Wed, 27 May 2026 19:00:39 +0200 Subject: [PATCH 2/6] [src] Update all code to use new SofaUtils method --- Core/Plugins/SofaUnityAPI/SofaContextAPI.cs | 5 +- Core/Scripts/Core/System/PluginManager.cs | 58 +++++++++---------- .../Editor/Config/CopyConfigPostProcessor.cs | 9 +-- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/Core/Plugins/SofaUnityAPI/SofaContextAPI.cs b/Core/Plugins/SofaUnityAPI/SofaContextAPI.cs index d2d239e8..65bef007 100644 --- a/Core/Plugins/SofaUnityAPI/SofaContextAPI.cs +++ b/Core/Plugins/SofaUnityAPI/SofaContextAPI.cs @@ -101,7 +101,7 @@ public SofaContextAPI(bool async) RegenerateSofaIni(); #endif // load the sofaIni file - string pathIni = Application.dataPath + "/SofaUnity/Core/Plugins/Native/x64/sofa.ini"; + string pathIni = SofaUtils.GetPluginFullPrefixPath() + "sofa.ini"; string sharePath = sofaPhysicsAPI_loadSofaIni(m_native, pathIni); if (sharePath.Contains("Error")) @@ -139,7 +139,7 @@ private static void RegenerateSofaIni() string pluginsPath = dataPath + "/Plugins/x86_64"; string scenesPath = dataPath + "/SofaUnity/scenes/SofaScenes"; string licensePath = dataPath + "/License/"; - string iniPath = dataPath + "/SofaUnity/Core/Plugins/Native/x64/sofa.ini"; + string iniPath = dataPath + SofaUtils.GetNativePluginPath() + "sofa.ini"; using (StreamWriter iniFile = new StreamWriter(iniPath)) { @@ -285,6 +285,7 @@ public void loadPlugin(string pluginName) { if (m_isReady) { + Debug.Log("SofaContextAPI.loadPlugin using fullPluginPath: " + pluginName); int res = sofaPhysicsAPI_loadPlugin(m_native, pluginName); if (res < 0) Debug.LogError("SofaContextAPI::loadPlugin: " + pluginName + ", method returns: " + SofaDefines.msg_error[res]); diff --git a/Core/Scripts/Core/System/PluginManager.cs b/Core/Scripts/Core/System/PluginManager.cs index 2348efcb..c17a210a 100644 --- a/Core/Scripts/Core/System/PluginManager.cs +++ b/Core/Scripts/Core/System/PluginManager.cs @@ -4,6 +4,9 @@ using UnityEditor; using SofaUnityAPI; using System.IO; +using System; +using Unity.VisualScripting; +using UnityEditor.VersionControl; namespace SofaUnity @@ -63,6 +66,7 @@ public List GetPluginList() return m_availablePlugins; } + public PluginInfo GetPluginByName(string pluginName) { for (int id = 0; id < m_availablePlugins.Count; id++) @@ -81,8 +85,26 @@ public bool CheckPluginExists(string pluginName) { if (m_dllList == null) { - string dllDirPath = Application.dataPath + "/SofaUnity/Core/Plugins/Native/x64/"; + + string dllDirPath = SofaUtils.GetPluginFullPrefixPath();// Application.dataPath + "/SofaUnity/Core/Plugins/Native/x64/"; + +#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN m_dllList = Directory.GetFiles(dllDirPath, "*.dll"); +#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX + m_dllList = Directory.GetFiles(dllDirPath, "*.dylib"); +#elif UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX + m_dllList = Directory.GetFiles(dllDirPath, "*.so"); +#elif UNITY_ANDROID + m_dllList = Directory.GetFiles(dllDirPath, "*.so"); +#else + m_dllList = null; +#endif + + if (m_dllList == null) + { + Debug.LogError("PluginManager: Can't find any plugin in directory " + dllDirPath); + return false; + } for (int i = 0; i < m_dllList.Length; i++) { @@ -203,37 +225,13 @@ public void ClearSavedPlugin() } - public string getPluginFullPrefixPath() - { - string pluginPath; - if (Application.isEditor) - pluginPath = "/SofaUnity/Core/Plugins/Native/x64/"; - else -#if UNITY_ANDROID - pluginPath = "/Plugins/Android/"; -#else - pluginPath = "/Plugins/x86_64/"; -#endif - return Application.dataPath + pluginPath; - } - - public string getPluginFullName(string pluginName) - { - string pluginFullPath = ""; -#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN - pluginFullPath = pluginName + ".dll"; -#elif UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX || UNITY_ANDROID - pluginFullPath = "lib" + pluginName + ".so"; -#endif - return pluginFullPath; - } - /// Method to load the plugins one by one from the list of enable plugins public void LoadPlugins() { - string fullPrefixPath = getPluginFullPrefixPath(); + string fullPrefixPath = SofaUtils.GetPluginFullPrefixPath(); // Internally load all default plugins from core and module + Debug.Log("m_sofaAPI.loadDefaultPlugins using path: " + fullPrefixPath); m_sofaAPI.loadDefaultPlugins(fullPrefixPath); foreach (PluginInfo plugin in m_savedPlugins) @@ -241,7 +239,7 @@ public void LoadPlugins() if (!plugin.IsEnable) continue; - string fullPluginPath = getPluginFullPrefixPath() + getPluginFullName(plugin.Name); + string fullPluginPath = SofaUtils.GetPluginFullPrefixPath() + SofaUtils.GetPluginFullName(plugin.Name); #if UNITY_EDITOR PluginInfo plug = GetPluginByName(plugin.Name); if (plug == null || plug.IsAvailable == false) @@ -251,7 +249,7 @@ public void LoadPlugins() continue; } else - { + { m_sofaAPI.loadPlugin(fullPluginPath); } #else @@ -262,7 +260,7 @@ public void LoadPlugins() public void LoadPlugin(string pluginName) { - string fullPluginPath = getPluginFullPrefixPath() + getPluginFullName(pluginName); + string fullPluginPath = SofaUtils.GetPluginFullPrefixPath() + SofaUtils.GetPluginFullName(pluginName); m_sofaAPI.loadPlugin(fullPluginPath); } diff --git a/Core/Scripts/Editor/Config/CopyConfigPostProcessor.cs b/Core/Scripts/Editor/Config/CopyConfigPostProcessor.cs index 7e9b1847..59ee862c 100644 --- a/Core/Scripts/Editor/Config/CopyConfigPostProcessor.cs +++ b/Core/Scripts/Editor/Config/CopyConfigPostProcessor.cs @@ -4,6 +4,7 @@ using UnityEditor.Callbacks; using UnityEngine.SceneManagement; using System.Collections.Generic; +using SofaUnityAPI; namespace SofaUnity { @@ -15,7 +16,7 @@ public class CopyConfigPostProcessor /// static CopyConfigPostProcessor() { - string sofaIniFile = Application.dataPath + "/SofaUnity/Core/Plugins/Native/x64/sofa.ini"; + string sofaIniFile = SofaUtils.GetPluginFullPrefixPath() + "sofa.ini"; using (StreamWriter outputIniFile = new StreamWriter(sofaIniFile)) { string SofaUnityDir = Application.dataPath + "/SofaUnity/scenes/SofaScenes"; @@ -23,7 +24,7 @@ static CopyConfigPostProcessor() outputIniFile.WriteLine("SHARE_DIR=C:/projects/sofa-src/share/"); outputIniFile.WriteLine("EXAMPLES_DIR=" + SofaUnityDir); outputIniFile.WriteLine("LICENSE_DIR=" + Application.dataPath + "/SofaUnity/License/"); - outputIniFile.WriteLine("BUILD_DIR=" + Application.dataPath + "/SofaUnity/Core/Plugins/Native/x64/"); + outputIniFile.WriteLine("BUILD_DIR=" + SofaUtils.GetPluginFullPrefixPath()); } } @@ -146,7 +147,7 @@ static void BuildForWindows(string pathToBuiltProject) string rootBuildPath = pathToBuiltProject.Replace(".exe", "") + "_Data"; // Create bin build path - string binBuildPath = rootBuildPath + "/SofaUnity/Core/Plugins/Native/x64/"; + string binBuildPath = rootBuildPath + SofaUtils.GetNativePluginPath(); string dataBuildPath = rootBuildPath + "/SofaUnity/scenes/SofaScenes"; Directory.CreateDirectory(binBuildPath); @@ -188,7 +189,7 @@ static void BuildForWindows(string pathToBuiltProject) } // Copy python3 folder if exists for python scene build - string sourcePython3Path = Application.dataPath + "/SofaUnity/Core/Plugins/Native/x64/python3/"; + string sourcePython3Path = SofaUtils.GetPluginFullPrefixPath() + "python3/"; string destPython3Path = rootBuildPath + "/Plugins/x86_64/python3/"; if (Directory.Exists(sourcePython3Path)) From 0f6dd350e189547d3f76aec1177c37f687f2d3b7 Mon Sep 17 00:00:00 2001 From: epernod Date: Wed, 27 May 2026 19:00:56 +0200 Subject: [PATCH 3/6] Update gitignore --- .gitignore | 3 ++- Core/Plugins/Native/x64.meta | 9 --------- 2 files changed, 2 insertions(+), 10 deletions(-) delete mode 100644 Core/Plugins/Native/x64.meta diff --git a/.gitignore b/.gitignore index 1969a6f1..2cc32d2e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ License/* Core/Scripts/Editor/Tests/logs/ Tests/logs/ Core/Scripts/UI/DataManager/DynamicDataSaves/*.JSON -Core/Scripts/UI/DataManager/DynamicDataSaves/*.meta \ No newline at end of file +Core/Scripts/UI/DataManager/DynamicDataSaves/*.meta +Core/Plugins/Native/ diff --git a/Core/Plugins/Native/x64.meta b/Core/Plugins/Native/x64.meta deleted file mode 100644 index 4c245409..00000000 --- a/Core/Plugins/Native/x64.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 9517f2bf7d62cad4bb7fdcd2f57591df -folderAsset: yes -timeCreated: 1487183133 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: From 79cd707e1ac043db6710dc3142f92de6447038ba Mon Sep 17 00:00:00 2001 From: PierreFonda3D Date: Mon, 1 Jun 2026 14:52:02 +0200 Subject: [PATCH 4/6] small editor modification --- Core/Scripts/Core/System/PluginManager.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Core/Scripts/Core/System/PluginManager.cs b/Core/Scripts/Core/System/PluginManager.cs index c17a210a..7b488419 100644 --- a/Core/Scripts/Core/System/PluginManager.cs +++ b/Core/Scripts/Core/System/PluginManager.cs @@ -6,7 +6,10 @@ using System.IO; using System; using Unity.VisualScripting; +#if UNITY_EDITOR using UnityEditor.VersionControl; +#endif + namespace SofaUnity From f3a5f8345bb85e9343de83b037c7119898661248 Mon Sep 17 00:00:00 2001 From: epernod Date: Wed, 3 Jun 2026 18:29:39 +0200 Subject: [PATCH 5/6] backup work --- .../Editor/Config/CopyConfigPostProcessor.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Core/Scripts/Editor/Config/CopyConfigPostProcessor.cs b/Core/Scripts/Editor/Config/CopyConfigPostProcessor.cs index 59ee862c..cdd0767d 100644 --- a/Core/Scripts/Editor/Config/CopyConfigPostProcessor.cs +++ b/Core/Scripts/Editor/Config/CopyConfigPostProcessor.cs @@ -21,7 +21,6 @@ static CopyConfigPostProcessor() { string SofaUnityDir = Application.dataPath + "/SofaUnity/scenes/SofaScenes"; outputIniFile.WriteLine("SHARE_DIR=" + SofaUnityDir); - outputIniFile.WriteLine("SHARE_DIR=C:/projects/sofa-src/share/"); outputIniFile.WriteLine("EXAMPLES_DIR=" + SofaUnityDir); outputIniFile.WriteLine("LICENSE_DIR=" + Application.dataPath + "/SofaUnity/License/"); outputIniFile.WriteLine("BUILD_DIR=" + SofaUtils.GetPluginFullPrefixPath()); @@ -149,14 +148,15 @@ static void BuildForWindows(string pathToBuiltProject) // Create bin build path string binBuildPath = rootBuildPath + SofaUtils.GetNativePluginPath(); string dataBuildPath = rootBuildPath + "/SofaUnity/scenes/SofaScenes"; + string licenseBuildPath = rootBuildPath + "/License/"; Directory.CreateDirectory(binBuildPath); - Debug.Log("[SofaUnity - BuildForWindows] Create directory: " + binBuildPath); + Debug.Log("[SofaUnity - BuildForWindows] Create 'binBuildPath' directory: " + binBuildPath); Directory.CreateDirectory(dataBuildPath); - Debug.Log("[SofaUnity - BuildForWindows] Create directory: " + dataBuildPath); + Debug.Log("[SofaUnity - BuildForWindows] Create 'dataBuildPath' directory: " + dataBuildPath); // Copy current License - DirectoryCopy(Application.dataPath + "/SofaUnity/License/", rootBuildPath + "/License/", true); + DirectoryCopy(Application.dataPath + "/SofaUnity/License/", licenseBuildPath, true); // Update SOFA ini file with build dir paths string outputIniPath = Path.Combine(binBuildPath, "sofa.ini"); @@ -164,8 +164,8 @@ static void BuildForWindows(string pathToBuiltProject) { outputIniFile.WriteLine("SHARE_DIR=" + dataBuildPath); outputIniFile.WriteLine("EXAMPLES_DIR=" + dataBuildPath); - outputIniFile.WriteLine("LICENSE_DIR=" + rootBuildPath + "/License/"); - outputIniFile.WriteLine("BUILD_DIR=" + rootBuildPath + "/Plugins/x86_64/"); + outputIniFile.WriteLine("LICENSE_DIR=" + licenseBuildPath); + outputIniFile.WriteLine("BUILD_DIR=" + binBuildPath); Debug.Log("[SofaUnity - BuildForWindows] Generate: " + outputIniPath + " file."); } @@ -190,12 +190,12 @@ static void BuildForWindows(string pathToBuiltProject) // Copy python3 folder if exists for python scene build string sourcePython3Path = SofaUtils.GetPluginFullPrefixPath() + "python3/"; - string destPython3Path = rootBuildPath + "/Plugins/x86_64/python3/"; + string destPython3Path = binBuildPath + "/python3/"; if (Directory.Exists(sourcePython3Path)) { DirectoryCopy(sourcePython3Path, destPython3Path, true); - Debug.Log("[SofaUnity - BuildForWindows] Copied python3 folder to: " + destPython3Path); + Debug.Log("[SofaUnity - BuildForWindows] Copied python3 from directory: " + sourcePython3Path + " -----> " + destPython3Path); } else { From 7c943390faea291fb03ff758a18c3d277f6836c3 Mon Sep 17 00:00:00 2001 From: epernod Date: Wed, 3 Jun 2026 21:25:49 +0200 Subject: [PATCH 6/6] Fix force build path in the postProcessing script as it is for the build but still run in the Editor mode --- Core/Plugins/SofaUnityAPI/SofaContextAPI.cs | 6 ++++-- Core/Plugins/SofaUnityAPI/SofaUtils.cs | 18 +++++++++++++++++- .../Editor/Config/CopyConfigPostProcessor.cs | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Core/Plugins/SofaUnityAPI/SofaContextAPI.cs b/Core/Plugins/SofaUnityAPI/SofaContextAPI.cs index 65bef007..03713361 100644 --- a/Core/Plugins/SofaUnityAPI/SofaContextAPI.cs +++ b/Core/Plugins/SofaUnityAPI/SofaContextAPI.cs @@ -101,8 +101,10 @@ public SofaContextAPI(bool async) RegenerateSofaIni(); #endif // load the sofaIni file - string pathIni = SofaUtils.GetPluginFullPrefixPath() + "sofa.ini"; - string sharePath = sofaPhysicsAPI_loadSofaIni(m_native, pathIni); + string iniPath = SofaUtils.GetPluginFullPrefixPath() + "sofa.ini"; + Debug.Log("[SofaUnity] loading sofa.ini at: " + iniPath); + + string sharePath = sofaPhysicsAPI_loadSofaIni(m_native, iniPath); if (sharePath.Contains("Error")) { diff --git a/Core/Plugins/SofaUnityAPI/SofaUtils.cs b/Core/Plugins/SofaUnityAPI/SofaUtils.cs index 0b0b7c6c..9f28f5f7 100644 --- a/Core/Plugins/SofaUnityAPI/SofaUtils.cs +++ b/Core/Plugins/SofaUnityAPI/SofaUtils.cs @@ -39,7 +39,23 @@ static public string GetNativePluginPath() { string path; #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN - path = "/SofaUnity/Core/Plugins/Native/Windows/x64/"; + if (Application.isEditor) + path = "/SofaUnity/Core/Plugins/Native/Windows/x64/"; + else + path = "/Plugins/x86_64/"; +#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX + path = "/SofaUnity/Core/Plugins/Native/macOS/"; +#elif UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX + path = "/SofaUnity/Core/Plugins/Native/Linux/x86_64/"; +#endif + return path; + } + + static public string GetNativeBuildPath() + { + string path; +#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN + path = "/Plugins/x86_64/"; #elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX path = "/SofaUnity/Core/Plugins/Native/macOS/"; #elif UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX diff --git a/Core/Scripts/Editor/Config/CopyConfigPostProcessor.cs b/Core/Scripts/Editor/Config/CopyConfigPostProcessor.cs index cdd0767d..708205a7 100644 --- a/Core/Scripts/Editor/Config/CopyConfigPostProcessor.cs +++ b/Core/Scripts/Editor/Config/CopyConfigPostProcessor.cs @@ -146,7 +146,7 @@ static void BuildForWindows(string pathToBuiltProject) string rootBuildPath = pathToBuiltProject.Replace(".exe", "") + "_Data"; // Create bin build path - string binBuildPath = rootBuildPath + SofaUtils.GetNativePluginPath(); + string binBuildPath = rootBuildPath + SofaUtils.GetNativeBuildPath(); string dataBuildPath = rootBuildPath + "/SofaUnity/scenes/SofaScenes"; string licenseBuildPath = rootBuildPath + "/License/";