$#include "pmd.h" $#include "vmd.h" $#include "mqo.h" $#include "la.h" $#include "color.h" $using namespace meshio; namespace meshio { namespace pmd { struct Vertex { //! 座標 Vector3 pos; //! 法線ベクトル Vector3 normal; //! テクスチャUV Vector2 uv; //! ブレンディングボーン1 unsigned short bone0; //! ブレンディングボーン2 unsigned short bone1; //! ウェイト[0 - 100] unsigned char weight0; //! 非エッジ unsigned char edge_flag; }; struct Material { //! Diffuse fRGBA diffuse; //! Shinness float shinness; //! Specular fRGB specular; //! Ambient fRGB ambient; //! トゥーンテクスチャ unsigned char toon_index; //! 輪郭/影 unsigned char flag; //! 面頂点数 unsigned int vertex_count; //! テクスチャ fixed_string<20> texture; }; //! ボーンの種類 enum BONE_TYPE { // 回転 BONE_ROTATE=0, // 回転と移動 BONE_ROTATE_MOVE, // IK BONE_IK, // 不明 BONE_UNKNOWN, // IK影響下 BONE_IK_INFLUENCED, // 回転影響下 BONE_ROTATE_INFLUENCED, // IK接続先 BONE_IK_CONNECT, // 非表示 BONE_INVISIBLE, // 捻り BONE_TWIST, // 回転連動 BONE_REVOLVE, }; struct Bone { //! 名前 fixed_string<20> name; //! 親ボーン unsigned short parent_index; //! 子ボーン unsigned short tail_index; //! ボーン種類 BONE_TYPE type; //! 影響IKボーン unsigned short ik_index; // ボーン座標 Vector3 pos; //! 英語名 fixed_string<20> english_name; //! ボーン階層構築用 Bone* parent; Vector3 tail; std::vector children; unsigned short index; Bone(); }; struct IK { //! IK(IKターゲット) unsigned short index; //! Target(エフェクター) unsigned short target; //! エフェクタに連動するボーン数 unsigned char length; //! IK値1。CCD-IK試行回数 unsigned short iterations; //! IK値2。CCD-IK試行一回辺りの影響度 float weight; //! エフェクタに連動するボーン(基本的に親ボーンに遡る) std::vector children; }; //! 表情の種類 enum MORPH_TYPE { //! ベース表情 MORPH_BASE=0, //! まゆ MORPH_MAYU, //! 目 MORPH_ME, //! リップ MORPH_LIP, //! その他 MORPH_OTHER, }; struct Morph { //! 表情名 fixed_string<20> name; //! 使用する頂点数 unsigned int vertex_count; //! 分類 unsigned char type; //! 頂点Index std::vector indices; //! 移動量 std::vector pos_list; //! 英語名 fixed_string<20> english_name; }; struct BoneGroup { fixed_string<50> name; fixed_string<50> english_name; }; //! 形状 enum SHAPE_TYPE { //! 球 SHAPE_SPHERE=0, //! 箱 SHAPE_BOX, //! カプセル SHAPE_CAPSULE, }; //! 剛体タイプ enum PROCESS_TYPE { //! ボーンと同じ動き RIGIDBODY_KINEMATICS=0, //! 物理演算 RIGIDBODY_PHYSICS, //! 物理演算結果をボーンに反映する RIGIDBODY_PHYSICS_WITH_BONE, }; struct RigidBody { //! 剛体名 fixed_string<20> name; //! 関連ボーン(ボーン追従とボーン位置合わせで必要) unsigned short boneIndex; //! グループ unsigned char group; //! 非衝突グループ unsigned short target; //! 形状 SHAPE_TYPE shapeType; //! サイズ float w; float h; float d; //! 姿勢 Vector3 position; Vector3 rotation; //! 質量 float weight; //! 物理演算パラメータ(bullet) float linearDamping; float angularDamping; float restitution; float friction; //! 剛体タイプ PROCESS_TYPE processType; }; //! Joint(物理演算でのJointとConstraintは同じ意味) struct Constraint { //! Joint名 fixed_string<20> name; //! 接続剛体A unsigned int rigidA; //! 接続剛体B unsigned int rigidB; //! 位置 Vector3 pos; //! 回転 Vector3 rot; //! 移動制限 Vector3 constraintPosMin; Vector3 constraintPosMax; //! 回転制限 Vector3 constraintRotMin; Vector3 constraintRotMax; //! ばね Vector3 springPos; Vector3 springRot; }; // IO struct IO { float version; fixed_string<20> name; fixed_string<256> comment; std::vector vertices; std::vector indices; std::vector materials; std::vector bones; std::vector ik_list; std::vector morph_list; std::vector face_list; std::vector bone_group_list; std::vector > bone_display_list; std::array, 10> toon_textures; std::vector rigidbodies; std::vector constraints; fixed_string<20> english_name; fixed_string<256> english_comment; IO(); bool read(const char *path); bool write(const char *path); }; typedef std::vector VertexVector; } // namespace pmd namespace mqo { struct Scene { Vector3 pos; Vector3 lookat; float head; float pitch; int ortho; float zoom2; Vector3 ambient; }; struct Material { std::string name; int shader; fRGBA color; float diffuse; float ambient; float emit; float specular; float power; std::string texture; std::string alphamap; std::string bumpmap; int vcol; }; struct Face { unsigned int index_count; unsigned int indices[4]; unsigned int material_index; Vector2 uv[4]; fRGBA color[4]; }; struct Object { std::string name; int depth; int folding; Vector3 scale; Vector3 rotation; Vector3 translation; int visible; int locking; int shading; float smoothing; Vector3 color; int color_type; int mirror; std::vector vertices; std::vector faces; }; struct IO { Scene scene; std::vector materials; std::vector objects; IO(); bool read(const char *path); bool write(const char *path); }; } struct Vector2 { float x; float y; Vector2(float _x, float _y); }; struct Vector3 { float x; float y; float z; Vector3(float _x, float _y, float _z); bool operator==(const Vector3 &rhs)const; Vector3 operator+(const Vector3 &rhs); Vector3 operator-(const Vector3 &rhs); }; struct Vector4 { float x; float y; float z; float w; Vector4(float _x, float _y, float _z, float _w); }; struct Quaternion { float x; float y; float z; float w; Quaternion(float _x, float _y, float _z, float _w); float dot(const Quaternion &rhs); }; struct fRGBA { float r; float g; float b; float a; }; class fixed_string { TOLUA_TEMPLATE_BIND(T, 20, 50, 100, 256); std::string str() const; void assign(const std::string &src); }; }