GMesh package released

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
theeth
Posts: 500
Joined: Wed Oct 16, 2002 5:47 am
Location: Montreal
Contact:

GMesh package released

Post by theeth »

Hey guys,

In the last month, I've been working on a mesh wrapper
to facilate certain operations often used in export or
just plain mesh manipulation.

The result was a package which I called GMesh (generic
mesh).

There's still some rough corners (converting from
NMesh could definitly be faster), but I thought I'd do
a first release and then we can see where it's going
to go from there.

GMesh is distributed under the LGPL.

(following bits are adapted from the docs)

GMesh is a generic mesh wrapper around Blender's NMesh
module.

Geometry structures in GMesh contains two-way links to
their subdata, meaning that faces are made out of
vertice and edges and that those element know which
face they are part of and so on, which makes a lot of
the operations much simpler and faster than using
straight NMesh.

GMesh has the following features:

* Powerful auto smoothing function
* Precise normal recalculation (better than
Blender's own)
* High level geometry splitting function (used in
the built in per image and per material split
functions)
* Face to Vertex UV conversion (can be used to
split UV islands)

Docs (generated from epydoc) are online there:
http://www.elysiun.com/~theeth/gmesh/GMesh_doc/
The docs also include some simple and less simple
examples.

A demo (avi/XVid compressed) showing the result of the
smoothing function can be downloaded there:
http://www.elysiun.com/~theeth/gmesh/Demo.avi
This demo shows a cone with its base stretched in a
point, an object that's rather hard to smooth
correctly (as demonstrated). The video is a
comparaison between Blender's autosmooth function,
GMesh's autosmooth function using normals recalculated
in Blender and GMesh's autosmooth using GMesh's normal
recalculation.

GMesh can be downloaded (including docs) there:
http://www.elysiun.com/~theeth/gmesh/GMesh.zip
The zip containts a single folder containing the GMesh
package. You can put it in your user defined script
folder or in the python lib or site packages folder.

Enjoy!

Martin
Life is what happens to you when you're busy making other plans.
- John Lennon

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

Post by kitsu »

I've had a peek at your code and I like this module very much! This is a much nicer and more pythonic interface to mesh objects. Besides making it simpler to work with Blender mesh data there is also a lot of utility packed in there. There are a couple tricks I would add to make it more user friendly. It might be nice if you could get at the x/y/z values of a vert more directly:

Code: Select all

def __getattr__(self, name):
	if name == "x":
		return self.co[0]
	elif name == "y": #etc. etc.

def __setattr__(self, name, vaue):
	if name == "x": # You may want to check that your getting a number here
		self.co[0] = value # or just let it cause an exception on its own
		return None
	elif name == "y": # etc.
So you could do "for vert in face: vert.z = 0" or some such. It just makes a vert seem more like an object. It would also be nice if you overloaded addition and subtraction for meshes and faces e.g. "face += vert" adds the vert to face. Then maybe raise a value error when a face contains more then four verts. I definatly think this should be included with Blender. This is a great example of something I've been thinking for a while now, but I'll leave that for a new thread. Great job and thanks.

theeth
Posts: 500
Joined: Wed Oct 16, 2002 5:47 am
Location: Montreal
Contact:

Post by theeth »

Thanks for the suggestions. I agree, it would make the vertice a little easier to manipulator. I'm not sure about the operator overloading though, I think it would just encourage criptic coding and not really give any added understanding in this case. Especially when you could end up with stuff like:

Code: Select all

mesh += face + v1 + v2 + v3
Again, thanks for the comments. :)

Martin
Life is what happens to you when you're busy making other plans.
- John Lennon

malCanDo
Posts: 1
Joined: Mon Oct 21, 2002 1:44 pm
Location: Ireland
Contact:

Post by malCanDo »

Does the wrapper allow for easy access of the normals of the vertices of a face?

Ie it auto handles the two cases ( one normal per face, individual normals per face ), so, just like you would ask for the vertices ( eg 3 or 4 ) of a face, you now ask for the normals ( same number ) of the face.

Regards...
Mal

theeth
Posts: 500
Joined: Wed Oct 16, 2002 5:47 am
Location: Montreal
Contact:

Post by theeth »

The normal is on the vertex, so you can do face.v[index].no directly to get the normal of a vertex in a face.

Martin
Life is what happens to you when you're busy making other plans.
- John Lennon

malCanDo
Posts: 1
Joined: Mon Oct 21, 2002 1:44 pm
Location: Ireland
Contact:

Post by malCanDo »

Hi Martin,

I thought that, if the model was using flat shading, that the face stored the single normal vertex, and that vertex normals were only used when the face was smoothed.

Will test when I get a chance...
Mal

Post Reply