From 467db204a85c46b56b1a6b92ce16c018b91137f9 Mon Sep 17 00:00:00 2001 From: Dimitrie Stefanescu Date: Thu, 28 Nov 2024 18:57:39 +0000 Subject: [PATCH 1/2] wip: adds event handlers for material changes --- .../Bindings/RhinoSendBinding.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Bindings/RhinoSendBinding.cs b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Bindings/RhinoSendBinding.cs index 1d4e454b8..113d7040c 100644 --- a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Bindings/RhinoSendBinding.cs +++ b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Bindings/RhinoSendBinding.cs @@ -96,6 +96,16 @@ private void SubscribeToRhinoEvents() } }; + RhinoDoc.RenderMaterialsTableEvent += (sender, args) => + { + var test = args; + if (args is RhinoDoc.RenderMaterialAssignmentChangedEventArgs changedEventArgs) + { + ChangedObjectIds[changedEventArgs.ObjectId.ToString()] = 1; + _idleManager.SubscribeToIdle(nameof(RhinoSendBinding), RunExpirationChecks); + } + }; + RhinoDoc.ActiveDocumentChanged += (_, e) => { PreviousUnitSystem = e.Document.ModelUnitSystem; @@ -152,7 +162,11 @@ private void SubscribeToRhinoEvents() // } // NOTE: not sure yet we want to track every attribute changes yet. TBD - if (e.OldAttributes.LayerIndex != e.NewAttributes.LayerIndex) + if ( + e.OldAttributes.LayerIndex != e.NewAttributes.LayerIndex + || e.OldAttributes.MaterialSource != e.NewAttributes.MaterialSource + || e.OldAttributes.MaterialIndex != e.NewAttributes.MaterialIndex // NOTE: this does not work when swapping around from custom doc materials, it works when you swap TO/FROM default material + ) { ChangedObjectIds[e.RhinoObject.Id.ToString()] = 1; _idleManager.SubscribeToIdle(nameof(RhinoSendBinding), RunExpirationChecks); From ace52876ac5846e7cfe3a4765aaaec8537466763 Mon Sep 17 00:00:00 2001 From: Dimitrie Stefanescu Date: Thu, 28 Nov 2024 19:07:14 +0000 Subject: [PATCH 2/2] feat: wraps up fix --- .../Bindings/RhinoSendBinding.cs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Bindings/RhinoSendBinding.cs b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Bindings/RhinoSendBinding.cs index 113d7040c..2e6c263c5 100644 --- a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Bindings/RhinoSendBinding.cs +++ b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Bindings/RhinoSendBinding.cs @@ -96,16 +96,6 @@ private void SubscribeToRhinoEvents() } }; - RhinoDoc.RenderMaterialsTableEvent += (sender, args) => - { - var test = args; - if (args is RhinoDoc.RenderMaterialAssignmentChangedEventArgs changedEventArgs) - { - ChangedObjectIds[changedEventArgs.ObjectId.ToString()] = 1; - _idleManager.SubscribeToIdle(nameof(RhinoSendBinding), RunExpirationChecks); - } - }; - RhinoDoc.ActiveDocumentChanged += (_, e) => { PreviousUnitSystem = e.Document.ModelUnitSystem; @@ -151,6 +141,17 @@ private void SubscribeToRhinoEvents() _idleManager.SubscribeToIdle(nameof(RhinoSendBinding), RunExpirationChecks); }); + // NOTE: Catches an object's material change from one user defined doc material to another. Does not catch (as the top event is not triggered) swapping material sources for an object or moving to/from the default material (this is handled below)! + RhinoDoc.RenderMaterialsTableEvent += (_, args) => + _topLevelExceptionHandler.CatchUnhandled(() => + { + if (args is RhinoDoc.RenderMaterialAssignmentChangedEventArgs changedEventArgs) + { + ChangedObjectIds[changedEventArgs.ObjectId.ToString()] = 1; + _idleManager.SubscribeToIdle(nameof(RhinoSendBinding), RunExpirationChecks); + } + }); + RhinoDoc.ModifyObjectAttributes += (_, e) => _topLevelExceptionHandler.CatchUnhandled(() => { @@ -162,6 +163,7 @@ private void SubscribeToRhinoEvents() // } // NOTE: not sure yet we want to track every attribute changes yet. TBD + // NOTE: we might want to track here user strings too (once we send them out), and more! if ( e.OldAttributes.LayerIndex != e.NewAttributes.LayerIndex || e.OldAttributes.MaterialSource != e.NewAttributes.MaterialSource