Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ License/*
Core/Scripts/Editor/Tests/logs/
Tests/logs/
Core/Scripts/UI/DataManager/DynamicDataSaves/*.JSON
Core/Scripts/UI/DataManager/DynamicDataSaves/*.meta
Core/Scripts/UI/DataManager/DynamicDataSaves/*.meta
Core/Plugins/Native/
9 changes: 0 additions & 9 deletions Core/Plugins/Native/x64.meta

This file was deleted.

9 changes: 6 additions & 3 deletions Core/Plugins/SofaUnityAPI/SofaContextAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ public SofaContextAPI(bool async)
RegenerateSofaIni();
#endif
// load the sofaIni file
string pathIni = Application.dataPath + "/SofaUnity/Core/Plugins/Native/x64/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"))
{
Expand Down Expand Up @@ -139,7 +141,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))
{
Expand Down Expand Up @@ -285,6 +287,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]);
Expand Down
83 changes: 83 additions & 0 deletions Core/Plugins/SofaUnityAPI/SofaUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

namespace SofaUnityAPI
{
static public class SofaUtils
{
/// Application.dataPath: Unity Editor: <path to project folder>/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
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
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;
}

}
}

12 changes: 12 additions & 0 deletions Core/Plugins/SofaUnityAPI/SofaUtils.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 31 additions & 30 deletions Core/Scripts/Core/System/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
using UnityEditor;
using SofaUnityAPI;
using System.IO;
using System;
using Unity.VisualScripting;
#if UNITY_EDITOR
using UnityEditor.VersionControl;
#endif



namespace SofaUnity
Expand Down Expand Up @@ -63,6 +69,7 @@ public List<PluginInfo> GetPluginList()
return m_availablePlugins;
}


public PluginInfo GetPluginByName(string pluginName)
{
for (int id = 0; id < m_availablePlugins.Count; id++)
Expand All @@ -81,8 +88,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++)
{
Expand Down Expand Up @@ -203,45 +228,21 @@ 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)
{
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)
Expand All @@ -251,7 +252,7 @@ public void LoadPlugins()
continue;
}
else
{
{
m_sofaAPI.loadPlugin(fullPluginPath);
}
#else
Expand All @@ -262,7 +263,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);
}
Expand Down
25 changes: 13 additions & 12 deletions Core/Scripts/Editor/Config/CopyConfigPostProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using UnityEditor.Callbacks;
using UnityEngine.SceneManagement;
using System.Collections.Generic;
using SofaUnityAPI;

namespace SofaUnity
{
Expand All @@ -15,15 +16,14 @@ public class CopyConfigPostProcessor
/// </summary>
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";
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=" + Application.dataPath + "/SofaUnity/Core/Plugins/Native/x64/");
outputIniFile.WriteLine("BUILD_DIR=" + SofaUtils.GetPluginFullPrefixPath());
}
}

Expand Down Expand Up @@ -146,25 +146,26 @@ 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.GetNativeBuildPath();
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");
using (StreamWriter outputIniFile = new StreamWriter(outputIniPath))
{
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.");
}

Expand All @@ -188,13 +189,13 @@ 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 destPython3Path = rootBuildPath + "/Plugins/x86_64/python3/";
string sourcePython3Path = SofaUtils.GetPluginFullPrefixPath() + "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
{
Expand Down