Skip to content

Commit 25c6647

Browse files
[Python] Fix Problem for python scenes use in builds (#253)
* fixed sofa.ini problem and copy sofa folder in build * small debug for plugin * update sofa ini path on runtime build * Return license update Co-authored-by: erik pernod <erik.pernod@gmail.com> * moved debug fonction to plugin manager * fix --------- Co-authored-by: erik pernod <erik.pernod@gmail.com>
1 parent f4a4ec7 commit 25c6647

4 files changed

Lines changed: 55 additions & 1 deletion

File tree

Core/Plugins/SofaUnityAPI/SofaContextAPI.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using UnityEngine;
33
using System.Runtime.InteropServices;
44
using System.Collections.Generic;
5+
using System.IO;
56

67
namespace SofaUnityAPI
78
{
@@ -80,7 +81,9 @@ public SofaContextAPI(bool async)
8081
}
8182

8283
CopyAssetToPersistent();
83-
84+
#if !UNITY_EDITOR
85+
RegenerateSofaIni();
86+
#endif
8487
// load the sofaIni file
8588
string pathIni = Application.dataPath + "/SofaUnity/Core/Plugins/Native/x64/sofa.ini";
8689
string sharePath = sofaPhysicsAPI_loadSofaIni(m_native, pathIni);
@@ -110,6 +113,29 @@ public SofaContextAPI(bool async)
110113
m_sofaVersion = sofaPhysicsAPI_version(m_native);
111114
}
112115

116+
117+
/// <summary>
118+
/// simple method to regenerate sofa.ini
119+
/// </summary>
120+
private static void RegenerateSofaIni()
121+
{
122+
string dataPath = Application.dataPath.Replace("\\", "/");
123+
string pluginsPath = dataPath + "/Plugins/x86_64";
124+
string scenesPath = dataPath + "/SofaUnity/scenes/SofaScenes";
125+
string licensePath = dataPath + "/License/";
126+
string iniPath = dataPath + "/SofaUnity/Core/Plugins/Native/x64/sofa.ini";
127+
128+
using (StreamWriter iniFile = new StreamWriter(iniPath))
129+
{
130+
iniFile.WriteLine("SHARE_DIR=" + scenesPath);
131+
iniFile.WriteLine("EXAMPLES_DIR=" + scenesPath);
132+
iniFile.WriteLine("LICENSE_DIR=" + licensePath);
133+
iniFile.WriteLine("BUILD_DIR=" + pluginsPath);
134+
}
135+
136+
Debug.Log("[SofaUnity] sofa.ini regenerated at: " + iniPath);
137+
}
138+
113139
/// Destructor
114140
~SofaContextAPI()
115141
{

Core/Scripts/Core/System/PluginManager.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public void AddPlugin(string pluginName)
127127
m_availablePlugins.Add(new PluginInfo(pluginName, exist));
128128
}
129129
}
130+
130131
}
131132

132133

@@ -302,6 +303,13 @@ public PluginInfo GetPluginByName(string pluginName)
302303
return null;
303304
}
304305

306+
public void printAvailablePlugin()
307+
{
308+
foreach (PluginInfo pi in m_savedPlugins)
309+
{
310+
Debug.Log("Loaded plugin " + pi.Name);
311+
}
312+
}
305313

306314
////////////////////////////////////////////
307315
////// PluginManager private API /////

Core/Scripts/Editor/Config/CopyConfigPostProcessor.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ static void BuildForWindows(string pathToBuiltProject)
164164
outputIniFile.WriteLine("SHARE_DIR=" + dataBuildPath);
165165
outputIniFile.WriteLine("EXAMPLES_DIR=" + dataBuildPath);
166166
outputIniFile.WriteLine("LICENSE_DIR=" + rootBuildPath + "/License/");
167+
outputIniFile.WriteLine("BUILD_DIR=" + rootBuildPath + "/Plugins/x86_64/");
167168
Debug.Log("[SofaUnity - BuildForWindows] Generate: " + outputIniPath + " file.");
168169
}
169170

@@ -185,6 +186,20 @@ static void BuildForWindows(string pathToBuiltProject)
185186
{
186187
Debug.LogError("No 'SofaScenes' folder found to copy Sofa scene related to: " + unityScenePath);
187188
}
189+
190+
// Copy python3 folder if exists for python scene build
191+
string sourcePython3Path = Application.dataPath + "/SofaUnity/Core/Plugins/Native/x64/python3/";
192+
string destPython3Path = rootBuildPath + "/Plugins/x86_64/python3/";
193+
194+
if (Directory.Exists(sourcePython3Path))
195+
{
196+
DirectoryCopy(sourcePython3Path, destPython3Path, true);
197+
Debug.Log("[SofaUnity - BuildForWindows] Copied python3 folder to: " + destPython3Path);
198+
}
199+
else
200+
{
201+
Debug.LogWarning("[SofaUnity - BuildForWindows] python3 folder not found at: " + sourcePython3Path + " — skipping python3 copy.");
202+
}
188203
}
189204

190205

Core/Scripts/SofaContext.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,11 @@ void Init()
431431
#if !UNITY_ANDROID
432432
m_pluginMgr.LoadPlugins();
433433
#endif
434+
if (m_log)
435+
{
436+
m_pluginMgr.printAvailablePlugin();
437+
}
438+
434439
// start sofa instance
435440
if (m_log)
436441
Debug.Log("## SofaContext status before start: " + m_impl.contextStatus());

0 commit comments

Comments
 (0)