Pickle Vec3

I have wondered how hard it would be to make Vec3 (and similar classes) pickable?

I have already had this issue a lot of times (i do lots of small projects), and everytime this gets to the point im have to getX, getY, getZ. At which point i also have to handle 2 variable types if i load (float list & vec3), or convert a vec3 to a list before i can create a object.

class myObj( NodePath ):
  def __init__( self, pos ):
    NodePath.__init__( self )
    if type(pos) == list:
      self.setPos( *pos )
    else:
      self.setPos( pos )

objA = myObj( Vec3(1,1,1) )
objB = myObj( [1,1,1] ) <- data would come from pickle

Or is there a better way to implement that?

I understand that i am raising the panda3d pythonic question again.
[/code]

Hmm. It could be possible using this code. I didnt test it or so.
Add this extension to pandac/libpandaModules.py:

def __getstate__(self):
        return (self.getX(), self.getY(), self.getZ())

Dtool_funcToMethod(__getstate__, Vec3)
del __getstate__

def __setstate__(self, obj):
        return Vec3(*obj)

Dtool_funcToMethod(__setstate__, Vec3)
del __setstate__

Check whether its pickleable after adding this extension.

…I don’t know if this actually works, but something like this could be an idea.