Sorry but I cannot debug this code. There’s too much of it and it’s too messy. You use identical names for class level variables and method arguments, the naming of variables is not at all self-documenting (ap1, ap2, aaa1, etc.) You’ll have to simplify your questions before I can answer them.
I suspect your problem is that you’re not duplicating your meshes enough. That your transformations somehow stack together because they are all accumulated into the same mesh. You’ll need to use DuplicateMesh() to create a copy of a mesh that you can then deform independently.
Creating new points to have another name than "Pts" etc... Is it slower than using them directly by writing Pts,Pts,Pts... ???
for (int i = 0; i < iPoints.Count; i++)
Point3d pt0 = Pts;
Point3d pt1 = Pts;
Point3d pt2 = Pts;
What is the fastest way to use a copy of an embedded mesh in the same script ???
Mesh teaPotMesh2 = teaPotMesh.Duplicate(); //Don't work :-/
GeometryBase teaPotMesh2 = teaPotMesh.Duplicate(); //Worked but I need a mesh. And when I want to convert it I'm getting the error bellow
teaPotMesh2 = GH_Convert.ToMesh; //Don't work either. getting : 2. Error (CS1503): cannot convert from 'Rhino.Geometry.GeometryBase' to 'Rhino.Geometry.Mesh'
I tried to be as clear as possible. It it is still messy let me know I’m learning every day
Copy will typically be slower when the type is a value type. But more important is that you are aware of that if you update the copy (i.e “pt0” in your code above), that doesn’t mean that you have updated the value in Pts. This may be a problem if you plan to use the point in the list (Pts) later in your code, and expect that it has been updated if you update the pt0.
Look at the following picture. It shows the output of Pts and pt0 after all the values of pt0 are set like so: (1,1,1) while Pts keeps it’s original values, which is (0,0,0):
And here’s the test code snippet so you can se for yourself what result you (may) expect, and the actual result (pictured above) :
private void RunScript(ref object OUT_Pts, ref object OUT_pt0)
var Pts = new List<Point3d>();
Pts.Add(new Point3d(0, 0, 0));
// Now copy the point
var pt0 = Pts;
// ... and modify its value
pt0.X = 1;
pt0.Y = 1;
pt0.Z = 1;
// and compare the two if they still are equal
OUT_Pts = Pts;
OUT_pt0 = pt0;
At the moment I don’t have the time to look deeper into your code (but someone else may have an extra minute or two), but check your code if you have this bug (expecting to have updated point residing in a list while the changes were made only on the copies).
If you did this mistake I say only; welcome to the club. You’re not alone.
In any case, you asked about copying values. Feel free to do so, but watch out for making copies of value types if a copy is not what you expect (Point3d is not a class, it’s a struct, which is a value type, and thus it gets copied, not referenced).
Regarding copying Meshes, I most often copy meshes like so:
var meshcopy = OriginalMesh.DuplicateMesh();
That’s equivalent to this:
Mesh meshcopy = OriginalMesh.DuplicateMesh();
… but the compiler will figure out that the DuplicateMesh() command will return a Mesh type, and so the “var” will actually become a Mesh.
Same thing with the first example above; the compiler deduces that “pt0” needs to be a Point3d.
Nice exemple to make things easy to understand.
Of course the output points will be differents because :
“OUT_Pts” is obviously the Input.
“OUT_pt0” is the new Point3d.
Yes… I wasn’t able to find a solution for lines strange windowsXp stacks like ^^
But !! I replicate the problem with your exemple, than we really enclose that problem now.
Should be easy to find what is wrong.
I think the problem is the way I transform the points… Maybe I should transform.translate instead of duplicate them.
I’m getting a bit confuse with this points right now ^^
If somebody has an Idea would be nice to show up.
As yellowWiresPts is a list, is not placed in RunScript and there is an add it means that at each click there was points added. So the list keep growing. If no need of list a buffer must be used to keep track of data wanted.
Thanks for the clear explanation
Do you have an idea for that mesh ?
Wich is the fastest way to use a mesh two times within the same script ?
I tried duplicate() but it gives a GeometryBase wich is not a mesh that can be used into
"public override void DrawViewportMeshes(IGH_PreviewArgs args)"
It is the same but as one is a derivate class it has to output a more general class. You can surely cast the output with (Mesh)Mesh.Duplicate().
Surely not all the good words for Object Oriented Programming.