Skip to content

Commit

Permalink
Merge pull request #420 from specklesystems/dimitrie/cnx-391-assignin…
Browse files Browse the repository at this point in the history
…g-material-doesnt-trigger-object-tracking-in-rhino

Dimitrie/cnx 391 assigning material doesnt trigger object tracking in rhino
  • Loading branch information
didimitrie authored Nov 28, 2024
2 parents 0be8897 + 0ae1ec0 commit eea6924
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -141,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(() =>
{
Expand All @@ -152,7 +163,12 @@ private void SubscribeToRhinoEvents()
// }

// NOTE: not sure yet we want to track every attribute changes yet. TBD
if (e.OldAttributes.LayerIndex != e.NewAttributes.LayerIndex)
// 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
|| 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);
Expand Down

0 comments on commit eea6924

Please sign in to comment.