OSDN Git Service

IK export.
[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 "std_wstring.i"
9 %include "../include/color.h"
10 %include "../include/la.h"
11 %include "../include/pmd.h"
12
13 %template(VertexVector) std::vector<meshio::pmd::Vertex>;
14 %template(MaterialVector) std::vector<meshio::pmd::Material*>;
15 %template(BoneVector) std::vector<meshio::pmd::Bone>;
16 %template(IKVector) std::vector<meshio::pmd::IK>;
17 %template(MorphVector) std::vector<meshio::pmd::Morph>;
18 %template(RigidBodyVector) std::vector<meshio::pmd::RigidBody>;
19 %template(ConstraintVector) std::vector<meshio::pmd::Constraint>;
20 %template(UintVector) std::vector<unsigned int>;
21 %template(UshortVector) std::vector<unsigned short>;
22 %template(Vector3Vector) std::vector<meshio::pmd::Vector3>;
23 %template(PBoneVector) std::vector<meshio::pmd::Bone*>;
24
25 ///////////////////////////////////////////////////////////////////////////////
26 // meshio::pmd::IO::each_vertex
27 ///////////////////////////////////////////////////////////////////////////////
28 %inline %{
29 //! Thin wrapper for ONLY the increment operator
30 void _vertices_incr(std::vector<meshio::pmd::Vertex>::const_iterator* iter)
31 {
32     // increment the iterator
33     ++(*iter);
34 }
35 %}
36
37 %extend meshio::pmd::IO {
38 %pythoncode {
39     def each_vertex(self):
40         iter = self._beginVertices()
41         while True:
42             vertex = self._dereferenceVertex(iter)
43             if vertex:
44                 _vertices_incr(iter)
45                 yield vertex
46             else:
47                 break
48 %}
49
50 //! get the first element in the vector
51 std::vector<meshio::pmd::Vertex>::const_iterator* _beginVertices()
52 {
53     return new std::vector<meshio::pmd::Vertex>::const_iterator(
54             ($self->vertices.begin()));
55 }
56
57 //! dereference the iterator; return NULL if at the end
58 const meshio::pmd::Vertex* _dereferenceVertex(
59         const std::vector<meshio::pmd::Vertex>::const_iterator* iter )
60 {
61     // if at the end, return NULL
62     if (*iter == ($self)->vertices.end() ) {
63         return NULL;
64     }
65     // otherwise, return the face to which this iterator points
66     return &(**iter);
67 }
68 }
69
70 ///////////////////////////////////////////////////////////////////////////////
71 // addVertex
72 // addMaterial
73 // addBone
74 // addMorph
75 ///////////////////////////////////////////////////////////////////////////////
76 %extend meshio::pmd::IO {
77
78 meshio::pmd::Vertex * addVertex()
79 {
80     $self->vertices.push_back(meshio::pmd::Vertex());
81     return &($self->vertices.back());
82 }
83
84 meshio::pmd::Material *addMaterial()
85 {
86     $self->materials.push_back(new meshio::pmd::Material);
87     return $self->materials.back();
88 }
89
90 meshio::pmd::Bone *addBone()
91 {
92     $self->bones.push_back(meshio::pmd::Bone());
93     return &($self->bones.back());
94 }
95
96 meshio::pmd::Morph *addMorph()
97 {
98     $self->morph_list.push_back(meshio::pmd::Morph());
99     return &($self->morph_list.back());
100 }
101
102 meshio::pmd::IK *addIK()
103 {
104     $self->ik_list.push_back(meshio::pmd::IK());
105     return &($self->ik_list.back());
106 }
107
108 }