Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rhino): adds names to all objects on bake #327

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ CancellationToken cancellationToken
onOperationProgressed.Report(new("Converting objects", (double)++count / atomicObjects.Count));
try
{
// 0: get the name of the incoming obj if any
string? name = obj["name"] as string;

// 1: get pre-created layer from cache in layer baker
int layerIndex = _layerBaker.GetAndCreateLayerFromPath(path, baseLayerName);

Expand All @@ -139,7 +142,7 @@ CancellationToken cancellationToken
var conversionIds = new List<string>();
if (result is GeometryBase geometryBase)
{
var guid = BakeObject(geometryBase, obj, layerIndex);
var guid = BakeObject(geometryBase, obj, layerIndex, name);
conversionIds.Add(guid.ToString());
}
else if (result is List<GeometryBase> geometryBases) // one to many raw encoding case
Expand All @@ -150,13 +153,13 @@ 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, layerIndex);
var guid = BakeObject(gb, obj, layerIndex, name);
conversionIds.Add(guid.ToString());
}
}
else if (result is IEnumerable<(object, Base)> fallbackConversionResult) // one to many fallback conversion
{
var guids = BakeObjectsAsGroup(fallbackConversionResult, obj, layerIndex, baseLayerName);
var guids = BakeObjectsAsGroup(fallbackConversionResult, obj, layerIndex, baseLayerName, name);
conversionIds.AddRange(guids.Select(id => id.ToString()));
}

Expand Down Expand Up @@ -253,7 +256,7 @@ private void PreReceiveDeepClean(string baseLayerName)
_groupBaker.PurgeGroups(baseLayerName);
}

private Guid BakeObject(GeometryBase obj, Base originalObject, int layerIndex)
private Guid BakeObject(GeometryBase obj, Base originalObject, int layerIndex, string? name = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we already have originalObject in relevant functions, I wouldn't pollute function arguments. You need to do it only in BakeObjects function and thats it

Copy link
Member Author

@clairekuang clairekuang Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't do it there, since originalObject could be a Base in a display value of an element that used fallback conversion for example. We need to do it in both the group converter and the bake then.

{
ObjectAttributes atts = new() { LayerIndex = layerIndex };
var objectId = originalObject.applicationId ?? originalObject.id;
Expand All @@ -270,14 +273,20 @@ private Guid BakeObject(GeometryBase obj, Base originalObject, int layerIndex)
atts.ColorSource = color.Item2;
}

if (name is not null)
{
atts.Name = name;
}

return _converterSettings.Current.Document.Objects.Add(obj, atts);
}

private List<Guid> BakeObjectsAsGroup(
IEnumerable<(object, Base)> fallbackConversionResult,
Base originatingObject,
int layerIndex,
string baseLayerName
string baseLayerName,
string? name = null
)
{
List<Guid> objectIds = new();
Expand All @@ -289,7 +298,7 @@ string baseLayerName
continue;
}

var id = BakeObject(geometryBase, originalBaseObject, layerIndex);
var id = BakeObject(geometryBase, originalBaseObject, layerIndex, name);
objectIds.Add(id);
}

Expand All @@ -298,6 +307,7 @@ string baseLayerName
objectIds
);
var group = _converterSettings.Current.Document.Groups.FindIndex(groupIndex);

objectIds.Insert(0, group.Id);
return objectIds;
}
Expand Down
Loading