diff --git a/README.md b/README.md
index d9f31dc..809da0b 100644
--- a/README.md
+++ b/README.md
@@ -4,12 +4,13 @@ A [ResoniteModLoader](https://github.com/resonite-modding-group/ResoniteModLoade
## Installation
1. Install [ResoniteModLoader](https://github.com/resonite-modding-group/ResoniteModLoader).
-1. Place [UnityPackageImporter.dll](https://github.com/dfgHiatus/ResoniteUnityPackagesImporter/releases/latest/download/UnityPackageImporter.dll) into your `rml_mods` folder. This folder should be at `C:\Program Files (x86)\Steam\steamapps\common\Resonite\rml_mods` for a default install. You can create it if it's missing, or if you launch the game once with ResoniteModLoader installed it will create the folder for you.
-1. Start the game. If you want to verify that the mod is working you can check your Resonite logs.
+2. Place [UnityPackageImporter.dll](https://github.com/dfgHiatus/ResoniteUnityPackagesImporter/releases/latest/download/UnityPackageImporter.dll) into your `rml_mods` folder. This folder should be at `C:\Program Files (x86)\Steam\steamapps\common\Resonite\rml_mods` for a default install. You can create it if it's missing, or if you launch the game once with ResoniteModLoader installed it will create the folder for you.
+3. Put [The contents of this zip](https://ci.appveyor.com/api/buildjobs/mk8takud6nqne47k/artifacts/YamlDotNet%2Fbin%2FRelease%2FRelease-Net47.zip) into your `rml_libs` folder. This folder should be at `C:\Program Files (x86)\Steam\steamapps\common\Resonite\rml_mods` for a default install. You can create it if it's missing, or if you launch the game once with ResoniteModLoader installed it will create the folder for you.
+4. Start the game. If you want to verify that the mod is working you can check your Resonite logs.
## FAQs
1. What does this mod do exactly? This mod solely extracts the assets of Unity Packages and imports them into Resonite
-1. Will this mod setup avatars for me? No, you'll need to set them up normally.
+1. Will this mod setup avatars for me? No, you'll need to set them up normally. It will do materials and textures though sometimes.
1. What kind of unity packages can I import? Anything! Avatar packages, world packages, anything you can think of!
1. Will this mod run on the Linux version of the game? Yes
1. How many packages can I import at once? In theory you should be able to import many at once, but in my experience one at a time is your best friend here given the massive file size Unity Packages can be
@@ -24,15 +25,13 @@ Presently, it supports:
- Fonts
- Videos
- And raw binary variants of the above for file sharing
+- Prefabs (ALPHA)
+- Scenes (ALPHA)
9. What will this mod NOT import?
-- Prefabs
-- Scenes
- Particle systems
- Animations/Animators
- Dynamic Bones
- Phys Bones
## Known Issues and Limitations
-- This will not work with the legacy file importer. Paste/drag and drop the UnityPackage onto the Resonite window instead
-- This doesn't place files under a single root
- This might hang a little bit during import. Recommended to import one unity package at a time, pairs nicely with [ResoniteModSettings](https://github.com/badhaloninja/ResoniteModSettings)
diff --git a/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/GameObject.cs b/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/GameObject.cs
index 60ef549..841c060 100644
--- a/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/GameObject.cs
+++ b/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/GameObject.cs
@@ -28,12 +28,17 @@ public async Task instanciateAsync(IUnityStructureImporter importer)
{
await default(ToWorld);
- if(m_CorrespondingSourceObject.guid == null)
+ if(m_CorrespondingSourceObject.guid == null && frooxEngineSlot == null)
{
- frooxEngineSlot = Engine.Current.WorldManager.FocusedWorld.AddSlot(this.m_Name);
+ frooxEngineSlot = importer.unityProjectImporter.world.AddSlot(this.m_Name);
frooxEngineSlot.SetParent(importer.CurrentStructureRootSlot, true); //let user managers not freak out that we're doing stuff in root.
frooxEngineSlot.ActiveSelf = m_IsActive == 1 ? true : false;
}
+ else if(frooxEngineSlot != null) //if being instanciated through prefab import while still in prefab hashes. Since it will have modifications done to it but have an in world object still.
+ {
+ frooxEngineSlot.ActiveSelf = m_IsActive == 1 ? true : false;
+ frooxEngineSlot.Name = this.m_Name;
+ }
else
{
if(importer.existingIUnityObjects.TryGetValue(m_PrefabInstance["fileID"], out IUnityObject prefab_inc))
@@ -44,7 +49,13 @@ public async Task instanciateAsync(IUnityStructureImporter importer)
await default(ToBackground);
if (prefab.PrefabHashes.TryGetValue(m_CorrespondingSourceObject, out IUnityObject existingobject))
{
- this.frooxEngineSlot = (existingobject as GameObject).frooxEngineSlot;
+ GameObject existing = (existingobject as GameObject);
+ await default(ToWorld);
+ this.m_Name = existing.m_Name;
+ this.frooxEngineSlot = existing.frooxEngineSlot;
+ this.frooxEngineSlot.Name = this.m_Name;
+ this.frooxEngineSlot.ActiveSelf = existing.m_IsActive == 1;
+ await default(ToBackground);
}
diff --git a/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/MonoBehavior.cs b/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/MonoBehaviour.cs
similarity index 96%
rename from UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/MonoBehavior.cs
rename to UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/MonoBehaviour.cs
index 4484fde..ef3e789 100644
--- a/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/MonoBehavior.cs
+++ b/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/MonoBehaviour.cs
@@ -8,7 +8,7 @@
namespace UnityPackageImporter.FrooxEngineRepresentation.GameObjectTypes
{
- public class MonoBehavior : IUnityObject
+ public class MonoBehaviour : IUnityObject
{
public ulong id { get; set; }
public bool instanciated { get; set; }
diff --git a/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/PrefabInstance.cs b/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/PrefabInstance.cs
index 3f55654..8a1365e 100644
--- a/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/PrefabInstance.cs
+++ b/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/PrefabInstance.cs
@@ -4,6 +4,7 @@
using System.Text;
using System.Threading.Tasks;
using UnityPackageImporter.Models;
+using static FrooxEngine.MeshEmitter;
namespace UnityPackageImporter.FrooxEngineRepresentation.GameObjectTypes
{
@@ -18,6 +19,9 @@ public class PrefabInstance : IUnityObject
public SourceObj m_CorrespondingSourceObject { get; set; }
public SourceObj m_SourcePrefab { get; set; }
+
+ public FileImportTaskScene importask = null;
+
public GameObject ImportRoot { get; set; }
public ModPrefab m_Modification { get; set; }
@@ -26,7 +30,6 @@ public class PrefabInstance : IUnityObject
public Dictionary PrefabHashes = new Dictionary(new SourceObjCompare());
-
public async Task instanciateAsync(IUnityStructureImporter importer)
{
await default(ToBackground);
@@ -49,10 +52,22 @@ public async Task instanciateAsync(IUnityStructureImporter importer)
Slot targetParent;
if (m_Modification != null)
{
- if (importer.existingIUnityObjects.TryGetValue(m_Modification.m_TransformParent["fileID"], out IUnityObject foundobjectparent))
+ if (importer.existingIUnityObjects.TryGetValue(m_Modification.m_TransformParent["fileID"], out IUnityObject foundtransformparent))
{
- await foundobjectparent.instanciateAsync(importer);
- targetParent = (foundobjectparent as GameObject).frooxEngineSlot;
+ await default(ToWorld);
+ await foundtransformparent.instanciateAsync(importer);
+ await default(ToBackground);
+ if(importer.existingIUnityObjects.TryGetValue((foundtransformparent as Transform).m_GameObjectID, out IUnityObject parentobjnew)){
+ await default(ToWorld);
+ await parentobjnew.instanciateAsync(importer);
+ await default(ToBackground);
+ targetParent = (parentobjnew as GameObject).frooxEngineSlot;
+ }
+ else
+ {
+ UnityPackageImporter.Warn("targetParent had a value for prefab \"" + id.ToString() + "\" but could not find the id \"" + (foundtransformparent as Transform).m_GameObjectID + "\" in the list of game objects that exist in scene!");
+ targetParent = importer.CurrentStructureRootSlot;
+ }
}
else
{
@@ -64,71 +79,118 @@ public async Task instanciateAsync(IUnityStructureImporter importer)
targetParent = importer.CurrentStructureRootSlot;
}
- ImportRoot = new GameObject();
+
UnityPackageImporter.Msg("is targetParent instanciated?: " + (targetParent != null));
- await default(ToWorld);
- ImportRoot.frooxEngineSlot = importer.unityProjectImporter.SharedImportedFBXScenes[m_SourcePrefab.guid].FinishedFileSlot.Duplicate();
- ImportRoot.frooxEngineSlot.SetParent(targetParent);
+
+ if(importask == null)
+ {
+ ImportRoot = new GameObject();
+ await default(ToWorld);
+ if (importer.unityProjectImporter.SharedImportedFBXScenes.ContainsKey(m_SourcePrefab.guid))
+ {
+ importask = await importer.unityProjectImporter.SharedImportedFBXScenes[m_SourcePrefab.guid].MakeCopyAndPopulatePrefabData();
+ ImportRoot.frooxEngineSlot = importask.FinishedFileSlot;
+ ImportRoot.frooxEngineSlot.SetParent(targetParent);
+ await default(ToBackground);
- await default(ToBackground);
+ SourceObj importrootsource = new SourceObj();
+ importrootsource.guid = this.m_SourcePrefab.guid;
+ importrootsource.fileID = 919132149155446097; //hash of root object path.
+ importrootsource.type = 3;
- this.PrefabHashes = importer.unityProjectImporter.SharedImportedFBXScenes[m_SourcePrefab.guid].FILEID_To_Slot_Pairs;
- if (m_Modification != null)
- {
- foreach (ModsPrefab mod in m_Modification.m_Modifications)
- {
- UnityPackageImporter.Msg("is the current modification instanciated?: " + (mod != null));
- if (this.PrefabHashes.TryGetValue(mod.target, out IUnityObject targetobj))
+ this.PrefabHashes = importask.FILEID_To_Slot_Pairs;
+ this.PrefabHashes.Add(importrootsource, ImportRoot);
+ List modifiedObjects = new List();
+ if (m_Modification != null)
{
- Type targettype = targetobj.GetType();
- try
+ foreach (ModsPrefab mod in m_Modification.m_Modifications)
{
- //This is so bad, since it does a lot of reflection, but there's no better way of doing this since the hash of the object we're targeting doesn't actually represent the class of the type we made from it. - @989onan
- if (targettype.GetProperty(mod.propertyPath).GetValue(targetobj).GetType() == typeof(int))
+ IUnityObject targetobj2 = null;
+ IUnityObject targetobj3 = null;
+ if (this.PrefabHashes.TryGetValue(mod.target, out IUnityObject targetobj) || importer.existingIUnityObjects.TryGetValue((ulong)(mod.target.fileID + (2 ^ 64)), out targetobj2) || importer.existingIUnityObjects.TryGetValue((ulong)(mod.target.fileID), out targetobj3))
{
- int.TryParse(mod.value, out int value);
- targettype.GetProperty(mod.propertyPath).SetValue(Convert.ChangeType(targetobj, targettype), value);
- }
- else if (targettype.GetProperty(mod.propertyPath).GetValue(targetobj).GetType() == typeof(float))
- {
- float.TryParse(mod.value, out float value);
- targettype.GetProperty(mod.propertyPath).SetValue(Convert.ChangeType(targetobj, targettype), value);
+ targetobj = targetobj ?? targetobj2 ?? targetobj3; //get first available match.
+
+ if (MModificationsParser.ParseModifcation(targetobj, mod))
+ {
+ UnityPackageImporter.Msg("The prefab with a file id of \"" + id.ToString() + "\" in the structure scene has parsed a modification with the hash \"" + mod.target.ToString() + "\" successfully.");
+ if (!modifiedObjects.Contains(targetobj))
+ {
+ modifiedObjects.Add(targetobj);
+ }
+ }
+ else
+ {
+ UnityPackageImporter.Warn("The prefab with a file id of \"" + id.ToString() + "\" in the structure scene is malformed!!! The modification with the hash \"" + mod.target.ToString() + "\" could not be parsed!");
+ }
+
}
- else if (targettype.GetProperty(mod.propertyPath).GetValue(targetobj).GetType() == typeof(bool))
+ else
{
- bool.TryParse(mod.value, out bool value);
- targettype.GetProperty(mod.propertyPath).SetValue(Convert.ChangeType(targetobj, targettype), value);
+ UnityPackageImporter.Warn("The prefab with a file id of \"" + id.ToString() + "\" in the structure scene is malformed!!! The modification with the hash \"" + mod.target.ToString() + "\" does not match any in the list of hashes on the prefab \"" + id.ToString() + "\"");
}
- else if (targettype.GetProperty(mod.propertyPath).GetValue(targetobj).GetType() == typeof(string))
+
+ }
+
+ }
+
+ instanciated = true;
+ //instanciate our objects with our modifications, so in case they're not referenced in the scene, the imported FBX we duplicated to make this inline prefab has the M_Modifications still applied.
+ //this is important to do, especially for skinned mesh renderers! - @989onan
+ UnityPackageImporter.Msg("reinitializing objects that were modified.");
+ foreach (IUnityObject obj in modifiedObjects)
+ {
+ obj.m_PrefabInstance = new Dictionary { { "fileID", this.id } }; //this is so that it can find it's source, which is ourselves to prevent errors - @989onan
+ try
+ {
+ UnityPackageImporter.Msg("reinitializing object that was modified. the object has an id of: \"" + obj.m_CorrespondingSourceObject.fileID + "\"");
+ }
+ catch (Exception e)
+ {
+ try
{
- targettype.GetProperty(mod.propertyPath).SetValue(Convert.ChangeType(targetobj, targettype), mod.value);
+ UnityPackageImporter.Msg("reinitializing object that was modified. the object has an id of: \"" + obj.m_CorrespondingSourceObject.fileID + "\" has failed to instanciate. This is probably fine.");
}
- else
+ catch (Exception ex)
{
- UnityPackageImporter.Warn("The prefab with a file id of \"" + id.ToString() + "\" in the current structure is malformed!!! The modification with the hash \"" + mod.target.fileID + "\" has a value of \"" + mod.value + "\", which doesn't cast to any: " +
- "int, float, string" +
- ".");
-
+ UnityPackageImporter.Msg("reinitializing object that was modified. the object has an id of: \"NULL\" has failed to instanciate. This is probably fine.");
+ UnityPackageImporter.Msg(ex.Message, ex.StackTrace);
}
-
+ UnityPackageImporter.Msg(e.Message, e.StackTrace);
}
- catch (Exception e)
+ try
{
- UnityPackageImporter.Warn("The prefab with a file id of \"" + id.ToString() + "\" in the structure scene is malformed!!! The modification with the hash \"" + mod.propertyPath + "\" does not exist! ");
- UnityPackageImporter.Warn(e.Message + e.StackTrace);
+
+ await default(ToWorld);
+ await obj.instanciateAsync(importer);
+ await default(ToBackground);
}
-
-
- }
- else
- {
- UnityPackageImporter.Warn("The prefab with a file id of \"" + id.ToString() + "\" in the structure scene is malformed!!! The modification with the hash \"" + mod.target.fileID + "\" does not match any in the list of hashes on the prefab \"" + id.ToString() + "\"");
+ catch(Exception e)
+ {
+ try
+ {
+ UnityPackageImporter.Msg("reinitializing object that was modified. the object has an id of: \"" + obj.m_CorrespondingSourceObject.fileID + "\" has failed to instanciate. This is probably fine.");
+ }
+ catch (Exception ex)
+ {
+ UnityPackageImporter.Msg("reinitializing object that was modified. the object has an id of: \"NULL\" has failed to instanciate. This is probably fine.");
+ UnityPackageImporter.Msg(ex.Message, ex.StackTrace);
+ }
+ UnityPackageImporter.Msg(e.Message, e.StackTrace);
+ }
+
}
-
}
-
+ else
+ {
+ UnityPackageImporter.Warn("The prefab with a file id of \"" + id.ToString() + "\" in the structure scene is malformed!!! cannot find file with GUID of \"" + m_SourcePrefab.guid.ToString() + "\" for this prefab! (does it exist in the unity project?)");
+ }
}
+
+
+
+
}
else
@@ -136,8 +198,8 @@ public async Task instanciateAsync(IUnityStructureImporter importer)
UnityPackageImporter.Warn("The prefab with a file id of \"" + id.ToString() + "\" in the structure scene is malformed!!! The file source of the prefab doesn't exist in the imported package or file list set.");
}
}
- instanciated = true;
+ instanciated = true;
}
}
diff --git a/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/SkinnedMeshRenderer.cs b/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/SkinnedMeshRenderer.cs
index 0983779..b08e3bd 100644
--- a/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/SkinnedMeshRenderer.cs
+++ b/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/SkinnedMeshRenderer.cs
@@ -1,4 +1,5 @@
using Assimp;
+using Elements.Core;
using FrooxEngine;
using System;
using System.Collections.Generic;
@@ -16,8 +17,8 @@ public class SkinnedMeshRenderer : IUnityObject
public bool instanciated { get; set; }
public Dictionary m_GameObject;
public int m_Enabled = 1;
- public Dictionary materials = new Dictionary();
- public List> m_Materials;
+ public List materials = new List();
+ public List m_Materials = new List();
public SourceObj m_Mesh;
public List> m_Bones;
public FrooxEngine.SkinnedMeshRenderer createdMeshRenderer;
@@ -35,8 +36,6 @@ public async Task instanciateAsync(IUnityStructureImporter importer)
bool NotFromInLinePrefab = true; //
instanciated = true;
- if (this.id == 0) return;//to get rid of a nasty bug I don't wanna find the source of TODO: What is causing this?
-
try
{
@@ -65,6 +64,9 @@ public async Task instanciateAsync(IUnityStructureImporter importer)
await gameobj.instanciateAsync(importer);
await default(ToWorld);
this.createdMeshRenderer = newskin.createdMeshRenderer;
+ this.materials = newskin.materials;
+ this.m_Materials = newskin.m_Materials;
+ UnityPackageImporter.Warn("assigned skinned mesh renderer \"" + newskin.createdMeshRenderer.Slot.Name + "\" some properties from one already created by a prefab.");
}
catch (Exception ex)
{
@@ -94,37 +96,36 @@ public async Task instanciateAsync(IUnityStructureImporter importer)
GameObject parentobj = null;
if (NotFromInLinePrefab)
{
- UnityPackageImporter.Msg("Importing skinned mesh renderer via mesh guid. this id is: \"" + this.id+"\"");
+ UnityPackageImporter.Msg("Importing skinned mesh renderer via mesh guid. this id is: \"" + this.id +"\"");
if (importer.unityProjectImporter.SharedImportedFBXScenes.TryGetValue(m_Mesh.guid, out FileImportTaskScene importedfbx2))
{
importer.existingIUnityObjects.TryGetValue(m_GameObject["fileID"], out IUnityObject parentobj_inc);
parentobj = parentobj_inc as GameObject;
-
+ UnityPackageImporter.Msg("Importing skinned mesh renderer via mesh guid. this id is: \"" + this.id + "\", parentobj = " + parentobj.ToString());
foreach (var pair in importedfbx2.FILEID_To_Slot_Pairs)
{
if (pair.Value.GetType() == typeof(SkinnedMeshRenderer))
{
-
+ UnityPackageImporter.Msg("Importing skinned mesh renderer via mesh guid 2. this id is: \"" + this.id + "\", parentobj = " + parentobj.ToString());
FrooxEngineRepresentation.GameObjectTypes.SkinnedMeshRenderer newskin = (pair.Value as FrooxEngineRepresentation.GameObjectTypes.SkinnedMeshRenderer);
- if (newskin.createdMeshRenderer.Slot.Name.Equals(parentobj.frooxEngineSlot.Name))
+ if (newskin.m_Mesh.fileID == this.m_Mesh.fileID)
{
-
+ UnityPackageImporter.Msg("Assigning parent object for skinned mesh renderer: \"" + this.id + "\"");
await default(ToWorld);
await parentobj.instanciateAsync(importer);
await default(ToWorld);
- Slot newslot = newskin.createdMeshRenderer.Slot.Duplicate();
- newslot.SetParent(parentobj.frooxEngineSlot.Parent, false);
+ Slot newslot = newskin.createdMeshRenderer.Slot.Duplicate(parentobj.frooxEngineSlot.Parent, false, new DuplicationSettings());
newslot.TRS = parentobj.frooxEngineSlot.TRS;
foreach (Slot child in parentobj.frooxEngineSlot.Children)
{
- child.SetParent(parentobj.frooxEngineSlot, false);
+ child.SetParent(newslot, false);
}
await default(ToWorld);
parentobj.frooxEngineSlot.Destroy();
@@ -174,61 +175,16 @@ public async Task instanciateAsync(IUnityStructureImporter importer)
}
+ FrooxEngine.SkinnedMeshRenderer FoundMesh = this.createdMeshRenderer;
- await default(ToBackground);
- foreach (Dictionary item in m_Bones)
- {
- if (importer.existingIUnityObjects.TryGetValue(item["fileID"], out IUnityObject bone_trans))
- {
- if (importer.existingIUnityObjects.TryGetValue(((Transform)bone_trans).m_GameObject["fileID"], out IUnityObject bone_obj))
- {
- GameObject obj2 = bone_obj as GameObject;
- await default(ToWorld);
- await bone_obj.instanciateAsync(importer);
- await default(ToBackground);
- }
- }
- else
- {
- UnityPackageImporter.Warn("The prefab is malformed!!! a skinned mesh render couldn't find it's bone with an id of \"" + item["fileID"].ToString() + "\" Your renderer will come out mis-shapen!");
- }
-
- }
int counter = 0;
- foreach(Dictionary material in m_Materials)
- {
-
- try
- {
- if (importer.unityProjectImporter.AssetIDDict.ContainsKey(material["guid"]))
- {
- await default(ToWorld);
- string file = importer.unityProjectImporter.AssetIDDict[material["guid"]];
- var matimporttask = new FileImportHelperTaskMaterial(material["guid"], file, importer.unityProjectImporter);
- materials.Add(counter, matimporttask);
- await default(ToBackground);
- }
-
- }
- catch (Exception e)
- {
- UnityPackageImporter.Warn("Importing a material threw an error!");
- UnityPackageImporter.Warn(e.Message + e.StackTrace);
- }
-
-
-
- counter += 1;
-
-
- }
-
if (NotFromInLinePrefab) //this basically says that this skinned renderer is not coming from an inline prefab from a scene import
{
- FrooxEngine.SkinnedMeshRenderer FoundMesh = this.createdMeshRenderer;
+
//FoundMesh.Mesh.ReferenceID = (skinnedMeshRenderer as FrooxEngineRepresentation.GameObjectTypes.SkinnedMeshRenderer).createdMeshRenderer.Mesh.ReferenceID;
await default(ToWorld);
+ importer.progressIndicator?.UpdateProgress(0f, "", "now loading a skinned mesh renderer named \""+FoundMesh.Slot.Name+"\" ");
while (!FoundMesh.Mesh.IsAssetAvailable)
{
await default(NextUpdate);
@@ -300,62 +256,131 @@ public async Task instanciateAsync(IUnityStructureImporter importer)
FoundMesh.SetupBones(bonemappings);
await default(ToBackground);
- if (this.m_Materials != null)
+ UnityPackageImporter.Msg("Setting up blend shapes");
+ await default(ToWorld);
+ FoundMesh.SetupBlendShapes();
+ await default(ToBackground);
+
+
+
+
+ await default(ToBackground);
+ foreach (Dictionary item in m_Bones)
{
- if(this.m_Materials.Count > 0)
+ if (importer.existingIUnityObjects.TryGetValue(item["fileID"], out IUnityObject bone_trans))
{
-
- UnityPackageImporter.Msg("clearing bad material objects for: \"" + FoundMesh.Slot.Name + "\"");
- await default(ToWorld);
- FoundMesh.Materials.Clear();
- await default(ToBackground);
-
- UnityPackageImporter.Msg("getting good material objects for: \"" + FoundMesh.Slot.Name + "\"");
- for (int index = 0; index < this.m_Materials.Count(); index++)
+ if (importer.existingIUnityObjects.TryGetValue(((Transform)bone_trans).m_GameObject["fileID"], out IUnityObject bone_obj))
{
+ GameObject obj2 = bone_obj as GameObject;
+ await default(ToWorld);
+ await bone_obj.instanciateAsync(importer);
+ await default(ToBackground);
+ }
+ }
+ else
+ {
+ UnityPackageImporter.Warn("The prefab is malformed!!! a skinned mesh render with the name \"" + FoundMesh.Slot.Name.ToString() + "\" couldn't find it's bone with an id of \"" + item["fileID"].ToString() + "\" Your renderer will come out mis-shapen!");
+ }
+
+ }
+
+
+
+
+
+
+
+
+ }
- if (this.materials.TryGetValue(index, out FileImportHelperTaskMaterial materialtask))
+ for (int i = 0; i < m_Materials.Count; i++)
+ {
+
+ SourceObj material = m_Materials[i];
+ try
+ {
+
+ if (material.guid != string.Empty)
+ {
+ if (importer.unityProjectImporter.AssetIDDict.ContainsKey(material.guid))
+ {
+ await default(ToWorld);
+ string filemat = importer.unityProjectImporter.AssetIDDict[material.guid];
+ try
{
- try
- {
- await default(ToWorld);
- FoundMesh.Materials.Add().Target = await materialtask.runImportFileMaterialsAsync();
- await default(ToBackground);
- }
- catch (Exception e)
- {
- UnityPackageImporter.Warn("Could not attach material \"" + index.ToString() + "\" on mesh \"" + FoundMesh.Slot.Name + "\" from skinned mesh renderer data. It's probably not in the project or in the files you dragged over.");
- UnityPackageImporter.Warn("stacktrace for material \"" + index.ToString() + "\" on mesh \"" + FoundMesh.Slot.Name + "\"");
- UnityPackageImporter.Warn(e.Message);
- await default(ToWorld);
- FoundMesh.Materials.Add();
- await default(ToBackground);
- }
+ materials.RemoveAt(i);
+ materials.Insert(i, new FileImportHelperTaskMaterial(material.guid, filemat, importer.unityProjectImporter));
+ UnityPackageImporter.Msg("Imported a material at index \"" + i + "\" on skinnedmeshrenderer named \"" + FoundMesh.Slot.Name + "\" by replacing one of the indices");
}
- else
+ catch
{
- UnityPackageImporter.Warn("Could not find material task for material \"" + index.ToString() + "\" on mesh \"" + FoundMesh.Slot.Name + "\" from skinned mesh renderer data. It's probably not in the project or in the files you dragged over.");
- await default(ToWorld);
- FoundMesh.Materials.Add();
- await default(ToBackground);
+ materials.Add(new FileImportHelperTaskMaterial(material.guid, filemat, importer.unityProjectImporter));
+ UnityPackageImporter.Msg("Imported a material at index \"" + i + "\" on skinnedmeshrenderer named \"" + FoundMesh.Slot.Name + "\" by tacking onto the end.");
}
+
+ await default(ToBackground);
+ }
+ else
+ {
+ await default(ToWorld);
+ UnityPackageImporter.Msg("Importing a material at index \"" + i + "\" on skinnedmeshrenderer named \"" + FoundMesh.Slot.Name + "\" has an overridden material but we can't find the material that has the override's GUID. (is it in the package?)");
+ try
+ {
+ materials.RemoveAt(i);
+ materials.Insert(i, new FileImportHelperTaskMaterial(importer.unityProjectImporter));
+ }
+ catch
+ {
+ materials.Add(new FileImportHelperTaskMaterial(importer.unityProjectImporter));
+ }
+ await default(ToBackground);
}
}
- }
+ else
+ {
+ UnityPackageImporter.Msg("Importing a material at index \"" + i + "\" on skinnedmeshrenderer named \"" + FoundMesh.Slot.Name + "\" did not override. Using material generated at import.");
+ }
-
-
+ }
+ catch (Exception e)
+ {
+ UnityPackageImporter.Warn("Importing a material at index \"" + i + "\" on skinnedmeshrenderer named \"" + FoundMesh.Slot.Name + "\" threw an error!");
+ UnityPackageImporter.Warn(e.Message + e.StackTrace);
+ }
- UnityPackageImporter.Msg("Setting up blend shapes");
- await default(ToWorld);
- FoundMesh.SetupBlendShapes();
- await default(ToBackground);
- UnityPackageImporter.Msg("Skinned Mesh Renderer \"" + FoundMesh.Slot.Name + "\" imported!");
}
-
+ UnityPackageImporter.Msg("clearing bad material objects for: \"" + FoundMesh.Slot.Name + "\"");
+ await default(ToWorld);
+ FoundMesh.Materials.Clear();
+ await default(ToBackground);
+ counter = 0;
+ UnityPackageImporter.Msg("getting good material objects for: \"" + FoundMesh.Slot.Name + "\" it has \"" + this.materials.Count.ToString() + " \" materials in the generated list to instanciate and m_Materials being instanciated is: \"" + (m_Materials.Count > 0) + "\" ");
+ foreach (FileImportHelperTaskMaterial materialtask in this.materials)
+ {
+ try
+ {
+ importer.progressIndicator?.UpdateProgress(0f, "", "now loading material " + counter.ToString() + " on a skinned mesh renderer named \"" + FoundMesh.Slot.Name + "\" ");
+ await default(ToWorld);
+ UnityPackageImporter.Msg("assigning material slot for: \"" + FoundMesh.Slot.Name + "\"");
+ FoundMesh.Materials.Add().Target = await materialtask.runImportFileMaterialsAsync();
+ await default(ToBackground);
+ }
+ catch (Exception e)
+ {
+ UnityPackageImporter.Warn("Could not attach material \"" + counter.ToString() + "\" on mesh \"" + FoundMesh.Slot.Name + "\" from skinned mesh renderer data. It's probably not in the project or in the files you dragged over.");
+ UnityPackageImporter.Warn("stacktrace for material \"" + counter.ToString() + "\" on mesh \"" + FoundMesh.Slot.Name + "\"");
+ UnityPackageImporter.Warn(e.Message);
+ await default(ToWorld);
+ FoundMesh.Materials.Add(await new FileImportHelperTaskMaterial(importer.unityProjectImporter).runImportFileMaterialsAsync());
+ await default(ToBackground);
+ }
+ counter++;
+ }
+
+ UnityPackageImporter.Msg("Skinned Mesh Renderer \"" + FoundMesh.Slot.Name + "\" imported, and imported \""+ counter.ToString() +"\" materials with it.");
}
@@ -380,6 +405,7 @@ public override string ToString()
{
result.AppendLine("m_CorrespondingSourceObject: null");
}
+
if (m_PrefabInstance != null)
{
result.AppendLine("m_PrefabInstance: " + m_PrefabInstance.ToString());
@@ -388,6 +414,29 @@ public override string ToString()
{
result.AppendLine("m_PrefabInstance: null");
}
+
+
+ if (this.m_GameObject != null)
+ {
+ if (this.m_GameObject.ContainsKey("fileID"))
+ {
+ result.AppendLine("m_GameObjectID: " + this.m_GameObject["fileID"].ToString());
+ }
+ }
+ else
+ {
+ result.AppendLine("m_GameObjectID: null");
+ }
+
+ if (m_Mesh != null)
+ {
+ result.AppendLine("m_Mesh: " + m_Mesh.ToString());
+ }
+ else
+ {
+ result.AppendLine("m_Mesh: null");
+ }
+
if (createdMeshRenderer != null)
{
result.AppendLine("createdMeshRenderer" + createdMeshRenderer.ToString());
@@ -397,7 +446,7 @@ public override string ToString()
result.AppendLine("createdMeshRenderer: null");
}
- return base.ToString();
+ return result.ToString();
}
diff --git a/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/Transform.cs b/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/Transform.cs
index 425c488..b3d328d 100644
--- a/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/Transform.cs
+++ b/UnityPackageImporter/FrooxEngineRepresentation/GameObjectTypes/Transform.cs
@@ -6,6 +6,7 @@
using System.Text;
using System.Threading.Tasks;
using UnityPackageImporter.Models;
+using static FrooxEngine.FinalIK.VRIKAvatar;
namespace UnityPackageImporter.FrooxEngineRepresentation.GameObjectTypes
{
@@ -15,8 +16,8 @@ public class Transform: IUnityObject
public TransformFloat4 m_LocalRotation;
public TransformFloat3 m_LocalPosition;
public TransformFloat3 m_LocalScale;
-
-
+ public TransformFloat3 m_LocalEulerAnglesHint; //this is an error supressor. this does nothing don't use it. - @989onan
+
public ulong id { get; set; }
public int m_RootOrder;
public bool instanciated { get; set; }
@@ -64,58 +65,51 @@ public async Task instanciateAsync(IUnityStructureImporter importer)
{
this.parentHashedGameObj = alreadydefined.parentHashedGameObj;
-
+ UnityPackageImporter.Msg("transform import stage 1");
foreach (IUnityObject variab in importer.existingIUnityObjects.Values)
{
- if(variab.GetType() == typeof(GameObject))
+ if (variab.GetType() == typeof(GameObject))
{
GameObject actual = variab as GameObject;
- if(actual.m_CorrespondingSourceObject != null)
+ if (actual.m_CorrespondingSourceObject != null)
{
- if(actual.m_CorrespondingSourceObject.fileID != 0)
+ if (actual.m_CorrespondingSourceObject.fileID != 0)
{
if (actual.m_CorrespondingSourceObject.fileID == alreadydefined.parentHashedGameObj.m_CorrespondingSourceObject.fileID
- && actual.m_CorrespondingSourceObject.guid.Equals(alreadydefined.parentHashedGameObj.m_CorrespondingSourceObject.guid)
- )
+ && actual.m_CorrespondingSourceObject.guid.Equals(alreadydefined.parentHashedGameObj.m_CorrespondingSourceObject.guid))
{
+ UnityPackageImporter.Msg("transform import stage 1.5");
this.parentHashedGameObj = actual;
}
}
}
-
- }
-
- }
-
-
- if (this.parentHashedGameObj.id == alreadydefined.parentHashedGameObj.id)
- {
- try
- {
- UnityPackageImporter.Warn("The inline prefab is malformed!!! the transform with an id \"" + id.ToString() + "\" and a target game object id of \"" + alreadydefined.parentHashedGameObj + "\"did not find it's parent transform's game object! this will split your import in half heiarchy wise! This should never happen!");
- }
- catch
- {
- UnityPackageImporter.Warn("The inline prefab is malformed!!! the transform with an id \"" + id.ToString() + "\" and a guid of \"null\"did not find it's parent transform's game object! this will split your import in half heiarchy wise! This should never happen!");
}
}
+ UnityPackageImporter.Msg("transform import stage 3");
await default(ToWorld);
await this.parentHashedGameObj.instanciateAsync(importer);
await default(ToBackground);
-
+ UnityPackageImporter.Msg("transform import stage 4");
this.m_GameObject = new Dictionary
{
{ "fileID", this.parentHashedGameObj.id}
};
m_GameObjectID = m_GameObject["fileID"];
- this.m_LocalPosition = new TransformFloat3(this.parentHashedGameObj.frooxEngineSlot.LocalPosition.x, this.parentHashedGameObj.frooxEngineSlot.LocalPosition.y, this.parentHashedGameObj.frooxEngineSlot.LocalPosition.z);
- this.m_LocalRotation = new TransformFloat4(this.parentHashedGameObj.frooxEngineSlot.LocalRotation.x, this.parentHashedGameObj.frooxEngineSlot.LocalRotation.y, this.parentHashedGameObj.frooxEngineSlot.LocalRotation.z, this.parentHashedGameObj.frooxEngineSlot.LocalRotation.w);
- this.m_LocalScale = new TransformFloat3(this.parentHashedGameObj.frooxEngineSlot.LocalScale.x, this.parentHashedGameObj.frooxEngineSlot.LocalScale.y, this.parentHashedGameObj.frooxEngineSlot.LocalScale.z);
+ UnityPackageImporter.Msg("transform import stage 5");
+ await default(ToWorld);
+ this.m_LocalRotation = alreadydefined.m_LocalRotation;
+ this.m_LocalPosition = alreadydefined.m_LocalPosition;
+ this.m_LocalScale = alreadydefined.m_LocalScale;
+ this.parentHashedGameObj.frooxEngineSlot.LocalPosition = new float3(this.m_LocalPosition.x, this.m_LocalPosition.y, this.m_LocalPosition.z);
+ this.parentHashedGameObj.frooxEngineSlot.LocalRotation = new floatQ(this.m_LocalRotation.x, this.m_LocalRotation.y, this.m_LocalRotation.z, this.m_LocalRotation.w);
+ this.parentHashedGameObj.frooxEngineSlot.LocalScale = new float3(this.m_LocalScale.x, this.m_LocalScale.y, this.m_LocalScale.z);
+ await default(ToBackground);
+ UnityPackageImporter.Msg("transform import stage 6");
}
catch (Exception ex)
{
diff --git a/UnityPackageImporter/FrooxEngineRepresentation/IUnityObject.cs b/UnityPackageImporter/FrooxEngineRepresentation/IUnityObject.cs
index caf5f2f..2436105 100644
--- a/UnityPackageImporter/FrooxEngineRepresentation/IUnityObject.cs
+++ b/UnityPackageImporter/FrooxEngineRepresentation/IUnityObject.cs
@@ -27,6 +27,14 @@ public class SourceObj
public int type { get; set; }
public SourceObj() { }
+
+ public SourceObj(long fileID, string guid, int type)
+ {
+ this.fileID = fileID;
+ this.guid = guid;
+ this.type = type;
+ }
+
public override string ToString()
{
StringBuilder result = new StringBuilder();
@@ -67,10 +75,10 @@ public class ModsPrefab
public SourceObj target { get; set; }
public string propertyPath { get; set; }
public string value { get; set; }
- public Dictionary objectReference { get; set; }
+ public SourceObj objectReference { get; set; }
public ModsPrefab() { }
- public ModsPrefab(SourceObj target, string propertyPath, string value, Dictionary objectReference)
+ public ModsPrefab(SourceObj target, string propertyPath, string value, SourceObj objectReference)
{
this.target = target;
this.propertyPath = propertyPath;
@@ -107,10 +115,7 @@ public override string ToString()
}
if (objectReference != null)
{
- foreach (var pair in objectReference)
- {
- result.AppendLine("objectReference+Item: (" + pair.Key.ToString() + ", " + pair.Value.ToString());
- }
+ result.AppendLine("objectReference: " + objectReference.ToString());
}
else
{
diff --git a/UnityPackageImporter/FrooxEngineRepresentation/MModificationsParser.cs b/UnityPackageImporter/FrooxEngineRepresentation/MModificationsParser.cs
new file mode 100644
index 0000000..e114c90
--- /dev/null
+++ b/UnityPackageImporter/FrooxEngineRepresentation/MModificationsParser.cs
@@ -0,0 +1,143 @@
+using Elements.Core;
+using HarmonyLib;
+using Leap.Unity.Query;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using UnityPackageImporter.Models;
+using static HarmonyLib.AccessTools;
+
+namespace UnityPackageImporter.FrooxEngineRepresentation
+{
+ public class MModificationsParser
+ {
+
+
+
+
+ public static bool ParseModifcation(IUnityObject targetobj, ModsPrefab mod)
+ {
+ Type targettype = targetobj.GetType();
+
+ List path = mod.propertyPath.Split('.').ToList();
+
+ foreach(string path2 in path) {
+ UnityPackageImporter.Msg("path item: " + path2);
+ }
+
+ //use reflection to get the first part of the path.
+ FieldInfo field = targettype.GetField(path.TakeFirst());
+ return recursiveSetTypeValue(targetobj, path, mod, field);
+ }
+
+
+ //m_rotation.w
+ private static bool recursiveSetTypeValue(object targetobj, List path, ModsPrefab mod, FieldInfo field)
+ {
+ if (field == null) {
+ UnityPackageImporter.Error("Modification field \"" + mod.ToString() + "\" Field ended up at null path when parsing!");
+ if (path.Count > 0)
+ {
+ UnityPackageImporter.Msg("path item: " + path[0]);
+ }
+ UnityPackageImporter.Error("targetobj: "+(targetobj != null ? targetobj.ToString() : "null"));
+
+ return false;
+
+ }
+
+ if (path.Count > 0)
+ {
+ string current = path.TakeFirst();
+ if (current.Equals("Array"))
+ {
+ return recursiveSetTypeValue(targetobj, path, mod, field);
+ }
+ else if (current.StartsWith("data["))
+ {
+ try
+ {
+ UnityPackageImporter.Msg("array type is: " + field.FieldType);
+ UnityPackageImporter.Msg("array enclosed type is: " + field.FieldType.GetGenericArguments()[0]);
+ UnityPackageImporter.Msg("targetobj type is: " + targetobj.GetType());
+ int arrayindex = int.Parse(current.Replace("data[", "").Replace("]", ""));
+ UnityPackageImporter.Msg("arrayindex is: " + arrayindex.ToString());
+ Type arraytype = field.FieldType.GetGenericArguments()[0];
+ IList array = field.GetValue(targetobj) as IList; //this should work in most cases.
+ try
+ {
+ UnityPackageImporter.Msg("array: " + array.ToString());
+ }
+ catch
+ {
+ UnityPackageImporter.Msg("array: null");
+ }
+
+ //in case the array has nothing inside of it
+ try
+ {
+ array.RemoveAt(arrayindex);
+ array.Insert(arrayindex, (mod.value != null) ? Convert.ChangeType(mod.value, arraytype) : mod.objectReference);
+ }
+ catch
+ {
+ array.Add((mod.value != null) ? Convert.ChangeType(mod.value, arraytype) : mod.objectReference);
+ }
+
+ return true;
+ }
+ catch (Exception e)
+ {
+ UnityPackageImporter.Error("Assigning final part of path for modification on an array hit an error!");
+ UnityPackageImporter.Error(e.Message, e.StackTrace);
+ return false;
+ }
+ }
+ else
+ {
+ FieldInfo fieldnew;
+ try
+ {
+
+ targetobj = field.GetValue(targetobj);
+ UnityPackageImporter.Msg(targetobj.GetType().ToString());
+ fieldnew = targetobj.GetType().GetField(current);
+ UnityPackageImporter.Msg(fieldnew.FieldType.ToString());
+ }
+ catch (Exception e)
+ {
+ UnityPackageImporter.Error("Finding next part of path for modification hit an error!");
+ UnityPackageImporter.Error(e.Message, e.StackTrace);
+ return false;
+ }
+
+ return recursiveSetTypeValue(targetobj, path, mod, fieldnew);
+ }
+ }
+ else
+ {
+ try
+ {
+ field.SetValue(targetobj, Convert.ChangeType(mod.value != null ? mod.value : mod.target, field.FieldType));
+ return true;
+ }
+ catch (Exception e)
+ {
+ UnityPackageImporter.Error("Assigning final part of path for modification hit an error!");
+ UnityPackageImporter.Error(e.Message, e.StackTrace);
+ UnityPackageImporter.Msg(targetobj.GetType().ToString());
+ UnityPackageImporter.Msg(field.FieldType.ToString());
+ return false;
+ }
+
+ }
+ }
+
+
+ }
+}
diff --git a/UnityPackageImporter/FrooxEngineRepresentation/UnityEngineObjectWrapper.cs b/UnityPackageImporter/FrooxEngineRepresentation/UnityEngineObjectWrapper.cs
index 7936ab3..bfdad14 100644
--- a/UnityPackageImporter/FrooxEngineRepresentation/UnityEngineObjectWrapper.cs
+++ b/UnityPackageImporter/FrooxEngineRepresentation/UnityEngineObjectWrapper.cs
@@ -55,6 +55,25 @@ namespace UnityPackageImporter.FrooxEngineRepresentation
{
public class UnityEngineObjectWrapper
{
+
+
+ ///
+ /// Use game object as a reference point.
+ /// this is how long the objects are generally gonna take. These values are realtive and don't represent time units.
+ /// instead, these get added one by one depending on the objects being imported into a total number.
+ ///
+ public static Dictionary addedProgress = new Dictionary
+ {
+ {typeof(Component), 0},
+ {typeof(GameObject), 1},
+ {typeof(Transform), 2},
+ {typeof(NullType), 0},
+ {typeof(SkinnedMeshRenderer), 10},
+ {typeof(PrefabInstance), 20},
+ {typeof(RotationConstraint), 2},
+ {typeof(MeshCollider), 10},
+ {typeof(MonoBehaviour), 30}
+ };
public Component Component;
public GameObject GameObject;
public Transform Transform;
@@ -63,7 +82,7 @@ public class UnityEngineObjectWrapper
public PrefabInstance PrefabInstance;
public RotationConstraint RotationConstraint;
public MeshCollider MeshCollider;
- public MonoBehavior MonoBehavior;
+ public MonoBehaviour MonoBehaviour;
public UnityEngineObjectWrapper()
{
@@ -80,7 +99,7 @@ public IUnityObject Result()
SkinnedMeshRenderer,
MeshCollider,
RotationConstraint,
- MonoBehavior,
+ MonoBehaviour,
NullType
}.Find(i => i != null);
diff --git a/UnityPackageImporter/FrooxEngineRepresentation/UnityNodeTypeResolver.cs b/UnityPackageImporter/FrooxEngineRepresentation/UnityNodeTypeResolver.cs
index 932ac67..3b5a8ed 100644
--- a/UnityPackageImporter/FrooxEngineRepresentation/UnityNodeTypeResolver.cs
+++ b/UnityPackageImporter/FrooxEngineRepresentation/UnityNodeTypeResolver.cs
@@ -42,6 +42,7 @@ public bool Resolve(NodeEvent nodeEvent, ref Type currentType)
class UnityObjectMapping
{
+
public static Dictionary IdToTypeName = new Dictionary()
{
{ 1, "GameObject" },
@@ -280,5 +281,21 @@ class UnityObjectMapping
{ 1113, "LightmapParameters" },
{ 1120, "LightmapSnapshot"}
};
+
+
+ public static Dictionary type_name_To_ID = type_name_To_ID_constructor();
+
+ private static Dictionary type_name_To_ID_constructor()
+ {
+ Dictionary type_name_To_ID = new Dictionary();
+ foreach(KeyValuePair pair in IdToTypeName)
+ {
+ type_name_To_ID.Add(pair.Value, pair.Key);
+ }
+
+ return type_name_To_ID;
+ }
+
+
}
}
diff --git a/UnityPackageImporter/Models/FileImportHelperTaskMaterial.cs b/UnityPackageImporter/Models/FileImportHelperTaskMaterial.cs
index 39accc9..e8193a9 100644
--- a/UnityPackageImporter/Models/FileImportHelperTaskMaterial.cs
+++ b/UnityPackageImporter/Models/FileImportHelperTaskMaterial.cs
@@ -7,6 +7,7 @@
using System.IO;
using System.Linq;
using System.Linq.Expressions;
+using System.Reflection;
using System.Security.Policy;
using System.Threading.Tasks;
using UnityPackageImporter.FrooxEngineRepresentation;
@@ -16,11 +17,14 @@ namespace UnityPackageImporter.Models
{
public class FileImportHelperTaskMaterial
{
- public string file;
- public string myID;
+ private string file;
+ private string myID;
public Slot assetsRoot;
public Slot matslot;
public UnityProjectImporter importer;
+ public FrooxEngine.PBS_Metallic finalMaterial;
+ public bool ismissing = false;
+ private bool finished = false;
public static string materialNameIdentifyEndingPrefab = " - Material";
@@ -30,22 +34,36 @@ public FileImportHelperTaskMaterial(string myID, string file, UnityProjectImport
this.file = file;
UnityPackageImporter.Msg("Importing material with ID: \""+myID+"\"");
assetsRoot = importer.importTaskAssetRoot;
- matslot = assetsRoot.AddSlot(Path.GetFileNameWithoutExtension(this.file) + materialNameIdentifyEndingPrefab);
+ matslot = assetsRoot.FindChildOrAdd(Path.GetFileNameWithoutExtension(this.file) + materialNameIdentifyEndingPrefab);
+ finalMaterial = matslot.GetComponentOrAttach();
this.myID = myID;
}
+
+ //to assign a material to a missing material during import if the fbx doesn't have a definition for it, so later we can assign the material.
+ public FileImportHelperTaskMaterial(UnityProjectImporter importer)
+ {
+ this.importer = importer;
+ UnityPackageImporter.Msg("Importing null material");
+ assetsRoot = importer.importTaskAssetRoot;
+ matslot = assetsRoot.FindChildOrAdd("MISSING_ERROR" + materialNameIdentifyEndingPrefab);
+ finalMaterial = importer.importTaskAssetRoot.FindChildOrAdd("MISSING_ERROR" + materialNameIdentifyEndingPrefab).GetComponentOrAttach();
+ finalMaterial.EmissiveColor.Value = new Elements.Core.colorX(1, 0, 1, 1, Elements.Core.ColorProfile.Linear);
+ finalMaterial.AlbedoColor.Value = new Elements.Core.colorX(1, 0, 1, 1, Elements.Core.ColorProfile.Linear);
+ ismissing = true;
+ finished = true;
+ }
+
public async Task runImportFileMaterialsAsync()
{
await default(ToBackground);
+ if (ismissing || finished) return finalMaterial; //so that if something trys to make ourselves but we were instanciated as missing, do nothing.
return await ImportFileMaterial();
}
private async Task ImportFileMaterial()
{
- await default(ToWorld);
- FrooxEngine.PBS_Metallic finalMaterial = matslot.AttachComponent();
- await default(ToBackground);
bool inTextureBlock = false;
await default(ToBackground);
string texturename = string.Empty;
@@ -224,6 +242,7 @@ public FileImportHelperTaskMaterial(string myID, string file, UnityProjectImport
}
await default(ToBackground);
+ finished = true;
return finalMaterial;
}
diff --git a/UnityPackageImporter/Models/FileImportTaskScene.cs b/UnityPackageImporter/Models/FileImportTaskScene.cs
index 06de2a4..9a4976c 100644
--- a/UnityPackageImporter/Models/FileImportTaskScene.cs
+++ b/UnityPackageImporter/Models/FileImportTaskScene.cs
@@ -10,14 +10,11 @@
using MonoMod.Utils;
using HashDepot;
using UnityPackageImporter.FrooxEngineRepresentation;
-using YamlDotNet.Serialization.NamingConventions;
-using YamlDotNet.Serialization;
-using YamlDotNet.Core;
-using SkyFrost.Base;
-using static UMP.Wrappers.WrapperStandalone;
-using Elements.Assets;
-using System.Reflection;
using System.Linq;
+using UnityPackageImporter.FrooxEngineRepresentation.GameObjectTypes;
+using SkyFrost.Base;
+using static OfficialAssets.Common;
+using Elements.Core;
namespace UnityPackageImporter.Models
{
@@ -31,28 +28,36 @@ public class FileImportTaskScene
public Slot importTaskAssetSlot;
public bool import_finished = false;
public MetaDataFile metafile;
+ private ProgressBarInterface import_dialogue;
- Slot targetSlot;
+ private Slot targetSlot;
public Slot FinishedFileSlot = null;
public bool postprocessfinished = false;
- public bool? isBiped;
- public bool running;
+ public bool running = false;
+ private float3 globalPosition;
- public FileImportTaskScene(Slot targetSlot, string assetID, UnityProjectImporter importer, string file)
+ public FileImportTaskScene(Slot targetSlot, string assetID, UnityProjectImporter importer, string file, float3 globalPosition)
{
- this.targetSlot = targetSlot.AddSlot(Path.GetFileNameWithoutExtension(file)+UnityPackageImporter.UNITY_PREFAB_EXTENSION);
+ this.targetSlot = targetSlot.AddSlot(Path.GetFileNameWithoutExtension(file)+ " - Temp.fbx");
this.file = file;
this.importer = importer;
- this.importTaskAssetSlot = importer.importTaskAssetRoot.AddSlot("Assets - "+ Path.GetFileNameWithoutExtension(file) + UnityPackageImporter.UNITY_PREFAB_EXTENSION);
+ this.importTaskAssetSlot = importer.importTaskAssetRoot.AddSlot("Assets - "+ Path.GetFileNameWithoutExtension(file) + ".fbx");
this.assetID = assetID;
+ this.globalPosition = globalPosition;
+ }
+
+ private FileImportTaskScene(Slot targetSlot, UnityProjectImporter importer)
+ {
+ this.targetSlot = targetSlot;
+ this.importer = importer;
+
}
//https://stackoverflow.com/a/31492250
//https://stackoverflow.com/a/10789196
-
public Task runnerWrapper()
{
if (!this.running)
@@ -66,7 +71,16 @@ public Task runnerWrapper()
private async Task ImportFileMeshes()
{
+
+
UnityPackageImporter.Msg("Start code block for file import for file " + file);
+
+ await default(ToWorld);
+ Slot Indicator = importer.world.AddSlot("FBX Import Indicator", false);
+ Indicator.GlobalPosition = globalPosition;
+ this.import_dialogue = await Indicator.SpawnEntity(FavoriteEntity.ProgressBar);
+ await default(ToBackground);
+
await default(ToWorld);
AssimpContext assimpContext = new AssimpContext();
assimpContext.Scale = 1f;
@@ -77,9 +91,9 @@ private async Task ImportFileMeshes()
await default(ToBackground);
this.metafile = new MetaDataFile();
-
- UnityPackageImporter.Msg("Start assimp file import for file \"" + file+ "\" If your log stops here, then Assimp crashed like a drunk man and took the game with it.\"");
+
+ this.import_dialogue?.UpdateProgress(0f,"","Start assimp file import for file \"" + Path.GetFileName(file)+ "\" If your import stops here, then Assimp crashed like a drunk man and took the game with it.\"");
FrooxEngineBootstrap.LogStream.Flush();
await default(ToBackground);
@@ -96,54 +110,125 @@ private async Task ImportFileMeshes()
{
assimpContext.Dispose();
}
-
- UnityPackageImporter.Msg("Preprocessing scene for file " + file);
+
+ this.import_dialogue?.UpdateProgress(0f, "", "Preprocessing scene for file " + Path.GetFileName(file));
FrooxEngineBootstrap.LogStream.Flush();
PreprocessScene(scene);
UnityPackageImporter.Msg("making model import data for file: " + file);
this.data = new ModelImportData(file, scene, this.targetSlot, this.importTaskAssetSlot, ModelImportSettings.PBS(true, true, false, false, false, false), null);
- UnityPackageImporter.Msg("importing node into froox engine, file: " + file);
+ this.import_dialogue?.UpdateProgress(0f, "", "importing nodes into froox engine, file: " + Path.GetFileName(file));
FrooxEngineBootstrap.LogStream.Flush();
await Task.WhenAll(ImportNodeAsync(scene.RootNode, targetSlot, data));
- UnityPackageImporter.Msg("retrieving scene root for file: " + file);
- FrooxEngineBootstrap.LogStream.Flush();
- this.FinishedFileSlot = this.targetSlot; //this is on purpose - @989onan
- UnityPackageImporter.Msg("scanning meta file for data");
- await this.metafile.ScanFile(this, this.FinishedFileSlot); //scanning rather than creating components is important here. also this needs to happen immedeatley after the assimp import is finished. - @989onan
- UnityPackageImporter.Msg("recurisively searching for slots in file: " + file);
+ UnityPackageImporter.Msg("retrieving scene root for file: " + Path.GetFileName(file));
FrooxEngineBootstrap.LogStream.Flush();
+ await this.metafile.ScanFile(this, data.TryGetSlot(scene.RootNode));
- //find each child slot of the whole thing
- foreach(Node childofroot in scene.RootNode.Children)
- {
- FILEID_To_Slot_Pairs.AddRange(RecusiveFileIDSlotFinder(this.data, childofroot, data.TryGetSlot(scene.RootNode), this.assetID));
- }
-
- //this is to scale it smaller while importing. we then scale it back up at the right moment.
foreach (Slot slot in data.TryGetSlot(scene.RootNode).GetAllChildren(false).ToArray())
{
if (null == slot.GetComponent())
{
await default(ToWorld);
- UnityPackageImporter.Msg("scaling bone " + slot.Name);
- slot.LocalPosition /= this.metafile.GlobalScale * 100;
+ UnityPackageImporter.Msg("scaling bone " + slot.Name + " with scale \"" + this.metafile.GlobalScale + "\"");
+
+ //prevent from taking over the world by the aliens-- I meant the model - @989onan
+
await default(ToBackground);
}
}
- foreach (FrooxEngine.SkinnedMeshRenderer mesh in this.data.skinnedRenderers)
+ await default(ToWorld);
+ data.TryGetSlot(scene.RootNode).Tag = "PREFABROOTTAG1234";
+ await default(ToBackground);
+
+ this.FinishedFileSlot = this.targetSlot;
+
+ this.import_dialogue?.UpdateProgress(0f, "", "Hashing slot paths with XXHash64 for file: " + Path.GetFileName(file));
+
+ foreach (Slot childofroot in data.TryGetSlot(scene.RootNode).Children)
{
+ this.FILEID_To_Slot_Pairs.AddRange(RecusiveFileIDSlotFinder(childofroot, data.TryGetSlot(scene.RootNode), this.assetID));//find each child slot of the whole thing
+ }
- string calculatedpath = FindSlotPath(mesh.Slot, data.TryGetSlot(scene.RootNode));
- SourceObj identifier = findRealSource(mesh.Slot.Name, "SkinnedMeshRenderer", calculatedpath);
- //UnityPackageImporter.Msg($"{Calculated_fileid} was made from SkinnedMeshRenderer with a slot \"{mesh.Slot.Name}\" with path \"{calculatedpath}\"");
+ this.import_dialogue?.UpdateProgress(0f, "", "Hashing skinned mesh renderers with XXHash64 for file: " + Path.GetFileName(file));
+ //this for statement thing is crazy. But it gets the job done - @989onan
+ foreach (FrooxEngine.SkinnedMeshRenderer mesh in this.FinishedFileSlot.GetAllChildren().FindAll(slot => slot.GetComponent() != null).Select(slot => slot.GetComponent()))
+ {
+
+ UnityPackageImporter.Msg("scanning files for ids for mesh renderer "+mesh.Slot.Name);
+ FrooxEngineRepresentation.GameObjectTypes.SkinnedMeshRenderer skinnedrenderer = new FrooxEngineRepresentation.GameObjectTypes.SkinnedMeshRenderer();
+ SourceObj identifier = this.findRealSource(mesh.Slot.Name, "SkinnedMeshRenderer", "//RootNode/root/" + mesh.Slot.Name);
+ identifier.guid = this.assetID;
+ skinnedrenderer.m_CorrespondingSourceObject = identifier;
+ skinnedrenderer.createdMeshRenderer = mesh;
+ skinnedrenderer.m_Mesh = this.findRealSource(mesh.Slot.Name, "Mesh", mesh.Slot.Name); //this allows us to identify this object by mesh, which is useful for prefabs.
+ skinnedrenderer.m_Mesh.guid = this.assetID;
+ UnityPackageImporter.Msg("id for mesh \""+mesh.Slot.Name+"\" is \""+ skinnedrenderer.m_Mesh.ToString() + "\"files for ids for mesh renderer " + mesh.Slot.Name);
+ UnityPackageImporter.Msg("id for skinned mesh renderer \"" + mesh.Slot.Name + "\" is \"" + identifier.ToString()+"\"");
+ this.FILEID_To_Slot_Pairs.Add(identifier, skinnedrenderer);
+ }
+
+
+
+
+
+ this.import_dialogue?.ProgressDone("Finished task for file " + Path.GetFileName(file));
+ this.running = false;
+ }
+
+
+ //this is trashy I know - @989onan
+ public async Task MakeCopyAndPopulatePrefabData()
+ {
+ FileImportTaskScene copy = new FileImportTaskScene(targetSlot, importer);
+ copy.file = this.file;
+ await default(ToWorld);
+ UnityPackageImporter.Msg("target slot instanciated?: "+(copy.targetSlot != null));
+ copy.targetSlot = copy.targetSlot.Duplicate(null, false, null);
+ copy.FinishedFileSlot = copy.targetSlot;
+ copy.metafile = new MetaDataFile();
+ copy.FILEID_To_Slot_Pairs.Clear();
+ copy.assetID = this.assetID;
+
+ //cleanup
+ Slot Sceneroot = copy.targetSlot.GetChildrenWithTag("PREFABROOTTAG1234").First();
+ Sceneroot.Tag = null;
+ await default(ToBackground);
+
+
+ UnityPackageImporter.Msg("scanning meta file for data");
+ UnityPackageImporter.Msg("file instanciated?: " + (copy.file != null));
+ UnityPackageImporter.Msg("targetSlot instanciated?: " + (copy.targetSlot != null));
+ UnityPackageImporter.Msg("FinishedFileSlot instanciated?: " + (copy.FinishedFileSlot != null));
+ await copy.metafile.ScanFile(copy, copy.targetSlot);
+ UnityPackageImporter.Msg("recurisively searching for slots in file: " + file);
+ FrooxEngineBootstrap.LogStream.Flush();
+
+ foreach (Slot childofroot in Sceneroot.Children)
+ {
+ copy.FILEID_To_Slot_Pairs.AddRange(RecusiveFileIDSlotFinder(childofroot, Sceneroot, copy.assetID));//find each child slot of the whole thing
+ }
+
+ //this for statement thing is crazy. But it gets the job done - @989onan
+ foreach (FrooxEngine.SkinnedMeshRenderer mesh in copy.FinishedFileSlot.GetAllChildren().FindAll(slot => slot.GetComponent() != null).Select(slot => slot.GetComponent()))
+ {
+
+ UnityPackageImporter.Msg("giving a skinned mesh renderer materials for file: " + file);
FrooxEngineRepresentation.GameObjectTypes.SkinnedMeshRenderer skinnedrenderer = new FrooxEngineRepresentation.GameObjectTypes.SkinnedMeshRenderer();
+ SourceObj identifier = copy.findRealSource(mesh.Slot.Name, "SkinnedMeshRenderer", "//RootNode/root/" + mesh.Slot.Name);
+ skinnedrenderer.m_CorrespondingSourceObject = identifier;
+ identifier.guid = copy.assetID;
+ UnityPackageImporter.Msg("path for mesh \""+ mesh.Slot.Name + "\"" + identifier.ToString());
+
+ skinnedrenderer.m_Mesh = copy.findRealSource(mesh.Slot.Name, "Mesh", mesh.Slot.Name); //this allows us to identify this object by mesh, which is useful for prefabs.
+
+ //UnityPackageImporter.Msg($"{Calculated_fileid} was made from SkinnedMeshRenderer with a slot \"{mesh.Slot.Name}\" with path \"{calculatedpath}\"");
+
skinnedrenderer.createdMeshRenderer = mesh;
await default(ToWorld);
@@ -158,86 +243,105 @@ private async Task ImportFileMeshes()
Dictionary bonemappings = new Dictionary();
foreach (var bone in skinnedrenderer.createdMeshRenderer.Mesh.Asset.Data.Bones)
{
- bonemappings.Add(bone.Name, this.FinishedFileSlot.FindChildInHierarchy(bone.Name));
+ bonemappings.Add(bone.Name, copy.FinishedFileSlot.FindChildInHierarchy(bone.Name));
}
skinnedrenderer.createdMeshRenderer.SetupBones(bonemappings);
skinnedrenderer.createdMeshRenderer.SetupBlendShapes();
-
+
//we will replace these missing ones later with m_modifications
List materialnames = new List();
-
+
for (int i = 0; i < skinnedrenderer.createdMeshRenderer.Materials.Count; i++)
{
materialnames.Add(skinnedrenderer.createdMeshRenderer.Materials[i].FindNearestParent().Name.Replace("Material: ", "").Trim());
}
- skinnedrenderer.createdMeshRenderer.Materials.Clear();
- for (int i = 0; i < skinnedrenderer.createdMeshRenderer.Mesh.Asset.Data.SubmeshCount; i++) {
- IAssetProvider finalmaterial;
+ for (int i = 0; i < skinnedrenderer.createdMeshRenderer.Mesh.Asset.Data.SubmeshCount; i++)
+ {
+ FileImportHelperTaskMaterial materialtask;
try
{
- if (this.metafile.externalObjects != null)
+ if (copy.metafile.externalObjects != null)
{
- if (this.metafile.externalObjects.TryGetValue(materialnames[i], out SourceObj material))
+ if (copy.metafile.externalObjects.TryGetValue(materialnames[i], out SourceObj material))
{
- if (this.importTaskAssetSlot.FindChildInHierarchy(materialnames[i] + FileImportHelperTaskMaterial.materialNameIdentifyEndingPrefab) == null)
- {
- await default(ToWorld);
- finalmaterial = await new FileImportHelperTaskMaterial(material.guid, this.importer.AssetIDDict[material.guid], this.importer).runImportFileMaterialsAsync();
- await default(ToBackground);
- }
- else
- {
- //lordie this statement length! - @989onan
- finalmaterial = this.importTaskAssetSlot.FindChildInHierarchy(materialnames[i] + FileImportHelperTaskMaterial.materialNameIdentifyEndingPrefab).Components.FirstOrDefault() as IAssetProvider;
- }
-
+ await default(ToWorld);
+ materialtask = new FileImportHelperTaskMaterial(material.guid, copy.importer.AssetIDDict[material.guid], copy.importer);
+ await default(ToBackground);
}
else
{
- UnlitMaterial missing = this.importTaskAssetSlot.FindChildOrAdd("Missing Material").GetComponentOrAttach();
- missing.TintColor.Value = new Elements.Core.colorX(1, 0, 1, 1, Elements.Core.ColorProfile.Linear);
- finalmaterial = missing;
- UnityPackageImporter.Msg("The material " + materialnames[i] + " importing could not find it's corrosponding mesh name!");
+ await default(ToWorld);
+ materialtask = new FileImportHelperTaskMaterial(copy.importer); //missing material for now. M_Modifications may modify later.
+ await default(ToBackground);
}
}
else
{
- UnlitMaterial missing = this.importTaskAssetSlot.FindChildOrAdd("Missing Material").GetComponentOrAttach();
- missing.TintColor.Value = new Elements.Core.colorX(1, 0, 1, 1, Elements.Core.ColorProfile.Linear);
- finalmaterial = missing;
+ await default(ToWorld);
+ materialtask = new FileImportHelperTaskMaterial(copy.importer);
+ await default(ToBackground);
}
+ await default(ToWorld);
+ skinnedrenderer.materials.Add(materialtask);
+ skinnedrenderer.m_Materials.Add(new SourceObj(0,string.Empty,0)); //this is to signify
+ await default(ToBackground);
}
catch (Exception e)
{
UnityPackageImporter.Msg("The material " + materialnames[i] + " importing encountered an error!");
+ skinnedrenderer.m_Materials.Add(new SourceObj(0, string.Empty, 0));
throw e;
}
await default(ToWorld);
-
- skinnedrenderer.createdMeshRenderer.Materials.Add().Target = finalmaterial;
+
+
}
- if (!FILEID_To_Slot_Pairs.ContainsKey(identifier))
+ if (!copy.FILEID_To_Slot_Pairs.ContainsKey(identifier))
{
- FILEID_To_Slot_Pairs.Add(identifier, skinnedrenderer);
+ copy.FILEID_To_Slot_Pairs.Add(identifier, skinnedrenderer);
}
- }
-
+ UnityPackageImporter.Msg("clearing bad material objects for initial import for: \"" + skinnedrenderer.createdMeshRenderer.Slot.Name + "\"");
+ await default(ToWorld);
+ skinnedrenderer.createdMeshRenderer.Materials.Clear();
+ await default(ToBackground);
+ int counter = 0;
+ UnityPackageImporter.Msg("getting good material objects for initial import for: \"" + skinnedrenderer.createdMeshRenderer.Slot.Name + "\" it has \"" + skinnedrenderer.materials.Count.ToString() + " \" materials in the generated list to instanciate");
+ foreach (FileImportHelperTaskMaterial materialtask in skinnedrenderer.materials)
+ {
+ try
+ {
+ await default(ToWorld);
+ UnityPackageImporter.Msg("assigning material for initial import slot for: \"" + skinnedrenderer.createdMeshRenderer.Slot.Name + "\"");
+ skinnedrenderer.createdMeshRenderer.Materials.Add().Target = await materialtask.runImportFileMaterialsAsync();
+ await default(ToBackground);
+ }
+ catch (Exception e)
+ {
+ UnityPackageImporter.Warn("Could not attach material \"" + counter.ToString() + "\" for initial import on mesh \"" + skinnedrenderer.createdMeshRenderer.Slot.Name + "\" from skinned mesh renderer data. It's probably not in the project or in the files you dragged over.");
+ UnityPackageImporter.Warn("stacktrace for material \"" + counter.ToString() + "\" for initial import on mesh \"" + skinnedrenderer.createdMeshRenderer.Slot.Name + "\"");
+ UnityPackageImporter.Warn(e.Message);
+ await default(ToWorld);
+ skinnedrenderer.createdMeshRenderer.Materials.Add(await new FileImportHelperTaskMaterial(copy.importer).runImportFileMaterialsAsync());
+ await default(ToBackground);
+ }
+ counter++;
+ }
+ }
- UnityPackageImporter.Msg("Finished task for file " + file);
- this.running = false;
+ return copy;
}
@@ -254,46 +358,52 @@ private static IEnumerator ImportNodeWrapper(Node node, Slot targetSlot
completion.SetResult(result: true);
}
- public Dictionary RecusiveFileIDSlotFinder(ModelImportData data2, Node root, Slot SceneRoot, string assetID)
+ public Dictionary RecusiveFileIDSlotFinder(Slot curnode, Slot Scene, string assetID)
{
//UnityPackageImporter.Msg($"checking slot \"{root.Name}\"");
FrooxEngineBootstrap.LogStream.Flush();
Dictionary FILEID_into_Slot_Pairs = new Dictionary(new SourceObjCompare());
- Slot curnode = data2.TryGetSlot(root);
-
//UnityPackageImporter.Msg($"{Calculated_fileid} was made from slot \"{curnode.Name}\" with path \"{gameobjpath}\"");
FrooxEngineBootstrap.LogStream.Flush();
FrooxEngineRepresentation.GameObjectTypes.GameObject calclatedobj = new FrooxEngineRepresentation.GameObjectTypes.GameObject();
- calclatedobj.instanciated = true;
calclatedobj.frooxEngineSlot = curnode;
- calclatedobj.m_CorrespondingSourceObject = findRealSource(curnode.Name, "GameObject", FindSlotPath(curnode, SceneRoot));
+ calclatedobj.m_CorrespondingSourceObject = findRealSource(curnode.Name, "GameObject", "//RootNode/root" + FindSlotPath(curnode, Scene));
+ calclatedobj.m_Name = curnode.Name;
if (!FILEID_into_Slot_Pairs.ContainsKey(calclatedobj.m_CorrespondingSourceObject))
{
FILEID_into_Slot_Pairs.Add(calclatedobj.m_CorrespondingSourceObject, calclatedobj);
}
+
+
+
FrooxEngineRepresentation.GameObjectTypes.Transform calclatedTransformobj = new FrooxEngineRepresentation.GameObjectTypes.Transform();
calclatedTransformobj.parentHashedGameObj = calclatedobj;
- calclatedTransformobj.instanciated = true;
- calclatedTransformobj.m_CorrespondingSourceObject = findRealSource(curnode.Name, "Transform", FindSlotPath(curnode, SceneRoot));
+
+ calclatedTransformobj.m_CorrespondingSourceObject = findRealSource(curnode.Name, "Transform", "//RootNode/root" + FindSlotPath(curnode, Scene));
+
+ //this is so m_modifications work - @989onan
+ calclatedTransformobj.m_LocalPosition = new TransformFloat3(calclatedobj.frooxEngineSlot.LocalPosition.x, calclatedobj.frooxEngineSlot.LocalPosition.y, calclatedobj.frooxEngineSlot.LocalPosition.z);
+ calclatedTransformobj.m_LocalScale = new TransformFloat3(calclatedobj.frooxEngineSlot.LocalScale.x, calclatedobj.frooxEngineSlot.LocalScale.y, calclatedobj.frooxEngineSlot.LocalScale.z);
+ calclatedTransformobj.m_LocalRotation = new TransformFloat4(calclatedobj.frooxEngineSlot.LocalRotation.x, calclatedobj.frooxEngineSlot.LocalRotation.y, calclatedobj.frooxEngineSlot.LocalRotation.z, calclatedobj.frooxEngineSlot.LocalRotation.w);
//UnityPackageImporter.Msg($"{Calculated_fileidtransform} was made from transform \"{curnode.Name}\" with path \"{transformpath}\"");
if (!FILEID_into_Slot_Pairs.ContainsKey(calclatedTransformobj.m_CorrespondingSourceObject))
{
FILEID_into_Slot_Pairs.Add(calclatedTransformobj.m_CorrespondingSourceObject, calclatedTransformobj);
}
- if (root.ChildCount > 0)
+ if (curnode.ChildrenCount > 0)
{
- foreach(Node child in root.Children)
+ foreach(Slot child in curnode.Children)
{
- FILEID_into_Slot_Pairs.AddRange(RecusiveFileIDSlotFinder(data2, child, SceneRoot, assetID));
+ FILEID_into_Slot_Pairs.AddRange(RecusiveFileIDSlotFinder(child, Scene, assetID));
}
}
@@ -305,11 +415,11 @@ public SourceObj findRealSource(string thisname, string type, string rawpath)
{
SourceObj sourceObj = new SourceObj();
string endingtype = "";
- if (!type.Equals("GameObject"))
+ if (!type.Equals("GameObject") && !type.Equals("Mesh"))
{
endingtype = "/"+type;
}
- string path = "Type:" + type + "->//RootNode/root" + rawpath + endingtype + "0";
+ string path = "Type:" + type + "->" + rawpath + endingtype + "0";
long calculated_gameobj_id = (long)XXHash.Hash64(Encoding.UTF8.GetBytes(path));
sourceObj.fileID = calculated_gameobj_id;
sourceObj.guid = this.assetID;
@@ -318,7 +428,10 @@ public SourceObj findRealSource(string thisname, string type, string rawpath)
foreach (KeyValuePair item in this.metafile.fileIDToRecycleName)
{
- if (thisname == item.Value)
+ string numident = UnityObjectMapping.type_name_To_ID[type].ToString();
+
+ string nummatch = item.Key.ToString();
+ if (thisname == item.Value && nummatch.Remove(nummatch.Length-5).Equals(numident)) //the format is: "{numident}+00002" or "{numident}+00012" and so on. So removing 5 chars gives us our identifier.
{
sourceObj.fileID = item.Key;//in case it's already defined in the metafile, because unity is weird - @989onan
}
@@ -327,6 +440,9 @@ public SourceObj findRealSource(string thisname, string type, string rawpath)
}
+
+
+
public static string FindSlotPath(Slot child, Slot StopAt)
{
if(child == null || StopAt == null)
diff --git a/UnityPackageImporter/Models/IUnityStructureImporter.cs b/UnityPackageImporter/Models/IUnityStructureImporter.cs
index c699499..cf40011 100644
--- a/UnityPackageImporter/Models/IUnityStructureImporter.cs
+++ b/UnityPackageImporter/Models/IUnityStructureImporter.cs
@@ -1,4 +1,5 @@
-using FrooxEngine;
+using Elements.Core;
+using FrooxEngine;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -15,6 +16,7 @@ public interface IUnityStructureImporter
UnityProjectImporter unityProjectImporter { get; set; }
+ ProgressBarInterface progressIndicator { get; set; }
Slot CurrentStructureRootSlot { get; set; }
public Slot allimportsroot { get; set; }
diff --git a/UnityPackageImporter/Models/MetaDataFile.cs b/UnityPackageImporter/Models/MetaDataFile.cs
index 42cd848..3674d4a 100644
--- a/UnityPackageImporter/Models/MetaDataFile.cs
+++ b/UnityPackageImporter/Models/MetaDataFile.cs
@@ -15,8 +15,8 @@ namespace UnityPackageImporter
{
public class MetaDataFile
{
- public BipedRig modelBoneHumanoidAssignments;
- public float GlobalScale = -1;
+ public float GlobalScale = 1;
+ private float LastScaleGlobalScale = 1;
public Dictionary externalObjects = new Dictionary();
@@ -32,43 +32,30 @@ public MetaDataFile() {
//this creates our biped rig under the slot we specify. in this case, it is the root.
//this MetaDataFile object class gives us access to the biped rig component directly if desired
- public async Task GenerateComponents(Slot ModelRootSlot) {
+ public async Task GenerateComponents(BipedRig rig) {
- if(this.modelBoneHumanoidAssignments == null)
- {
-
- await default(ToWorld);
- this.modelBoneHumanoidAssignments = ModelRootSlot.AttachComponent();
- UnityPackageImporter.Msg("Humanoid bone description being instanciated is: " + (modelBoneHumanoidAssignments != null));
- await default(ToBackground);
+ UnityPackageImporter.Msg("Humanoid bone description being instanciated is: " + (rig != null));
+ await default(ToBackground);
- //so that we add the bone without parsing it's children
- //if we use """AssignBones(Rig.BoneNode root, bool ignoreDuplicates)""" that will cause errors.
- foreach (var BoneNode in storagebones)
+ //so that we add the bone without parsing it's children
+ //if we use """AssignBones(Rig.BoneNode root, bool ignoreDuplicates)""" that will cause errors.
+ foreach (var BoneNode in storagebones)
+ {
+ if (BoneNode.Value != null)
{
- if (BoneNode.Value != null)
- {
- UnityPackageImporter.Msg("assigning bone: " + BoneNode.Value.Name);
- await default(ToWorld);
- this.modelBoneHumanoidAssignments.Bones.Add(BoneNode.Key, BoneNode.Value);
- await default(ToBackground);
- }
- else
- {
- UnityPackageImporter.Msg("assigning bone was null! Idk what it was...");
- }
-
+ UnityPackageImporter.Msg("assigning bone: " + BoneNode.Value.Name);
+ await default(ToWorld);
+ rig.Bones.Add(BoneNode.Key, BoneNode.Value);
+ await default(ToBackground);
}
-
- await default(ToWorld);
- UnityPackageImporter.Msg("detecting forward flipped of model biped.");
- //this is here to initialize our Rig's biped forward at the end of the import for VRIK later on.
- modelBoneHumanoidAssignments.GuessForwardFlipped();
- modelBoneHumanoidAssignments.DetectHandRigs();
- await default(ToBackground);
+ else
+ {
+ UnityPackageImporter.Msg("assigning bone was null! Idk what it was...");
+ }
+
}
}
@@ -115,17 +102,23 @@ public async Task ScanFile(FileImportTaskScene task, Slot ModelRootSlot)
continue;
}
- if (line.StartsWith(" globalScale:"))
+ if (line.StartsWith(" - name:"))
+ {
+ UnityPackageImporter.Msg("Name of scale is: \""+line.Split(':')[1].Trim()+"\"");
+ }
+ if (line.StartsWith(" scale:"))
{
+ UnityPackageImporter.Msg("scaleblock3.5");
try
{
- string numberStr = line.Split(':')[1].Trim();
- UnityPackageImporter.Msg("found scale \"" + numberStr + "\", parsing to get our scale");
- GlobalScale = float.Parse(numberStr);
+ string numberStr = line.Split(':')[2].Split(',')[0].Trim();
+ UnityPackageImporter.Msg("found scale last \"" + numberStr + "\", parsing to get our scale");
+ LastScaleGlobalScale = Math.Abs(float.Parse(numberStr));
}
catch
{
- GlobalScale = 1;
+ UnityPackageImporter.Msg("scaleblock fail");
+ UnityPackageImporter.Msg("scaleblock fail");
}
continue;
}
@@ -205,6 +198,7 @@ public async Task ScanFile(FileImportTaskScene task, Slot ModelRootSlot)
break;
}
}
+ GlobalScale = LastScaleGlobalScale;
}
//Since Unity names and Froox Engine names are the same, just parse them as enums and return.
diff --git a/UnityPackageImporter/Models/UnityPrefabImportTask.cs b/UnityPackageImporter/Models/UnityPrefabImportTask.cs
index fb9c0d2..03cb9db 100644
--- a/UnityPackageImporter/Models/UnityPrefabImportTask.cs
+++ b/UnityPackageImporter/Models/UnityPrefabImportTask.cs
@@ -1,4 +1,6 @@
-using FrooxEngine;
+using Elements.Core;
+using FrooxEngine;
+using SkyFrost.Base;
using System;
using System.Collections.Generic;
using System.IO;
@@ -19,14 +21,18 @@ internal class UnityPrefabImportTask : IUnityStructureImporter
public Slot allimportsroot { get; set; }
public KeyValuePair ID { get; set; }
+ private float3 GlobalIndicatorPosition;
+
+ public ProgressBarInterface progressIndicator { get; set; }
public UnityProjectImporter unityProjectImporter { get; set; }
- public UnityPrefabImportTask(Slot root, KeyValuePair ID, UnityProjectImporter unityProjectImporter)
+ public UnityPrefabImportTask(float3 globalPosition, Slot root, KeyValuePair ID, UnityProjectImporter unityProjectImporter)
{
this.ID = ID;
this.unityProjectImporter = unityProjectImporter;
this.allimportsroot = root;
+ this.GlobalIndicatorPosition = globalPosition;
}
public async Task StartImport()
{
@@ -34,12 +40,48 @@ public async Task StartImport()
try {
existingIUnityObjects = new Dictionary();
await default(ToWorld);
- this.CurrentStructureRootSlot = Engine.Current.WorldManager.FocusedWorld.AddSlot(Path.GetFileName(ID.Value));
+ this.CurrentStructureRootSlot = unityProjectImporter.world.AddSlot(Path.GetFileName(ID.Value));
this.CurrentStructureRootSlot.SetParent(this.allimportsroot, false);
- this.CurrentStructureRootSlot.PositionInFrontOfUser(null, null, 0.7f, null, false, false, true);
+ this.CurrentStructureRootSlot.GlobalPosition = this.GlobalIndicatorPosition;
+ Slot indicator = this.unityProjectImporter.root.AddSlot("Unity Prefab Import Indicator");
+ indicator.GlobalPosition = this.GlobalIndicatorPosition;
+ indicator.PersistentSelf = false;
+ this.progressIndicator = await indicator.SpawnEntity(FavoriteEntity.ProgressBar);
+ progressIndicator?.Initialize(false);
await default(ToBackground);
+ progressIndicator?.UpdateProgress(0f, "", "now loading unity YAML objects for Prefab.");
+ //we first have to remove "stripped" since those cause yaml parsing errors
+ string[] initialstream = File.ReadAllLines(ID.Value);
+ string[] newcontent = new string[initialstream.Length];
+ for (int i = 0; i < initialstream.Length; i++)
+ {
+ string line = initialstream[i];
+ newcontent[i] = line;
+ if (line.StartsWith("--- !u!"))
+ {
+ newcontent[i] = newcontent[i].Replace(" stripped", "");
+
+ }
+ }
+ File.WriteAllLines(ID.Value, newcontent);
+
+
+ int totalProgress = 0;
+
+ foreach (KeyValuePair obj in existingIUnityObjects)
+ {
+ Type type = obj.Value.GetType();
+ int progressitem = 4;
+
+ UnityEngineObjectWrapper.addedProgress.TryGetValue(type, out progressitem);
+ totalProgress += progressitem;
+
+ }
+
+
+
this.existingIUnityObjects = YamlToFrooxEngine.parseYaml(this.ID.Value);
@@ -48,15 +90,46 @@ public async Task StartImport()
UnityPackageImporter.Msg("Loaded " + existingIUnityObjects.Count.ToString() + " Unity objects/components/meshes for prefab!");
-
- //instanciate our objects to generate our prefab entirely, using the ids we assigned ealier to identify our prefab elements in our list.
await default(ToWorld);
- foreach (var obj in existingIUnityObjects)
+ int counter = 0;
+ int progress = 0;
+ //instanciate our objects to generate our prefab entirely, using the ids we assigned ealier to identify our prefab elements in our list.
+ foreach (KeyValuePair obj in existingIUnityObjects)
{
- await obj.Value.instanciateAsync(this);
- debugPrefab.Append(obj.Value.ToString());
+ counter++;
+ Type type = obj.Value.GetType();
+ int progressitem = 4;
+
+ UnityEngineObjectWrapper.addedProgress.TryGetValue(type, out progressitem);
+ progress += progressitem;
+ progressIndicator?.UpdateProgress(MathX.Clamp01((float)progress / (float)totalProgress), "", "now loading " + this.existingIUnityObjects.Count.ToString() + "/" + counter.ToString() + " objects for Prefab");
+ UnityPackageImporter.Msg("loading object for prefab \"" + ID.Value + "\" with an id of \"" + obj.Value.id.ToString() + "\"");
+ try
+ {
+ await obj.Value.instanciateAsync(this);
+ }
+ catch (Exception e)
+ {
+ UnityPackageImporter.Warn("Prefab IUnityObject failed to instanciate!");
+ UnityPackageImporter.Msg("Prefab IUnityObject ID: \"" + obj.Value.id.ToString() + "\"");
+ UnityPackageImporter.Warn(e.Message + e.StackTrace);
+ }
+ try
+ {
+ debugPrefab.Append(obj.Value.ToString());
+ }
+ catch (Exception e)
+ {
+ UnityPackageImporter.Warn("Prefab IUnityObject could not be turned into a string!");
+ UnityPackageImporter.Msg("Prefab IUnityObject ID: \"" + obj.Value.id.ToString() + "\"");
+ UnityPackageImporter.Warn(e.Message + e.StackTrace);
+ }
+
+
+
}
- await default(ToBackground);
+
+ progressIndicator?.UpdateProgress(0f, "", "instanciated " + existingIUnityObjects.Count.ToString() + " Unity objects/components/meshes for prefab! Now cleaning up.");
List movethese = new List();
@@ -107,12 +180,13 @@ public async Task StartImport()
FrooxEngineRepresentation.GameObjectTypes.PrefabInstance prefab = obj.Value as FrooxEngineRepresentation.GameObjectTypes.PrefabInstance;
await UnityProjectImporter.SettupHumanoid(
- unityProjectImporter.SharedImportedFBXScenes[prefab.m_SourcePrefab.guid],
- prefab.ImportRoot.frooxEngineSlot);
+ prefab.importask,
+ prefab.ImportRoot.frooxEngineSlot,
+ true);
}
}
- UnityPackageImporter.Msg("Setting up IK Root");
+
foreach (var obj in existingIUnityObjects)
{
if (obj.Value.GetType() == typeof(FrooxEngineRepresentation.GameObjectTypes.SkinnedMeshRenderer))
@@ -125,6 +199,8 @@ await UnityProjectImporter.SettupHumanoid(
}
}
+ progressIndicator?.UpdateProgress(0f, "", "setting up IK for prefab.");
+
foreach (var obj in existingIUnityObjects)
{
if (obj.Value.GetType() == typeof(FrooxEngineRepresentation.GameObjectTypes.SkinnedMeshRenderer))
@@ -135,7 +211,7 @@ await UnityProjectImporter.SettupHumanoid(
{
if (this.unityProjectImporter.SharedImportedFBXScenes.TryGetValue(newobj.m_Mesh.guid, out FileImportTaskScene importedfbx)) {
await default(ToWorld);
- await UnityProjectImporter.SettupHumanoid(importedfbx, this.CurrentStructureRootSlot);
+ await UnityProjectImporter.SettupHumanoid(importedfbx, this.CurrentStructureRootSlot, true);
await default(ToBackground);
break; //all skinned mesh renderers should go to the current prefab if they're under the root. I think that is the root above in the if statement with "RootNode" - @989onan
}
@@ -148,6 +224,10 @@ await UnityProjectImporter.SettupHumanoid(
}
}
+
+ progressIndicator?.ProgressDone("Finished Prefab!");
+ progressIndicator?.UpdateProgress(1f, "", "Finished!");
+
}
catch (Exception e)
{
@@ -155,6 +235,7 @@ await UnityProjectImporter.SettupHumanoid(
UnityPackageImporter.Warn(e.Message + e.StackTrace);
UnityPackageImporter.Msg(debugPrefab.ToString());
FrooxEngineBootstrap.LogStream.Flush();
+ progressIndicator?.ProgressFail("Failed to decode the Unity Prefab due to an error!");
throw e;
}
diff --git a/UnityPackageImporter/Models/UnityProjectImporter.cs b/UnityPackageImporter/Models/UnityProjectImporter.cs
index e728618..9656a1a 100644
--- a/UnityPackageImporter/Models/UnityProjectImporter.cs
+++ b/UnityPackageImporter/Models/UnityProjectImporter.cs
@@ -4,12 +4,14 @@
using FrooxEngine;
using FrooxEngine.FinalIK;
using HarmonyLib;
+using SkyFrost.Base;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
+using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using UnityPackageImporter.FrooxEngineRepresentation;
@@ -37,11 +39,14 @@ public class UnityProjectImporter
public List files;
public Slot root;
-
+
+ public World world;
+
+
public ReadOnlyDictionary ListOfPrefabs;
- public UnityProjectImporter(IEnumerable files, Dictionary AssetIDDict, Dictionary ListOfPrefabs, Dictionary ListOfMetas, Dictionary ListOfUnityScenes, Slot root, Slot assetsRoot)
+ public UnityProjectImporter(IEnumerable files, Dictionary AssetIDDict, Dictionary ListOfPrefabs, Dictionary ListOfMetas, Dictionary ListOfUnityScenes, Slot root, Slot assetsRoot, World world)
{
this.files = files as List;
this.importTaskAssetRoot = assetsRoot;
@@ -52,6 +57,7 @@ public UnityProjectImporter(IEnumerable files, Dictionary(ListOfMetas);
this.AssetIDDict = new ReadOnlyDictionary(AssetIDDict);
this.ListOfUnityScenes = new ReadOnlyDictionary(ListOfUnityScenes);
+ this.world = world;
}
public async Task startImports()
@@ -62,26 +68,38 @@ public async Task startImports()
//I feel so smart making the wait all import fbx tasks code. - @989onan
await default(ToWorld);
- await Task.WhenAll(fillFBXFiles().Select(task => task.runnerWrapper()).ToArray());
+ IEnumerable fbx_tasks = fillFBXFiles();
+
+ await Task.WhenAll(fbx_tasks.Select(task => task.runnerWrapper()).ToArray());
await default(ToBackground);
//now we have a full list of meta files and prefabs regarding this import file list from our prefix (where ever this is even if not a unity package folder) we now begin the hard part
// *drums* making the files go onto the model!
-
List unityImportTasks = new List();
+ int total = this.ListOfPrefabs.Count + this.ListOfUnityScenes.Count;
+ int rowSize = MathX.Max(1, MathX.CeilToInt(MathX.Sqrt((float)total)));
+
+
+ float3 GlobalPosition = new float3(0,0,0);
+ floatQ GlobalRotation = new floatQ(0, 0, 0, 1);
+
+ await default(ToWorld);
+ this.world.LocalUser.GetPointInFrontOfUser(out GlobalPosition, out GlobalRotation, null, null, 0.7f,true);
+ await default(ToBackground);
+ int counter = 0;
foreach (KeyValuePair Prefab in this.ListOfPrefabs)
{
-
UnityPackageImporter.Msg("create prefab import task obj for prefab \"" + Prefab.Value + "\"");
await default(ToWorld);
- unityImportTasks.Add(new UnityPrefabImportTask(root, Prefab, this));
+ unityImportTasks.Add(new UnityPrefabImportTask((GlobalRotation * UniversalImporter.GridOffset(ref counter, rowSize)) + GlobalPosition, root, Prefab, this));
await default(ToBackground);
}
- foreach(var Scene in this.ListOfUnityScenes)
+ foreach(KeyValuePair Scene in this.ListOfUnityScenes)
{
+
UnityPackageImporter.Msg("create scene import task obj for scene \""+ Scene.Value+ "\"");
await default(ToWorld);
- unityImportTasks.Add(new UnitySceneImportTask(root, Scene, this));
+ unityImportTasks.Add(new UnitySceneImportTask((GlobalRotation * UniversalImporter.GridOffset(ref counter, rowSize)) + GlobalPosition, root, Scene, this));
await default(ToBackground);
}
await default(ToWorld);
@@ -104,47 +122,75 @@ public async Task startImports()
private IEnumerable fillFBXFiles()
{
-
- foreach(KeyValuePair pair in AssetIDDict)
+ int total = 0;
+
+ foreach (KeyValuePair pair in AssetIDDict)
{
string[] filename = pair.Value.Split('.');
if(new string[]{"fbx"}.Contains(filename[filename.Length-1].ToLower())){
+ if (!SharedImportedFBXScenes.ContainsKey(pair.key))
+ {
+ total++;
+
+ }
+ }
+
+
+ }
+ int rowSize = MathX.Max(1, MathX.CeilToInt(MathX.Sqrt((float)total)));
+ int counter = 0;
+ this.world.LocalUser.GetPointInFrontOfUser(out float3 GlobalPosition, out floatQ GlobalRotation, null, null, 0.7f, true);
+ foreach (KeyValuePair pair in AssetIDDict)
+ {
+ string[] filename = pair.Value.Split('.');
+ if (new string[] { "fbx" }.Contains(filename[filename.Length - 1].ToLower()))
+ {
+
if (!SharedImportedFBXScenes.ContainsKey(pair.key))
{
UnityPackageImporter.Debug("now importing \"" + pair.Value + "\" for later use by prefabs and scenes!");
- FileImportTaskScene importtask = new FileImportTaskScene(this.root, pair.key, this, this.AssetIDDict[pair.key]);
+ FileImportTaskScene importtask = new FileImportTaskScene(this.root, pair.key, this, this.AssetIDDict[pair.key], (GlobalRotation * UniversalImporter.GridOffset(ref counter, rowSize)) + GlobalPosition);
this.SharedImportedFBXScenes.Add(pair.key, importtask);
yield return importtask;
+
}
}
-
+
}
+
yield break;
}
+
+
//this is static for a reason to be shared, don't use any fields from this importer that aren't static, and make sure to use locking to be thread safe
- public static async Task SettupHumanoid(FileImportTaskScene task, Slot FBXRoot)
+ public static async Task SettupHumanoid(FileImportTaskScene task, Slot FBXRoot, bool needsScaleComp)
{
UnityPackageImporter.Msg("checking if this FBX is a humanoid");
Slot taskSlot = FBXRoot;
- await task.metafile.ScanFile(task, taskSlot); //we have to scan again here, since the slots may have changed names.
- await task.metafile.GenerateComponents(taskSlot);
+ BipedRig biped = taskSlot.AttachComponent();
+ await task.metafile.ScanFile(task, FBXRoot);
+ await task.metafile.GenerateComponents(biped);
+
- bool isBiped = task.metafile.modelBoneHumanoidAssignments.IsBiped;
//EXPLAINATION OF THIS CODE:
//we are using the froox engine data made from assimp to force our model onto what we generated instead of
//what froox engine made. This is better than asking froox engine to fully import the model for us
//we get more control this way.
- if (isBiped) {
+ if (biped.IsBiped) {
await default(ToWorld);
-
+
+ Slot movecenter = taskSlot.Parent.AddSlot(taskSlot.Name + " - Move Me With This!");
+ movecenter.TRS = taskSlot.TRS;
+ taskSlot.SetParent(movecenter);
+
Rig rig = taskSlot.GetComponent();
if (rig == null)
{
@@ -161,7 +207,7 @@ public static async Task SettupHumanoid(FileImportTaskScene task, Slot FBXRoot)
await default(ToWorld);
UnityPackageImporter.Msg("Finding if we set up VRIK and are biped.");
- if (isBiped)
+ if (biped.IsBiped)
{
UnityPackageImporter.Msg("We have not set up vrik!");
@@ -180,8 +226,10 @@ public static async Task SettupHumanoid(FileImportTaskScene task, Slot FBXRoot)
if (null == slot.GetComponent())
{
- UnityPackageImporter.Msg("scaling bone " + slot.Name);
- slot.LocalPosition *= task.metafile.GlobalScale * 100;
+ UnityPackageImporter.Msg("adding bone " + slot.Name +" with scale \""+ task.metafile.GlobalScale + "\"");
+
+ slot.LocalPosition *= needsScaleComp?task.metafile.GlobalScale:1;
+ rig.Bones.AddUnique(slot);
}
@@ -189,7 +237,7 @@ public static async Task SettupHumanoid(FileImportTaskScene task, Slot FBXRoot)
BodyNode node = BodyNode.NONE;
try
{
- node = task.metafile.modelBoneHumanoidAssignments.Bones.FirstOrDefault(i => i.Value.Target.Name.Equals(slot.Name)).key;
+ node = biped.Bones.FirstOrDefault(i => i.Value.Target.Name.Equals(slot.Name)).key;
}
catch (Exception) { } //this is to catch key not found so we shouldn't handle this.
@@ -226,8 +274,8 @@ public static async Task SettupHumanoid(FileImportTaskScene task, Slot FBXRoot)
await default(ToWorld);
CapsuleCollider capsuleCollider = slotcollider.AttachComponent();
- capsuleCollider.Radius.Value = value*100;
- capsuleCollider.Height.Value = magnitude*100;
+ capsuleCollider.Radius.Value = value;
+ capsuleCollider.Height.Value = magnitude;
}
}
@@ -238,7 +286,7 @@ public static async Task SettupHumanoid(FileImportTaskScene task, Slot FBXRoot)
Elements.Core.BoundingBox boundingBox = Elements.Core.BoundingBox.Empty();
await default(ToWorld);
- float num = FBXRoot.ComputeBoundingBox(false, FBXRoot, null, null).Size.y/1.8f;
+ float num = FBXRoot.ComputeBoundingBox(true, FBXRoot, null, null).Size.y/1.8f;
rootnode.LocalScale /= new float3(num, num, num);
await default(ToBackground);
@@ -258,18 +306,29 @@ public static async Task SettupHumanoid(FileImportTaskScene task, Slot FBXRoot)
VRIK vrik = rootnode.AttachComponent(true, null);
vrik.Solver.SimulationSpace.Target = rootnode.Parent;
vrik.Solver.OffsetSpace.Target = rootnode.Parent;
+ //this is here to initialize our Rig's biped forward at the end of the import for VRIK later on.
+ biped.GuessForwardFlipped();
+ try
+ {
+ biped.DetectHandRigs();
+ }
+ catch (Exception e)
+ {
+ UnityPackageImporter.Msg("Error when detecting hand rigs for model \"" + task.file + "\"");
+ UnityPackageImporter.Msg(e.Message,e.StackTrace);
+ }
vrik.Initiate();//create our vrik component using our custom biped rig as our humanoid. Since it's on the same slot.
//set our ik draggables up so people can play with the model and know it worked. - @989onan
//ps, stolen from FrooxEngine decompiled code.
- Slot slot3 = task.metafile.modelBoneHumanoidAssignments[BodyNode.Head];
- Slot slot4 = task.metafile.modelBoneHumanoidAssignments[BodyNode.Hips];
- Slot slot5 = task.metafile.modelBoneHumanoidAssignments[BodyNode.LeftHand];
- Slot slot6 = task.metafile.modelBoneHumanoidAssignments[BodyNode.RightHand];
- Slot slot7 = task.metafile.modelBoneHumanoidAssignments[BodyNode.LeftFoot];
- Slot slot8 = task.metafile.modelBoneHumanoidAssignments[BodyNode.RightFoot];
- Slot slot9 = task.metafile.modelBoneHumanoidAssignments.TryGetBone(BodyNode.LeftToes);
- Slot slot10 = task.metafile.modelBoneHumanoidAssignments.TryGetBone(BodyNode.RightToes);
+ Slot slot3 = biped[BodyNode.Head];
+ Slot slot4 = biped[BodyNode.Hips];
+ Slot slot5 = biped[BodyNode.LeftHand];
+ Slot slot6 = biped[BodyNode.RightHand];
+ Slot slot7 = biped[BodyNode.LeftFoot];
+ Slot slot8 = biped[BodyNode.RightFoot];
+ Slot slot9 = biped.TryGetBone(BodyNode.LeftToes);
+ Slot slot10 = biped.TryGetBone(BodyNode.RightToes);
ModelImporter.SetupDraggable(slot3, vrik.Solver, vrik.Solver.spine.IKPositionHead, vrik.Solver.spine.IKRotationHead, vrik.Solver.spine.PositionWeight);
ModelImporter.SetupDraggable(slot4, vrik.Solver, vrik.Solver.spine.IKPositionPelvis, vrik.Solver.spine.IKRotationPelvis, vrik.Solver.spine.PelvisPositionWeight);
ModelImporter.SetupDraggable(slot5, vrik.Solver, vrik.Solver.leftArm.IKPosition, vrik.Solver.leftArm.IKRotation, vrik.Solver.leftArm.PositionWeight);
diff --git a/UnityPackageImporter/Models/UnitySceneImportTask.cs b/UnityPackageImporter/Models/UnitySceneImportTask.cs
index 5d86c33..670c98e 100644
--- a/UnityPackageImporter/Models/UnitySceneImportTask.cs
+++ b/UnityPackageImporter/Models/UnitySceneImportTask.cs
@@ -1,7 +1,10 @@
-using FrooxEngine;
+using Elements.Core;
+using FrooxEngine;
+using SkyFrost.Base;
using System;
using System.CodeDom;
using System.Collections.Generic;
+using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
@@ -21,15 +24,19 @@ public class UnitySceneImportTask: IUnityStructureImporter
public Slot CurrentStructureRootSlot { get; set; }
public KeyValuePair ID { get; set; }
-
public Slot allimportsroot { get; set; }
+
+ private float3 GlobalIndicatorPosition;
+ public ProgressBarInterface progressIndicator { get; set; }
+
public UnityProjectImporter unityProjectImporter { get; set; }
- public UnitySceneImportTask(Slot allimportsroot, KeyValuePair ID, UnityProjectImporter unityProjectImporter)
+ public UnitySceneImportTask(float3 globalPosition, Slot root, KeyValuePair ID, UnityProjectImporter unityProjectImporter)
{
this.ID = ID;
this.unityProjectImporter = unityProjectImporter;
- this.allimportsroot = allimportsroot;
+ this.allimportsroot = root;
+ this.GlobalIndicatorPosition = globalPosition;
}
@@ -42,10 +49,16 @@ public async Task StartImport()
existingIUnityObjects = new Dictionary();
await default(ToWorld);
- this.CurrentStructureRootSlot = Engine.Current.WorldManager.FocusedWorld.AddSlot(Path.GetFileName(ID.Value));
- UnityPackageImporter.Msg("Current slot for scene import is: ");
- UnityPackageImporter.Msg(CurrentStructureRootSlot.ToString());
+ this.CurrentStructureRootSlot = unityProjectImporter.world.AddSlot(Path.GetFileName(ID.Value));
this.CurrentStructureRootSlot.SetParent(this.allimportsroot, false);
+ this.CurrentStructureRootSlot.GlobalPosition = new float3(0, 0, 0);
+ Slot indicator = this.unityProjectImporter.root.AddSlot("Unity Scene Import Indicator");
+ indicator.GlobalPosition = GlobalIndicatorPosition;
+ indicator.PersistentSelf = false;
+ this.progressIndicator = await indicator.SpawnEntity(FavoriteEntity.ProgressBar);
+ progressIndicator?.Initialize(false);
+
+ progressIndicator?.UpdateProgress(0f, "", "now loading unity YAML objects for Scene.");
await default(ToBackground);
@@ -67,39 +80,56 @@ public async Task StartImport()
this.existingIUnityObjects = YamlToFrooxEngine.parseYaml(this.ID.Value);
- UnityPackageImporter.Msg("Loaded " + existingIUnityObjects.Count.ToString() + " Unity prefabs/transforms/special_components for scene!");
+ int totalProgress = 0;
+
+ foreach (KeyValuePair obj in existingIUnityObjects)
+ {
+ Type type = obj.Value.GetType();
+ int progressitem = 4;
+
+ UnityEngineObjectWrapper.addedProgress.TryGetValue(type, out progressitem);
+ totalProgress += progressitem;
+
+ }
+
//instanciate everything else.
+ int counter = 0;
+ int progress = 0;
await default(ToWorld);
foreach (var obj in existingIUnityObjects)
{
+ counter++;
+ Type type = obj.Value.GetType();
+ int progressitem = 4;
+
+ UnityEngineObjectWrapper.addedProgress.TryGetValue(type, out progressitem);
+ progress += progressitem;
+ progressIndicator?.UpdateProgress( MathX.Clamp01((float)progress / (float)totalProgress), "", "now loading " + this.existingIUnityObjects.Count.ToString() + "/" + counter.ToString() + " objects for scene");
+ UnityPackageImporter.Msg("loading object for scene \"" + ID.Value + "\" with an id of \"" + obj.Value.id.ToString() + "\"");
try
{
- try
- {
- debugScene.Append(obj.Value.ToString());
- }
- catch (Exception e)
- {
- UnityPackageImporter.Warn("Scene object could not be turned into a string!");
- UnityPackageImporter.Msg("Scene object ID: \"" + obj.Value.id.ToString() + "\"");
- UnityPackageImporter.Warn(e.Message + e.StackTrace);
- }
- UnityPackageImporter.Msg("loading object for scene \"" + ID.Value + "\" with an id of \"" + obj.Value.id.ToString() + "\"");
- if (obj.Value.GetType() != typeof(FrooxEngineRepresentation.GameObjectTypes.PrefabInstance))
- {
- await obj.Value.instanciateAsync(this);
- }
-
-
+ await obj.Value.instanciateAsync(this);
+ }
+ catch (Exception e)
+ {
+ UnityPackageImporter.Warn("Scene IUnityObject failed to instanciate!");
+ UnityPackageImporter.Msg("Scene IUnityObject ID: \"" + obj.Value.id.ToString() + "\"");
+ UnityPackageImporter.Warn(e.Message + e.StackTrace);
+ }
+ try
+ {
+ debugScene.Append(obj.Value.ToString());
}
catch (Exception e)
{
- UnityPackageImporter.Warn("Scene object failed to instanciate!");
- UnityPackageImporter.Msg("Scene object ID: \"" + obj.Value.id.ToString() + "\"");
+ UnityPackageImporter.Warn("Scene IUnityObject could not be turned into a string!");
+ UnityPackageImporter.Msg("Scene IUnityObject ID: \"" + obj.Value.id.ToString() + "\"");
UnityPackageImporter.Warn(e.Message + e.StackTrace);
}
+
+
}
await default(ToBackground);
@@ -158,6 +188,8 @@ public async Task StartImport()
}
}
+
+ progressIndicator?.UpdateProgress(0f, "", "setting up IK for objects in scene");
UnityPackageImporter.Msg("Setting up IK for Prefabs in scene \"" + ID.Value + "\"");
await default(ToWorld);
foreach (var obj in existingIUnityObjects)
@@ -177,8 +209,9 @@ public async Task StartImport()
{
await default(ToWorld);
await UnityProjectImporter.SettupHumanoid(
- unityProjectImporter.SharedImportedFBXScenes[prefab.m_SourcePrefab.guid],
- prefab.ImportRoot.frooxEngineSlot);
+ prefab.importask,
+ prefab.ImportRoot.frooxEngineSlot,
+ false);
await default(ToBackground);
}
else
@@ -196,6 +229,14 @@ await UnityProjectImporter.SettupHumanoid(
}
}
await default(ToBackground);
+
+ progressIndicator?.ProgressDone("Finished Scene!");
+ progressIndicator?.UpdateProgress(1f,"","Finished!");
+
+
+ UnityPackageImporter.Msg("Yaml generation done");
+
+ UnityPackageImporter.Msg("Scene finished!");
}
catch (Exception e)
{
@@ -203,13 +244,11 @@ await UnityProjectImporter.SettupHumanoid(
UnityPackageImporter.Warn(e.Message + e.StackTrace);
UnityPackageImporter.Msg(debugScene.ToString());
FrooxEngineBootstrap.LogStream.Flush();
+ progressIndicator?.ProgressFail("Failed to decode the Unity Scene due to an error!");
throw e;
}
-
- UnityPackageImporter.Msg("Yaml generation done");
-
- UnityPackageImporter.Msg("Scene finished!");
+
}
}
diff --git a/UnityPackageImporter/UnityPackageImporter.cs b/UnityPackageImporter/UnityPackageImporter.cs
index eb15e89..b85d2fe 100644
--- a/UnityPackageImporter/UnityPackageImporter.cs
+++ b/UnityPackageImporter/UnityPackageImporter.cs
@@ -2,10 +2,12 @@
using Elements.Core;
using FrooxEngine;
using HarmonyLib;
+using Leap.Unity;
using ResoniteModLoader;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Security.Policy;
using System.Threading.Tasks;
using UnityPackageImporter.Extractor;
@@ -22,6 +24,7 @@ public class UnityPackageImporter : ResoniteMod
internal const string UNITY_PREFAB_EXTENSION = ".prefab";
internal const string UNITY_SCENE_EXTENSION = ".unity";
internal const string UNITY_META_EXTENSION = ".meta";
+ internal static readonly HashSet UNITY_PACKAGE_EXTENSIONS = new() { "unitypackage" }; //must not have a "." in the name anywhere!!- @989onan
internal static ModConfiguration Config;
internal static string cachePath = Path.Combine(
@@ -68,6 +71,7 @@ public override void OnEngineInit()
new Harmony("net.dfgHiatus.UnityPackageImporter").PatchAll();
Config = GetConfiguration();
Directory.CreateDirectory(cachePath);
+ Engine.Current.RunPostInit(AssetPatch); //patch unity packages in
}
public static string[] DecomposeUnityPackage(string file)
@@ -111,159 +115,168 @@ public static string[] DecomposeUnityPackage(string file)
return dirsToImport.ToArray();
}
- /*
- Maybe the importer could be made smarter to detect a Unity project with just the prefab's PC path as reference? Then use all of those files to find the dependencies I guess?
- Though, this is fine for now, since the package might have all the dependencies (sometimes)
- If the package doesn't, we just skip those files. Later, a unity project dependency finder should be implemented. So use a way to see the prefab is in a unity project and act from there.
- */
- [HarmonyPatch(typeof(UniversalImporter), "Import", typeof(AssetClass), typeof(IEnumerable),
- typeof(World), typeof(float3), typeof(floatQ), typeof(bool))]
- public partial class UniversalImporterPatch
+ //patch unity packages into file metadata stuff so we can use them
+ private static void AssetPatch()
{
-
-
-
- public static bool Prefix(ref IEnumerable files)
+ var aExt = Traverse.Create(typeof(AssetHelper)).Field>>("associatedExtensions");
+ foreach(string hash in UNITY_PACKAGE_EXTENSIONS)
{
+ aExt.Value[AssetClass.Model].Add(hash);
+ }
+
+ }
- List hasUnityPackage = new List();
- List notUnityPackage = new List();
-
+ private static async Task scanfiles(List hasUnityPackage, Slot slot, World world)
+ {
+ List imports = new List();
+ await default(ToBackground);
+ foreach (string unitypackage in hasUnityPackage)
+ {
+ List scanthesefiles = new List(DecomposeUnityPackage(unitypackage));
- Msg("Start import of unity packages.");
-
- foreach (var file in files)
+ Msg("CALLING FindPrefabsAndMetas");
+ List notprefabsandmetas = (await FindPrefabsAndMetas(scanthesefiles, slot, imports, world)).ToList();
+ if (Config.GetValue(dumpPackageContents))
{
- if (Path.GetExtension(file).ToLower() == UNITY_PACKAGE_EXTENSION)
- hasUnityPackage.Add(file);
+ if (Config.GetValue(ImportPrefab))
+ {
+ //get all files that don't have metas
+ BatchFolderImporter.BatchImport(slot, scanthesefiles.FindAll(i => !Path.GetExtension(i).ToLower().Equals(UNITY_META_EXTENSION)), Config.GetValue(importAsRawFiles));
+ }
else
- notUnityPackage.Add(file);
- }
- if(hasUnityPackage.Count > 0)
- {
- var slot = Engine.Current.WorldManager.FocusedWorld.AddSlot("Unity Package Import");
- slot.GlobalPosition = new float3(0, 0, 0); //we want scenes to position themselves at 0,0,0. There is an edge case where the thing this is parented under would be moving, but that's just a skill issue on the user's part. - @989onan
- slot.SetParent(Engine.Current.WorldManager.FocusedWorld.LocalUserSpace, true); //let user managers not freak out that we're doing stuff in root. - @989onan
- slot.StartGlobalTask(async () => await scanfiles(hasUnityPackage, slot));
-
+ {
+ //bring in no prefabs or metas
+ BatchFolderImporter.BatchImport(slot, notprefabsandmetas, Config.GetValue(importAsRawFiles));
+ }
}
- //once we have removed the prefabs, now we let the original stuff go through so we have the files normally
- //idk if we really need this if the stuff above is going to eventually just import prefabs and textures already set up... - @989onan
+ }
+ await default(ToWorld);
+ await Task.WhenAll(imports);
+ await default(ToBackground);
+ Msg("FINISHED ALL IMPORTS AND DONE WITH ALL TASKS!!");
+ }
-
- if (hasUnityPackage.Count <= 0) return true;
+ private static async Task> FindPrefabsAndMetas(IEnumerable files, Slot importSlotContainment, List imports, World world)
+ {
+ /*DebugMSG*/
+ Msg("Start Finding Prefabs and Metas");
+ //remove the meta files from the rest of the code later on in the return statements, since we don't want to let the importer bring in fifty bajillion meta files...
+ List ListOfNotMetasAndPrefabs = new List();
+ foreach (var file in files)
+ {
+ var ending = Path.GetExtension(file).ToLower();
+ if (!(ending.Equals(UNITY_PREFAB_EXTENSION) || ending.Equals(UNITY_META_EXTENSION) || ending.Equals(UNITY_SCENE_EXTENSION)))
+ {
+ ListOfNotMetasAndPrefabs.Add(file);
+ }
+ }
- var slotbatch = Engine.Current.WorldManager.FocusedWorld.AddSlot("Batch Import", false);
- slotbatch.PositionInFrontOfUser(null, null, 0.7f, null, false, false, true);
- slotbatch.SetParent(Engine.Current.WorldManager.FocusedWorld.LocalUserSpace, true); //let user managers not freak out that we're doing stuff in root.
- BatchFolderImporter.BatchImport(slotbatch, notUnityPackage, Config.GetValue(importAsRawFiles));
-
- return false;
- }
+ Dictionary AssetIDDict = new Dictionary();
+ Dictionary ListOfPrefabs = new Dictionary();
+ Dictionary ListOfMetas = new Dictionary();
+ Dictionary ListOfUnityScenes = new Dictionary();
+ //first we iterate over every file to find metas and prefabs
- private static async Task scanfiles(List hasUnityPackage, Slot slot)
+ //we make a dictionary that associates the GUID of unity files with their paths. The files given to us are in a cache, with the directories already structured properly and the names fixed.
+ // all we do is read the meta file and steal the GUID from there to get our identifiers in the Prefabs
+ foreach (var file in files)
{
+ //UnityPackageImporter.Msg("A file being imported is \""+file+"\"");
+ var ending = Path.GetExtension(file).ToLower();
-
- List imports = new List();
- await default(ToBackground);
- foreach(string unitypackage in hasUnityPackage)
+ switch (ending)
{
- List scanthesefiles = new List(DecomposeUnityPackage(unitypackage));
-
-
-
- Msg("CALLING FindPrefabsAndMetas");
- List notprefabsandmetas = (await FindPrefabsAndMetas(scanthesefiles, slot, imports)).ToList();
- if (Config.GetValue(dumpPackageContents))
- {
- if (Config.GetValue(ImportPrefab))
+ case UNITY_META_EXTENSION:
+ string filename = file.Substring(0, file.Length - Path.GetExtension(file).Length); //since every meta is filename + extension + ".meta" we can cut off the extension and have the original file name and path.
+ string fileGUID = File.ReadLines(file).ToArray()[1].Split(':')[1].Trim(); // the GUID is on the first line in the file (not 0th) after a colon and space, so trim it to get id.
+ AssetIDDict.Add(fileGUID, filename);
+ if (Path.GetExtension(filename).ToLower() == UNITY_PREFAB_EXTENSION)//if our meta coorisponds to a prefab
{
- //get all files that don't have metas
- BatchFolderImporter.BatchImport(slot, scanthesefiles.FindAll(i => !Path.GetExtension(i).ToLower().Equals(UNITY_META_EXTENSION)), Config.GetValue(importAsRawFiles));
+ ListOfPrefabs.Add(fileGUID, filename);
}
- else
+ if (Path.GetExtension(filename).ToLower() == UNITY_SCENE_EXTENSION)//if our meta coorisponds to a scene
{
- //bring in no prefabs or metas
- BatchFolderImporter.BatchImport(slot, notprefabsandmetas, Config.GetValue(importAsRawFiles));
+ ListOfUnityScenes.Add(fileGUID, filename);
}
- }
-
-
+ ListOfMetas.Add(fileGUID, file);
+ break;
}
+ }
+ Msg("Creating importer object");
+ if (Config.GetValue(ImportPrefab))
+ {
await default(ToWorld);
- await Task.WhenAll(imports);
+ imports.Add(new UnityProjectImporter(files, AssetIDDict, ListOfPrefabs, ListOfMetas, ListOfUnityScenes, importSlotContainment, world.AssetsSlot.AddSlot("UnityPackageImport - Assets"), world).startImports());
await default(ToBackground);
- Msg("FINISHED ALL IMPORTS AND DONE WITH ALL TASKS!!");
}
- private static async Task> FindPrefabsAndMetas(IEnumerable files, Slot importSlotContainment, List imports)
+
+ Msg("end Finding Prefabs and Metas");
+ return ListOfNotMetasAndPrefabs.ToArray();
+ }
+
+
+ [HarmonyPatch(typeof(UniversalImporter),
+ "ImportTask",
+ typeof(AssetClass),
+ typeof(IEnumerable),
+ typeof(World),
+ typeof(float3),
+ typeof(floatQ),
+ typeof(float3),
+ typeof(bool))]
+ public partial class UniversalImporterPatch
+ {
+ public static bool Prefix(ref IEnumerable files, ref World world)
{
- /*DebugMSG*/Msg("Start Finding Prefabs and Metas");
- //remove the meta files from the rest of the code later on in the return statements, since we don't want to let the importer bring in fifty bajillion meta files...
- List ListOfNotMetasAndPrefabs = new List();
+
+ List hasUnityPackage = new List();
+ List notUnityPackage = new List();
+
+ Msg("Run UnityPackageImporter patch.");
foreach (var file in files)
{
- var ending = Path.GetExtension(file).ToLower();
- if (!(ending.Equals(UNITY_PREFAB_EXTENSION) || ending.Equals(UNITY_META_EXTENSION) || ending.Equals(UNITY_SCENE_EXTENSION)))
- {
- ListOfNotMetasAndPrefabs.Add(file);
- }
+ if (Path.GetExtension(file).ToLower() == UNITY_PACKAGE_EXTENSION)
+ hasUnityPackage.Add(file);
+ else
+ notUnityPackage.Add(file);
}
-
- Dictionary AssetIDDict = new Dictionary();
- Dictionary ListOfPrefabs = new Dictionary();
- Dictionary ListOfMetas = new Dictionary();
- Dictionary ListOfUnityScenes = new Dictionary();
- //first we iterate over every file to find metas and prefabs
-
- //we make a dictionary that associates the GUID of unity files with their paths. The files given to us are in a cache, with the directories already structured properly and the names fixed.
- // all we do is read the meta file and steal the GUID from there to get our identifiers in the Prefabs
- foreach (var file in files)
+ World curworld = world.RootSlot.World;
+ if (hasUnityPackage.Count > 0)
{
- //UnityPackageImporter.Msg("A file being imported is \""+file+"\"");
- var ending = Path.GetExtension(file).ToLower();
+ Msg("Start import of unity packages.");
+ var slot = world.AddSlot("Unity Package Import");
+ slot.GlobalPosition = new float3(0, 0, 0); //we want scenes to position themselves at 0,0,0. There is an edge case where the thing this is parented under would be moving, but that's just a skill issue on the user's part. - @989onan
+ slot.SetParent(world.LocalUserSpace, true); //let user managers not freak out that we're doing stuff in root. - @989onan
+ slot.StartGlobalTask(async () => await scanfiles(hasUnityPackage, slot, curworld));
- switch (ending)
- {
- case UNITY_META_EXTENSION:
- string filename = file.Substring(0, file.Length - Path.GetExtension(file).Length); //since every meta is filename + extension + ".meta" we can cut off the extension and have the original file name and path.
- string fileGUID = File.ReadLines(file).ToArray()[1].Split(':')[1].Trim(); // the GUID is on the first line in the file (not 0th) after a colon and space, so trim it to get id.
- AssetIDDict.Add(fileGUID, filename);
- if (Path.GetExtension(filename).ToLower() == UNITY_PREFAB_EXTENSION)//if our meta coorisponds to a prefab
- {
- ListOfPrefabs.Add(fileGUID, filename);
- }
- if (Path.GetExtension(filename).ToLower() == UNITY_SCENE_EXTENSION)//if our meta coorisponds to a scene
- {
- ListOfUnityScenes.Add(fileGUID, filename);
- }
- ListOfMetas.Add(fileGUID, file);
- break;
- }
}
- Msg("Creating importer object");
+
+
+ //once we have removed the prefabs, now we let the original stuff go through so we have the files normally
+ //idk if we really need this if the stuff above is going to eventually just import prefabs and textures already set up... - @989onan
+
+
+ files = notUnityPackage;
- if (Config.GetValue(ImportPrefab))
+ if(notUnityPackage.Count > 0)
{
- await default(ToWorld);
- imports.Add(new UnityProjectImporter(files, AssetIDDict, ListOfPrefabs, ListOfMetas, ListOfUnityScenes, importSlotContainment, Engine.Current.WorldManager.FocusedWorld.AssetsSlot.AddSlot("UnityPackageImport - Assets")).startImports());
- await default(ToBackground);
+ return true;
+ }
+ else{
+ return false; //we have only unity packages, so don't run the rest and make some random model import dialogue
}
-
- Msg("end Finding Prefabs and Metas");
- return ListOfNotMetasAndPrefabs.ToArray();
}
}
diff --git a/UnityPackageImporter/UnityPackageImporter.csproj b/UnityPackageImporter/UnityPackageImporter.csproj
index 9a04efc..6695d51 100644
--- a/UnityPackageImporter/UnityPackageImporter.csproj
+++ b/UnityPackageImporter/UnityPackageImporter.csproj
@@ -86,12 +86,13 @@
-
+
+
@@ -108,6 +109,7 @@
+
diff --git a/UnityPackageImporter/UnityPackageImporterDialogue.cs b/UnityPackageImporter/UnityPackageImporterDialogue.cs
new file mode 100644
index 0000000..59dbc29
--- /dev/null
+++ b/UnityPackageImporter/UnityPackageImporterDialogue.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace UnityPackageImporter
+{
+ internal class UnityPackageImporterDialogue
+ {
+ }
+}