How can I create a multires mesh from Python?

I’m working on an import script for Second Life sculpties. These use a bitmap where X, Y and Z co-ords are encoded into an RGB image. I’d like to be able to manage LOD levels through multires but can’t find any information on creating a multires mesh in Python.

Are there any examples or docs on doing this?

In the Mesh module there’s some multires functions, I hope it is what you need. I haven’t used those myself yet, just wanted to show you where the docs are.

I’m sure it’s part of what I need. It’s what comes after setting multires to True that has me stuck. Basically I’ll be adding a base mesh of 9 x 9 vertices and two levels of multires data to give 17 x 17 and a 33 x 33 meshes. It’s how I add these additional levels and how they relate to the base mesh that I need help with.

I’m still stuck on this. I can’t seem to find the python equivalent of the multires_add_level call in BKE_multires.h

I just had a quick look at the mesh module and can’t find it either. Maybe it’s not possible yet. You could try to ask the developers in #blendercoders on irc.freenode.net, if nobody here knows. Good luck! :slight_smile:

its not possible right now, not all that hard to add.

Ok. Given how much my head hurts trying to figure this out I’m glad it isn’t hard :eek:

Are there any examples or tutorials on adding python wrappers on functions like this or do I need to keeping reading source until it sinks in?

My current sticking point is in python/api2_2x/mesh.c where I need to add:


static PyObject *Mesh_addMultiresLayer( BPy_Mesh * self, PyObject * args )
{
    if (!self->mesh->mr)
        return EXPP_ReturnIntError( PyExc_RuntimeError,
                    "the mesh has no multires data" );
    // bit stuck here at the moment.. in blenkernel/intern/multires.c the
    // multires_add_level call wants an object and a mesh.. where do I
    // get the object pointer from? Is it just self?
}

And I wonder if I should be adding Mesh_addMultiresLayer_internal rather the just putting the code in the main function. Are there current coding guidelines on this?

I’m new to the Blender codebase and for what C experience I have you can consider me a newbie there too. I’m happy to learn what I need to, just need a friendly pointer or two in the right direction :slight_smile:

Edited post as sorted out the System error problem.

Note to self: int functions are for getters and setters, changed to a PyObject one and all is working :slight_smile:

Bug Tracker - Patch Submitted