PDA

View Full Version : How to weld points to average but without welding

Boris Goreta
10-12-2016, 06:57 AM
Hi, I would like to move points to their average position. There is a weld to average command but I don't want the points to be welded, just moved to their average position based on some threshold value.

134751

Danner
10-12-2016, 07:26 AM
Only thing that comes to mind is to select the group of 4, and just size it down, using "AC:Selection" as the action center.

In some cases I imagine Point Normal Move could be used to scale many sets of 4 at the same time.

Boris Goreta
10-12-2016, 07:34 AM
I know but I need to do this massively on the entire model, this would be too time consuming.

Point normal move would work if all points were at the same distance from their averaged center, but this is not the case.

rustythe1
10-12-2016, 08:15 AM
if you could create a spline at the centre of it with a point in the middle of each of the 4 points in the back ground (you would probably have to make a copy of the object then hand weld average each set of 4 so maybe still a bit of time needed) and then I think "shrink wrap" has a nearest point option that may work

erikals
10-12-2016, 09:26 AM
UVing a Tree...?

maybe there is a plugin for it?

there is the plugin Edge Opener, but that works the other way around

(hmm, Edge Opener is 32bit only it seems, even though DStorm page says 32/64)

Kryslin
10-12-2016, 09:30 AM
Does this require anything special, like it has to respect islands of points (as in, you've selected multiple islands, and need each one to collapse, or is it the simple case, where your selecting a large group of points to collapse into a single point (but not weld)? The solution, for lscript, is trivial.

@script modeler
@warnings off
@name Snap to Avg.

main
{
//debug();
totPntVal = < 0, 0, 0>;
selmode(DIRECT);
pntCnt = pointcount();
if(pntCnt == 0)
{
error("No points selected!"”);
}
editbegin();
for(currPnt = 1; currPnt <= pntCnt; currPnt++)
{
currPntVal = pointinfo(points[currPnt]);
totPntVal = totPntVal + currPntVal;
}
pntAvgPos = <totPntVal.x / pntCnt, totPntVal.y/pntCnt, totPntVal.z/pntCnt>;

for(currPnt = 1; currPnt <= pntCnt; currPnt++)
{
pointmove(points[currPnt],pntAvgPos);
}
editend();
}

Cut and Paste this to a text editor, then save it as <filename>.ls. You can add it as a plugin via Lightwave, and then give it a button via the menu editor.

This is an old script, and I can't even take credit for it. A good portion of the code is shared between weld, weld pairs, weld average, and weld average pairs scripts, the main difference is in how the points get moved before being merged.

Hope this at least (partly) helps.

iain_r
10-12-2016, 09:36 AM
Why not just select the points, weld averge then unweld unless you don't want them exactly at the same point.

jeric_synergy
10-12-2016, 10:16 AM
Kryslin, is native WELD AVERAGE a script??

Kryslin
10-12-2016, 11:17 AM
No, it's an actual compiled plugin. However, it is easily duplicated in lscript. The redone weld/weld avg/weld pairs/weld pairs avg scripts all come from the original lscript documentation, about how one can get rid of the pesky message box that used to pop up every time you used weld.

The lscript versions do have a small problem - if there is any difference between the points being welded (like morph maps), it won't weld them. Move them, yes, but not weld them.

I think Iain_r's suggestion, however, might be faster for large numbers of points.

erikals
10-12-2016, 11:35 AM
not sure if this could be of help,...

Danner
10-12-2016, 12:19 PM
...The lscript versions do have a small problem - if there is any difference between the points being welded (like morph maps), it won't weld them. Move them, yes, but not weld them....
.

That sounds exactly like what the Original poster wanted.

Erikals, I don't think anybody is talking about UVs... Iain's suggestion might not work because you are merging 4 points that come from quads but they turn into triangles, so unwelding gives you triangles not quads. (I'm not sure what the OP had in mind but my guess is that he needed to stay in quads)

erikals
10-12-2016, 12:55 PM
That sounds exactly like what the Original poster wanted.
yep, think that is the solution.

regarding UV's, it looks like from the original picture he is UV mapping a tree? ...not quite sure.

jeric_synergy
10-12-2016, 05:08 PM
No, it's an actual compiled plugin. However, it is easily duplicated in lscript. The redone weld/weld avg/weld pairs/weld pairs avg scripts all come from the original lscript documentation, about how one can get rid of the pesky message box that used to pop up every time you used weld.

The lscript versions do have a small problem - if there is any difference between the points being welded (like morph maps), it won't weld them. Move them, yes, but not weld them.
That is NOT a bug, that's a definite FEATURE: I use a m.map named "NO_MERGE" to preserve points from inadvertant merging.

I think Iain_r's suggestion, however, might be faster for large numbers of points.
I rather moderated my question because iain_r's method was the first that occurred to me, if there were simple LScript commands for WELD_AVERAGE immediately followed by UNWELD. I'm not sure what the OP's application for this routine is, but the illustration seemed to indicate a desire to collapse branches or tentacular-type meshes to a central spline. This I think would require a threshold value to avoid collapsing far-distant points, although a real pro routine would also avoid re-curve situations.

Hmmmm... do we already have a tool that would step down via NEXT LOOP a mesh, collapsing subsequent loops??? :stumped: That might be pretty convenient for use with tree structures.

Kryslin
10-12-2016, 11:20 PM
That is NOT a bug, that's a definite FEATURE: I use a m.map named "NO_MERGE" to preserve points from inadvertant merging.

I rather moderated my question because iain_r's method was the first that occurred to me, if there were simple LScript commands for WELD_AVERAGE immediately followed by UNWELD. I'm not sure what the OP's application for this routine is, but the illustration seemed to indicate a desire to collapse branches or tentacular-type meshes to a central spline. This I think would require a threshold value to avoid collapsing far-distant points, although a real pro routine would also avoid re-curve situations.

Hmmmm... do we already have a tool that would step down via NEXT LOOP a mesh, collapsing subsequent loops??? :stumped: That might be pretty convenient for use with tree structures.

Ok, now someone's got me curious. I think it could be done. I think next loop and previous loop are CMDSEQ operations (and can be called from lscript), but the problem I forsee is detecting when the operation fails. I'll have to read up on cmdseq() and see if it returns a value or not... Drat, cmdseq() is one way. You can invoke another plugin, but not get information back...

jeric_synergy
10-13-2016, 12:13 AM
... Drat, cmdseq() is one way. You can invoke another plugin, but not get information back...
Well, the WELD_AVERAGE code is, as you've demonstrated, no big deal, so you wouldn't have to invoke another plugin. That would be elegant, but is apparently not to be.

I'd think (for certain low values of 'think') that branching would be more of an issue: it'd be slick as hell if you could collapse a whole tree to a series of splines, but I smell recursion in the air, so I'm running away.....

But, a little bit of user interaction can go a long way, so as long as any given branch/tentacle got collapsed, it'd still be a worthy addition to the toolbox.

JoePoe
10-14-2016, 02:02 PM
This (the original problem) can be done with not too much fuss. :hey:

In theory it's just two steps:
1) Create cross section polys (this can be done en masse)
2) Run MF Poly Islands and crank the scale all the way down. (this is a tricky plugin. Be careful.)

