OSDN Git Service

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