%module pmd %{ #include using namespace meshio; using namespace pmd; %} %include "std_vector.i" %include "std_wstring.i" %include "../include/color.h" %include "../include/la.h" %include "../include/pmd.h" %template(VertexVector) std::vector; %template(MaterialVector) std::vector; %template(BoneVector) std::vector; %template(IKVector) std::vector; %template(MorphVector) std::vector; %template(RigidBodyVector) std::vector; %template(ConstraintVector) std::vector; %template(UintVector) std::vector; %template(UshortVector) std::vector; %template(Vector3Vector) std::vector; %template(PBoneVector) std::vector; /////////////////////////////////////////////////////////////////////////////// // meshio::pmd::IO::each_vertex /////////////////////////////////////////////////////////////////////////////// %inline %{ //! Thin wrapper for ONLY the increment operator void _vertices_incr(std::vector::const_iterator* iter) { // increment the iterator ++(*iter); } %} %extend meshio::pmd::IO { %pythoncode { def each_vertex(self): iter = self._beginVertices() while True: vertex = self._dereferenceVertex(iter) if vertex: _vertices_incr(iter) yield vertex else: break %} //! get the first element in the vector std::vector::const_iterator* _beginVertices() { return new std::vector::const_iterator( ($self->vertices.begin())); } //! dereference the iterator; return NULL if at the end const meshio::pmd::Vertex* _dereferenceVertex( const std::vector::const_iterator* iter ) { // if at the end, return NULL if (*iter == ($self)->vertices.end() ) { return NULL; } // otherwise, return the face to which this iterator points return &(**iter); } } /////////////////////////////////////////////////////////////////////////////// // addVertex // addMaterial // addBone /////////////////////////////////////////////////////////////////////////////// %extend meshio::pmd::IO { meshio::pmd::Vertex * addVertex() { $self->vertices.push_back(meshio::pmd::Vertex()); return &($self->vertices.back()); } meshio::pmd::Material *addMaterial() { $self->materials.push_back(new meshio::pmd::Material); return $self->materials.back(); } meshio::pmd::Bone *addBone() { $self->bones.push_back(meshio::pmd::Bone()); return &($self->bones.back()); } }