In practice:
Step 1, in and of itself, is a couple step process. But can be done for any number of polys very quickly.
And step 2 might take a while if that number is particularly large. But even if used on chunks at a time, a huge time saver.

Step 1 deconstructed: Select edge, select loop, select ring. Copy and paste edges into new layer. Select ALL points, hit P. Delete 2 pt polys. Rename surface to something like "cross Section". Copy/paste back into original object, hit merge.
You now have cross sections.

Step 2 deconstructed: Select polys by surface (Cross Section). Run Poly Islands. Delete Cross Section Polys.
(Very unforgiving plug. No undoing this, so use on a copied object. And I think you only get one swipe at the sliders. Adjusting multiple times causes problems. So crank it down in one fell swoop.)

(I didn't include the base of each branch on purpose)
134782

Kryslin: Nice plug. Maybe you can combine it with a Poly Island type functionality?

jeric_synergy
10-14-2016, 02:29 PM
Trying step #1 with a simple box divided vertically, I'm not getting cross sections, just one BIG wonky polygon.
134783

JoePoe
10-14-2016, 02:55 PM
You're copying edges into the new layer right? Not points.
Select points after you've pasted the edge loops...

This is what I get on a simple vertical box....
134784

Boris Goreta
10-14-2016, 03:30 PM
Thanks JoePoe, your method is working very well, I've tested it on a vertical box, with success. I don't need this for UV mapping, the tree is already UV mapped. I need it for wind simulation purposes. I have a low branch count proxy model which I use to simulate branches in the wind. Then I drive the high poly model using the proxy model as a cage ( meta plug deformer ). If I apply it to the original tree model I get undesired stretching of the mesh, if all cross sections are scaled to zero then there is no stretching since all points are at the same place and so are deformed equally, after that I just morph it to the original mesh.

Is the first step possible on multiple branches in one go ?

I remember sometimes getting mass cross sections when I didn't want them, if only I could remember how to do that. After that step it is easy.

jeric_synergy
10-14-2016, 03:37 PM
Is this contingent on not selecting the top and bottom of the stack?

I just tried again, copied edges, and one oddity I've noticed (and have noticed for quite a while) is that the new-ish behaviour of "pasted things are selected" isn't 100%: out of 44 Edges pasted, only 42 are Selected.
134785

Be that as it may, all the points seem to have come thru , so when I Select (All) Points and hit "p", I'm seeing this:
134786

JoePoe
10-14-2016, 04:13 PM
Jeric: I can't imagine what's going on. I don't think it's contingent on anything special. In fact I'm trying to break it with all sorts of crazy selections and broken 2 pt chains, and I still get individual polys (not on the broken chains of course). Care to upload what you're working with?

Boris: Glad to help. The first step can be done for any number of branches. But I do want to amend the the order of things slightly, just so the bottom and top loops are included in the selection.
The order is now..... Select edges (one on each branch), select loop, select ring (I'm going to change the original post too). The rest stays the same.
But the Poly Island plug slows down quickly. I did the multiple branches here all at once and it needed a couple seconds to think about it.

134788

jeric_synergy
10-14-2016, 04:24 PM
Here ya go. I started to wonder if I had remapped PerspicaciousQuads to "p", so I tried again with "Make Polygon" via button, same effect.

One question: I would have NEVER thought of your system, because when I select n points and hit "Make Polygon", it includes all the selected n points. I'm baffled that yours does not.

134789

JoePoe
10-14-2016, 04:37 PM
Got it. I ran unify polys on your tower and it removed 50. So, somehow you got doubled up. Happens to the best of us :).
Doing the edge thing without doing that first did something similar to what you've been getting.

Sending it back. Layer 6= after unify. Layer 7=pasted edge loops. Layer 8=select points and P (still includes the 2 pt chains as well).

I really don't know why it works.... Gotta have something to do with the closed chain(s).

jeric_synergy
10-14-2016, 05:20 PM
Got it. I ran unify polys on your tower and it removed 50. So, somehow you got doubled up. Happens to the best of us :).
And me also! ;) Here's the thing: I made 3 different 'towers' using only BOX each time, from scratch, New Object. The one I sent you was #3. So what the heck is going on?

