PDA

View Full Version : "Untangle" /Circlify for _POINTS_ , aka LOOP>Circle



jeric_synergy
08-31-2015, 05:45 PM
TMK, both MF Circlify and native Untangle (ughh, bad name) work on polygons, not points.

As I build cartoony limbs, one boring task is maintaining circular forms in the spaghetti-like arms and legs. It would be extremely convenient if I could select a point loop around a limb and hit 'Circle It!" (® --kidding!) and the loop would become a flat circle (flat, but in any orientation).

It wouldn't even have to have a LOT of specificity, because it's pretty easy to size and rotate a circle. This is just to avoid the tedium of moving a buncha points manually. It'd be NICE if the routine made a good guess as to the direction of the tube it was part of, but... nothing critical here.

A circle can be described with 3 points, so if the average of 3 points evenly distributed along the loop were used as the description of the circle, that would probably be Good Enough. The remaining points would be distributed evenly along the circle.

FEATURE REQUEST SUBMITTED

ernpchan
08-31-2015, 11:13 PM
Does making a polygon with those points and then running Untangle work for now?

jeric_synergy
08-31-2015, 11:47 PM
Does making a polygon with those points and then running Untangle work for now?
Yeah, but that's a terrible workflow.

+++++++++

Case LWF-406

probiner
09-01-2015, 07:02 AM
https://www.youtube.com/watch?v=znjO6NltRaI&t=1m20s

jeric_synergy
09-01-2015, 08:20 AM
https://www.youtube.com/watch?v=znjO6NltRaI&t=1m20s
That's interesting & useful (to Wings users), but not what I'm wanting.

What I'm wanting is more like when you have a vacuum cleaner with a hose that keeps getting kinks-- my tool would undo those kinks. It does not act on POLYGONS, it acts on POINT LOOPS.

++++++++
You should forward that video to the devs so they can see how UnTangle SHOULD work.

Kryslin
09-01-2015, 08:24 AM
It's not also useful for cartoon style limbs - as you slice in control edges for subD geometry, you can wind up with flat spots on a circle...

Oedo 808
09-01-2015, 08:39 AM
A request for modelling enhancements?


https://www.youtube.com/watch?v=FopyRHHlt3M

jeric_synergy
09-01-2015, 08:47 AM
A serious request for modelling enhancements?

https://www.youtube.com/watch?v=FopyRHHlt3M
Brutal.

Well, this particular action is, if crudely implemented, akin to the plugin "3pt Circle", except with added points to be conformed. IMO it doesn't even need to do much of a job of alignment, just force the points to a circle and up to the user to rotate into place.

IMM, the psuedo-code goes:

Make point loop
chose 3 points as circle definition
move all other points to be on circle


Waällagh!

Photogram
09-13-2015, 08:57 AM
I rarely need this command but i need it today!
I cannot find the Untangle menu, where it is?

Thanks :)

jeric_synergy
09-13-2015, 09:03 AM
I rarely need this command but i need it today!
I cannot find the Untangle menu, where it is?
Thanks :)
Use the MENU EDITOR to search for functions that you cannot locate. I do it All The Time, my memory is awful. Fortunately, in 2015 LW3dG made the Search function a lot better.


+++
Reading back on this thread, I shoulda lead with "LOOP-TO-CIRCLE".

Photogram
09-13-2015, 10:12 AM
Thanks Jeric, i wasn't sure if that command was LW native, now i found it with the menu editor ;)

After using it i decided to go with another command from MentalFish that do exactly what i need. (MFCirclify)

jeric_synergy
09-13-2015, 10:29 AM
IIRC, there's some issue w/MFCirclify, you may run into it (don't remember specfics).

--Just thought of enhancement to my request: the ability to either select multiple loops (not polys) to Circlify, or to have it automatically crawl down a series of loops, Circlifying as it goes. But, just one at a time would be a great start.

Kryslin
09-13-2015, 12:08 PM
Since you are looking for 1st party solutions (from Newtek, integrated into Lightwave), You're probably not interested in this...


@warnings
@name "Circlize Points"

main{
//Set all points to the same distance from a common center
selmode(USER);
editbegin();
pts = points;
pcnt = pts.count();
cp = <0,0,0>;
//get center point
for(i=1;i<=pcnt; i++)
{
cp += pointinfo(pts[i]);
}
cp /= pcnt;
//get greatest distance from center
d = -1;
for(i=1; i<= pcnt; i++)
{
td = vmag(cp -pointinfo(pts[i]));
if ( td >= d ) d = td;
}
//now, make all the points that distance...
for(i=1; i<= pcnt;i++)
{
tv = normalize(pointinfo(pts[i]) - cp);
np = cp + (d * tv);
pointmove(pts[i],np);
}
editend();
}

