Skip to content

Commit

Permalink
receive colors with fallback conversions (#408)
Browse files Browse the repository at this point in the history
* receive colors with fallback conversions

* don't pass Base unnecessarily

* material fix

* only pass applicationId

* note for the new variable

* typo

* typo2

* typo3

---------

Co-authored-by: Claire Kuang <[email protected]>
Co-authored-by: Oğuzhan Koral <[email protected]>
  • Loading branch information
3 people authored Nov 27, 2024
1 parent 3ad4d46 commit 0ccefea
Showing 1 changed file with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ CancellationToken cancellationToken
var conversionIds = new List<string>();
if (result is GeometryBase geometryBase)
{
var guid = BakeObject(geometryBase, obj, atts);
var guid = BakeObject(geometryBase, obj, null, atts);
conversionIds.Add(guid.ToString());
}
else if (result is List<GeometryBase> geometryBases) // one to many raw encoding case
Expand All @@ -156,7 +156,7 @@ CancellationToken cancellationToken
// EXTRA EXTRA NOTE: TY Ogu, i am no longer than unhappy about it. It's legit "mess".
foreach (var gb in geometryBases)
{
var guid = BakeObject(gb, obj, atts);
var guid = BakeObject(gb, obj, null, atts);
conversionIds.Add(guid.ToString());
}
}
Expand Down Expand Up @@ -267,13 +267,14 @@ private void PreReceiveDeepClean(string baseLayerName)
/// </summary>
/// <param name="obj"></param>
/// <param name="originalObject"></param>
/// <param name="parentObjectId">Parent object ID for color and material proxies search (if fallback conversion was used)</param>
/// <param name="atts"></param>
/// <returns></returns>
/// <remarks>
/// Material and Color attributes are processed here due to those properties existing sometimes on fallback geometry (instead of parent).
/// and this method is called by <see cref="BakeObjectsAsFallbackGroup(IEnumerable{ValueTuple{object, Base}}, Base, ObjectAttributes, string)"/>
/// </remarks>
private Guid BakeObject(GeometryBase obj, Base originalObject, ObjectAttributes atts)
private Guid BakeObject(GeometryBase obj, Base originalObject, string? parentObjectId, ObjectAttributes atts)
{
var objectId = originalObject.applicationId ?? originalObject.id;

Expand All @@ -282,12 +283,28 @@ private Guid BakeObject(GeometryBase obj, Base originalObject, ObjectAttributes
atts.MaterialIndex = mIndex;
atts.MaterialSource = ObjectMaterialSource.MaterialFromObject;
}
else if (
parentObjectId is not null
&& (_materialBaker.ObjectIdAndMaterialIndexMap.TryGetValue(parentObjectId, out int mIndexSpeckleObj))
)
{
atts.MaterialIndex = mIndexSpeckleObj;
atts.MaterialSource = ObjectMaterialSource.MaterialFromObject;
}

if (_colorBaker.ObjectColorsIdMap.TryGetValue(objectId, out (Color, ObjectColorSource) color))
{
atts.ObjectColor = color.Item1;
atts.ColorSource = color.Item2;
}
else if (
parentObjectId is not null
&& (_colorBaker.ObjectColorsIdMap.TryGetValue(parentObjectId, out (Color, ObjectColorSource) colorSpeckleObj))
)
{
atts.ObjectColor = colorSpeckleObj.Item1;
atts.ColorSource = colorSpeckleObj.Item2;
}

return _converterSettings.Current.Document.Objects.Add(obj, atts);
}
Expand All @@ -300,6 +317,8 @@ string baseLayerName
)
{
List<Guid> objectIds = new();
string parentId = originatingObject.applicationId ?? originatingObject.id;

foreach (var (conversionResult, originalBaseObject) in fallbackConversionResult)
{
if (conversionResult is not GeometryBase geometryBase)
Expand All @@ -308,12 +327,12 @@ string baseLayerName
continue;
}

var id = BakeObject(geometryBase, originalBaseObject, atts);
var id = BakeObject(geometryBase, originalBaseObject, parentId, atts);
objectIds.Add(id);
}

var groupIndex = _converterSettings.Current.Document.Groups.Add(
$@"{originatingObject.speckle_type.Split('.').Last()} - {originatingObject.applicationId ?? originatingObject.id} ({baseLayerName})",
$@"{originatingObject.speckle_type.Split('.').Last()} - {parentId} ({baseLayerName})",
objectIds
);

Expand Down

0 comments on commit 0ccefea

Please sign in to comment.