Clone PolygonMesh
-
Hi.
I take it one cannot Clone/Copy a PolygonMesh ?
Something like mesh2 = mesh1.clone.
PolygonsMesh do respond_to?(:clone) (or dup), so I thought there was a slight possibility there..
However it gives an error: "reference to deleted PolygonMesh" when calling fill_from_mesh.
Would be convenient to be able to copy P.meshes around as containers for points, since transforming Polygonmesh is so fast.
I already have workarounds if this is not possible BTW.
Thanks!
-
The Ruby
clone
anddup
methods that are inherited, need to be overridden in the API class definitions.I have already logged this as an API bug. (It just has not yet been fixed.)
-
Aha.. Thank you Dan.
You are meaning that the console is showing methods that does not belong there, right ?
Just want to make sure I understood you correctly.. -
@jolran said:
I already have workarounds if this is not possible BTW.
It is possible. One intermediate step would be changing the
add_point()
method to iterate an array of points argument. (Currently it only adds the 1st point in the array, and ignores the rest of the array members.)Here's one workaround:
mesh2 = Geom;;PolygonMesh;;new() mesh1.points.map {|pt| mesh2.add_point(pt) }
-
@jolran said:
You are meaning that the console is showing methods that does not belong there, right ?
Just want to make sure I understood you correctly..NO they would be VERY useful IF they worked.
But correcting how they work (by redefining these two methods, and
intialize_copy
in the API subclasses,) was never done.So they have never worked for SketchUp API classes, especially for
SketchUp::Entity
subclasses. -
@unknownuser said:
NO they would be VERY useful IF they worked.
Thanks for clearing that up, and for the code suggestion.
edit: I think I described my scenario poorly. I need to have the Polygonmesh cloned with polygons as well. So a container for only points wasent perhaps an accurate description..
-
Well how about:
mesh2 = Geom;;PolygonMesh;;new() mesh1.polygons.map {|poly| mesh2.add_polygon( mesh1.point_at(poly[0].abs), mesh1.point_at(poly[1].abs), mesh1.point_at(poly[2].abs) ) }
You need to "absolutify" each index, in case any edges are hidden. They will have negative index numbers returned by the
polygons()
method. -
Thanks a lot for the code Dan, I will definately test it!
Doing mostly JS for the past 6 months, is the good old for loop abandoned in Ruby ?
The code:
@unknownuser said:
You need to "absolutify" each index, in case any edges are hidden
Yeah, I noticed that. But it was a hard lesson learned.
I'm revisiting old code and I see some comments regarding abs performance issues.
So for some reason I used this. However you abs method looks slicker.def self.positivVal(a) a = a < 0 ? -a ; a end
To further clarify, this concerns my parametric node modeler( long going project unfortunately )
It displays temporary geometry via the view draw class.So I have to build compatible arrays or hashes not only for the PolygonMesh but also for the view draw methods in the update methods.
I've decided to build a solution for each node. So next node in "chain" that takes this polygonMesh as an input will have to be clone it.I'm using this code for that
#Clone 1 mesh def self.clone_polyMesh(mesh) #Counts npolys = mesh.count_polygons #mesh meshclone = Geom;;PolygonMesh.new( mesh.count_points, npolys ) for i in (1..npolys) plps = mesh.polygon_points_at( i ) meshclone.add_polygon( plps ) end meshclone end
But your code looks more compact, so I might try that instead.
The question is if I have to build the polygons until the mesh is baked ?
Like the first code you posted Dan. For just adding points might be sufficient.
Keep the polygonMeshes with points only. And when it's time to bake build the polygons.
I might be overlooking something that must be done in the right context/scope.... -
Well this would be the simplest and avoid any
abs
issue:def self.clone_polyMesh(mesh) meshclone = Geom;;PolygonMesh.new() for i in (1..mesh.count_polygons) meshclone.add_polygon( mesh.polygon_points_at(i) ) end meshclone end
P.S.: Ruby 2.0 has been optimized much more than the old Ruby 1.8 trunk.
-
@jolran said:
To further clarify, this concerns my parametric node modeler( long going project unfortunately )
It displays temporary geometry via the view draw class.Have you seen:http://www.thomthom.net/software/vertex_tools/
-
That code looks compact enough.
Does it matter for performance not providing arguments in PolygonMesh.new(), or is the docks wrong(again) ?@unknownuser said:
P.S.: Ruby 2.0 has been optimized much more than the old Ruby 1.8 trunk.
I know Still klingin on to SU8.. Poor old sod.
And regarding that, I was looking for a way to iterate by 3 (for converting a quadpoints-array
to tri-points-array that I can push to GL_TRIANGLES.)so each_slice(3) looked suitable. Turned out was only compatible with ranges for ruby 1.8.
Edit: removed code that wasent working...
@unknownuser said:
Have you seen:http://www.thomthom.net/software/vertex_tools/
Yeah! Amazing tool. He's draw class is an inspiration. I do have peeked inside there
updates:
I forgot Polygonmesh removes duplicates. (It seams so anyway.)
So it may be hard to recreate polygons later in another context without adding in the polygons..
It's also peculiar to update the mesh points.
Assuming the only way to edit/replace points is use of set_point(index, point) ?
PolygonMesh.points.clear! would be good to have.. -
I'm toast.
One cannot refresh the Polygonsmesh. Polygons keeps getting added even if updating points with setpoint(which make sense though). I presume there is no way to delete polygons ?
I noticed cpu worked hard. So I counted polygons. + + + ++++I guess only way is to use PolygonMesh.new() at every update ?
Not so funny since a sliderhandle may update values 100+ times in milliseconds..
I'm not sure about best practices here, sounds expensive to create new objects frequently.Update: Polygonmesh.new() works.
Don't know if there is any sideeffects appart form heavy GC lifting..
Considering one often creates and dispose Point3d objects quite frequently I can't see why it couldent be done with a PolygonMesh -
Yey! It works! At least at Cube level
-
Holy sheet!
I wanna play with this!!So how did you do the UI in the end? Is it a webdialog or external?
-
Hi. Jiminy wasent expecting any response..
It's a standard webdialog. Pure JS and HTML.
The canvas and nodes are all SVG. Then the rest are plain html elements. like Tooltips, contextmenus etc.I switched to D3.js. Not a compability layer, but have some nice selectors and methods.
It has such nice zooming and panning. Also very fast!
You should check it out! People think one can only use it with SVG, but that is not true.It needed quite a bit of Javascript code to get the interaction working, since d3 is quite lowlevel. There are no solution for handling multiproperty nodes. There's layouts, but I'm basically only using the selectors and the zoom/pan functions.
Everything is programmed from scratch. Connections, nodes etc.. So I am expecting hickups here and there.. -
Would you be willing to upload your project on github? I would love to take a look at how you did that. And maybe help if I can.
If that's ok with you of course.
-
No sorry.
I havent decided the future for this plugin yet.
Was thinking a free version and then if things progress well maybe a more advanced Pro version. That will keep everyone happy.
That also means restrictions on the license, so Github will not fit.
I hope you understand.
This may change. Plugin's status isent release ready anyway.
I did not post the gif to show off. Just was so god damn happy it worked I needed to share my joy.BTW I appreciate you offering help. PM me for questions regarding code. No Problem.
-
@jolran said:
I hope you understand.
I completely understand! If you're going to monetize your work, don't make it public
I asked because I was thinking about a plugin using a similar node-based UI (A material editor for render engines). But I haven't found any convincing JS framework (You told me about JSplumb a while back, but it doesn't seem really strong and stable).
I guess I'll have to make my own, like you didAs for the help I can provide, I'm curently working on a scattering plugin. So let me know if you have any question regarding this topic.
-
Thanks for the understanding! It's a touchy subject.
A material editor! Is it possible to hook up to thoose from within Sketchup ? I thought they kept their code closed. The Render-engines that is.
Then, I shouldent rule out Jsplumb completely, if I was you.
It wasent an easy decision to restart from scratch and change library.
For the record I had no stability problems with Jsplumb. It was more a matter of performance in combination with JQ UI, and a few features I did not manage to implement.A few things have changed since then for Jsplumb. It's not dependent of Jquery UI draggable for one. = faster.
It has Jquery style syntax, so you would feel at home directly, don't need to learn about SVG, if you don't know it already that is. Also more compatible with browsers than d3.
Has inbuilt events for connections, so it's MUCH easier to set up. But it's quite a large library. 10K +So if you are not 100% dependent on zooming/multidragging go for jsplumb. At least give it a go. You will get going in a couple of days, Ive seen your layerspanel. No prob.
That said. You would have a lot of fun learning d3, when you passed the init threshold.
My goal was to learn as little as possible, cause it's easy to get stuck with experiments Amazing stuff they do..Scattering plugin, you say. Sounds very interesting indeed. Can be as complex as you like it, I presume.
@unknownuser said:
So let me know if you have any question regarding this topic.
I sure will! And the same goes for you. Can PM snippets and shiat..
-
@jolran said:
A material editor! Is it possible to hook up to thoose from within Sketchup ? I thought they kept their code closed. The Render-engines that is.
The data has to be stored somewhere. At least for Vray, the properties are stored as an XML structure in the material's attributes.
@jolran said:
So if you are not 100% dependent on zooming/multidragging go for jsplumb.
Well I think I would be. I mean, this king of UI without zooming is kind of cumbersome, don't you think?
Anyway, thanks a lot for all the tips
Advertisement