Breaking intersected surfaces into separate meshes

Hi all,

I was wondering if any of you could help me out. I got this script that basically redundantly creates a motion path and snapshot of a given object that is to be duplicated along multiple cureved paths. My use for this is for creating road paths. However, I am having the darnest hard time trying to resolve the question, what do you do when 2 or more given roads intersect with each other. I have 2 images to demonstate my situation, the first being what does 2 intersected roads look like after running the motion path and snapahot script, and the second being what I need for the meshes to happen. As you can see in the second image, each road needs to be its own mesh, this way I can texture the meshes accordingly. If anyone has an idea, please let me know.

you'd be off better by doing this before turning the curves into a road

when your curves are snapped that makes things easier

you must find when two paths cross eachother (intersect curve may help out) and at these intersection points cut & prune the surrounding curves by an arbitrary value so that your roads will leave an open space at any T-junction (or cross section)

you could intersect all curves and at all intersection points found create a circle, then cut all curves using all circles and delete any segments that are inside the circles to clear all your junctions of roads

the remaining task is to somehow store what curves have cut eachother, so that you can group the end points together (all end points created by cutting one such circle belong in one group) and then place geometry between them

How you go about that is up to you but you could create predifined shapes for T junctions, splits, cross sections, 5 roads coming together etc, then use clusters which you snap to the points in the group and aim to the curve tangent

Edit: just made a little test by taking a plane (without divisions), extruding it's edges outwards and making a little constrain & cluster construction

Every extruded edge gets a cluster, at this position I also place a locator
Then in the direction of the locator  I add another locator, the first aims to the second, the first locator also parent constraints the cluster

This way the locators can be placed  at the first 2 CVs of a curve to have the cross section attach in the right direction, repeat it 4 times for a cross section and there you go

THe only thing remaining are the  4 original vertices, those I give one cluster per vertex and then one vertex gets constrained by it's adjacent connection locators

Trevor, this was really unexpected, but in a good way. It is just I think I need to take some time to sink this all in. However, in the mean time, I need to ask some qeustions about your method. This plane that you have created and extruded outwards, is this a surface plane or a polygonal plane? Second, and I quote...

 
and which direction are you referring to? Thirdly, I am assuming that the yellow lines with the yellow dots are the original curves and the circles are used for the cutting and prunning? 

I'm using polygons for this. The yellow dotted curves are indeed the original road curves, the circles are the intersection curves I used to cut out the centers of the crossroads (circles were placed at the intersection points of the original curves before they were cut). The circles can also be deleted when you're done.

The direction is from the center of the cross section towards the locator (which is also the center of the edge at which we wish to continue the street)

So essentially I make a reference point in the center of the cross section (where also the circle is placed), put a locator there.

Then I cluster the vertices of an edge I wish to attach to another street and put a locator at the spot of that cluster.

Then I duplicate that locator, snap it's pivot to the first locator and then snap the object back on the second locator, offsetting it twice as far from the center as the second locator.

Then I aim the second locator to the third locator, last I parent the cluster to the second locator, the first locator can be deleted. The second locator should be at the end CV of a curve, the last locator at the next CV for the cross section's road to align to the bitangency of the curve and match up with any extruded roads you already have.

Ohhhhhhhhhh, ammmmmm I think I see what you did in the example. you used a pre-defined cross-road and are attaching the end edges to the edges that are created from the curve. Am I right? If so, I would like to lean off from doing it that way because from what I see, if the intersection is not perfectly 90 angles, the back vertices creates harsh angle as you can like in your 4 sided cross section example above.

I was fooling around the other day and found that it is better to  leave out the middle part, I calculated the end point and bitangent of the curve to offset points sideways from each curve end to create proper road attachments and used createPolygon to wrap around the intersection so that there's a solid looking polygon there instead of having the roads extend a little further (unlike in the example above in which I did indeed use a predefined mesh).

The only problem I faced was that sharp intersections give flipped faces, so maybe you should find a way to cut the curves further down the road until their end-points are at least a certain distance away.

Trevor,
Actually, I been working too, and I think I have come up with something. So far, I have a script that finds the intersect and places a circle. For now the radius is set to 1, but I think I can make this a parameter that the user can specify when I get this sript working. I then see that I can use the cutCurve command, which produces detachCurve nodes. If I can grab these nodes through listConnections, and know which curvers are inside the cirlcle, then I can continue from there. However, I am not sure if there is a mel or python feature that can tell me which curvers are inside the circle. Is there? 

Here is my code so far

IntersectCurve -ch 1;
string $IntCrves[] = `ls -type curveIntersect`;
string $connections[];
string $IntCrvCircle[];
float $vCoords[];
float $uCoords[];
float $pos[];
string $tempCircle[];
 
