How to connect plygons without twisting?
-
On 16/06/2015 at 09:03, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 15
Platform: Windows ; Mac ; Mac OSX ;
Language(s) : C.O.F.F.E.E ; C++ ; PYTHON ;---------
I need to connect faces of an object to faces of itself. So, we are dealing with just one object but I guess this could apply even to two different objects.
Also, I just need to connect ONE face (four vertexes) with ANOTHER face (four vertexes).If I know the index of both faces (hence, I also know the indexes of all vertexes), I can easily determine what vertexes of each face are nearer.
So, knowing all that, how can I determine, after finding vertex A0 from polygon A and vertex B0 from polygon B, that are the closest vertexes, which direction must I follow in each polygon to connect all remaining vertexes without twisting?I think the Bridge command does that. So, what algorithm does it use?
-
On 17/06/2015 at 07:25, xxxxxxxx wrote:
Hi Rui,
I'm afraid, we are not allowed to reveal any C4D internals. Sorry.
-
On 17/06/2015 at 07:28, xxxxxxxx wrote:
I think the easiest approach would be:
you have 4 points "2 edges" that you want to bridge.
they will create 1 polygon, this polygon got 2 rails "bridge rails"
get length of these 2 rails, shorter length = correct polygon. -
On 17/06/2015 at 08:13, xxxxxxxx wrote:
-
On 17/06/2015 at 08:23, xxxxxxxx wrote:
Hi Rui.
Have you looked into the Neighbor class? I have used it to find loops.
You can use it to find the edges and polygons around the hole and that info could help you sort out the points.
Joe -
On 17/06/2015 at 13:41, xxxxxxxx wrote:
I was not wanting the exact internal Cinema 4D code
I was just asking for the steps that I should follow.
What I need to do, in code, is to make the coordinates of each of the four points of face A equal to the coordinates of each of the four points of face B. But I need to know how to find the order that I must follow at each polygon to make sure that the least amount of twisting occurs.
I believe that the Neighbor class would provide me with the loop but I already know what points I need. I just need to know what order must I follow. -
On 17/06/2015 at 19:15, xxxxxxxx wrote:
Hi Rui,
Here is a link to download source files for a CommandData plugin that fills a polygon hole using a point selection.
https://s3-us-west-1.amazonaws.com/pcuploads/fillpolyhole/fillpolyhole.zip
It uses the Neighbor class to find a loop around the polygon hole. This loop orders the points so they don't make a twisty polygon.
It's messy, long and untested, so I did not feel like posting it as a complete answer.
I'm sure there are better ways to do this, but the example works.
Hope this helps.
Joe Buck
-
On 18/06/2015 at 05:17, xxxxxxxx wrote:
Thank you for the code, Joe. It is, in fact, very confusing
I'm coding in Python and the problem is that, in Python, I can't get the list of edges of an object.
I already started fiddling with the Neighbor class but I still could not figure out how to get an ordered list of the four points that define a polygon.
Using the GetPolyInfo from the Neighbor class, I do get a list of edges. I assume they are ordered. But... I don't know how to get the points indexes that compose an edge -
On 18/06/2015 at 05:18, xxxxxxxx wrote:
Oh, by the way... I did found CPolygon.EdgePoints(edge) in the SDK, but that is for R16 and I want my code to work in R14 and R15 also.
-
On 18/06/2015 at 06:34, xxxxxxxx wrote:
Hi Rui,
Sorry the code is confusing, but it's a pretty hard thing you are trying to do and until you grasp the concept, it's probably useless. I spent days wrapping my head around finding edge loops. Here is an overview:
1. get a starting point(will be lowest index)
2. test other 3 points for an edge
> a. use neighbor to get the polys associated with the other 3 points
> b. test and see if original point and one of the 3 test points forms an edge in any of the polys from neighbor
> c. first found edge can end search.3. Now you have one edge and 2 points around the hole
4. Test remaining 2 points for an edge.
> a. use neighbor to get the polys associated with the remaining 2 points
> b. test and see if 2nd found point(point # 2 of edge #1) forms an edge with the 2 remaining points in any of the polys from neighbor.
> c. stop search as soon as an edge is found.5. Now you have 2 edges and 3 points around the hole.
6. Use the last found point(point #2 of edge #2) and see if it forms an edge with the polys associated with the remaining point.I already started fiddling with the Neighbor class but I still could not figure out how to get an ordered list of the four points that define a polygon.
The ordered list is in alphabetical order in CPolygon.a .b .c .d not Neighbor.
Oh, by the way... I did found CPolygon.EdgePoints(edge) in the SDK, but that is for R16 and I want my code to work in R14 and R15 also.
Write your own python function for R14 and R15 to test for an edge. Just go through each edge and see if you have a match: CPolygon a->b, b->c, c->d are actually edges.
Joe
-
On 18/06/2015 at 06:43, xxxxxxxx wrote:
Thank you, Joe.
I will try to implement that.
I needed something FAST!!! If we could only get a list of edges... -
On 18/06/2015 at 06:59, xxxxxxxx wrote:
Rui!!! The edges are in CPolygon! Please read entire previous post.
-
On 18/06/2015 at 08:49, xxxxxxxx wrote:
A fast test on a python script seems to be making it all work fine
It was, actually, quite easy:def getpoints(pli,poly) : ptlist=[] for side in xrange(4) : if side==0: p1=poly.a elif side==1: p1=poly.b elif side==2: p1=poly.c elif side==3: p1=poly.d ptlist.append(p1) return ptlist
Now I will try it on the plugin.
Thank you ALL