Usage :
1) Select loop of points
2) Run script.
Points should be equidistant from a common center point.
You can use select next/prev loop to cycle through a series of loops.

I use this to re-round subd geometry that I've had to cut hold loops into.

Photogram
09-13-2015, 12:18 PM
Hello Kryslin,

Oh that is working!

Thanks a lot!!!!

jeric_synergy
09-13-2015, 12:20 PM
Since you are looking for 1st party solutions (from Newtek, integrated into Lightwave), You're probably not interested in this...
:ohmy:: Still fine tuning the standup routine?

:bowdown: Thanks very much! Also, I'ma gonna examine the code in this to hone my (minimal) trig skills. Like, how to determine the plane of the circle so one doesn't get a sphere....

And THANKS for posting the code, so more can learn!

Photogram
09-13-2015, 12:26 PM
It can be verryy usefull i there is an option to set all the points value to the average plane!!

Kryslin
09-13-2015, 01:02 PM
Jeric: No trig involved - however, it does require some vector math :
1) Find the center point
2) Using the center point and the 1st 2 points, create 2 vectors A (Cp - P1) and B (Cp-P2)
3) Normal of plane = A x B (Take the cross product of A and B)
4) The equation of a plane is N ∙ P + D = 0; N dot P = -D. D being the distance from the plane (∙ being the dot product of 2 vectors)
5) New P = P + (-D * N)

Photogram: This was written as a quicky to do one thing without any other input from the user. If I do the planar points thing, it would be a separate script, because menus and check boxes in scripts like these slow things down. When using them, I just wanna click on a button and have done.

jeric_synergy
09-13-2015, 01:34 PM
Thanks for the pointer Kryslin-- saved me some time no doubt! And +1 on the "one function/one buttonpress" paradigm-- fast beats powerful very often.

::scary font:: Vector math!!! ;)

Photogram
09-13-2015, 05:01 PM
Thank you so much everybody, you make my day!

Kryslin
09-13-2015, 05:04 PM
Looking at my code, I think there is a way to get things done faster...

@warnings
@name "Circlize Points"

main{
//Set all points to the same distance from a common center
bb = nil;
cp = <0,0,0>;

debug();
selmode(USER);
//Faster, less accurate center point method...
bb = boundingbox();
cp = (bb[1] + bb[2]) / 2;
editbegin();
pts = points;
pcnt = pts.count();
//get greatest distance from center
d = -1;
for(i=1; i<= pcnt; i++)
{
td = vmag(cp -pointinfo(pts[i]));
if ( td >= d ) d = td;
}
//now, make all the points that distance...
for(i=1; i<= pcnt;i++)
{
tv = normalize(pointinfo(pts[i]) - cp);
np = cp + (d * tv);
pointmove(pts[i],np);
}
editend();
}

Boundingbox returns the bounding box of the selection; Taking (A + B) / 2, I should hit the center point in much less time than iterating through the selection and adding everything, then dividing...

There's also one final step in my circlfy loop on average plane; once the points are moved to the plane, they need to be made equidistant from the center point...


@warnings
@name "Planar Circlize Points"

main{
//Set all points to the same distance from a common center
bb = nil;
cp = <0,0,0>;
selmode(USER);
//Faster, less accurate center point method...
bb = boundingbox();
cp = (bb[1] + bb[2]) / 2;
editbegin();
pts = points;
pcnt = pts.count();
//Let's make a surface normal for a plane!
vA = pointinfo(pts[1]) - cp;
vB = pointinfo(pts[2]) - cp;
N = normalize(cross3d(vA,vB));
//And solve for D for the centerpoint
D = -(dot3d(N,cp));
//get greatest distance from center
d = -1;
for(i=1; i<= pcnt; i++)
{
td = vmag(cp -pointinfo(pts[i]));
if ( td >= d ) d = td;
}
//Move the points into the plane defined by N, then make them equidistant around CP
for(i=1; i<= pcnt;i++)
{
tp = pointinfo(pts[i]);
//First, move the point to the plane...
// If N dot P + D != 0, the result is the distance from the plane
tD = (dot3d(N, tp)) + D;
tp += N * -tD;
//Then make it equidistant from the center
tv = normalize(tp - cp);
np = cp + (d * tv);
pointmove(pts[i],np);
}
editend();
}