Thanks for persevering. I'm still wondering about the N-point Make Polygon thing.

Prince Charming
10-14-2016, 05:36 PM
I think another way that would work is to cut the edge cross sections like you are doing, then use dp center_part script to place points at the center of all the cross sections. Then you could use shrink wrap set to nearest point, or use nearest point node in Layout to do it nondestructively if you needed.

JoePoe
10-14-2016, 07:01 PM
Ahhh. Very good. Don't even need DP. Make Pole does fine too. When doing this, though, special attention needs to be paid to branch tips (if they come to a point). I had to add those points separately.
But that's no big deal.

I did have an issue at a couple of the branch "connection" spots. Nearest point got a little "misguided" (although it was technically going to the nearest point).

134792

I think that side stepping Poly Islands is huge. Probably worth some time spent hand massaging some trouble spots. :thumbsup:

Prince Charming
10-14-2016, 07:29 PM
Ahhh. Very good. Don't even need DP. Make Pole does fine too. When doing this, though, special attention needs to be paid to branch tips (if they come to a point). I had to add those points separately.
But that's no big deal.

I did have an issue at one of the branch "connection" spots. Nearest point got a little "misguided" (although it was technically going to the nearest point).

134792

I think that side stepping Poly Islands is huge. Probably worth some time spent hand massaging some trouble spots. :thumbsup:

