specklesystems / speckle-unity

AEC Interoperability for Unity through Speckle
https://speckle.systems/tag/unity/
Apache License 2.0
55 stars 20 forks source link

Editor updates #25

Closed haitheredavid closed 3 years ago

haitheredavid commented 3 years ago

Fixes to loading basic meshes into editor scene

JR-Morgan commented 3 years ago

Hi @haitheredavid, Just checking out this PR.

Looks like I'm getting a null reference exception on this line while trying to receive during edit mode.

NullReferenceException: Object reference not set to an instance of an object

NullReferenceException: Object reference not set to an instance of an object
Objects.Converter.Unity.ConverterUnity.MeshToNative (Objects.Geometry.Mesh speckleMesh, Objects.Other.RenderMaterial renderMaterial, System.Collections.Generic.Dictionary`2[TKey,TValue] properties) (at Assets/Speckle Connector/ConverterUnity.Geometry.cs:311)
Objects.Converter.Unity.ConverterUnity.MeshToNative (Speckle.Core.Models.Base speckleMeshObject) (at Assets/Speckle Connector/ConverterUnity.Geometry.cs:235)
Objects.Converter.Unity.ConverterUnity.ConvertToNative (Speckle.Core.Models.Base object) (at Assets/Speckle Connector/ConverterUnity.cs:69)
Speckle.ConnectorUnity.RecursiveConverter.TryConvertItemToNative (System.Object value) (at Assets/Speckle Connector/RecursiveConverter.cs:124)
Rethrow as SpeckleException: Object reference not set to an instance of an object
Speckle.ConnectorUnity.RecursiveConverter.TryConvertItemToNative (System.Object value) (at Assets/Speckle Connector/RecursiveConverter.cs:138)
Speckle.ConnectorUnity.RecursiveConverter.RecurseTreeToNative (System.Object object) (at Assets/Speckle Connector/RecursiveConverter.cs:80)
Speckle.ConnectorUnity.RecursiveConverter.b__2_0 (System.Object x) (at Assets/Speckle Connector/RecursiveConverter.cs:72)
System.Linq.Enumerable+SelectListIterator`2[TSource,TResult].MoveNext () (at <351e49e2a5bf4fd6beabb458ce2255f3>:0)
System.Linq.Enumerable+WhereEnumerableIterator`1[TSource].ToList () (at <351e49e2a5bf4fd6beabb458ce2255f3>:0)
System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable`1[T] source) (at <351e49e2a5bf4fd6beabb458ce2255f3>:0)
Speckle.ConnectorUnity.RecursiveConverter.RecurseTreeToNative (System.Object object) (at Assets/Speckle Connector/RecursiveConverter.cs:72)
Speckle.ConnectorUnity.RecursiveConverter.ConvertRecursivelyToNative (Speckle.Core.Models.Base base, System.String name) (at Assets/Speckle Connector/RecursiveConverter.cs:51)
Speckle.ConnectorUnity.StreamManager.ConvertRecursivelyToNative (Speckle.Core.Models.Base base, System.String id) (at Assets/Speckle Connector/StreamManager.cs:39)
Speckle.ConnectorUnity.StreamManagerEditor+d__43.MoveNext () (at Assets/Speckle Connector/Editor/StreamManagerEditor.cs:151)
Rethrow as SpeckleException: Object reference not set to an instance of an object
Speckle.ConnectorUnity.StreamManagerEditor+d__43.MoveNext () (at Assets/Speckle Connector/Editor/StreamManagerEditor.cs:156)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0)
Speckle.ConnectorUnity.StreamManagerEditor+d__44.MoveNext () (at Assets/Speckle Connector/Editor/StreamManagerEditor.cs:272)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__6_0 (System.Object state) (at <695d1cc93cca45069c528c15c9fdd749>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <127e81e1cb3441cc97d26b1910daae77>:0)
UnityEngine.UnitySynchronizationContext:ExecuteTasks()

It looks like speckleMesh.bbox is null for objects on the stream I'm trying to receive (https://speckle.xyz/streams/59185c5b8a)

haitheredavid commented 3 years ago

@JR-Morgan oh interesting...I'm not entirely sure about Base objects coming in from Revit into unity. Currently the unity connector has a limited set of Base types it can convert properly from. Here is quick hack I added the PR to avoid that issue

JR-Morgan commented 3 years ago

Looks great to me, this PR closes #24

teocomi commented 3 years ago

Thanks both! @haitheredavid @JR-Morgan