OSDN Git Service

723b7817e42487e61452ee77cd4cd6450324a97c
[meshio/meshio.git] / swig / pmd.i
1 %module pmd
2 %{
3 #include <pmd.h>
4 using namespace meshio;
5 using namespace pmd;
6 %}
7 %include "std_vector.i"
8 %include "../include/color.h"
9 %include "../include/la.h"
10 %include "../include/pmd.h"
11
12 %template(VertexVector) std::vector<meshio::pmd::Vertex>;
13 %template(MaterialVector) std::vector<meshio::pmd::Material*>;
14 %template(BoneVector) std::vector<meshio::pmd::Bone>;
15 %template(IKVector) std::vector<meshio::pmd::IK>;
16 %template(MorphVector) std::vector<meshio::pmd::Morph>;
17 %template(RigidBodyVector) std::vector<meshio::pmd::RigidBody>;
18 %template(ConstraintVector) std::vector<meshio::pmd::Constraint>;
19 %template(UintVector) std::vector<unsigned int>;
20 %template(UshortVector) std::vector<unsigned short>;
21 %template(Vector3Vector) std::vector<meshio::pmd::Vector3>;
22 %template(PBoneVector) std::vector<meshio::pmd::Bone*>;
23
24 ///////////////////////////////////////////////////////////////////////////////
25 // vertices
26 ///////////////////////////////////////////////////////////////////////////////
27 %inline %{
28 //! Thin wrapper for ONLY the increment operator
29 void _vertices_incr(std::vector<meshio::pmd::Vertex>::const_iterator* iter)
30 {
31     // increment the iterator
32     ++(*iter);
33 }
34 %}
35
36 %extend meshio::pmd::IO {
37 %pythoncode {
38     def each_vertex(self):
39         iter = self._beginVertices()
40         while True:
41             vertex = self._dereferenceVertex(iter)
42             if vertex:
43                 _vertices_incr(iter)
44                 yield vertex
45             else:
46                 break
47 %}
48
49 //! get the first element in the vector
50 std::vector<meshio::pmd::Vertex>::const_iterator* _beginVertices()
51 {
52     return new std::vector<meshio::pmd::Vertex>::const_iterator(
53             ($self->vertices.begin()));
54 }
55
56 //! dereference the iterator; return NULL if at the end
57 const meshio::pmd::Vertex* _dereferenceVertex(
58         const std::vector<meshio::pmd::Vertex>::const_iterator* iter )
59 {
60     // if at the end, return NULL
61     if (*iter == ($self)->vertices.end() ) {
62         return NULL;
63     }
64     // otherwise, return the face to which this iterator points
65     return &(**iter);
66 }
67 }
68