Dont forget that you can use shrink wrap on selections, so it should be pretty easy to copy the trouble points from the point cloud into another layer, and use shrink wrap on just a selection of the trouble area... then the rest should work ok.

Also, another option is to use a weight map and do it in layout with two nearest point nodes, and a weight map mask.

Prince Charming
10-14-2016, 07:54 PM
I just found a way that will work without issue. Do the same thing with the edges, but instead of collapsing them to a point... go to layout and use part move to scale them to 0. Then in layout you can use nearest point node to stick the tree points to the deformed edge points, and since they are right on top of each other you wont get the same problem as the other set up. I will put a test scene together.

Uses part move and nearest point nodes, so if you don have them it wont work. Open scene and hit play...

jeric_synergy
10-15-2016, 12:22 AM
Do we even know why the OP wanted to do this??

Prince Charming
10-15-2016, 01:01 AM
Do we even know why the OP wanted to do this??

I think he wants to collapse the tree so that he can apply meta link from a mesh that has different topology, but since they are scaled down it deforms it like a ploy chain. Then he can morph it back to the original shape, and it will deform properly. I think that is what he was getting at...

Here is another test... uses same technique to grow tree.

Kryslin
10-15-2016, 01:56 PM
Kryslin: Nice plug. Maybe you can combine it with a Poly Island type functionality?

I think that's do-able. There would have to be some list management (remove those polys that have been collapsed into an average point from the list, a trivial matter). It would go something like this:

1) Get Selection
2) For each poly in list...
_a) Select Connected (This should select all the polygons in the island)
_b) Get the new selection
_c) Move all the points in the new selection to the average for the island
_d) remove all the polygons so moved from the main list.
3) When list is empty, exit script.

I'll slap some code together, see if to works later tonight.

jeric_synergy
10-15-2016, 02:25 PM
Do we even know why the OP wanted to do this??

RIGHT, there it is in #19. Sorry.

Kryslin
10-15-2016, 09:55 PM
Ok, I have a working prototype script. It works on polygon islands, but has to go through some creative software engineering to get it to work correctly.

Of course, I was using it on islands selected out of larger meshes, instead of discontinuous groups of polygons, which is why selpolygon(SET, CONNECT) would select multiple polygons that appeared to be discontinuous. Solution? Cut and Paste the polygons out of the parent mesh, then merge the groups into discontinuous islands. Crude, but it works. If anyone is interested in the thing, I'll post it here.

jeric_synergy
10-15-2016, 10:58 PM
Got it.
Joe, when you select one Edge, then SELECT RING, then SELECT LOOP, do you get 2 unSelected Edges at the top and bottom of the stack for a total of 4 unSelected Edges?

(BTW, I found that PerspicaciousQuads definitely does not work for this procedure.)