PDA

View Full Version : Node / node tree to get edge length/ 2p poly lenght or part size?



dnch
12-12-2017, 06:49 AM
is there a way in layout nodes to get edge length? or 2point poly length? could be also part size (if i make those 2p polys into parts by unwelding)?
i want it to simulate Plexus behavior by changing transparency of a polygon dependent of its lenght

Sensei
12-12-2017, 08:21 AM
You can use Point info node from DPKit,
two times, for two different vertexes by index,
then calculate length of vector using Math > Vector > Distance.

MonroePoteet
12-12-2017, 09:36 AM
Is the geometry on which you want to do this dynamic in Layout? In other words, does it have displacement plug-in(s) applied such that the points / polygons defined in Modeler aren't static, and they stretch or contract during the scene? I'm guessing "yes".

RE: DPKit Point Info, the issue is how to relate a particular pair of points to a particular 2-point polygon (or a 3+ set of points to a polygon). LScript provides access to the polygon.points[] array, but I don't see an equivalent Node to take a Polygon index and process each pair of nodes. If your polychain is linear (i.e. created from a single sequence of points rather than polygons in a more complex mesh), then you can calculate the length of each 2-point poly using the method Sensei indicates, but then determing and setting the transparency of the associated polygon is the issue. I think! :)

mTp

Sensei
12-12-2017, 09:44 AM
Open Modeler, select point/edge/polygon, press i to Point Info/Edge Info/Polygon Info. There is index of element.

If plugin uses enumeration from 0, you will need to subtract 1.

Sensei
12-12-2017, 10:10 AM
but then determing and setting the transparency of the associated polygon is the issue. I think!

Reading transparency would be an issue.

But he wants to set it (not read it).. ? I think. So just Math > Vector > Distance, truncate it to 0...1 range (Gradient?).. Then to Transparency, and the longer edge, the more transparent surface will be.

MonroePoteet
12-12-2017, 02:04 PM
I don't know if it will meet your needs, but attached is a sample scene which might provide some ideas / solutions. I tried figuring out a way to avoid separate "Parts" and Surfaces as described, but couldn't get it to work.

138806

The basic setup was to create a 2-point poly chain in Modeler using Add Points (+) and Create=>Polygons=>Create Poly Chain. This was then Unwelded to provide "Parts" for the DPKit Part Info node. I also selected each subsequent 2-point polygon and set it a separate Surface (simply named 1 through 8 in this case), which might be prohibitive for a many-segmented polychain, although there's probably a plug-in to assign separate surfaces to subsequent polygons in an object.

The node setup is then this, copied from Surface 1 and pasted to all eight surfaces using SHIFT-Click on 2 then 8:

138801

which is the Subtract & Length approach suggested by Sensei, but using the Part Info Index to calculate the index of each corresponding pair of points in the polychain:


Part Info=>Index (zero based) * 2 + 1 = first point index of the 2-point poly
first point + 1 = second point index of the 2-point poly


The length is then calculated accordingly using the indices into Point Info nodes. Note the Divide and Clamp nodes after the Length is calculated. These nodes provide scaling to determine how long the distance between points must be for the segment to start vanishing, and the minimum and maximum transparency values. These need to be set according to the scale of your geometry.

For testing, the sample scene just uses X and Y scaling on the 2-point polychain to expand and contract the distance between points, but it should work with displacement plug-ins or any other modification to the point locations.

Hope it's something close to what you're trying to do!

mTp

MonroePoteet
12-12-2017, 02:07 PM
Reading transparency would be an issue.

But he wants to set it (not read it).. ? I think. So just Math > Vector > Distance, truncate it to 0...1 range (Gradient?).. Then to Transparency, and the longer edge, the more transparent surface will be.

Yes, my previous response was mis-worded. It should have been worded:


but then determing the associated polygon and setting its transparency is the issue.

Sorry!
mTp

P.S. BTW, I should have posted this first rather than after the potential solution / sample scene earlier - take a look! :)

dnch
12-12-2017, 02:58 PM
thank you both! i was able to calculate the distance (with distance node, it outputs scalar directly) and remap it to whatever (transparency in my case, using gradient) but i was struggling with the point IDs.. i didnt realise LW sorts them in pairs by part!
clever solution MonroePoteet

dnch
12-12-2017, 03:03 PM
works exactly as I needed!
138810

EDIT: Should be in World Position to work with displacements!

dnch
12-12-2017, 03:22 PM
aditional question.. is there a way to connect all points to each other with 2 point polys in modeler?

Sensei
12-12-2017, 03:29 PM
which is the Subtract & Length approach suggested by Sensei,

Math > Vector > Distance is equal to

dx = x2-x1;
dy = y2-y1;
dz = z2-z1;
length = sqrt( dx^2 + dy^2 + dz^2 );