And there we go. Same usage as it's cousin... Select loop and run.

Photogram
09-13-2015, 06:14 PM
I just try it and it is working good!

Photogram
09-13-2015, 06:32 PM
It was very usefull to get perfect circle in the nozzle and where the points are selected :)

Thanks again!

pinkmouse
09-14-2015, 03:29 AM
It would be nice to be able to select the axis to work in whilst locking the the others. Say, for instance, I'm working on a pipe, running in the x axis and I have a group of points on the top I need to make into a circle to create a branch. It would be cool to restrict the circlify to just the x, so the curvature of the pipe in the Y stays unchanged. Does that make sense? :)

jeric_synergy
09-14-2015, 10:03 AM
Sounds like more of a drill operation. --I like the "one click" aspect of this, adding more user-interaction is going to break the flow. But of course a similar thing with some UI can be a separate tool, this would just be the fast one.

Pinkmouse, do you have a sketch of this situation? Because I'm thinking "how did those points get there?" Which would usually be a drill operation (pour moi), from a perfect circle anyway. And/or Bridging might get involved.

Kryslin
09-14-2015, 10:12 AM
A long time ago, I noticed that there was no equivalent for flatten for points; It flattens along an axis (and soon, along an average plane, now that I have the math worked out), least/avg/greater. I needed this for working with hair guides. In your instance, Pinkmouse, you are circling in the XZ plane. And yes, it's doable, because what you want done is been (mostly) done before.

Jeric : I think you're right, I'd use Drill and extend plus. I might do some creative multishifting so I can get a fillet around the join as well...

jeric_synergy
09-14-2015, 10:47 AM
I'm using the Edge Edit tool to add fillets nowadays. Your new script will help w/that too. :thumbsup:

++++++++

Some sort of sticky thread and/or online archive with the TYPES of math you posted above would be useful for script writers, don't you think? As people solve small-ish problems a library of the equations involved would be quite handy, no?

EG, there's a class of equations I call "toggle equations" which flop back and forth between 0/1 or -1/0/1. They're not very complicated but quite clever, and I always have to go hunting for them when I need them. ONE centralized archive with good tagging would be efficient for all.

IMO this is the kind of facility vendors should support, as it just makes their product that more valuable.

pinkmouse
09-14-2015, 01:26 PM
The pipe was just an easy to visualize example. The object I was modelling a few days ago was much more complex. ;)

And yes, Drill is good.

jeric_synergy
09-14-2015, 02:13 PM
There's room for both FAST!!!® versions and more complete versions: the Mirror Tool is my go-to example-- I rarely rarely rarely need it. 99% of my mirroring needs are met by "Mirror X".


Also, a thank you to Kryslin for posting the code so we can cherry-pick routines and math we need.

jeric_synergy
09-14-2015, 03:23 PM
For those not up to speed in LScript,

Looking at my code, I think there is a way to get things done faster..
JFYI, in "Circlize Points" I commented out the debug() line, because it was calling up the console. (For non-lscripters, put two slashes in front of the line.)

+++++++++