for($i=0; $i<size($IntCrves); $i++) {
    clear($connections);
    clear($uCoords);
    clear($vCoords);
    $connections = `listConnections -source 1 -destination 0 -plugs 0 ($IntCrves[$i]+".inputCurve1")`;
    $uCoords = `getAttr ($IntCrves[$i] +".p1")`;
    $vCoords = `getAttr ($IntCrves[$i] +".p2")`;
 
    if ((size($uCoords) > 2) || (size($vCoords) > 2)) {
        error "multiple parameters are not supported.";
    }
    else {
        if($uCoords[0] == 0) {
            if ($vCoords[0] == 0) {
                error "no parameters found";
            }
            else
                error "parameter was found on vCoord"; //$pos = `pointOnCurve -pr $vCoord -p $connections[0]`;
        }
        else {
            clear($tempCircle);
            $pos = `pointOnCurve -pr $uCoords[0] -p $connections[0]`;
            $tempCircle = `circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 4.5 -d 3 -ut 0 -tol 0 -s 8 -ch 1 -name ("Intersect_")`;
            $IntCrvCircle[size($IntCrvCircle)] = $tempCircle[0];
            setAttr ($IntCrvCircle[size($IntCrvCircle)-1] +".translate") $pos[0] $pos[1] $pos[2]; //$myPos[0] $myPos[1] $myPos[2];
        }
    }    
}

 

to find objects inside the circle what you could do is use

exactWorldBoundingBox

on all new / cut curves , then calculate the center

(bb[3]-bb[0], bb[4]-bb[1], bb[5]-bb[2]) 

and measure the distance between the circle center and bounding box center,

dist = sqrt( (center[0]-circlePos[0])*(center[0]-circlePos[0])+(center[1]-circlePos[1])*(center[1]-circlePos[1])+(center[2]-circlePos[2])*(center[2]-circlePos[2]) )

if this is less than the circle radius then it's inside and you should delete it

this may give issues because if you have two curves intersecting and draw a circle around that intersection it's bounding box center will still be inside that intersection no matter how far large & far away from everything your surrounding cicle is, but if all roads intersect and aren't too long and complex you'll be fine

Ok, so I have done some studing with the curveIntersect node and I have found some interesting results. I have found out that after cutting all of the curves based on their intersections, I can grab a list of all of the connected intersecting curve nodes each curveShape node has, which gives me the beief that it can also tell me the group of all connected curveShapes that intersect each other. Here is the code that creates the print out info....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

//convert selection from curve node to curveShape node
string $cvs[] = ls -dag -leaf -sl;
string $connections1[];

//loop thourgh all of the curveShape nodes
for($i=0; $i<size($cvs); $i++) {
//print current cuvreShape node
print($cvs[$i] + "\n");
clear($connections1);

//collect all curveIntersect nodes that are connected to current curveShape node
$connections1 = `listConnections -source 1 -destination 1 -type curveIntersect $cvs[$i]`;
for($c=0; $c<size($connections1); $c++) {
    print("\t" + $connections1[$c] + "\n"); 
    print("\t\t"); print(`listConnections -source 1 -destination 0 -plugs 0 ($connections1[$c] + ".inputCurve1")`);
    print("\t\t"); print(`listConnections -source 1 -destination 0 -plugs 0 ($connections1[$c] + ".inputCurve2")`);
    print("\n");
}
print("\n");

}

An example of this code above, the diagram below, starting with selecting curveShape27, it states that curveIntersect2 and curveIntersect1 are connected to this curveShape node. Originally, from the diagram below named Group1, curveShapes 27, 28 , and 27DetachedCurve2 forms a "T" intersection. curveShape27 is the top->left->tail curveShape27DetachedCurve2 is the top->right->tail and curveShape28 is the bottom->tail. So if you look at this diagram, you can see that curveShape27 and curveShape28 both have the same curveIntersection names called curveIntersect2. So in reality, you could say that you can cancel out one of them. In addition, curveIntersect3 and curveIntersect1 share the same curveShape named curve27detachedCurve2. Therefore, you could technically just canel out all info from curveShape27 and read off the data just from curveShape28, which you can then see that the following is true...curve28 is the bottom tail because curve28 is in both intersectionscurve27 is the top->left-tail because it is not the detachedNameand curve27detachedCurve2 is obviusly the top->right->tail .... now this all sounds great on paper, but I am having a bit of troubles finding the patterns and relations with programming. Therefore, if anyone could help....

I wander if I should start a new topic? True, this is still under the same problem, but it has now become a totally different question from the topic title.

If you wonder then yes you need a new thread.