OSDN Git Service

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