Mapped it to SHIFT+C (can't believe that was open) and LOOPUP circle LOOPUP circle LOOPUP circle LOOPUP circle LOOPUP circle LOOPUP circle.....yeahhhh! Now we're talkin'!

Kryslin
09-14-2015, 11:44 PM
With some 3D Artists I know, the mention of the words "Math", "Programming", and "Expressions" will give them a pained look, with glazed over eyes if the discussion goes on much longer than that. Most if what I use, I've known for years...

And ooops! on the debug. I'll delete it from the source file.

pinkmouse
09-15-2015, 01:56 AM
It's curious. I can quite happily assemble chains of nodes to do very complex maths, yet if I try to do exactly the same thing in an expression, my eyes glaze over and I end up banging my head against a wall... :)

Kryslin
09-15-2015, 11:33 AM
Going through Dodgy's lscript reference, I found a way to do something with even less code...

I forgot, lscript has a center function... so cp = center(boundingbox()); and I can remove the bb variable entirely...

Kryslin
09-19-2015, 12:20 AM
Here we go again... Last iterations of Circlize Points / Planar Circlize Points
- Reduced the number of loops in each down to one.
- Using some down and dirty methods to quickly determine the greatest distance, since an outlying point will always be on the bounding box.
- Removed that pesky debug statement.

Circlize Points :

@warnings
@name "Circlize Points"

main{
//Set all points to the same distance from a common center
cp = <0,0,0>;
bb = @<0,0,0>,<0,0,0>@;

selmode(USER);
//Faster, less accurate center point method...
bb = boundingbox();
cp = center(bb);

//Faster Method to determine max distance
d = -1;
e = cp - bb[1];
if( e.x > d ) d = e.x;
if( e.y >= d ) d = e.y;
if( e.z >= d ) d = e.z;

editbegin();
pts = points;

//now, make all the points that distance...
for(i=1; i<= pts.count();i++)
{
tv = normalize(pointinfo(pts[i]) - cp);
np = cp + (d * tv);
pointmove(pts[i],np);
}
editend();
}

Planar Circlize:

@warnings
@name "Planar Circlize Points"

main{
//Set all points to the same distance from a common center
cp = <0,0,0>;
bb = @<0,0,0>,<0,0,0>@;

selmode(USER);
//Faster, less accurate center point method...
bb = boundingbox();
cp = center(bb);

//Faster Method to determine max distance
d = -1;
e = cp - bb[1];
if( e.x > d ) d = e.x;
if( e.y >= d ) d = e.y;
if( e.z >= d ) d = e.z;

editbegin();
pts = points;
pcnt = pts.count();
//Let's make a surface normal for a plane!
vA = pointinfo(pts[1]) - cp;
vB = pointinfo(pts[2]) - cp;
N = normalize(cross3d(vA,vB));
//And solve for D for the centerpoint
D = -(dot3d(N,cp));

//Move the points into the plane defined by N, then make them equidistant around CP
for(i=1; i<= pcnt;i++)
{
tp = pointinfo(pts[i]);
//First, move the point to the plane...
// If N dot P + D != 0, the result is the distance from the plane
tD = (dot3d(N, tp)) + D;
tp += N * -tD;
//Then make it equidistant from the center
tv = normalize(tp - cp);
np = cp + (d * tv);
pointmove(pts[i],np);
}
editend();
}

jeric_synergy
09-19-2015, 12:38 AM
Kudos to you for chipping away at it-- I hope everybody finds it useful. :bowdown:

And again, thanks for the code example. Non-commercial LSCs drive me crazy! If you're not going to sell it, why compile it???

ernpchan
09-19-2015, 01:48 AM
If you're not going to sell it, why compile it???

It's possible there's code that's in scripts that they are selling or code that they're not allowed to release due to prior commitments.

Kryslin
09-19-2015, 09:58 AM
Jeric : What Ernpchan said; A programmer who writes a script who works for a studio may not be able to release the source code, as doing that may violate the terms of his employment, since his employer owns whatever he makes. However, by compiling it, he can get a useful tool out to people who need it.

If I've had any problems with the community, it's that many of the script writers don't or can't share information, for whatever reason. If my source code helps someone else... Cool.

I keep seeing ways to improve things, but at this point, the improvements are refactoring, to make it easier for me to read / understand (using a foreach() loop, moving a block of code to a function... that kind of stuff) rather than making it more efficient.

lightscape
09-19-2015, 09:11 PM
Thanks for this Kryslin. Ever had time to collect all those useful tools you created for lw? I think you mentioned it before.

Also empchan has a not so known but extremely useful plugin that I use atleast 100 times a day. Clear modeller. :D
Check out his website.

Kryslin
09-20-2015, 03:34 PM
I have about 30 finished scripts, some very useful (like Build Null Object, mass Record Pivot Rotation, circlize points, quad poles, hair tools...) and others not so useful (fractal landscape generator using simplex noise) for modeler and layout. The actual number might be a bit more.

I'm working on securing new web hosting for my various projects, since my previous host won't give me the password to my webspace...

OjN
09-20-2015, 06:37 PM
Thanks Kristin:)

jeric_synergy
09-20-2015, 08:06 PM
I have about 30 finished scripts, some very useful (like Build Null Object, mass Record Pivot Rotation, circlize points, quad poles, hair tools...) and others not so useful (fractal landscape generator using simplex noise) for modeler and layout. The actual number might be a bit more.

I'm working on securing new web hosting for my various projects, since my previous host won't give me the password to my webspace...
Outstanding, looking forward to it.