Fill Mesh problem

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
buschhardt
Posts: 0
Joined: Fri Jan 21, 2005 4:14 pm
Location: Cairo
Contact:

Fill Mesh problem

Post by buschhardt »

Hallo,
I've a problem and I hope You can help me out. I got a list of vertex points, that are representing a polygon (only 2D z-axis allways 0.0) and I want make that polygon(s) in Blender. Here my way:
1. I make a new NMesh object
2. I put all vertex in this mesh
3. I connect all vertexes with their neighbors with a NFace
4. I select all vertexes
5. Write the mesh object back
Now the problem:
I want to fill the mesh with faces (in Blender: Mesh-Faces-Fill "Shift+F"). It's possible in Blender-Python?

I can not make this by Hand because that are ca. 8000 polygons.

Thank you
Here is the example-script:

Code: Select all

import Blender

punkte=((0.0,0.0,0.0),
(1.0,2.0,0.0),
(3.0,3.0,0.0),
(2.0,0.0,0.0))

#neues Mesh Object erstellen
neu=Blender.NMesh.New()

for i in punkte:
	a=Blender.NMesh.Vert(i[0],i[1],i[2])
	neu.verts.append(a)

for i in range(len(neu.verts)):
	b=Blender.NMesh.Face()
	b.append(neu.verts[i])
	if i==len(neu.verts)-1:
		b.append(neu.verts[0])
	else:
		b.append(neu.verts[i+1])
	neu.faces.append(b)

#alle verts selectieren
for i in neu.verts:
	i.sel=1

Blender.NMesh.PutRaw(neu,"sodom_is_near")

#in den editmode umschalten
Blender.Window.EditMode(1)

#fill aufrufen
# Shift-F ???

#in den editmode ausschalten
Blender.Window.EditMode(0)

paleajed
Posts: 0
Joined: Fri Feb 11, 2005 1:19 pm

Post by paleajed »

You don't have to fill the faces yourself, this is done automatically when you create them.

You have to add your verts to mesh.v (list of mesh verts), not the mesh object itself (which is only a wrapper that points to the internal mesh structure Blender keeps in memory).

This is the proper way of doing this:

Code: Select all

import Blender
# following line so you don't have to type "Blender." every time.
from Blender import NMesh, Window, Object, Scene

punkte=((0.0,0.0,0.0), 
(1.0,2.0,0.0), 
(3.0,3.0,0.0), 
(2.0,0.0,0.0)) 

#neues Mesh Object erstellen 
neu=Blender.NMesh.New() 

b=Blender.NMesh.Face()
for i in punkte: 
   a=Blender.NMesh.Vert(i[0],i[1],i[2]) 
   neu.verts.append(a)
   # following line is correct way of adding a vertice to a face
   b.v.append(a)
neu.faces.append(b)   

# No reason for this:
#alle verts selectieren 
#for i in neu.verts: 
#   i.sel=1 

# you need to link your mesh to an object
sword_of_justice = Object.New("Mesh", "ill_stay_in_gomorra_then")
sword_of_justice.link(neu)

# no need for this
#Blender.NMesh.PutRaw(neu,"sodom_is_near") 

# and link this object to a scene
scene = Scene.GetCurrent()
scene.link(sword_of_justice)

# redraw 3d view to show object properly
Window.Redraw(Window.Types.VIEW3D)
________________________________
Don't feed your ego, feed the duckies...

buschhardt
Posts: 0
Joined: Fri Jan 21, 2005 4:14 pm
Location: Cairo
Contact:

Post by buschhardt »

Hi paleajed,

:) nice try - ok my example isn't correct: in this example i have 4 Points, but in the realworld I've polygons with more then 4.

The problem is: how can I make a polygon fill up with faces? I would use the "fillmesh"-function, but my knowledge about C is not so good to - write a patch :)

The reason for selecting all vertexes is that the "fillmesh"-function need it.

Thank you write Thomas

buschhardt
Posts: 0
Joined: Fri Jan 21, 2005 4:14 pm
Location: Cairo
Contact:

Post by buschhardt »

Has really no one a idea or a livesaving patch.
Again my problem:
I have a polygon full of vertexlists (z is everywhere 0)

vertexlist1=[x,y,z]
vertexlist2=[x,y,z]
vertexlist3=[x,y,z]
vertexlist4=[x,y,z]
vertexlist5=[x,y,z]

polygon=[[vertexlist1],[vertexlist2],....]

now I want to make a polygon (mesh) in Blender by using Python. The only problem is to fill this mesh. I found some (really huge) algorithms to do this, but why its not possible to use the Blender-own function "fill_mesh" in the sourcefile "editmesh-tools.c"?
Its here the wrong place to ask this please drop me a mail.

Bye wrote Thomas

PS: No I can't do this "by hand" because there are more then 8000 polygons and they have all different numbers of vertexes.

M_i_c_h_e_l
Posts: 6
Joined: Mon Dec 29, 2003 1:59 pm

Post by M_i_c_h_e_l »

Hi buschhardt!

The problen is that Blender can only create faces with 3 or 4 vertices.
If you have an n-Gon to fill you can select all vertices of the n-Gon and press shift-F. This fills the n-Gon with triangles. After that you can press F again to combine all these triangles to a Blender n-Gon (all the inner egdes are hidden)

So your problem is filling an n-Gon with triangles first - That is simulating shift-F as you said.

This code does it (paste it into the code you posted first):

...
#fill aufrufen
# Shift-F ???
winid = Blender.Window.GetScreenInfo(Blender.Window.Types.VIEW3D)[0]['id']
Blender.Window.SetKeyQualifiers(Blender.Window.Qual.SHIFT)
Blender.Window.QAdd(winid, Blender.Draw.FKEY,1)
Blender.Window.QHandle(winid)
Blender.Window.SetKeyQualifiers(0)
...

Just simutates pressing Shift-F...

Hope it helps!
Michael S.

buschhardt
Posts: 0
Joined: Fri Jan 21, 2005 4:14 pm
Location: Cairo
Contact:

Post by buschhardt »

Thank you very much! That was exactly what I'm looking for! :) :D :lol:

joeri
Posts: 96
Joined: Fri Jan 10, 2003 6:41 pm
Contact:

Post by joeri »

M_i_c_h_e_l wrote:Hi buschhardt!
winid = Blender.Window.GetScreenInfo(Blender.Window.Types.VIEW3D)[0]['id']
Blender.Window.SetKeyQualifiers(Blender.Window.Qual.SHIFT)
Blender.Window.QAdd(winid, Blender.Draw.FKEY,1)
Blender.Window.QHandle(winid)
Blender.Window.SetKeyQualifiers(0)
...

Just simutates pressing Shift-F...
Wauw! Why do I see this only now?
All blender keystrokes can be captured into a macro?

M_i_c_h_e_l
Posts: 6
Joined: Mon Dec 29, 2003 1:59 pm

Post by M_i_c_h_e_l »

Wauw! Why do I see this only now?
All blender keystrokes can be captured into a macro?
Yep - well not really all...
If a command can be invoked by a hotkey you can use this method. But there's one catch: If the command opens a popup or submenu you cannot sent commands to it (at least i don't know how). For example: This Shift-F works because there's no confirmation or further selection required. If you'd like to do the same again using the F-Key only (to join the triangles just created to form a Blender n-Gon) this method does no longer work. Pressing F only would open a popup where the user is asked to confirm the conversion (usually just press return). It's not possible send the return character to this popup using the method here...

Post Reply