Skip to content

Commit

Permalink
refactor(rhino): removes DirectShapeToNative conversion (#3042)
Browse files Browse the repository at this point in the history
* uses basegeometries instead of displayvalue for ds rhino receive

* removes directshape conversion
  • Loading branch information
clairekuang authored Nov 14, 2023
1 parent d9c9594 commit e780b2d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,16 @@ private void BakeObject(
var attributes = new ObjectAttributes();

// handle display style
if (obj[@"displayStyle"] is Base display)
Base display = obj["displayStyle"] as Base ?? obj["@displayStyle"] as Base;
Base render = obj["renderMaterial"] as Base ?? obj["@renderMaterial"] as Base;
if (display != null)
{
if (converter.ConvertToNative(display) is ObjectAttributes displayAttribute)
{
attributes = displayAttribute;
}
}
else if (obj[@"renderMaterial"] is Base renderMaterial)
else if (render != null)
{
attributes.ColorSource = ObjectColorSource.ColorFromMaterial;
}
Expand Down Expand Up @@ -527,23 +531,28 @@ private void BakeObject(
}

if (parent != null)
{
parent.Update(id.ToString());
}
else
{
appObj.Update(id.ToString());
}

bakedCount++;

// handle render material
if (obj[@"renderMaterial"] is Base render)
if (render != null)
{
var convertedMaterial = converter.ConvertToNative(render); //Maybe wrap in try catch in case no conversion exists?
if (convertedMaterial is RenderMaterial rm)
var convertedMaterial = converter.ConvertToNative(render) as RenderMaterial; //Maybe wrap in try catch in case no conversion exists?
if (convertedMaterial != null)
{
var rhinoObject = Doc.Objects.FindId(id);
rhinoObject.RenderMaterial = rm;
RhinoObject rhinoObject = Doc.Objects.FindId(id);
rhinoObject.RenderMaterial = convertedMaterial;
rhinoObject.CommitChanges();
}
}

break;

case RhinoObject o: // this was prbly a block instance, baked during conversion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,37 +151,6 @@ private RhinoViewport SetViewParams(RhinoViewport viewport, Base speckleView)
return viewport;
}

// direct shape
public List<object> DirectShapeToNative(RV.DirectShape directShape, out List<string> log)
{
log = new List<string>();
if (directShape.displayValue == null)
{
log.Add($"Skipping DirectShape {directShape.id} because it has no {nameof(directShape.displayValue)}");
return null;
}

if (directShape.displayValue.Count == 0)
{
log.Add($"Skipping DirectShape {directShape.id} because {nameof(directShape.displayValue)} was empty");
return null;
}

IEnumerable<object> subObjects = directShape.displayValue.Select(ConvertToNative).Where(e => e != null);

var nativeObjects = subObjects.ToList();

if (nativeObjects.Count == 0)
{
log.Add(
$"Skipping DirectShape {directShape.id} because {nameof(directShape.displayValue)} contained no convertable elements"
);
return null;
}

return nativeObjects;
}

// level
public ApplicationObject LevelToNative(Level level)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,6 @@ public object ConvertToNative(Base @object)
rhinoObj = CurveToNative(o.baseCurve);
break;

case DirectShape o:
rhinoObj = DirectShapeToNative(o, out notes);
break;

case View3D o:
rhinoObj = ViewToNative(o);
break;
Expand Down Expand Up @@ -675,7 +671,6 @@ public bool CanConvertToNative(Base @object)
// This types are not supported in GH!
case Pointcloud _:
case ModelCurve _:
case DirectShape _:
case View3D _:
case Instance _:
case GridLine _:
Expand Down
2 changes: 1 addition & 1 deletion Objects/Objects/BuiltElements/Revit/DirectShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public DirectShape(string name, string builtInCategory, List<Base> baseGeometrie
public string elementId { get; set; }

[DetachProperty]
public List<Base> baseGeometries { get; set; }
public List<Base> baseGeometries { get; set; } = new();

public string units { get; set; }

Expand Down

0 comments on commit e780b2d

Please sign in to comment.