Grasshopper

algorithmic modeling for Rhino

Hi there,

I'm struggling with this problem for a while now, so I thought i'd see whether someone could help me. What I'm trying to do is set the preview colours of a list of breps through the following method:

 

public override void DrawViewportMeshes(IGH_PreviewArgs args)

{         

for (int i = 0; i /font> this.m_ViewPortBreps.Count; i++)

{

Rhino.Display.DisplayMaterial mat = new Rhino.Display.DisplayMaterial(Color.FromArgb(255 - this.m_RGBNrs[i], this.m_RGBNrs[i], this.m_RGBNrs[i]), 0.9);

 

args.Display.DrawBrepShaded(this.m_ViewPortBreps[i], mat);

 

base.DrawViewportMeshes(args);

}

}

Where the m_ViewPortBreps contains the breps for colouring and the m_RGBNrs contains the associated specific colour nr.

Somehow this doesn't work, the method gets called several times, and the colours do not change.

I would be very grateful if somebody could help me out.

 

Thanks, Joost

 

Views: 2429

Replies to This Discussion

Hi Joost,

the code seems to be right. I've done the same a lot of times...check your values in the m_RGBNrs Array/List!

 

Here you can see an example:

 private void RunScript(List<Brep> x, ref object A)
{
breps = x;
color = new List<int>();
for(int i = 0; i < x.Count; i++){
color.Add(i * (255 / x.Count));
}
}

//<Custom additional code>
List<Brep> breps;
List<int> color;

//Draw all meshes in this method.
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
for(int i = 0; i < breps.Count; i++){
args.Display.DrawBrepShaded(breps[i], new Rhino.Display.DisplayMaterial(System.Drawing.Color.FromArgb(color[i], 0, 0)));
}
}
Attachments:

Thanks Florian,

I would expect the code to work as well but somehow all the breps turn dark red. I've checked the m_RGBNrs and they hold different numbers for the different breps.

The thing which I can't explain is that the DrawViewportMeshes method gets called several times, this might be the reason that the it mixes up the colors. I've attached the component.


Joost

Attachments:

Ok so this its displaying the same color cause it's called for every brep...

do you have set the input of your Breps to List Access, as i is in my example?

The input should be of Type "List<Brep>" and NOT "Brep"...

If it doesn't work, you should try this:

if (runCount == 0){
...
}


If you're working on a Custom Component to be compiled use DA.Iteration instead of "runCount".

Thanks Florian,

I've used this runCount == 0 statement to clear the rgb and brep lists, is that what you're hinting at?

I've come a bit closer to the problem, but still haven't resolved it. It seems that the breps are coloured according to the specified rgb's, but these colors are somehow mixed with the standard red preview colour, so differences between breps become almost unnoticeable...

Any ideas?

Yes...runCount is important if your Script gets executed several times within one change of data (supplied Brep list).

Hm so your specified colors are all close to red? Did you use a DisplayMaterial with opacity or without? If the opacity is really low the preview color from GH might overlay your custom preview.

Do you output the same Breps from the script component? So in this case you have to turn the preview for the specified output off.

...see the code in the attached definition.

(It's an example from David that i translated to C#)

If this doesn't work, can you send any example, so i can take a look at it?

Attachments:

Yes, you're right, the breps are output in the same component. I made the mistake of setting the opacity to 0.9, which made the colour difference very hard to notice. I've adjusted that to 0.5. However still the standard red color blends with the set colours. If I understood you correctly there is a way of turning that of while remaining the set colours.

Could you sent me the code which enables me to do that? I couldn't read the code from the .gh file you attached.

Thanks for your help so far!

if (runCount == 0)

{

IGH_Component component = (IGH_Component) owner;

IGH_Param param = component.Params.Output[2]; //2 is the index of the Output to hide

IGH_PreviewObject prvObject = param as IGH_PreviewObject;

if ((prvObject != null)) prvObject.Hidden = true;

}

Thanks,

So this should be included in the SolveInstance method? The part I don't understand is (IGH_Component) owner, how should that be translated for a custom component?

if (DA.Iteration == 0)
{
IGH_Component component = (IGH_Component)owner;
IGH_Param param = component.Params.Output[0];
IGH_PreviewObject prvObject = param as IGH_PreviewObject;
if ((prvObject != null)) prvObject.Hidden = true;
}

for a custom component this doesn't work...

DA.Iteration == 0 was just thought to work for your custom display code

If you're doing a custom component you might write in your "RegisterOutputParams" method:

pManager.HideParameter(index)

This will not draw the geometry from the output at the specified index.

I'm a bit confused now...are you working on a custom component or on the script component. the two differ a little bit and i don't want to create more confusion by not knowing what's your aim.

Yes! I've fixed it! Finally... Also thanks to some of your suggestions.
Eventually I found a way to display the individually coloured breps without the red overlay.

Sorry for the confusion, I am indeed working on a group of custom components.

Thanks again.

Did you manage to build the components Joost?

This is certainly an issue I keep coming up against.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service