diff --git a/Runtime/Plugins/AssimpNet/AssimpUnity.cs b/Runtime/Plugins/AssimpNet/AssimpUnity.cs index a266708..4616fd9 100644 --- a/Runtime/Plugins/AssimpNet/AssimpUnity.cs +++ b/Runtime/Plugins/AssimpNet/AssimpUnity.cs @@ -25,8 +25,13 @@ * This file is modified by Dongho Kang to distributed as a Unity package 2019. */ +#if (UNITY_64 && UNITY_STANDALONE) || UNITY_STANDALONE_WIN || UNITY_EDITOR + using Assimp.Unmanaged; using System.IO; +#if UNITY_EDITOR +using UnityEditor; +#endif using UnityEngine; namespace Assimp @@ -53,8 +58,12 @@ public static bool IsAssimpAvailable } } + #if UNITY_EDITOR + [InitializeOnLoadMethod] + #else [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] - private static void InitializePlugin() + #endif + public static void InitializePlugin() { //Only try once during runtime if(s_triedLoading) @@ -69,13 +78,13 @@ private static void InitializePlugin() s_triedLoading = true; return; } - //First time initialization, need to set a probing path (at least in editor) to resolve the native dependencies string pluginsFolder = Path.Combine(Application.dataPath, "Plugins"); +#if UNITY_EDITOR string editorPluginNativeFolder = Path.Combine(Path.GetFullPath(string.Format($"Packages/{packageName}")), "Runtime", "Plugins", "AssimpNet", "Native"); +#endif string native64LibPath = null; string native32LibPath = null; - //Set if any platform needs to tweak the default name AssimpNet uses for the platform, null clears using an override at all string override64LibName = null; string override32LibName = null; @@ -84,23 +93,15 @@ private static void InitializePlugin() //Unity copies the native DLLs for the specific target architecture into a single Plugin folder. switch(Application.platform) { +#if UNITY_EDITOR case RuntimePlatform.WindowsEditor: native64LibPath = Path.Combine(editorPluginNativeFolder, "win", "x86_64"); native32LibPath = Path.Combine(editorPluginNativeFolder, "win", "x86"); break; - case RuntimePlatform.WindowsPlayer: - native64LibPath = pluginsFolder + "/x86_64"; - native32LibPath = pluginsFolder + "/x86"; - break; case RuntimePlatform.LinuxEditor: native64LibPath = Path.Combine(editorPluginNativeFolder, "linux", "x86_64"); native32LibPath = Path.Combine(editorPluginNativeFolder, "linux", "x86"); break; - case RuntimePlatform.LinuxPlayer: - //Linux also drop package plugins inside Plugins folder - native64LibPath = pluginsFolder; - native32LibPath = pluginsFolder; - break; case RuntimePlatform.OSXEditor: native64LibPath = Path.Combine(editorPluginNativeFolder, "osx", "x86_64"); native32LibPath = Path.Combine(editorPluginNativeFolder, "osx", "x86"); @@ -113,6 +114,16 @@ private static void InitializePlugin() override32LibName = bundlelibName; } break; +#endif + case RuntimePlatform.WindowsPlayer: + native64LibPath = pluginsFolder + "/x86_64"; + native32LibPath = pluginsFolder + "/x86"; + break; + case RuntimePlatform.LinuxPlayer: + //Linux also drop package plugins inside Plugins folder + native64LibPath = pluginsFolder; + native32LibPath = pluginsFolder; + break; case RuntimePlatform.OSXPlayer: native64LibPath = pluginsFolder; native32LibPath = pluginsFolder; @@ -153,3 +164,5 @@ private static void InitializePlugin() } } } + +#endif \ No newline at end of file diff --git a/Runtime/Scripts/MeshImporter.cs b/Runtime/Scripts/MeshImporter.cs index 992bd5a..ceabae9 100644 --- a/Runtime/Scripts/MeshImporter.cs +++ b/Runtime/Scripts/MeshImporter.cs @@ -59,6 +59,10 @@ public static GameObject Load(string meshPath, float scaleX=1, float scaleY=1, f if(!File.Exists(meshPath)) return null; + #if UNITY_EDITOR // It is possible the library is not loaded when calling from ExecuteInEditModeScript. + AssimpUnity.InitializePlugin(); + #endif + AssimpContext importer = new AssimpContext(); Scene scene = importer.ImportFile(meshPath); if (scene == null) @@ -72,7 +76,7 @@ public static GameObject Load(string meshPath, float scaleX=1, float scaleY=1, f { foreach (var m in scene.Materials) { - UnityEngine.Material uMaterial = new UnityEngine.Material(Shader.Find("Standard")); + UnityEngine.Material uMaterial = new UnityEngine.Material(Shader.Find("Universal Render Pipeline/Lit")); // Albedo if (m.HasColorDiffuse) @@ -160,12 +164,19 @@ public static GameObject Load(string meshPath, float scaleX=1, float scaleY=1, f foreach (var f in m.Faces) { // Ignore non-triangle faces - if (f.IndexCount != 3) + if (f.IndexCount != 3 && f.IndexCount != 4) continue; uIndices.Add(f.Indices[2]); uIndices.Add(f.Indices[1]); uIndices.Add(f.Indices[0]); + + if (f.IndexCount == 4) + { + uIndices.Add(f.Indices[0]); + uIndices.Add(f.Indices[3]); + uIndices.Add(f.Indices[2]); + } } } diff --git a/package.json b/package.json index a89d675..6832a20 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "Unity Mesh Importer", "name": "com.donghok.meshimporter", "unity": "2019.2", - "version": "0.1.1", + "version": "0.1.2", "dependencies": {}, "keywords": [ "Mesh",