Skip to content

Commit

Permalink
Merge pull request #111 from specklesystems/dev
Browse files Browse the repository at this point in the history
* 2.18 Update

* fixed bug with selection not correctly restoring after deserializing

* Bump core to 2.18.0-rc

* FE2 terms (#112)

* FE2 terms

* SendComponent

* Removed terminology switching

* Bumped core version (#113)
  • Loading branch information
JR-Morgan authored Mar 14, 2024
2 parents edeec70 + 790e5d8 commit 5359731
Show file tree
Hide file tree
Showing 28 changed files with 1,176 additions and 736 deletions.
2 changes: 1 addition & 1 deletion Assets/Extra/AttachSpecklePropertiesExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class AttachSpecklePropertiesExample : MonoBehaviour

public virtual void Start()
{
Client speckleClient = new(AccountManager.GetDefaultAccount());
Client speckleClient = new(AccountManager.GetDefaultAccount()!);

StartCoroutine(AttachSpeckleProperties(speckleClient, streamId, objectId));
}
Expand Down
50 changes: 23 additions & 27 deletions Assets/Extra/ManualReceive.cs
Original file line number Diff line number Diff line change
@@ -1,71 +1,67 @@
using System;
using System.Collections;
using System.Threading.Tasks;
using Speckle.ConnectorUnity;
using Speckle.ConnectorUnity.Components;
using Speckle.Core.Api;
using Speckle.Core.Credentials;
using Speckle.Core.Models;
using Speckle.Core.Transports;
using UnityEngine;

[AddComponentMenu("Speckle/Extras/Manual Receiver")]
[RequireComponent(typeof(RecursiveConverter))]
public class ManualReceive : MonoBehaviour
{

public string authToken;
public string serverUrl;
public string streamId, objectId;

private RecursiveConverter receiver;
public string streamId,
objectId;

private RecursiveConverter receiver;

void Awake()
{
receiver = GetComponent<RecursiveConverter>();
}


IEnumerator Start()
{
Debug.developerConsoleVisible = true;
if(Time.timeSinceLevelLoad > 20) yield return null;
if (Time.timeSinceLevelLoad > 20)
yield return null;
Receive();
}

[ContextMenu(nameof(Receive))]
public void Receive()
{
var account = new Account()
{
token = authToken,
serverInfo = new ServerInfo() {url = serverUrl},
serverInfo = new ServerInfo() { url = serverUrl },
};

Task.Run(async () =>
{
var transport = new ServerTransport(account, streamId);
var localTransport = new MemoryTransport();
var @base = await Operations.Receive(
using ServerTransport transport = new(account, streamId);
MemoryTransport localTransport = new();
Base speckleObject = await Operations.Receive(
objectId,
remoteTransport: transport,
localTransport: localTransport,
onErrorAction: (m, e) => Debug.LogError(m + e),
disposeTransports: true
localTransport: localTransport
);
if (@base == null) throw new Exception("received data was null!");
Dispatcher.Instance().Enqueue(() =>
{
var parentObject = new GameObject(name);
receiver.RecursivelyConvertToNative_Sync(@base, parentObject.transform);
Debug.Log($"Receive {objectId} completed");
});
Dispatcher
.Instance()
.Enqueue(() =>
{
var parentObject = new GameObject(name);
receiver.RecursivelyConvertToNative_Sync(speckleObject, parentObject.transform);
Debug.Log($"Receive {objectId} completed");
});
});
}
}

39 changes: 22 additions & 17 deletions Assets/Extra/PerformanceTestSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Speckle.ConnectorUnity.Components;
using Speckle.Core.Api;
using Speckle.Core.Credentials;
using Speckle.Core.Models;
using Speckle.Core.Transports;
using UnityEngine;
Expand All @@ -18,24 +19,25 @@ public sealed class PerformanceTestSender : MonoBehaviour
{
[Range(0, 100)]
public int numberOfIterations = 10;

public Vector3 translation = Vector3.forward * 100;

public GameObject objectToSend;

private SpeckleSender sender;

private void Awake()
{
sender = GetComponent<SpeckleSender>();
}

public async Task SendIterations()
{
GameObject go = new GameObject();
for (int i = 0; i < numberOfIterations; i++)
{
Instantiate(objectToSend, translation * i, Quaternion.identity, go.transform);

Base b = sender.Converter.RecursivelyConvertToSpeckle(go, _ => true);
await Send(b, $"{i}");
}
Expand All @@ -44,20 +46,23 @@ public async Task SendIterations()

private async Task<string> Send(Base data, string branchName)
{
var client = sender.Account.Client;
var stream = sender.Stream.Selected;
ServerTransport transport = new ServerTransport(sender.Account.Selected, stream!.id);

await client.BranchCreate(new BranchCreateInput(){streamId = stream.id, name = branchName});

return await SpeckleSender.SendDataAsync(CancellationToken.None,
Client client = sender.Account.Client!;
Stream stream = sender.Stream.Selected;
Account selectedAccount = sender.Account.Selected!;

using ServerTransport transport = new(selectedAccount, stream!.id);

string branchId = await client.BranchCreate(
new BranchCreateInput() { streamId = stream.id, name = branchName }
);

return await SpeckleSender.SendDataAsync(
remoteTransport: transport,
data: data,
client: client!,
branchName: branchName,
createCommit: true,
onProgressAction: null,
onErrorAction: (m, e) => throw e);
data,
client,
branchId,
true
);
}
}

Expand All @@ -68,7 +73,7 @@ public sealed class PerformanceTestSenderEditor : UnityEditor.Editor
public override async void OnInspectorGUI()
{
DrawDefaultInspector();

if (GUILayout.Button("Create and send"))
{
await ((PerformanceTestSender)target).SendIterations();
Expand Down
1 change: 0 additions & 1 deletion Assets/SpeckleExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using UnityEngine;
using Speckle.Core.Credentials;
using System.Linq;
using UnityEngine.Events;
using UnityEngine.UI;
using Stream = Speckle.Core.Api.Stream;

Expand Down
4 changes: 2 additions & 2 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"dependencies": {
"com.unity.2d.sprite": "1.0.0",
"com.unity.collab-proxy": "2.0.5",
"com.unity.collab-proxy": "2.0.7",
"com.unity.ide.rider": "3.0.24",
"com.unity.ide.visualstudio": "2.0.18",
"com.unity.ide.vscode": "1.2.5",
"com.unity.test-framework": "1.1.33",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.6.5",
"com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.2",
"com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.4",
"com.unity.ugui": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
Expand Down
8 changes: 4 additions & 4 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {}
},
"com.unity.collab-proxy": {
"version": "2.0.5",
"version": "2.0.7",
"depth": 0,
"source": "registry",
"dependencies": {},
Expand Down Expand Up @@ -94,12 +94,12 @@
"url": "https://packages.unity.com"
},
"com.unity.toolchain.win-x86_64-linux-x86_64": {
"version": "2.0.2",
"version": "2.0.4",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.sysroot": "2.0.3",
"com.unity.sysroot.linux-x86_64": "2.0.2"
"com.unity.sysroot": "2.0.5",
"com.unity.sysroot.linux-x86_64": "2.0.4"
},
"url": "https://packages.unity.com"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#nullable enable
using System;
using System.Collections.Concurrent;
using System.Threading.Tasks;
Expand All @@ -13,6 +12,12 @@ namespace Speckle.ConnectorUnity.Components.Editor
[CustomEditor(typeof(SpeckleReceiver))]
public class SpeckleReceiverEditor : UnityEditor.Editor
{
private SerializedProperty _accountSelection;
private SerializedProperty _streamSelection;
private SerializedProperty _branchSelection;
private SerializedProperty _commitSelection;

#nullable enable
private static bool _generateAssets;
private bool _foldOutStatus = true;
private Texture2D? _previewImage;
Expand All @@ -21,7 +26,11 @@ public override async void OnInspectorGUI()
{
var speckleReceiver = (SpeckleReceiver)target;

DrawDefaultInspector();
//Selection
EditorGUILayout.PropertyField(_accountSelection);
EditorGUILayout.PropertyField(_streamSelection, new GUIContent("Project"));
EditorGUILayout.PropertyField(_branchSelection, new GUIContent("Model"));
EditorGUILayout.PropertyField(_commitSelection, new GUIContent("Version"));

//Preview image
{
Expand Down Expand Up @@ -64,8 +73,8 @@ public override async void OnInspectorGUI()
else if (userRequestedReceive)
{
var id = Progress.Start(
"Receiving Speckle data",
"Fetching commit data",
"Receiving Speckle Model",
"Fetching data from Speckle",
Progress.Options.Sticky
);
Progress.ShowDetails();
Expand Down Expand Up @@ -96,6 +105,19 @@ public override async void OnInspectorGUI()
public void OnEnable()
{
Init();

_accountSelection = serializedObject.FindProperty(
$"<{nameof(SpeckleReceiver.Account)}>k__BackingField"
);
_streamSelection = serializedObject.FindProperty(
$"<{nameof(SpeckleReceiver.Stream)}>k__BackingField"
);
_branchSelection = serializedObject.FindProperty(
$"<{nameof(SpeckleReceiver.Branch)}>k__BackingField"
);
_commitSelection = serializedObject.FindProperty(
$"<{nameof(SpeckleReceiver.Commit)}>k__BackingField"
);
}

public void Reset()
Expand Down Expand Up @@ -163,7 +185,7 @@ private async Task ReceiveSelection(int progressId)

bool BeforeConvert(TraversalContext context)
{
Base b = context.current;
Base b = context.Current;

//NOTE: progress wont reach 100% because not all objects are convertable
float progress = (childrenConverted + childrenFailed) / totalChildrenFloat;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
Expand All @@ -9,7 +10,6 @@
using UnityEngine.SceneManagement;
using Component = UnityEngine.Component;

#nullable enable
namespace Speckle.ConnectorUnity.Components.Editor
{
public enum SelectionFilter
Expand All @@ -35,12 +35,32 @@ public enum SelectionFilter
[CanEditMultipleObjects]
public class SpeckleSendEditor : UnityEditor.Editor
{
private SerializedProperty _accountSelection;
private SerializedProperty _streamSelection;
private SerializedProperty _branchSelection;

#nullable enable
private SelectionFilter _selectedFilter = SelectionFilter.Children;

public void OnEnable()
{
_accountSelection = serializedObject.FindProperty(
$"<{nameof(SpeckleSender.Account)}>k__BackingField"
);
_streamSelection = serializedObject.FindProperty(
$"<{nameof(SpeckleSender.Stream)}>k__BackingField"
);
_branchSelection = serializedObject.FindProperty(
$"<{nameof(SpeckleSender.Branch)}>k__BackingField"
);
}

public override async void OnInspectorGUI()
{
//Draw events in a collapsed region
DrawDefaultInspector();
//Selection
EditorGUILayout.PropertyField(_accountSelection);
EditorGUILayout.PropertyField(_streamSelection, new GUIContent("Project"));
EditorGUILayout.PropertyField(_branchSelection, new GUIContent("Model"));

bool shouldSend = GUILayout.Button("Send!");
_selectedFilter = (SelectionFilter)
Expand Down Expand Up @@ -77,10 +97,9 @@ public override async void OnInspectorGUI()
),
};

//TODO onError action?
if (data["@objects"] is IList l && l.Count == 0)
{
Debug.LogWarning($"Nothing to send", speckleSender);
Debug.LogWarning("Nothing to send", speckleSender);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public StreamSelectionDrawer()

details = new (string, Func<Stream, string>)[]
{
("Stream id", s => s.id),
("Project id", s => s.id),
("Description", s => s.description),
("Is Public", s => s.isPublic.ToString()),
("Role", s => s.role),
Expand Down Expand Up @@ -88,7 +88,7 @@ public CommitSelectionDrawer()
{
details = new (string, Func<Commit, string>)[]
{
("Commit Id", s => s.id),
("Version Id", s => s.id),
("Author Name", s => s.authorName),
("Created At", s => s.createdAt.ToString(CultureInfo.InvariantCulture)),
("Source Application", s => s.sourceApplication),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void Send(

cancellationTokenSource = new CancellationTokenSource();

var client = new Client(account ?? AccountManager.GetDefaultAccount());
var client = new Client(account ?? AccountManager.GetDefaultAccount()!);
transport = new ServerTransport(client.Account, streamId);
transport.CancellationToken = cancellationTokenSource.Token;

Expand Down
Loading

0 comments on commit 5359731

Please sign in to comment.