Finding an edge (algorythm found, need review)

Um. I thought it would be easy. Just loop through the vertices on two faces until you find the two vertices that create a common edge. I tried to do that by comparing the vertices’ coordinates. Anyway, needless to say, I’m lost.

The scenario:
Two square faces meeting at only one edge. Once the edge is found, a bevel will take place based on two parameters: resolution and radius.

Needed (at least for now):
An algorithym to find the edge, and subsequently store (in a managable order) the adjacent edges needed to calculate the angles (I think I’ve already gotten the bevel algorithym, so don’t worry about that).

Future possibilities:
The user selects two faces, the script bevels the edge between them.

This is only an educational exploration to expand my knowledge of 3D programming operations. So don’t get your hopes up for a useful tool.

you can check if nmvert objects are the same by using ==, but you will have to compare values if you want to act is if verts at the same spot are all one.

You probably ran into problems because there can be 4 verts per face, and the order they come in does not say much about the face (other than which side is up). So you have to check if the same two verticies are used in two faces, and they have to be next to each other in the order of vertcies in the face (only a problem for quads)

or, if you have verticies 1 2 3 4 5 and 6
a face that uses (in order) 1 2 3 4 is not adjacent to a face that
uses (in order) 5 2 6 3

they share verticies 2 and 3, but they don’t share any edges.

that said, the face with verticies (in order) 1 2 3 4 would be sharing an edge with a face with the verticies
(in order) 5 6 3 2

this can get really complex fast, and seems like something I will have to do if I ever act on one of my [newer] script plans.

A while back I wrote this:

http://www.flippyneck.com/wip/meshplus.zip

It’s a Python class that allows you to access edges and adjacent faces from a Blender mesh. You can also see it at work in my ‘SLiM’ script for drawing outlines in Blender (do a search of the WIP forum for ‘SLiM’ if you’re interested).

I don’t think it’s a complete solution to your problem as there would be no way for the user to pick faces, but it may give a few pointers as to how to go about your script. Good luck.

Okay, it was easier than I thought to actually find the edge. Just like you said, z3r0 d, you can check if nmvert objects are the same by using ==. A quick nested loop through the two faces comparing the actual vertice objects was easy. I’m just very ignorant about how vertices are stored, and didn’t know that. Great! That was about all I could decipher from your post, z3r0 d, but it was all I needed, hopefully.
The hard part came in when I had to determine some way to store the other vertices in the faces that determine the angle that the faces meet. I did that by storing the index of the vertice object on each face, and then created a function that would return the adjacent vertices’ coordinates. I’m still a little unsure about the performance of the algorythm, but everything looked okay in the few tests I did.
Here’s the code, if anyone has suggestions on how to optimize it, I’d appreciate it.


###########################################################
#
# Edge Finder
#
# This script finds the edge between two faces, and stores
# the coordinates of the vertices that determine the angle
# of the edge
#
# by Levi Schooley (aka. reD_Fox)
#
###########################################################

import Blender
from Blender import *

obj=Object.GetSelected()[0].data
face1=obj.faces[0]
face2=obj.faces[1]
indx1=[]
indx2=[]

#
#Function declarations
###########################################################

#findAdj(face face, list[vertindx1,vertindx2] indx), finds
#and stores the coordinates of the adjacent vertices given
#the index positions of the edge such that va is adjacent
#to indx[0] and vb is adjacent to indx[1]
def findAdj(face, indx):
	n=len(face.v)-1
	if (indx[0] == 0 or indx[0] == n) and (indx[1] == 0 or indx[1] == n):
		if indx[0] == 0:
			va=face.v[1].co
			vb=face.v[n-1].co
		else:
			va=face.v[n-1].co
			vb=face.v[1].co
	elif (indx[0] == 0 or indx[0] == n) or (indx[1] == 0 or indx[1] == n):
		if indx[0] == 0 or indx[0] == n:
			if indx[0] == 0:
				va=face.v[n].co
				vb=face.v[2].co
			else:
				va=face.v[0].co
				vb=face.v[n-2].co
		else:
			if indx[1] == 0:
				va=face.v[2].co
				vb=face.v[n].co
			else:
				va=face.v[n-2].co
				vb=face.v[0].co
	else:
		va=face.v[2*indx[0]-indx[1]].co
		vb=face.v[2*indx[1]-indx[0]].co
	return (va,vb)

#
#Main Program
###########################################################

#Store the index position of the vertices bordering the edge
for v1 in face1.v:
	for v2 in face2.v:
		if v1 == v2:
			indx1.append(face1.v.index(v1))
			indx2.append(face2.v.index(v1))

#Check to make sure there is a valid edge
if len(indx1) != 2:
	print "Not a valid edge!"
else:
	(v1a,v1b)=findAdj(face1,indx1)
	(v2a,v2b)=findAdj(face2,indx2)
print ""

Thanks!

Levi Schooley