Forum: Poser Python Scripting


Subject: Moving morphs between different figures

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


Spanki posted Sat, 15 March 2008 at 4:27 AM

Some initial test results...

First off, after reviewing the current code again, I see that we're already using Numeric.  With that in mind, I now have a basic 'vector' type module/extension, that keeps track of and manipulates 3 doubles (xyz but can also be referenced as rgb or uvw or even v[0], v[1], v[2]).

Example usage:

>> v1 = Vector(1.0, 2.0, 3.0)<br></br>
>> print v1.x     # xyz access<br></br>
1.0<br></br>
>> print v1.g     # rgb access<br></br>
2.0<br></br>
>> print v1.w     # uvw access<br></br>
3.0<br></br>
>> print v1[2]    # indexed access<br></br>
3.0<br></br>
>> v1[2] = 5.0    # assignment works same
way...<br></br>
>> print v.z<br></br>
5.0<br></br>
>> v1.b = 3.0<br></br>
>> print v1.w<br></br>
3.0<br></br>
>> v2 = Vector(2.0, 2.0, 2.0)<br></br>
>> v3 = v1 + v2   # addition<br></br>
>> print v3<br></br>
Vector(3.0, 4.0, 5.0)<br></br>
>> v3 = v1 - v2   # subtraction<br></br>
>> print v3<br></br>
Vector(-1.0, 0.0, 1.0)<br></br>
>> v3 = v1 *  v2  # multiplication<br></br>
>> print v3<br></br>
Vector(2.0, 4.0, 6.0)<br></br>
>> v3 = -v1       #
negation<br></br>
>> print v3<br></br>
Vector(-1.0, -2.0, -3.0)<br></br>
etc.<br></br><br></br>
support is also currently provided for:<br></br>
cross_product   #  vc = v1 % v2<br></br>
dot_product     # dot = v1 ^ v2<br></br>
normalize       #  vn =
~v1<br></br>
abs()          
#  v2 = abs(v1)<br></br>
nonzero test    # if v1<br></br>
magnitude       # mag =
v1.length()<br></br>

I've written a test script that:

----- start timer
----- extract the vertices as the new Vector() type ('list' of vectors)
----- call same test function, but set up to work with  vectors
----- free the verts
----- print timing

...the test loop is set up to do similar computations that the current linecast_loop() does (mostly a bunch of multiplies used in dot_product() calcs), but doesn't have pre-computed normals or regions, etc. so it just fakes some of that.

So far, it looks like my new Vecor-type is (a bit better than) 3x faster than using Numeric.  Keep in mind that the Vector-type is provided by a compiled C++ .pyd file, but the test routine itself is still written in Python.

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.