Skip to content

Commit bd53b9b

Browse files
committed
slight optimization to not retrieve material twice when color is inherited from material
1 parent a4e4775 commit bd53b9b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Connectors/Rhino/Speckle.Connectors.GrasshopperShared/Parameters/Wrappers/SpeckleGeometryWrapperGoo.ModelObjects.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ private bool HandleModelObject(ModelObject modelObject)
4646
// get layer, props, color, and mat
4747
SpeckleCollectionWrapper? collection = GetLayerCollectionFromModelObject(modelObject);
4848
SpecklePropertyGroupGoo? props = GetPropsFromModelObjectAndAssignToBase(modelObject, converted);
49-
Color? color = GetColorFromModelObject(modelObject);
5049
SpeckleMaterialWrapper? material = GetMaterialFromModelObject(modelObject);
50+
Color? color = GetColorFromModelObject(modelObject, material);
5151

5252
// get the definition if this is an instance
5353
SpeckleBlockDefinitionWrapper? definition = GetBlockDefinition(geometryBase);
@@ -270,7 +270,7 @@ private SpecklePropertyGroupGoo GetPropsFromModelObjectAndAssignToBase(ModelObje
270270
return null;
271271
}
272272

273-
private Color? GetColorFromModelObject(ModelObject modelObject)
273+
private Color? GetColorFromModelObject(ModelObject modelObject, SpeckleMaterialWrapper? material)
274274
{
275275
// we need to retrieve the actual color by the color source (otherwise will return default color for anything other than by object)
276276
int? argb = null;
@@ -283,8 +283,10 @@ private SpecklePropertyGroupGoo GetPropsFromModelObjectAndAssignToBase(ModelObje
283283
argb = modelObject.Display.Color?.Color.ToArgb();
284284
break;
285285
case ObjectColorSource.ColorFromMaterial:
286-
Rhino.Render.RenderMaterial? mat = GetRenderMaterial(modelObject);
287-
argb = mat?.ToMaterial(Rhino.Render.RenderTexture.TextureGeneration.Skip)?.DiffuseColor.ToArgb();
286+
if (material is not null)
287+
{
288+
argb = material.Material.diffuse;
289+
}
288290
break;
289291
default:
290292
break;

0 commit comments

Comments
 (0)