MeshOutline and Polysurfaces in RhinoScript


#1

Hi,
MeshOutline in Rhino, takes surfaces, Polysurfaces as well as Meshes.
While Coding, Rhino.MeshOutline ,however, seems to be friendly with meshes only.
I would rather not to convert polysurfaces to mesh in order to apply Rhino.MeshOutline on them.
Any Ideas?
This is an Example:

Call Main()
Sub Main()

    Dim strPol,strExt
    strPol = Rhino.AddPolygon(Rhino.WorldXYPlane, 10, 5)
    strExt = Rhino.ExtrudeCurveStraight(strPol, array(0, 0, 10))
    Rhino.CapPlanarHoles strExt
    Rhino.MeshOutline strExt

End Sub

#2

Hi @Clive,

you might script the _MeshOutline command:

Option Explicit
    
Call Main()
Sub Main()

    Dim strPol, strExt, blnResult, arrOutline
    
    strPol = Rhino.AddPolygon(Rhino.WorldXYPlane, 10, 5)
    strExt = Rhino.ExtrudeCurveStraight(strPol, Array(0, 0, 10))
    Rhino.CapPlanarHoles strExt

    Rhino.SelectObject strExt
    blnResult = Rhino.Command("_MeshOutline", vbFalse)
    If blnResult Then
        arrOutLine = Rhino.LastCreatedObjects(vbFalse)
    End If

End Sub

In case of a single outline result the outline is the first object in the resulting array:

strOutline = arrOutline(0)

c.


#3

@clement
Thanks a lot,
I would also like to know if we could control where the outline is formed.
I mean how far or close to the viewpoint,


#4

@Clive, you could control this by scaling the outlines using the camera location as scale origin. To get closer to the camera, scale with values smaller than 1.0 eg:

Option Explicit
    
Call Main()
Sub Main()

    Dim strPol, strExt, blnResult, arrOutline
        Dim strView, arrCamera, arrScale
    
        strPol = Rhino.AddPolygon(Rhino.WorldXYPlane, 10, 5)
        strExt = Rhino.ExtrudeCurveStraight(strPol, Array(0, 0, 10))
        Rhino.CapPlanarHoles strExt

        Rhino.SelectObject strExt
        blnResult = Rhino.Command("_MeshOutline", vbFalse)
        If blnResult Then
            arrOutLine = Rhino.LastCreatedObjects(vbFalse)
            strView = Rhino.CurrentView()
            arrCamera = Rhino.ViewCamera(strView)
            arrScale = Array(0.5, 0.5, 0.5)
            Rhino.ScaleObjects arrOutline, arrCamera, arrScale, vbFalse
        End If

End Sub

Note that this works in perspective views only.

c.


#5

@clement
Thanks
I have already tried that method.
What I mean is:

  1. to define a camera,
  2. To set CPlane to View
  3. Rhino.Command("_MeshOutline", vbFalse)
    Since there is not always a fixed distance between camera and its corresponding Cplane, I wanted to code it in a way so that the meshoutline always gets projected on the Cplane regardless of the arrScale.

The outlines formed in this image took the following scale factors:
arrScale = Array (.5,.5,.5)
arrScale = Array (1,1,1)
arrScale = Array (2,2,2)
arrScale = Array (4,4,4)
I initially assumed that the arrScale = Array (1,1,1) would project the outline on the Cplane.


(Dale Fugier) #6

Hi Clive,

RhinoScript’s MeshOutline method creates polyline curve outlines of mesh objects (only).

– Dale


#7

@Clive, a scale of 1 will not scale at all. I think that a projection would result in a deviation from the original outline judging from the view, as the projecton does not factor the perspective distorsion.

But you could try to compute which scale from the camera position is required to end in a pre-defined CPlane, eg. intersect an infinite line from the camera position to the camera target with your desired CPlane to get a point. Then scale from one of the meshoutline points to the resulting point (the camera position is the origin of the scale).

c.


#8

@clement
Got it,
Thanks


#9

@Dale,
Yep,
Thanks


#10

The Issue is still confusing to me guys,
There should be a procedure that provides the exact location where the MeshOutline forms.
If you randomly applied MeshOutline over a Polysurface, from different angles,
the results would scatter in the space, randomly closer or farther away from the viewpoint.
How Come?


#11

I think it is just created in a plane perpendicular to the camera and target in the current view with no respect to the distance from the camera. It just respects that the plane is parallel to the screen plane.

To create it in a predefined plane, you can provide one in a script and use my suggestion above to either scale the resulting outlines (this ensures that the results remains to end in a plane parallel to the screenplane) or “project” the points of the mesh outlines in any other plane by intersecting rays. The example below does this, it just uses the current views CPlane and then removes the old meshoutline.

Clive_MeshOutlineToCPlane.rvb (1.3 KB)

I am not sure if this is what you want though :wink:

c.


#12

@clement

Absolutely,
Prior to your code, I managed another method:

  1. Scale the Outline beyond the desired CPlane, with the camera position as the origin of the scale.
    2.Extrude the result back to the camera point.
    3.The Intersection between the extrusion and the CPlane provides the result.
    This is simulating the behavior of light and embodying the shadows.
    By the way your code helped a lot,
    Thanks :slight_smile: