Vertices, Meshes, Faces and the API

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
kaiser
Posts: 0
Joined: Mon Nov 01, 2004 5:40 pm

Vertices, Meshes, Faces and the API

Post by kaiser »

I just have a couple of questions on how to do some things with the Blender API. I've looked through the documentation and tried some things, but some guidance would be great.

Right now, I'm using blender to draw some fairly simplistic 3D geometric shapes. It's nothing incredibly complex. Once I have these shapes drawn, I need to export the vertices for use in another program.

What I need to do seems like it should be fairly simple, but I haven't been able to get it to work out right yet. In my drawings, most of the vertices are connected to 3 or 4 other vertices. The program I'm exporting to will, if given two vertices will draw a line between them. Simple, right?

So, what I need is to be able to grab a vertex and then be able to grab all the vertices that it is directly connected to.

I'm assuming this information has to be contained somewhere in the mesh data, or face data, or something. But I haven't been able to find any documentation on where that would be.

Thanks for any help you guys can provide.

kitsu
Posts: 0
Joined: Sun Jun 06, 2004 8:08 am

Post by kitsu »

unfortunatly this will not be very easy but it is possible. This is what I came up with. I tried to get this to select the connected verts but it doesn't seem to work with the CVS version I'm using...

First making the quad:

Code: Select all

from Blender import *

scene = Scene.GetCurrent()
obj = Object.New('Mesh','container')
mesh = NMesh.New('mesh')

obj.link(mesh)
scene.link(obj)
obj.select(1)

mverts = mesh.verts
mfaces = mesh.faces

verts = []
verts.append(NMesh.Vert(0,0,0))
verts.append(NMesh.Vert(1,0,0))
verts.append(NMesh.Vert(1,1,0))
verts.append(NMesh.Vert(0,1,0))

mverts.extend(verts)

face = NMesh.Face(verts)

mfaces.append(face)
mesh.update()
Redraw()
Now get the connected verts:

Code: Select all

from Blender import *
	
obj = Object.GetSelected()[0]
mesh = obj.getData()
face = mesh.faces[0]
verts = face.v
	
#Selected vert is verts[0]
Window.EditMode = 1 #Should be Window.EditMode(1)...	
Redraw()
sel = verts[0]
sel.sel = 1 #select it

# Assuming quad faces, for each face:
attached = [] # Our list of connected verts
for i in range(len(face)-1):
	if face[i] is sel:
		if i == 0:
			attached.append(face[1])
			attached.append(face[2])
		if i == 1:
			attached.append(face[0])
			attached.append(face[3])
		if i == 2:
			attached.append(face[1])
			attached.append(face[2])
		if i == 3:
			attached.append(face[0])
			attached.append(face[3])
			
print attached
for v in attached:
	v.sel = 1
Does anyone know why Window.EditMode and NMVert.sel are not working?

jms
Posts: 33
Joined: Sat Oct 19, 2002 3:04 pm

Re: Vertices, Meshes, Faces and the API

Post by jms »

kaiser wrote:
So, what I need is to be able to grab a vertex and then be able to grab all the vertices that it is directly connected to. .
1/ find all faces conneted to a point :
http://jmsoler.free.fr/didacticiel/blen ... vertex.htm

2/ translate all these faces in segment:
faces to segment :
http://jmsoler.free.fr/didacticiel/blen ... egment.htm

3/ keep only the segments with the selected vertex, my script unweld do this operation:
http://jmsoler.free.fr/didacticiel/blen ... tm#exemple
Zoo-3D.Blender, Ze French-Speaking Community SKB My french book about Blender.

Post Reply