algorithmic modeling for Rhino
Hi,
 I am not able to find the source of this failure. What happens is that I give a preview color to a mesh in a custom component, and it looks the default color of gh (red/green when selected) under the given color. Or if there are no color, the default red is like duplicated (have less transparency).
 It seems that are being displayed the mesh twice, first with default colors and then with personalized color, but I do not understand why. I would bet that this is a silly mistake but...
What I want do is let the preview by default when the user does not give any color, and give custom color when the color parameter is not empty.
Something strange is that this error does not happen from a script component.
 This is the code involved, the parameters _col and _mesh are filled in the solve instance.
Private _mesh As Mesh = Nothing
 Private _col As Drawing.Color = Nothing
Public Overrides Sub DrawViewPortMeshes(args As IGH_PreviewArgs)
   MyBase.DrawViewportMeshes(args)
  If (Hidden) Then Return
   If (Locked) Then Return
   Dim mat As New Rhino.Display.DisplayMaterial()
   If (_col = Nothing) Or (_col = Drawing.Color.Empty) Then
     If (Attributes.Selected) Then
       mat = args.ShadeMaterial_Selected
     Else
       mat = args.ShadeMaterial
     End If
   Else
     Dim t As Double = (Convert.ToDouble(_col.A) / 255) * (-1) + 1
     mat = New Rhino.Display.DisplayMaterial(_col, t)
     mat.Shine = 0.3
     mat.Emission = Drawing.Color.Black
     mat.Specular = Drawing.Color.White
   End If
   args.Display.DrawMeshShaded(_mesh, mat)
 End Sub
Public Overrides Sub DrawViewportWires(args As IGH_PreviewArgs)
   MyBase.DrawViewportWires(args)
  If (Hidden) Then Return
   If (Locked) Then Return
   Dim color As New System.Drawing.Color()
   If (_col = Nothing) Or (_col = Drawing.Color.Empty) Then
     If (Grasshopper.CentralSettings.PreviewMeshEdges) Then
       If (Attributes.Selected) Then
         color = args.WireColour_Selected
       Else
         color = args.WireColour
       End If
       args.Display.DrawMeshWires(_mesh, color)
     End If
   Else
     If (Grasshopper.CentralSettings.PreviewMeshEdges) Then
       If (MyBase.Attributes.Selected) Then
         color = Drawing.Color.FromArgb(255, 255, 0)
       Else
         color = _col
       End If
       args.Display.DrawMeshWires(_mesh, color)
     End If
   End If
 End Sub
Public Overrides ReadOnly Property ClippingBox As BoundingBox
   Get
     Dim box As BoundingBox = MyBase.ClippingBox
     If (_mesh IsNot Nothing) AndAlso (_mesh.IsValid) Then
       box.Union(_mesh.GetBoundingBox(True))
     End If
   Return box
   End Get
 End Property
Protected Overrides Sub BeforeSolveInstance()
   MyBase.ClearData()
   _mesh = Nothing
   _col = Nothing
 End Sub
Does anyone see what I'm doing wrong?
I hope I explained well, feel free to ask.
Thanks!
Tags:
Resolved.
MyBase.DrawViewportMeshes(args) was calling the preview with the defaults values.
Removing this line the problem is corrected.
It seems that args.Display.DrawMeshShaded(_mesh, mat) also calls the preview.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
    © 2025               Created by Scott Davidson.             
    Powered by
    