MMDPmxParser.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2017, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. #pragma once
  34. #include <vector>
  35. #include <string>
  36. #include <iostream>
  37. #include <fstream>
  38. #include <memory>
  39. #include "MMDCpp14.h"
  40. namespace pmx
  41. {
  42. /// インデックス設定
  43. class PmxSetting
  44. {
  45. public:
  46. PmxSetting()
  47. : encoding(0)
  48. , uv(0)
  49. , vertex_index_size(0)
  50. , texture_index_size(0)
  51. , material_index_size(0)
  52. , bone_index_size(0)
  53. , morph_index_size(0)
  54. , rigidbody_index_size(0)
  55. {}
  56. /// エンコード方式
  57. uint8_t encoding;
  58. /// 追加UV数
  59. uint8_t uv;
  60. /// 頂点インデックスサイズ
  61. uint8_t vertex_index_size;
  62. /// テクスチャインデックスサイズ
  63. uint8_t texture_index_size;
  64. /// マテリアルインデックスサイズ
  65. uint8_t material_index_size;
  66. /// ボーンインデックスサイズ
  67. uint8_t bone_index_size;
  68. /// モーフインデックスサイズ
  69. uint8_t morph_index_size;
  70. /// 剛体インデックスサイズ
  71. uint8_t rigidbody_index_size;
  72. void Read(std::istream *stream);
  73. };
  74. /// 頂点スキニングタイプ
  75. enum class PmxVertexSkinningType : uint8_t
  76. {
  77. BDEF1 = 0,
  78. BDEF2 = 1,
  79. BDEF4 = 2,
  80. SDEF = 3,
  81. QDEF = 4,
  82. };
  83. /// 頂点スキニング
  84. class PmxVertexSkinning
  85. {
  86. public:
  87. virtual void Read(std::istream *stream, PmxSetting *setting) = 0;
  88. };
  89. class PmxVertexSkinningBDEF1 : public PmxVertexSkinning
  90. {
  91. public:
  92. PmxVertexSkinningBDEF1()
  93. : bone_index(0)
  94. {}
  95. int bone_index;
  96. void Read(std::istream *stresam, PmxSetting *setting);
  97. };
  98. class PmxVertexSkinningBDEF2 : public PmxVertexSkinning
  99. {
  100. public:
  101. PmxVertexSkinningBDEF2()
  102. : bone_index1(0)
  103. , bone_index2(0)
  104. , bone_weight(0.0f)
  105. {}
  106. int bone_index1;
  107. int bone_index2;
  108. float bone_weight;
  109. void Read(std::istream *stresam, PmxSetting *setting);
  110. };
  111. class PmxVertexSkinningBDEF4 : public PmxVertexSkinning
  112. {
  113. public:
  114. PmxVertexSkinningBDEF4()
  115. : bone_index1(0)
  116. , bone_index2(0)
  117. , bone_index3(0)
  118. , bone_index4(0)
  119. , bone_weight1(0.0f)
  120. , bone_weight2(0.0f)
  121. , bone_weight3(0.0f)
  122. , bone_weight4(0.0f)
  123. {}
  124. int bone_index1;
  125. int bone_index2;
  126. int bone_index3;
  127. int bone_index4;
  128. float bone_weight1;
  129. float bone_weight2;
  130. float bone_weight3;
  131. float bone_weight4;
  132. void Read(std::istream *stresam, PmxSetting *setting);
  133. };
  134. class PmxVertexSkinningSDEF : public PmxVertexSkinning
  135. {
  136. public:
  137. PmxVertexSkinningSDEF()
  138. : bone_index1(0)
  139. , bone_index2(0)
  140. , bone_weight(0.0f)
  141. {
  142. for (int i = 0; i < 3; ++i) {
  143. sdef_c[i] = 0.0f;
  144. sdef_r0[i] = 0.0f;
  145. sdef_r1[i] = 0.0f;
  146. }
  147. }
  148. int bone_index1;
  149. int bone_index2;
  150. float bone_weight;
  151. float sdef_c[3];
  152. float sdef_r0[3];
  153. float sdef_r1[3];
  154. void Read(std::istream *stresam, PmxSetting *setting);
  155. };
  156. class PmxVertexSkinningQDEF : public PmxVertexSkinning
  157. {
  158. public:
  159. PmxVertexSkinningQDEF()
  160. : bone_index1(0)
  161. , bone_index2(0)
  162. , bone_index3(0)
  163. , bone_index4(0)
  164. , bone_weight1(0.0f)
  165. , bone_weight2(0.0f)
  166. , bone_weight3(0.0f)
  167. , bone_weight4(0.0f)
  168. {}
  169. int bone_index1;
  170. int bone_index2;
  171. int bone_index3;
  172. int bone_index4;
  173. float bone_weight1;
  174. float bone_weight2;
  175. float bone_weight3;
  176. float bone_weight4;
  177. void Read(std::istream *stresam, PmxSetting *setting);
  178. };
  179. /// 頂点
  180. class PmxVertex
  181. {
  182. public:
  183. PmxVertex()
  184. : edge(0.0f)
  185. {
  186. uv[0] = uv[1] = 0.0f;
  187. for (int i = 0; i < 3; ++i) {
  188. position[i] = 0.0f;
  189. normal[i] = 0.0f;
  190. }
  191. for (int i = 0; i < 4; ++i) {
  192. for (int k = 0; k < 4; ++k) {
  193. uva[i][k] = 0.0f;
  194. }
  195. }
  196. }
  197. /// 位置
  198. float position[3];
  199. /// 法線
  200. float normal[3];
  201. /// テクスチャ座標
  202. float uv[2];
  203. /// 追加テクスチャ座標
  204. float uva[4][4];
  205. /// スキニングタイプ
  206. PmxVertexSkinningType skinning_type;
  207. /// スキニング
  208. std::unique_ptr<PmxVertexSkinning> skinning;
  209. /// エッジ倍率
  210. float edge;
  211. void Read(std::istream *stream, PmxSetting *setting);
  212. };
  213. /// マテリアル
  214. class PmxMaterial
  215. {
  216. public:
  217. PmxMaterial()
  218. : specularlity(0.0f)
  219. , flag(0)
  220. , edge_size(0.0f)
  221. , diffuse_texture_index(0)
  222. , sphere_texture_index(0)
  223. , sphere_op_mode(0)
  224. , common_toon_flag(0)
  225. , toon_texture_index(0)
  226. , index_count(0)
  227. {
  228. for (int i = 0; i < 3; ++i) {
  229. specular[i] = 0.0f;
  230. ambient[i] = 0.0f;
  231. edge_color[i] = 0.0f;
  232. }
  233. for (int i = 0; i < 4; ++i) {
  234. diffuse[i] = 0.0f;
  235. }
  236. }
  237. /// モデル名
  238. std::string material_name;
  239. /// モデル英名
  240. std::string material_english_name;
  241. /// 減衰色
  242. float diffuse[4];
  243. /// 光沢色
  244. float specular[3];
  245. /// 光沢度
  246. float specularlity;
  247. /// 環境色
  248. float ambient[3];
  249. /// 描画フラグ
  250. uint8_t flag;
  251. /// エッジ色
  252. float edge_color[4];
  253. /// エッジサイズ
  254. float edge_size;
  255. /// アルベドテクスチャインデックス
  256. int diffuse_texture_index;
  257. /// スフィアテクスチャインデックス
  258. int sphere_texture_index;
  259. /// スフィアテクスチャ演算モード
  260. uint8_t sphere_op_mode;
  261. /// 共有トゥーンフラグ
  262. uint8_t common_toon_flag;
  263. /// トゥーンテクスチャインデックス
  264. int toon_texture_index;
  265. /// メモ
  266. std::string memo;
  267. /// 頂点インデックス数
  268. int index_count;
  269. void Read(std::istream *stream, PmxSetting *setting);
  270. };
  271. /// リンク
  272. class PmxIkLink
  273. {
  274. public:
  275. PmxIkLink()
  276. : link_target(0)
  277. , angle_lock(0)
  278. {
  279. for (int i = 0; i < 3; ++i) {
  280. max_radian[i] = 0.0f;
  281. min_radian[i] = 0.0f;
  282. }
  283. }
  284. /// リンクボーンインデックス
  285. int link_target;
  286. /// 角度制限
  287. uint8_t angle_lock;
  288. /// 最大制限角度
  289. float max_radian[3];
  290. /// 最小制限角度
  291. float min_radian[3];
  292. void Read(std::istream *stream, PmxSetting *settingn);
  293. };
  294. /// ボーン
  295. class PmxBone
  296. {
  297. public:
  298. PmxBone()
  299. : parent_index(0)
  300. , level(0)
  301. , bone_flag(0)
  302. , target_index(0)
  303. , grant_parent_index(0)
  304. , grant_weight(0.0f)
  305. , key(0)
  306. , ik_target_bone_index(0)
  307. , ik_loop(0)
  308. , ik_loop_angle_limit(0.0f)
  309. , ik_link_count(0)
  310. {
  311. for (int i = 0; i < 3; ++i) {
  312. position[i] = 0.0f;
  313. offset[i] = 0.0f;
  314. lock_axis_orientation[i] = 0.0f;
  315. local_axis_x_orientation[i] = 0.0f;
  316. local_axis_y_orientation[i] = 0.0f;
  317. }
  318. }
  319. /// ボーン名
  320. std::string bone_name;
  321. /// ボーン英名
  322. std::string bone_english_name;
  323. /// 位置
  324. float position[3];
  325. /// 親ボーンインデックス
  326. int parent_index;
  327. /// 階層
  328. int level;
  329. /// ボーンフラグ
  330. uint16_t bone_flag;
  331. /// 座標オフセット(has Target)
  332. float offset[3];
  333. /// 接続先ボーンインデックス(not has Target)
  334. int target_index;
  335. /// 付与親ボーンインデックス
  336. int grant_parent_index;
  337. /// 付与率
  338. float grant_weight;
  339. /// 固定軸の方向
  340. float lock_axis_orientation[3];
  341. /// ローカル軸のX軸方向
  342. float local_axis_x_orientation[3];
  343. /// ローカル軸のY軸方向
  344. float local_axis_y_orientation[3];
  345. /// 外部親変形のkey値
  346. int key;
  347. /// IKターゲットボーン
  348. int ik_target_bone_index;
  349. /// IKループ回数
  350. int ik_loop;
  351. /// IKループ計算時の角度制限(ラジアン)
  352. float ik_loop_angle_limit;
  353. /// IKリンク数
  354. int ik_link_count;
  355. /// IKリンク
  356. std::unique_ptr<PmxIkLink []> ik_links;
  357. void Read(std::istream *stream, PmxSetting *setting);
  358. };
  359. enum class MorphType : uint8_t
  360. {
  361. Group = 0,
  362. Vertex = 1,
  363. Bone = 2,
  364. UV = 3,
  365. AdditionalUV1 = 4,
  366. AdditionalUV2 = 5,
  367. AdditionalUV3 = 6,
  368. AdditionalUV4 = 7,
  369. Matrial = 8,
  370. Flip = 9,
  371. Implus = 10,
  372. };
  373. enum class MorphCategory : uint8_t
  374. {
  375. ReservedCategory = 0,
  376. Eyebrow = 1,
  377. Eye = 2,
  378. Mouth = 3,
  379. Other = 4,
  380. };
  381. class PmxMorphOffset
  382. {
  383. public:
  384. void virtual Read(std::istream *stream, PmxSetting *setting) = 0;
  385. };
  386. class PmxMorphVertexOffset : public PmxMorphOffset
  387. {
  388. public:
  389. PmxMorphVertexOffset()
  390. : vertex_index(0)
  391. {
  392. for (int i = 0; i < 3; ++i) {
  393. position_offset[i] = 0.0f;
  394. }
  395. }
  396. int vertex_index;
  397. float position_offset[3];
  398. void Read(std::istream *stream, PmxSetting *setting); //override;
  399. };
  400. class PmxMorphUVOffset : public PmxMorphOffset
  401. {
  402. public:
  403. PmxMorphUVOffset()
  404. : vertex_index(0)
  405. {
  406. for (int i = 0; i < 4; ++i) {
  407. uv_offset[i] = 0.0f;
  408. }
  409. }
  410. int vertex_index;
  411. float uv_offset[4];
  412. void Read(std::istream *stream, PmxSetting *setting); //override;
  413. };
  414. class PmxMorphBoneOffset : public PmxMorphOffset
  415. {
  416. public:
  417. PmxMorphBoneOffset()
  418. : bone_index(0)
  419. {
  420. for (int i = 0; i < 3; ++i) {
  421. translation[i] = 0.0f;
  422. }
  423. for (int i = 0; i < 4; ++i) {
  424. rotation[i] = 0.0f;
  425. }
  426. }
  427. int bone_index;
  428. float translation[3];
  429. float rotation[4];
  430. void Read(std::istream *stream, PmxSetting *setting); //override;
  431. };
  432. class PmxMorphMaterialOffset : public PmxMorphOffset
  433. {
  434. public:
  435. PmxMorphMaterialOffset()
  436. : specularity(0.0f)
  437. , edge_size(0.0f)
  438. {
  439. for (int i = 0; i < 3; ++i) {
  440. specular[i] = 0.0f;
  441. ambient[i] = 0.0f;
  442. }
  443. for (int i = 0; i < 4; ++i) {
  444. diffuse[i] = 0.0f;
  445. edge_color[i] = 0.0f;
  446. texture_argb[i] = 0.0f;
  447. sphere_texture_argb[i] = 0.0f;
  448. toon_texture_argb[i] = 0.0f;
  449. }
  450. }
  451. int material_index;
  452. uint8_t offset_operation;
  453. float diffuse[4];
  454. float specular[3];
  455. float specularity;
  456. float ambient[3];
  457. float edge_color[4];
  458. float edge_size;
  459. float texture_argb[4];
  460. float sphere_texture_argb[4];
  461. float toon_texture_argb[4];
  462. void Read(std::istream *stream, PmxSetting *setting); //override;
  463. };
  464. class PmxMorphGroupOffset : public PmxMorphOffset
  465. {
  466. public:
  467. PmxMorphGroupOffset()
  468. : morph_index(0)
  469. , morph_weight(0.0f)
  470. {}
  471. int morph_index;
  472. float morph_weight;
  473. void Read(std::istream *stream, PmxSetting *setting); //override;
  474. };
  475. class PmxMorphFlipOffset : public PmxMorphOffset
  476. {
  477. public:
  478. PmxMorphFlipOffset()
  479. : morph_index(0)
  480. , morph_value(0.0f)
  481. {}
  482. int morph_index;
  483. float morph_value;
  484. void Read(std::istream *stream, PmxSetting *setting); //override;
  485. };
  486. class PmxMorphImplusOffset : public PmxMorphOffset
  487. {
  488. public:
  489. PmxMorphImplusOffset()
  490. : rigid_body_index(0)
  491. , is_local(0)
  492. {
  493. for (int i = 0; i < 3; ++i) {
  494. velocity[i] = 0.0f;
  495. angular_torque[i] = 0.0f;
  496. }
  497. }
  498. int rigid_body_index;
  499. uint8_t is_local;
  500. float velocity[3];
  501. float angular_torque[3];
  502. void Read(std::istream *stream, PmxSetting *setting); //override;
  503. };
  504. /// モーフ
  505. class PmxMorph
  506. {
  507. public:
  508. PmxMorph()
  509. : offset_count(0)
  510. {
  511. }
  512. /// モーフ名
  513. std::string morph_name;
  514. /// モーフ英名
  515. std::string morph_english_name;
  516. /// カテゴリ
  517. MorphCategory category;
  518. /// モーフタイプ
  519. MorphType morph_type;
  520. /// オフセット数
  521. int offset_count;
  522. /// 頂点モーフ配列
  523. std::unique_ptr<PmxMorphVertexOffset []> vertex_offsets;
  524. /// UVモーフ配列
  525. std::unique_ptr<PmxMorphUVOffset []> uv_offsets;
  526. /// ボーンモーフ配列
  527. std::unique_ptr<PmxMorphBoneOffset []> bone_offsets;
  528. /// マテリアルモーフ配列
  529. std::unique_ptr<PmxMorphMaterialOffset []> material_offsets;
  530. /// グループモーフ配列
  531. std::unique_ptr<PmxMorphGroupOffset []> group_offsets;
  532. /// フリップモーフ配列
  533. std::unique_ptr<PmxMorphFlipOffset []> flip_offsets;
  534. /// インパルスモーフ配列
  535. std::unique_ptr<PmxMorphImplusOffset []> implus_offsets;
  536. void Read(std::istream *stream, PmxSetting *setting);
  537. };
  538. /// 枠内要素
  539. class PmxFrameElement
  540. {
  541. public:
  542. PmxFrameElement()
  543. : element_target(0)
  544. , index(0)
  545. {
  546. }
  547. /// 要素対象
  548. uint8_t element_target;
  549. /// 要素対象インデックス
  550. int index;
  551. void Read(std::istream *stream, PmxSetting *setting);
  552. };
  553. /// 表示枠
  554. class PmxFrame
  555. {
  556. public:
  557. PmxFrame()
  558. : frame_flag(0)
  559. , element_count(0)
  560. {
  561. }
  562. /// 枠名
  563. std::string frame_name;
  564. /// 枠英名
  565. std::string frame_english_name;
  566. /// 特殊枠フラグ
  567. uint8_t frame_flag;
  568. /// 枠内要素数
  569. int element_count;
  570. /// 枠内要素配列
  571. std::unique_ptr<PmxFrameElement []> elements;
  572. void Read(std::istream *stream, PmxSetting *setting);
  573. };
  574. class PmxRigidBody
  575. {
  576. public:
  577. PmxRigidBody()
  578. : target_bone(0)
  579. , group(0)
  580. , mask(0)
  581. , shape(0)
  582. , mass(0.0f)
  583. , move_attenuation(0.0f)
  584. , rotation_attenuation(0.0f)
  585. , repulsion(0.0f)
  586. , friction(0.0f)
  587. , physics_calc_type(0)
  588. {
  589. for (int i = 0; i < 3; ++i) {
  590. size[i] = 0.0f;
  591. position[i] = 0.0f;
  592. orientation[i] = 0.0f;
  593. }
  594. }
  595. /// 剛体名
  596. std::string girid_body_name;
  597. /// 剛体英名
  598. std::string girid_body_english_name;
  599. /// 関連ボーンインデックス
  600. int target_bone;
  601. /// グループ
  602. uint8_t group;
  603. /// マスク
  604. uint16_t mask;
  605. /// 形状
  606. uint8_t shape;
  607. float size[3];
  608. float position[3];
  609. float orientation[3];
  610. float mass;
  611. float move_attenuation;
  612. float rotation_attenuation;
  613. float repulsion;
  614. float friction;
  615. uint8_t physics_calc_type;
  616. void Read(std::istream *stream, PmxSetting *setting);
  617. };
  618. enum class PmxJointType : uint8_t
  619. {
  620. Generic6DofSpring = 0,
  621. Generic6Dof = 1,
  622. Point2Point = 2,
  623. ConeTwist = 3,
  624. Slider = 5,
  625. Hinge = 6
  626. };
  627. class PmxJointParam
  628. {
  629. public:
  630. PmxJointParam()
  631. : rigid_body1(0)
  632. , rigid_body2(0)
  633. {
  634. for (int i = 0; i < 3; ++i) {
  635. position[i] = 0.0f;
  636. orientaiton[i] = 0.0f;
  637. move_limitation_min[i] = 0.0f;
  638. move_limitation_max[i] = 0.0f;
  639. rotation_limitation_min[i] = 0.0f;
  640. rotation_limitation_max[i] = 0.0f;
  641. spring_move_coefficient[i] = 0.0f;
  642. spring_rotation_coefficient[i] = 0.0f;
  643. }
  644. }
  645. int rigid_body1;
  646. int rigid_body2;
  647. float position[3];
  648. float orientaiton[3];
  649. float move_limitation_min[3];
  650. float move_limitation_max[3];
  651. float rotation_limitation_min[3];
  652. float rotation_limitation_max[3];
  653. float spring_move_coefficient[3];
  654. float spring_rotation_coefficient[3];
  655. void Read(std::istream *stream, PmxSetting *setting);
  656. };
  657. class PmxJoint
  658. {
  659. public:
  660. std::string joint_name;
  661. std::string joint_english_name;
  662. PmxJointType joint_type;
  663. PmxJointParam param;
  664. void Read(std::istream *stream, PmxSetting *setting);
  665. };
  666. enum PmxSoftBodyFlag : uint8_t
  667. {
  668. BLink = 0x01,
  669. Cluster = 0x02,
  670. Link = 0x04
  671. };
  672. class PmxAncherRigidBody
  673. {
  674. public:
  675. PmxAncherRigidBody()
  676. : related_rigid_body(0)
  677. , related_vertex(0)
  678. , is_near(false)
  679. {}
  680. int related_rigid_body;
  681. int related_vertex;
  682. bool is_near;
  683. void Read(std::istream *stream, PmxSetting *setting);
  684. };
  685. class PmxSoftBody
  686. {
  687. public:
  688. PmxSoftBody()
  689. : shape(0)
  690. , target_material(0)
  691. , group(0)
  692. , mask(0)
  693. , blink_distance(0)
  694. , cluster_count(0)
  695. , mass(0.0)
  696. , collisioni_margin(0.0)
  697. , aero_model(0)
  698. , VCF(0.0f)
  699. , DP(0.0f)
  700. , DG(0.0f)
  701. , LF(0.0f)
  702. , PR(0.0f)
  703. , VC(0.0f)
  704. , DF(0.0f)
  705. , MT(0.0f)
  706. , CHR(0.0f)
  707. , KHR(0.0f)
  708. , SHR(0.0f)
  709. , AHR(0.0f)
  710. , SRHR_CL(0.0f)
  711. , SKHR_CL(0.0f)
  712. , SSHR_CL(0.0f)
  713. , SR_SPLT_CL(0.0f)
  714. , SK_SPLT_CL(0.0f)
  715. , SS_SPLT_CL(0.0f)
  716. , V_IT(0)
  717. , P_IT(0)
  718. , D_IT(0)
  719. , C_IT(0)
  720. , LST(0.0f)
  721. , AST(0.0f)
  722. , VST(0.0f)
  723. , anchor_count(0)
  724. , pin_vertex_count(0)
  725. {}
  726. std::string soft_body_name;
  727. std::string soft_body_english_name;
  728. uint8_t shape;
  729. int target_material;
  730. uint8_t group;
  731. uint16_t mask;
  732. PmxSoftBodyFlag flag;
  733. int blink_distance;
  734. int cluster_count;
  735. float mass;
  736. float collisioni_margin;
  737. int aero_model;
  738. float VCF;
  739. float DP;
  740. float DG;
  741. float LF;
  742. float PR;
  743. float VC;
  744. float DF;
  745. float MT;
  746. float CHR;
  747. float KHR;
  748. float SHR;
  749. float AHR;
  750. float SRHR_CL;
  751. float SKHR_CL;
  752. float SSHR_CL;
  753. float SR_SPLT_CL;
  754. float SK_SPLT_CL;
  755. float SS_SPLT_CL;
  756. int V_IT;
  757. int P_IT;
  758. int D_IT;
  759. int C_IT;
  760. float LST;
  761. float AST;
  762. float VST;
  763. int anchor_count;
  764. std::unique_ptr<PmxAncherRigidBody []> anchers;
  765. int pin_vertex_count;
  766. std::unique_ptr<int []> pin_vertices;
  767. void Read(std::istream *stream, PmxSetting *setting);
  768. };
  769. /// PMXモデル
  770. class PmxModel
  771. {
  772. public:
  773. PmxModel()
  774. : version(0.0f)
  775. , vertex_count(0)
  776. , index_count(0)
  777. , texture_count(0)
  778. , material_count(0)
  779. , bone_count(0)
  780. , morph_count(0)
  781. , frame_count(0)
  782. , rigid_body_count(0)
  783. , joint_count(0)
  784. , soft_body_count(0)
  785. {}
  786. /// バージョン
  787. float version;
  788. /// 設定
  789. PmxSetting setting;
  790. /// モデル名
  791. std::string model_name;
  792. /// モデル英名
  793. std::string model_english_name;
  794. /// コメント
  795. std::string model_comment;
  796. /// 英語コメント
  797. std::string model_english_comment;
  798. /// 頂点数
  799. int vertex_count;
  800. /// 頂点配列
  801. std::unique_ptr<PmxVertex []> vertices;
  802. /// インデックス数
  803. int index_count;
  804. /// インデックス配列
  805. std::unique_ptr<int []> indices;
  806. /// テクスチャ数
  807. int texture_count;
  808. /// テクスチャ配列
  809. std::unique_ptr< std::string []> textures;
  810. /// マテリアル数
  811. int material_count;
  812. /// マテリアル
  813. std::unique_ptr<PmxMaterial []> materials;
  814. /// ボーン数
  815. int bone_count;
  816. /// ボーン配列
  817. std::unique_ptr<PmxBone []> bones;
  818. /// モーフ数
  819. int morph_count;
  820. /// モーフ配列
  821. std::unique_ptr<PmxMorph []> morphs;
  822. /// 表示枠数
  823. int frame_count;
  824. /// 表示枠配列
  825. std::unique_ptr<PmxFrame [] > frames;
  826. /// 剛体数
  827. int rigid_body_count;
  828. /// 剛体配列
  829. std::unique_ptr<PmxRigidBody []> rigid_bodies;
  830. /// ジョイント数
  831. int joint_count;
  832. /// ジョイント配列
  833. std::unique_ptr<PmxJoint []> joints;
  834. /// ソフトボディ数
  835. int soft_body_count;
  836. /// ソフトボディ配列
  837. std::unique_ptr<PmxSoftBody []> soft_bodies;
  838. /// モデル初期化
  839. void Init();
  840. /// モデル読み込み
  841. void Read(std::istream *stream);
  842. ///// ファイルからモデルの読み込み
  843. //static std::unique_ptr<PmxModel> ReadFromFile(const char *filename);
  844. ///// 入力ストリームからモデルの読み込み
  845. //static std::unique_ptr<PmxModel> ReadFromStream(std::istream *stream);
  846. };
  847. }