OSDN Git Service

implement pmd import.
[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 // vertices
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