Forum: Poser Python Scripting


Subject: Moving morphs between different figures

Cage opened this issue on Dec 20, 2006 · 1232 posts


Spanki posted Thu, 13 March 2008 at 1:42 PM

I'll take a look at struct, thanks.  In our current code, we're using lists-of-lists-of-floats to represent multiple vertices.  For example, 2 vertices would be represented as:

2verts = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]

...except that there's (10s of) thousands of verts in each list (however many make up the model).  Using the above format, to get at each element (x, y or z value of some vertex), we ultimately do something like:

for vNdx in some_index_list:          # Loop through vertices
    vert = verts_list[vNdx]     # get desired vertex
    vX = vert[0]                       # de-reference each element
    vY = vert[1]
    vZ = vert[2]

...except that it's usually more involved than that, because we're typically looping through the triangles in some list, then grabbing the 3 vertices of each triangle.

I think I finally figured out how to get at each element in C last night, but I fell asleep before verifying it.  Here's my simple testing code:

//==================================================================<br></br>
// test( *pVerts )<br></br>
//==================================================================<br></br>
static PyObject *ex_test(PyObject *self, PyObject *args)<br></br>
{<br></br>
 PyListObject *pVectorList;  // the passed in vector list
(list-of-lists)<br></br>
 PyListObject *pVector;<br></br>
 PyFloatObject *pElement;<br></br>
 double vX = 0.0, vY = 0.1, vZ = 0.2;<br></br>
 long vCount, i;

 // start by deconstructing the args<br></br>
 if (!PyArg_ParseTuple(args, "O", &pVectorList
))<br></br>
  return NULL;

 // get vertex count<br></br>
 vCount = PyList_GET_SIZE(pVectorList);<br></br>
 <br></br>
 // try to modify each vertex...<br></br>
 for(i=0; i<vCount; i++)<br></br>
 {<br></br>
  // get each vertex/vector (another list)...<br></br>
  pVector = (PyListObject *)PyList_GET_ITEM(pVectorList,
i);

  // ...then each element of the vertex (a
float)<br></br>
  pElement = (PyFloatObject *)PyList_GET_ITEM(pVector,
0);<br></br>
  // vX = PyFloat_AS_DOUBLE(pElement);<br></br>
  PyFloat_SET_DOUBLE(pElement, i+vX);

  pElement = (PyFloatObject
*)PyList_GET_ITEM(pVector, 1);<br></br>
  // vY = PyFloat_AS_DOUBLE(pElement);<br></br>
  PyFloat_SET_DOUBLE(pElement, i+vY);

  pElement = (PyFloatObject
*)PyList_GET_ITEM(pVector, 2);<br></br>
  // vZ = PyFloat_AS_DOUBLE(pElement);<br></br>
  PyFloat_SET_DOUBLE(pElement, i+vZ);<br></br>
 }

 Py_INCREF(Py_None);<br></br>
 return Py_None;<br></br>
}<br></br>

...etc.

Note that the PyFloat_SET_DOUBLE() is my own macro and may not be functioning properly at this point.

Cinema4D Plugins (Home of Riptide, Riptide Pro, Undertow, Morph Mill, KyamaSlide and I/Ogre plugins) Poser products Freelance Modelling, Poser Rigging, UV-mapping work for hire.