OSDN Git Service

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