Sensei
12-12-2017, 03:33 PM
but then determing the associated polygon and setting its transparency is the issue.

If it would be just one polygon per entire mesh,
user could select polygon, then make weight map with initial value 100%.
Then in Layout read weight map using node, and then check if it's 1.0 (values 0.0 .... 1.0 would not be our polygon anymore).

Vertex Maps > Weight -> Math > Scalar > Logic -> (compare equal to) 1.0 -> true if it's our poly, false if it's not.

MonroePoteet
12-12-2017, 09:55 PM
aditional question.. is there a way to connect all points to each other with 2 point polys in modeler?

It depends on what you mean by "connect all points to each other". From the example you posted, you know how to create a convoluted 2-point polychain containing all points: select all points using double-quote in Point Mode, use Create Poly Chain to create a 2-point polygon between each successive pair of points. If there are N points, this creates (N-1) 2-point polygons.

If you mean create a 2-point polygon between each and every pair of points, I don't know how to do that other than an LScript (walk the points[] array, using addpolygon() to create a polygon between each unique pair). Note that the simple Part index to point-pair algorithm used in my sample scene won't work for an exhaustive point-pair set of 2-point polygons, since each point will be contained in more than two polygons of the total.

mTp

dnch
12-13-2017, 01:32 AM
Note that the simple Part index to point-pair algorithm used in my sample scene won't work for an exhaustive point-pair set of 2-point polygons, since each point will be contained in more than two polygons of the total.

mTp

not if you unweld them, and yes i mean between every and each of them
i should really learn some lscript basics hehe

MonroePoteet
12-13-2017, 01:47 PM
not if you unweld them, and yes i mean between every and each of them
i should really learn some lscript basics hehe

Well, the LScript for creating one (and only one) 2-point polygon between each unique pair of points is quite simple (included below), and the resulting 2-point polygons will not be "welded". However, since each of the N points in the point array may have 1, 2, ... up to N-1 2-point polygons as one of their end-points, determining the Point indices of the end-points given ONLY the "Part #" becomes more difficult.

For example, if you select 5 points for the LScript, Point #1 will have polygons created to Points 2,3,4 and 5 (for N-1 outgoing 2-point polygons). Point #2 will then have polygons created to Points 3,4 and 5, and so forth. Thus, given only the "Part index", you cannot use the simple algorithm in the previously posted sample scene to determine the correct end point's indices.

There's probably a simple equation to calculate the start / end points given the original number of points selected for the LScript, and given an iterative loop in the Node graph editor, it'd be easy. If I have the time I'll try to work out the formula.

mTp

-----------------------------------------

dnch
12-13-2017, 06:18 PM
thanks for the script! it does exactly what i want, there wasnt even a need for creating "one and only one" polygon between two points because i could ged rid of that using unify polys in modeler..

and the node network determining the point id from part id by just multiplying by 2 and adding 1 and 2 respectively works perfectly well .. i guess modeler reassigns new point ids after unwelding.. of course you have to keep the model 2point poly only with no "loose" points or 1 point polys

138849



Well, the LScript for creating one (and only one) 2-point polygon between each unique pair of points is quite simple (included below), and the resulting 2-point polygons will not be "welded". However, since each of the N points in the point array may have 1, 2, ... up to N-1 2-point polygons as one of their end-points, determining the Point indices of the end-points given ONLY the "Part #" becomes more difficult.

For example, if you select 5 points for the LScript, Point #1 will have polygons created to Points 2,3,4 and 5 (for N-1 outgoing 2-point polygons). Point #2 will then have polygons created to Points 3,4 and 5, and so forth. Thus, given only the "Part index", you cannot use the simple algorithm in the previously posted sample scene to determine the correct end point's indices.

There's probably a simple equation to calculate the start / end points given the original number of points selected for the LScript, and given an iterative loop in the Node graph editor, it'd be easy. If I have the time I'll try to work out the formula.

mTp

-----------------------------------------

dnch
12-14-2017, 03:59 AM
updated the script so you can input max distance between points

@version 2.2
@warnings
@script modeler
@name *Exhaustive2PointPolysD

main
{
reqbegin("Max lenght");
MyLenth = ctlnumber("Distance",1);

reqpost();
MyLen=getvalue(MyLenth);
reqend();
selmode(GLOBAL);
nPoints = pointcount();
if(nPoints <= 1) error("Please select at least two points.");

editbegin();
for (nOuter = 1; nOuter < nPoints; ++nOuter)
{
for (nInner = nOuter+1; nInner <= nPoints; ++nInner)
{
v1 = pointinfo(points[nInner]);
v2 = pointinfo(points[nOuter]);
d = vmag(v1-v2);
if(d<MyLen){
aThisPair[1] = points[nOuter];
aThisPair[2] = points[nInner];
addpolygon(aThisPair);
}
}
}
editend();
}