Converting a script from using NMesh To Mesh

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
etr9j
Posts: 0
Joined: Fri Mar 10, 2006 2:40 am

Converting a script from using NMesh To Mesh

Post by etr9j » Wed Mar 07, 2007 6:17 pm

I noticed that ideasman had changed a few scripts (the lightwave exporter comes to mind) from using NMesh to using Mesh. I'm pursuing changing the Sunflow exporter from using NMesh to Mesh, put I'm not sure the difference between the two and the advantages of of switching. More importantly, I'm not sure if switching is as easy as changing a line or two in the script or I need to do an enitre re-write of the mesh exporting. Any thoughts?

reD_Fox
Posts: 0
Joined: Sat Mar 12, 2005 2:56 pm
Location: Abilene, KS

Post by reD_Fox » Mon Mar 12, 2007 3:45 pm

Hey, I'm not really the one to be answering this, since it's been a while since I've used NMesh, and I don't think I've ever really used Mesh, but you've been sitting here for a while, so I thought I'd see what kind of help I could lend (for the future, sometimes the python forum over at blenderartists.org is a little more frequented http://blenderartists.org/forum/forumdisplay.php?f=11 ).
I'm not sure the difference between the two and the advantages of switching.
NMesh makes a copy of the mesh in memory. While this may be a nice thing in some circumstances, for an exporter that is just reading data, making a copy first doesn't really make good sense. Mesh provides direct access to the data with little overhead (it's less resource intensive and generally faster). In most cases you won't see a huge difference, but it's there. Also, although your script won't be using it, Mesh provides faster mesh construction/deconstruction operations (if vert/face/deletion data is passed to it in bulk), and eliminates the need to completely replace the entire mesh (like NMesh does) after simply modifying existing data.
I'm not sure if switching is as easy as changing a line or two in the script or I need to do an enitre re-write of the mesh exporting.
You'd have to bug someone with more experience than me with the conversion process for a definitive answer, but, from my understanding, switching can involve as little effort as changing a few lines of code, to as much effort as (practically) re-writing the entire script. It just depends on how you are using NMesh. If you're only reading data, the conversion process is fairly easy, since data is read from both NMesh and Mesh in practically the same way. If you are modifying existing data, the conversion should be pretty straight-forward as well. If you are constructing/deconstructing the mesh topology, though, the conversion process can/should result in a total re-write.

So, in summary, if you feel like switching, go for it. There are plenty of advantages, and it will give you a chance to get familiar with the new Mesh stuff. If you start into it and realize, "Hey, this is pretty complicated," then go back to NMesh. I don't think NMesh will be eliminated any time soon.

Levi
A three-legged stool never wobbles.

Post Reply