Conversion Bug fixes and category parenting
This commit is contained in:
+4
-99303
File diff suppressed because one or more lines are too long
@@ -8,6 +8,7 @@
|
||||
"com.unity.test-framework": "1.1.30",
|
||||
"com.unity.textmeshpro": "3.0.6",
|
||||
"com.unity.timeline": "1.4.8",
|
||||
"com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.2",
|
||||
"com.unity.ugui": "1.0.0",
|
||||
"com.unity.modules.ai": "1.0.0",
|
||||
"com.unity.modules.androidjni": "1.0.0",
|
||||
|
||||
@@ -64,6 +64,22 @@
|
||||
},
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.sysroot": {
|
||||
"version": "2.0.3",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {},
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.sysroot.linux-x86_64": {
|
||||
"version": "2.0.2",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.sysroot": "2.0.3"
|
||||
},
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.test-framework": {
|
||||
"version": "1.1.30",
|
||||
"depth": 0,
|
||||
@@ -96,6 +112,16 @@
|
||||
},
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.toolchain.win-x86_64-linux-x86_64": {
|
||||
"version": "2.0.2",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.sysroot": "2.0.3",
|
||||
"com.unity.sysroot.linux-x86_64": "2.0.2"
|
||||
},
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ugui": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
|
||||
@@ -69,7 +69,13 @@ namespace Objects.Converter.Unity
|
||||
switch (component)
|
||||
{
|
||||
case MeshFilter meshFilter:
|
||||
speckleObject["@displayValue"] = MeshToSpeckle(meshFilter);
|
||||
var displayValues = MeshToSpeckle(meshFilter);
|
||||
|
||||
if(speckleObject.GetInstanceMembersNames().Any(name => name == "displayValue"))
|
||||
speckleObject["displayValue"] = displayValues;
|
||||
else
|
||||
speckleObject["@displayValue"] = displayValues;
|
||||
|
||||
break;
|
||||
// case Camera camera:
|
||||
// speckleObject["cameraComponent"] = CameraToSpeckle(camera);
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace Speckle.ConnectorUnity.Editor
|
||||
|
||||
if (r == null)
|
||||
{
|
||||
EditorGUILayout.TextField(propName, item == null? "NULL" : item.ToString());
|
||||
EditorGUILayout.TextField(i.ToString(), item == null? "NULL" : item.ToString());
|
||||
continue;
|
||||
}
|
||||
//Update list item
|
||||
|
||||
@@ -7,6 +7,7 @@ using Speckle.Core.Api;
|
||||
using Speckle.Core.Credentials;
|
||||
using Speckle.Core.Kits;
|
||||
using Speckle.Core.Logging;
|
||||
using Speckle.Core.Models;
|
||||
using Speckle.Core.Transports;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
@@ -154,52 +155,57 @@ namespace Speckle.ConnectorUnity.Editor
|
||||
|
||||
private async Task Receive()
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("Receiving data...", "", 0);
|
||||
var transport = new ServerTransport(SelectedAccount, SelectedStream.id);
|
||||
EditorUtility.DisplayProgressBar($"Receiving data from {transport.BaseUri}...", "", 0);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var transport = new ServerTransport(SelectedAccount, SelectedStream.id);
|
||||
// Receive Speckle Objects
|
||||
var @base = await Operations.Receive(
|
||||
Branches[SelectedBranchIndex].commits.items[SelectedCommitIndex].referencedObject,
|
||||
remoteTransport: transport,
|
||||
onProgressAction: dict =>
|
||||
Branches[SelectedBranchIndex].commits.items[SelectedCommitIndex].referencedObject,
|
||||
remoteTransport: transport,
|
||||
onProgressAction: dict =>
|
||||
{
|
||||
UnityEditor.EditorApplication.delayCall += () =>
|
||||
{
|
||||
UnityEditor.EditorApplication.delayCall += () =>
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("Receiving data...", "",
|
||||
Convert.ToSingle(dict.Values.Average() / _totalChildrenCount));
|
||||
};
|
||||
},
|
||||
onTotalChildrenCountKnown: count => { _totalChildrenCount = count; }
|
||||
EditorUtility.DisplayProgressBar($"Receiving data from {transport.BaseUri}...", "",
|
||||
Convert.ToSingle(dict.Values.Average() / _totalChildrenCount));
|
||||
};
|
||||
},
|
||||
onTotalChildrenCountKnown: count => { _totalChildrenCount = count; }
|
||||
);
|
||||
|
||||
EditorUtility.ClearProgressBar();
|
||||
|
||||
//Convert Speckle Objects
|
||||
int childrenConverted = 0;
|
||||
void BeforeConvertCallback(Base b)
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("Converting To Native...", $"{b.speckle_type} - {b.id}",
|
||||
Convert.ToSingle(childrenConverted++ / _totalChildrenCount));
|
||||
}
|
||||
|
||||
var go = _streamManager.ConvertRecursivelyToNative(@base,
|
||||
Branches[SelectedBranchIndex].commits.items[SelectedCommitIndex].id);
|
||||
Branches[SelectedBranchIndex].commits.items[SelectedCommitIndex].id, BeforeConvertCallback);
|
||||
|
||||
try
|
||||
// Read Receipt
|
||||
await Client.CommitReceived(new CommitReceivedInput
|
||||
{
|
||||
await Client.CommitReceived(new CommitReceivedInput
|
||||
{
|
||||
streamId = SelectedStream.id,
|
||||
commitId = Branches[SelectedBranchIndex].commits.items[SelectedCommitIndex].id,
|
||||
message = $"received commit from {VersionedHostApplications.Unity} Editor",
|
||||
sourceApplication = VersionedHostApplications.Unity
|
||||
});
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Do nothing!
|
||||
}
|
||||
|
||||
streamId = SelectedStream.id,
|
||||
commitId = Branches[SelectedBranchIndex].commits.items[SelectedCommitIndex].id,
|
||||
message = $"received commit from {VersionedHostApplications.Unity} Editor",
|
||||
sourceApplication = VersionedHostApplications.Unity
|
||||
});
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UnityEditor.EditorApplication.delayCall += () => { EditorUtility.ClearProgressBar(); };
|
||||
throw new SpeckleException(e.Message, e, true, SentryLevel.Error);
|
||||
}
|
||||
|
||||
UnityEditor.EditorApplication.delayCall += () => { EditorUtility.ClearProgressBar(); };
|
||||
finally
|
||||
{
|
||||
EditorApplication.delayCall += EditorUtility.ClearProgressBar;
|
||||
}
|
||||
}
|
||||
|
||||
public override async void OnInspectorGUI()
|
||||
|
||||
@@ -15,20 +15,20 @@ namespace Speckle.ConnectorUnity
|
||||
/// Given <paramref name="baseObject"/>,
|
||||
/// will recursively convert any objects in the tree
|
||||
/// </summary>
|
||||
/// <param name="baseObject">The Speckle object to convert + its children</param>
|
||||
/// <param name="o">The object to convert (<see cref="Base"/> or <see cref="List{T}"/> of)</param>
|
||||
/// <param name="parent">Optional parent transform for the created root <see cref="GameObject"/>s</param>
|
||||
/// <returns> A list of all created <see cref="GameObject"/>s</returns>
|
||||
public virtual List<GameObject> RecursivelyConvertToNative(Base baseObject, Transform? parent)
|
||||
=> RecursivelyConvertToNative(baseObject, parent, o => ConverterInstance.CanConvertToNative(o));
|
||||
public virtual List<GameObject> RecursivelyConvertToNative(object? o, Transform? parent)
|
||||
=> RecursivelyConvertToNative(o, parent, o => ConverterInstance.CanConvertToNative(o));
|
||||
|
||||
/// <inheritdoc cref="RecursivelyConvertToNative(Base, Transform)"/>
|
||||
/// <inheritdoc cref="RecursivelyConvertToNative(object, Transform)"/>
|
||||
/// <param name="predicate">A function to determine if an object should be converted</param>
|
||||
public virtual List<GameObject> RecursivelyConvertToNative(Base baseObject, Transform? parent, Func<Base, bool> predicate)
|
||||
public virtual List<GameObject> RecursivelyConvertToNative(object? o, Transform? parent, Func<Base, bool> predicate)
|
||||
{
|
||||
LoadMaterialOverrides();
|
||||
|
||||
var createdGameObjects = new List<GameObject>();
|
||||
RecurseTreeToNative(baseObject, parent, predicate, createdGameObjects);
|
||||
ConvertChild(o, parent, predicate, createdGameObjects);
|
||||
//TODO track event
|
||||
|
||||
return createdGameObjects;
|
||||
@@ -76,8 +76,9 @@ namespace Speckle.ConnectorUnity
|
||||
|
||||
// For geometry, only traverse `elements` prop, otherwise, try and convert everything
|
||||
IEnumerable<string> potentialChildren;
|
||||
if (ConverterInstance.CanConvertToNative(baseObject)) potentialChildren = new []{"elements"};
|
||||
else potentialChildren = baseObject.GetMemberNames();
|
||||
potentialChildren = ConverterInstance.CanConvertToNative(baseObject)
|
||||
? new []{"elements"}
|
||||
: baseObject.GetMemberNames();
|
||||
|
||||
// Convert Children
|
||||
foreach (string propertyName in potentialChildren)
|
||||
@@ -124,7 +125,7 @@ namespace Speckle.ConnectorUnity
|
||||
//using the ApplicationPlaceholderObject to pass materials
|
||||
//available in Assets/Materials to the converters
|
||||
var materials = Resources.LoadAll("", typeof(Material)).Cast<Material>().ToArray();
|
||||
if (materials.Length == 0) Debug.Log("To automatically assign materials to received meshes, materials have to be in the \'Assets/Resources\' folder!");
|
||||
//if (materials.Length == 0) Debug.Log("To automatically assign materials to received meshes, materials have to be in the \'Assets/Resources\' folder!");
|
||||
var placeholderObjects = materials.Select(x => new ApplicationPlaceholderObject { NativeObject = x }).ToList();
|
||||
ConverterInstance.SetContextObjects(placeholderObjects);
|
||||
}
|
||||
|
||||
@@ -49,19 +49,19 @@ namespace Speckle.ConnectorUnity
|
||||
return RecursivelyConvertToSpeckle(new[] {rootObject}, predicate);
|
||||
}
|
||||
|
||||
public virtual void RecurseTreeToSpeckle(GameObject rootObject, Func<GameObject, bool> predicate, List<Base> outConverted)
|
||||
public virtual void RecurseTreeToSpeckle(GameObject currentObject, Func<GameObject, bool> predicate, List<Base> outConverted)
|
||||
{
|
||||
// Convert children first
|
||||
var convertedChildren = new List<Base>(rootObject.transform.childCount);
|
||||
foreach(Transform child in rootObject.transform)
|
||||
var convertedChildren = new List<Base>(currentObject.transform.childCount);
|
||||
foreach(Transform child in currentObject.transform)
|
||||
{
|
||||
RecurseTreeToSpeckle(child.gameObject, predicate, convertedChildren);
|
||||
}
|
||||
|
||||
if (ConverterInstance.CanConvertToSpeckle(rootObject) && predicate(rootObject))
|
||||
if (ConverterInstance.CanConvertToSpeckle(currentObject) && predicate(currentObject))
|
||||
{
|
||||
// Convert and output
|
||||
Base converted = ConverterInstance.ConvertToSpeckle(rootObject);
|
||||
Base converted = ConverterInstance.ConvertToSpeckle(currentObject);
|
||||
converted["@elements"] = convertedChildren;
|
||||
outConverted.Add(converted);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,6 @@ using System;
|
||||
using Speckle.Core.Api;
|
||||
using Speckle.Core.Credentials;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Objects.Other;
|
||||
using Objects.Utils;
|
||||
using Speckle.Core.Models;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -32,21 +29,44 @@ namespace Speckle.ConnectorUnity
|
||||
#if UNITY_EDITOR
|
||||
public static bool GenerateMaterials = false;
|
||||
#endif
|
||||
public List<GameObject> ConvertRecursivelyToNative(Base @base, string name)
|
||||
|
||||
#nullable enable
|
||||
public GameObject ConvertRecursivelyToNative(Base @base, string rootObjectName, Action<Base>? beforeConvertCallback)
|
||||
{
|
||||
|
||||
var rc = GetComponent<RecursiveConverter>();
|
||||
if (rc == null)
|
||||
rc = gameObject.AddComponent<RecursiveConverter>();
|
||||
|
||||
var rootObject = new GameObject(name);
|
||||
|
||||
Func<Base, bool> predicate = o =>
|
||||
rc.ConverterInstance.CanConvertToNative(o) //Accept geometry
|
||||
|| o.speckle_type == "Base" && o.totalChildrenCount > 0; // Or Base objects that have children
|
||||
var rootObject = new GameObject(rootObjectName);
|
||||
|
||||
bool Predicate(Base o)
|
||||
{
|
||||
beforeConvertCallback?.Invoke(o);
|
||||
return rc.ConverterInstance.CanConvertToNative(o) //Accept geometry
|
||||
|| o.speckle_type == "Base" && o.totalChildrenCount > 0; // Or Base objects that have children
|
||||
}
|
||||
|
||||
|
||||
return rc.RecursivelyConvertToNative(@base, rootObject.transform, predicate);
|
||||
// For the rootObject only, we will create property GameObjects
|
||||
// i.e. revit categories
|
||||
foreach (var prop in @base.GetMembers())
|
||||
{
|
||||
var converted = rc.RecursivelyConvertToNative(prop.Value, null, Predicate);
|
||||
|
||||
//Skip empties
|
||||
if(converted.Count <= 0) continue;
|
||||
|
||||
var propertyObject = new GameObject(prop.Key);
|
||||
propertyObject.transform.SetParent(rootObject.transform);
|
||||
foreach (var o in converted)
|
||||
{
|
||||
if(o.transform.parent == null) o.transform.SetParent(propertyObject.transform);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return rootObject;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
Reference in New Issue
Block a user