using a face as a boundary and finding connected faces

I’m not to sure if it’s better to post this in the python forum or the game forum…

I found this information which I’m sure will be useful http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/Advanced_Tutorials/Python_Scripting/Export_scripts

But I’m not sure how to use this information for my application. What I’d like to do is (1) restrict a game actor within the limits of a face and also (2) find connected faces. Yes I’m trying to make a navigation system. If anyone has knowledge on either I’d be very grateful.
Thank you.

A map of adjacent faces to a face for ALL faces in a mesh is the fif dict in the following code:

from Blender import *
import bpy
import MeshUtils

sce = Scene.GetCurrent()
editmode = Window.EditMode()
Window.EditMode(0)
ob = Object.GetSelected()[0]
me = ob.getData(mesh=1)
ekif = MeshUtils.Make_ekif(me)
fif = MeshUtils.Make_fif_ekif(ekif)

print ob.name
print fif[2]
print

Window.EditMode(editmode)


It prints the object name and adjacent faces for a face with index 2. For the Blender’s default cube the result is [0, 1, 3, 5]

You can download my MeshUtils module with AUX procs for dealing with meshes following the links given here.

Hope this helps.

This looks useful though I’m not entirely sure how to use it. Do you happen to have any documentation for this? It looks like there might be a lot of interesting possibilitys.

Yes, many possibilities do exist! I agree with that :wink: That is why I stick to the “module approach” :slight_smile: There are a lot of procs/functions in MeshUtils module which implementation you dont need to know but just USE… Me too :wink: After their fine tuning of course :wink: I use such procs/functions from that module (and other mine 3 listed in my support thread + another 3 NOT listed there) thousand of times during my development work on certain problem. This saves me a lot of time and coding :spin:

MeshUtils module contains many functions like the listed in my previous posting code: They are similar and deal with mesh description and such. For example, the interface to these procs is:

def Make_vie(me):
def Make_vif(me):
def Make_eiv(me):
def Make_fiv(me):
def Make_ekie(me):
def Make_ekif(me):  # edge keys (+ ed.index) in faces
def Make_fie_ekif(me,ekif):
def Make_fie(me):                                          #   <<   OK......... ???
def Make_fke(me):                                          #   <<   OK......... ???
def Make_ekf(me):
def Make_eif(me):
def Make_eif_ekif(ekif):
def Make_viv(me):
def Make_fiv_and_vif(me):
def Make_fif_ekif(ekif):
def Make_fif_flat_ekif(ekif,lst_nonPlanarFaces):
def Make_eif_faces(eif):
def Make_vie_set(me,lst):
def Make_viv_set(me,lst):
def Make_eiv_set(me,lst):

I think, those marked with (???) do have some problems. But it seems that it doesnt happend to me to use such a combination :wink: The list of combination is incomplete. But covers most cases.

How to read and use these? Letters v,e,f stand for verts,edges,faces; ek - edge key(s); flat means add in result ONLY the flat faces given in the lst_nonPlanarFaces list (comlicated, pls dont touch this issue now); set means to search for results only amongst the selected verts,edges,faces in Edit Mode - otherwise ALL are iterated; finally - the result of each function is ALWAYS a dictionary. For example, Make_vie() says "give me a dict with vert indices and corresponding edges which contain them. The result’s dict structure is {vi:ei} where vi is the i-vertex index (0,1,2…,n-1) of the mesh and ei is the i-edge index (0,1,2…,n-1) of the mesh which contains the said vi. You can easily print the result. For the default cube it is:

{0: [0, 1, 2], 1: [0, 3, 4], 2: [3, 5, 6], 3: [1, 5, 7], 4: [2, 8, 9], 5: [4, 8, 10], 6: [6, 10, 11], 7: [7, 9, 11]}

In the General module I have some general procs that give me the result in a more comprehensive form at the console (or in a file) such as:

vie =   8 elements
======================================================================================
0 - [0, 1, 2]
1 - [0, 3, 4]
2 - [3, 5, 6]
3 - [1, 5, 7]
4 - [2, 8, 9]
5 - [4, 8, 10]
6 - [6, 10, 11]
7 - [7, 9, 11]
======================================================================================

It looks better and more readable, heh :wink:

Make_fiv(), for example, will give you faces (indices) and their verts (indices). Make_ekif() - edge keys and their corresponding faces that use them, Make_viv() - verts with their adjacent verts (neighbors) etc… You can try them.

Hope you find this useful :wink:

Regards,

Wow. looks like I’ll have to play around with this for sure.:eek: