algorithmic modeling for Rhino
Hi,
I'm playing with GH and I was trying to do a simple control to move GeometryBase 10mm. Not so complex! :D But nothing is displayed. BUT if I get the result and I do a transformation, the result of this transformation works. Do you have any idea?
Protected Overrides Sub SolveInstance(ByVal DA As Grasshopper.Kernel.IGH_DataAccess)
Dim GeometryIn As New List(Of GeometryBase)
Dim GeometryOut As New List(Of GeometryBase)
If (Not DA.GetDataList(0, GeometryIn)) Then Return
If (GeometryIn.Count = 0) Then Return
MoveObjects(GeometryIn.ToArray, GeometryOut)
DA.SetDataList(0, GeometryOut)
End Sub
Public Function MoveGeom(ByVal GeomIn As Rhino.Geometry.GeometryBase(), ByRef GeomOut As List(Of Rhino.Geometry.GeometryBase)) As Boolean
GeomOut = New List(Of Rhino.Geometry.GeometryBase)
For i As Integer = 0 To GeomIn.Length - 1
If GeomIn(i) Is Nothing Then Continue For
Dim pGeom As GeometryBase = GeomIn(i).Duplicate
Dim xForm As Transform = Transform.Translation(New Vector3d(10, 0, 0))
pGeom.Transform(xForm)
GeomOut.Add(pGeom)
Next
Return True
End Function
Thanks
Rafa
Tags:
Ok guys, is there an error when you run this component? I.e. does it turn red and have a little balloon on the top right corner?
I can replicate this problem on some types of geometry, others just fail to work entirely. I'll dig a little deeper, but I think it's safe to say you should use IGH_GeometricGoo, not GeometryBase, and Transform is to be preferred to Translate until I figure this out.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
I found the problem, it's to do with me trying to convert GeometyBase back into Grasshopper data types. Instead of creating GH_Curves I create a GH_GeometricGooWrapper, which is only supposed to be used as a last ditch attempt at maintaining data.
Once I fix the conversion you should be able to use GeometryBase again, even though I still recommend you use IGH_GeometricGoo.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Ok fixed. If you provide a type of geometry that can be represented as GeometryBase then it will work now. However, there are geometry types in Grasshopper that cannot be represented by a GeometryBase class, at least not without significant refactoring. Circles and Lines for example need to be converted to real curves. Boxes will need to be converted to Breps (a very expensive operation) and Planes cannot be converted at all.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
This function works for me with either Transform or Translate:
Public Function MoveGeom( _
ByVal geo As IEnumerable(Of GeometryBase), _
ByVal motion As Vector3d) As List(Of GeometryBase)
Dim rc As New List(Of GeometryBase)
Dim xform As Transform = Transform.Translation(motion)
For Each g As GeometryBase In geo
If (g Is Nothing) Then Continue For
g = g.Duplicate()
g.Translate(motion) 'Translation
'g.Transform(xform) 'Transformation
rc.Add(g)
Next
Return rc
End Function
I tried Boxes, Lines and Circles. What sort of geometry are you translating?
Finally, if you're doing this inside a GH_Component, I recommend you use IGH_GeometricGoo instead of GeometryBase. This is what the SolveInstance function of the Move component looks like (C# and only a single object, but it should convey the general gist):
IGH_GeometricGoo geo = null;
Vector3d vec = Vector3d.Unset;
if (!DA.GetData(0, ref geo)) { return; }
if (!DA.GetData(1, ref vec)) { return; }
if (!vec.IsValid) { return; }
if (vec.IsZero)
{
DA.SetData(0, geo);
}
else
{
IGH_GeometricGoo copy = geo.DuplicateGeometry();
copy = copy.Transform(Transform.Translation(vec));
DA.SetData(0, copy);
}
The Transform function on IGH_GeometricGoo works differently from GeometryBase, it will return an instance of IGH_GeometricGoo which is either the same object or a new object. For example, imagine you're scaling a Circle non-uniformly. This should turn it into an ellipse. But a circle cannot represent an ellipse. So when a GH_Circle decides that the transformation will result in another circle, it transforms itself and returns itself. If however the circle decides it has to become an ellipse, it will create a new GH_Curve with a circular nurbs-curve inside of it, then transform that curve and return it instead. This is why you need to say "copy = copy.Transform()"
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Yes It works for me too! Thanks for your great help
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2025 Created by Scott Davidson.
Powered by