Guest User

Untitled

a guest
Jul 18th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.06 KB | None | 0 0
  1. Index: include/MMDFiles.h
  2. ===================================================================
  3. --- include/MMDFiles.h (revision 39)
  4. +++ include/MMDFiles.h (working copy)
  5. @@ -50,7 +50,12 @@
  6. #define MMDFILES_DEG(a) (a * (180.0f / 3.1415926f))
  7.  
  8. #define MMDFILES_MAXBUFLEN 1024
  9. +
  10. +#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
  11. #define MMDFILES_DIRSEPARATOR '¥¥'
  12. +#else
  13. +#define MMDFILES_DIRSEPARATOR '/'
  14. +#endif
  15.  
  16. #include "btBulletDynamicsCommon.h"
  17.  
  18. Index: include/MotionManager.h
  19. ===================================================================
  20. --- include/MotionManager.h (revision 39)
  21. +++ include/MotionManager.h (working copy)
  22. @@ -109,16 +109,16 @@
  23. ~MotionManager();
  24.  
  25. /* startMotion: start a motion */
  26. - bool startMotion(VMD *vmd, char *name, bool full, bool once, bool enableSmooth, bool enableRePos);
  27. + bool startMotion(VMD *vmd, const char *name, bool full, bool once, bool enableSmooth, bool enableRePos);
  28.  
  29. /* startMotionSub: initialize a motion */
  30. void startMotionSub(VMD *vmd, MotionPlayer *m);
  31.  
  32. /* swapMotion: swap a motion, keeping parameters */
  33. - bool swapMotion(VMD *vmd, char *name);
  34. + bool swapMotion(VMD *vmd, const char *name);
  35.  
  36. /* deleteMotion: delete a motion */
  37. - bool deleteMotion(char *name);
  38. + bool deleteMotion(const char *name);
  39.  
  40. /* update: apply all motion players */
  41. bool update(double frame);
  42. Index: include/PMDTexture.h
  43. ===================================================================
  44. --- include/PMDTexture.h (revision 39)
  45. +++ include/PMDTexture.h (working copy)
  46. @@ -57,16 +57,16 @@
  47. private:
  48.  
  49. /* loadBMP: load BMP texture */
  50. - bool loadBMP(char *fileName);
  51. + bool loadBMP(const char *fileName);
  52.  
  53. /* loadTGA: load TGA texture */
  54. - bool loadTGA(char *fileName);
  55. + bool loadTGA(const char *fileName);
  56.  
  57. /* loadPNG: load PNG texture */
  58. - bool loadPNG(char *fileName);
  59. + bool loadPNG(const char *fileName);
  60.  
  61. /* loadJPG: load JPG texture */
  62. - bool loadJPG(char *fileName);
  63. + bool loadJPG(const char *fileName);
  64.  
  65. /* initialize: initialize texture */
  66. void initialize();
  67. @@ -83,7 +83,7 @@
  68. ~PMDTexture();
  69.  
  70. /* load: load from file name */
  71. - bool load(char *fileName);
  72. + bool load(const char *fileName);
  73.  
  74. /* getID: get OpenGL texture ID */
  75. GLuint getID();
  76. Index: include/PMDModel.h
  77. ===================================================================
  78. --- include/PMDModel.h (revision 39)
  79. +++ include/PMDModel.h (working copy)
  80. @@ -39,8 +39,6 @@
  81. /* POSSIBILITY OF SUCH DAMAGE. */
  82. /* ----------------------------------------------------------------- */
  83.  
  84. -#define PMDMODEL_CENTERBONENAME "センター"
  85. -
  86. #define PMDMODEL_MINBONEWEIGHT 0.0001f
  87. #define PMDMODEL_MINFACEWEIGHT 0.001f
  88.  
  89. @@ -151,10 +149,10 @@
  90. bool load(const char *file, BulletPhysics *bullet, SystemTexture *systex);
  91.  
  92. /* getBone: find bone data by name */
  93. - PMDBone *getBone(char *name);
  94. + PMDBone *getBone(const char *name);
  95.  
  96. /* getFace: find face data by name */
  97. - PMDFace *getFace(char *name);
  98. + PMDFace *getFace(const char *name);
  99.  
  100. /* getChildBoneList: return list of child bones, in decent order */
  101. int getChildBoneList(PMDBone **bone, unsigned short boneNum, PMDBone **childBoneList, unsigned short childBoneNumMax);
  102. @@ -190,7 +188,7 @@
  103. PMDBone *getCenterBone();
  104.  
  105. /* getName: get model name */
  106. - char * getName();
  107. + const char *getName();
  108.  
  109. /* getNumVertex: get number of vertics */
  110. unsigned long getNumVertex();
  111. @@ -223,10 +221,10 @@
  112. float getMaxHeight();
  113.  
  114. /* getComment: get comment of PMD */
  115. - char *getComment();
  116. + const char *getComment();
  117.  
  118. /* getModelDir: get model directory */
  119. - char *getModelDir();
  120. + const char *getModelDir();
  121.  
  122. /* updateBone: update bones */
  123. void updateBone();
  124. Index: include/SystemTexture.h
  125. ===================================================================
  126. --- include/SystemTexture.h (revision 39)
  127. +++ include/SystemTexture.h (working copy)
  128. @@ -65,7 +65,7 @@
  129. ~SystemTexture();
  130.  
  131. /* load: load system texture from current directory */
  132. - bool load(char *dir);
  133. + bool load(const char *dir);
  134.  
  135. /* getTextureID: get toon texture ID */
  136. unsigned int getTextureID(int i);
  137. Index: include/MotionController.h
  138. ===================================================================
  139. --- include/MotionController.h (revision 39)
  140. +++ include/MotionController.h (working copy)
  141. @@ -42,7 +42,7 @@
  142. #define MOTIONCONTROLLER_BONESTARTMARGINFRAME 20.0f /* frame lengths for bone motion smoothing at loop head */
  143. #define MOTIONCONTROLLER_FACESTARTMARGINFRAME 6.0f /* frame lengths for face motion smoothing at loop head */
  144.  
  145. -#define MOTIONCONTROLLER_CENTERBONENAME "センター"
  146. +#define MOTIONCONTROLLER_CENTERBONENAME { 0x83, 0x5a, 0x83, 0x93, 0x83, 0x5e, 0x81, 0x5b }
  147.  
  148. /* MotionControllerBoneElement: motion control element for bone */
  149. typedef struct _MotionControllerBoneElement {
  150. Index: include/PTree.h
  151. ===================================================================
  152. --- include/PTree.h (revision 39)
  153. +++ include/PTree.h (working copy)
  154. @@ -86,8 +86,8 @@
  155. void release();
  156.  
  157. /* add: add an entry to the tree */
  158. - void add(char *str, void *data, char *matchStr);
  159. + void add(const char *str, void *data, const char *matchStr);
  160.  
  161. /* findNearest: return the nearest entry */
  162. - void *findNearest(char *str);
  163. + void *findNearest(const char *str);
  164. };
  165. Index: include/PMDFile.h
  166. ===================================================================
  167. --- include/PMDFile.h (revision 39)
  168. +++ include/PMDFile.h (working copy)
  169. @@ -92,7 +92,7 @@
  170. float ambient[3]; /* ambient color */
  171. unsigned char toonID; /* toon index: 0xff -> toon0.bmp, other -> toon(val+1).bmp */
  172. unsigned char edgeFlag; /* 1 if edge should be drawn */
  173. - unsigned long numSurfaceIndex; /* number of surface indices for this material */
  174. + unsigned int numSurfaceIndex; /* number of surface indices for this material */
  175. char textureFile[20]; /* texture file name */
  176. } PMDFile_Material;
  177.  
  178. @@ -117,7 +117,7 @@
  179.  
  180. /* PMDFile_Face_Vertex: face vertex element */
  181. typedef struct {
  182. - unsigned long vertexID; /* vertex index of this model to be controlled */
  183. + unsigned int vertexID; /* vertex index of this model to be controlled */
  184. /* if base face, this is index for model vertex index */
  185. /* if not base, this is index for base face vertices */
  186. float pos[3]; /* position to be placed if this face rate is 1.0 */
  187. @@ -126,7 +126,7 @@
  188. /* PMDFile_Face: face element */
  189. typedef struct {
  190. char name[20]; /* name of this face */
  191. - unsigned long numVertex; /* number of vertices controlled by this face */
  192. + unsigned int numVertex; /* number of vertices controlled by this face */
  193. unsigned char type; /* face type (PMD_FACE_TYPE) */
  194. } PMDFile_Face;
  195.  
  196. @@ -153,8 +153,8 @@
  197. /* Bulletphysics Constraint element */
  198. typedef struct {
  199. char name[20]; /* name of this constraint */
  200. - unsigned long bodyIDA; /* ID of body A */
  201. - unsigned long bodyIDB; /* ID of body B */
  202. + unsigned int bodyIDA; /* ID of body A */
  203. + unsigned int bodyIDB; /* ID of body B */
  204. float pos[3]; /* position (x, y, z), relative to related bone */
  205. float rot[3]; /* rotation (x, y, z), in radian */
  206. float limitPosFrom[3]; /* position move limit from (x, y, z) */
  207. Index: include/VMD.h
  208. ===================================================================
  209. --- include/VMD.h (revision 39)
  210. +++ include/VMD.h (working copy)
  211. @@ -102,16 +102,16 @@
  212. float m_maxFrame; /* max frame */
  213.  
  214. /* addBoneMotion: add new bone motion to list */
  215. - void addBoneMotion(char *name);
  216. + void addBoneMotion(const char *name);
  217.  
  218. /* addFaceMotion: add new face motion to list */
  219. - void addFaceMotion(char *name);
  220. + void addFaceMotion(const char *name);
  221.  
  222. /* getBoneMotion: find bone motion by name */
  223. - BoneMotion * getBoneMotion(char *name);
  224. + BoneMotion * getBoneMotion(const char *name);
  225.  
  226. /* getFaceMotion: find face motion by name */
  227. - FaceMotion * getFaceMotion(char *name);
  228. + FaceMotion * getFaceMotion(const char *name);
  229.  
  230. /* setInterpolationTable: set up motion interpolation parameter */
  231. void setInterpolationTable(BoneKeyFrame *bf, char ip[]);
  232. @@ -131,10 +131,10 @@
  233. ~VMD();
  234.  
  235. /* load: initialize and load from file name */
  236. - bool load(char *file);
  237. + bool load(const char *file);
  238.  
  239. /* parse: initialize and load from data memories */
  240. - bool parse(unsigned char *data, unsigned long size);
  241. + bool parse(unsigned char *data, size_t size);
  242.  
  243. /* getTotalKeyFrame: get total number of key frames */
  244. unsigned long getTotalKeyFrame();
  245. Index: include/VMDFile.h
  246. ===================================================================
  247. --- include/VMDFile.h (revision 39)
  248. +++ include/VMDFile.h (working copy)
  249. @@ -51,7 +51,7 @@
  250. /* VMDFile_BoneFrame: bone motion element structure for VMD file reading */
  251. typedef struct _VMDFile_BoneFrame {
  252. char boneName[15]; /* bone name */
  253. - unsigned long keyFrame; /* key frame */
  254. + unsigned int keyFrame; /* key frame */
  255. float pos[3]; /* position (x, y, z) */
  256. float rot[4]; /* rotation (x, y, z, w) */
  257. char interpolation[64]; /* interpolation parameters */
  258. @@ -60,7 +60,7 @@
  259. /* VMDFile_FaceFrame: face motion element structure for VMD file reading */
  260. typedef struct _VMDFile_FaceFrame {
  261. char faceName[15]; /* face name */
  262. - unsigned long keyFrame; /* key frame */
  263. + unsigned int keyFrame; /* key frame */
  264. float weight; /* weight (0.0 - 1.0) */
  265. } VMDFile_FaceFrame;
  266.  
  267. Index: include/PMDTextureLoader.h
  268. ===================================================================
  269. --- include/PMDTextureLoader.h (revision 39)
  270. +++ include/PMDTextureLoader.h (working copy)
  271. @@ -55,10 +55,10 @@
  272. bool m_hasError; /* true then some error occured at texture loading */
  273.  
  274. /* lookup: lookup texture in cache */
  275. - PMDTexture *lookup(char *fileName, bool *alreadyFailRet);
  276. + PMDTexture *lookup(const char *fileName, bool *alreadyFailRet);
  277.  
  278. /* store: add a texture to cache */
  279. - void store(PMDTexture *tex, char *fileName);
  280. + void store(PMDTexture *tex, const char *fileName);
  281.  
  282. /* initialize: initialize texture loader */
  283. void initialize();
  284. @@ -75,7 +75,7 @@
  285. ~PMDTextureLoader();
  286.  
  287. /* load: load texture from file name (multi-byte char) */
  288. - PMDTexture *load(char *fileName);
  289. + PMDTexture *load(const char *fileName);
  290.  
  291. /* getErrorTextureString: get newline-separated list of error textures */
  292. void getErrorTextureString(char *buf, int maxlen);
  293. Index: src/lib/MotionManager.cpp
  294. ===================================================================
  295. --- src/lib/MotionManager.cpp (revision 39)
  296. +++ src/lib/MotionManager.cpp (working copy)
  297. @@ -136,7 +136,7 @@
  298. }
  299.  
  300. /* MotionManager::startMotion start a motion */
  301. -bool MotionManager::startMotion(VMD * vmd, char *name, bool full, bool once, bool enableSmooth, bool enableRePos)
  302. +bool MotionManager::startMotion(VMD * vmd, const char *name, bool full, bool once, bool enableSmooth, bool enableRePos)
  303. {
  304. MotionPlayer *m, *tmp1, *tmp2;
  305.  
  306. @@ -242,7 +242,7 @@
  307. }
  308.  
  309. /* MotionManager::swapMotion: swap a motion, keeping parameters */
  310. -bool MotionManager::swapMotion(VMD * vmd, char * name)
  311. +bool MotionManager::swapMotion(VMD * vmd, const char * name)
  312. {
  313. MotionPlayer *m;
  314.  
  315. @@ -268,7 +268,7 @@
  316. }
  317.  
  318. /* MotionManager::deleteMotion: delete a motion */
  319. -bool MotionManager::deleteMotion(char *name)
  320. +bool MotionManager::deleteMotion(const char *name)
  321. {
  322. MotionPlayer *m;
  323.  
  324. Index: src/lib/PMDModel.cpp
  325. ===================================================================
  326. --- src/lib/PMDModel.cpp (revision 39)
  327. +++ src/lib/PMDModel.cpp (working copy)
  328. @@ -278,17 +278,29 @@
  329. fgetpos(fp, &size);
  330.  
  331. /* allocate memory for reading data */
  332. +#if defined(__linux) || defined(__linux__) || defined(linux)
  333. + data = (unsigned char *) malloc((size_t) size.__pos);
  334. +#else
  335. data = (unsigned char *) malloc((size_t) size);
  336. +#endif
  337.  
  338. /* read all data */
  339. fseek(fp, 0, SEEK_SET);
  340. +#if defined(__linux) || defined(__linux__) || defined(linux)
  341. + fread(data, 1, (size_t) size.__pos, fp);
  342. +#else
  343. fread(data, 1, (size_t) size, fp);
  344. +#endif
  345.  
  346. /* close file */
  347. fclose(fp);
  348.  
  349. /* initialize and load from the data memories */
  350. +#if defined(__linux) || defined(__linux__) || defined(linux)
  351. + ret = parse(data, (unsigned long) size.__pos, bullet, systex, dir);
  352. +#else
  353. ret = parse(data, (unsigned long) size, bullet, systex, dir);
  354. +#endif
  355.  
  356. /* release memory for reading */
  357. free(data);
  358. @@ -298,7 +310,7 @@
  359. }
  360.  
  361. /* PMDModel::getBone: find bone data by name */
  362. -PMDBone *PMDModel::getBone(char *name)
  363. +PMDBone *PMDModel::getBone(const char *name)
  364. {
  365. PMDBone *match = (PMDBone *) m_name2bone.findNearest(name);
  366.  
  367. @@ -309,7 +321,7 @@
  368. }
  369.  
  370. /* PMDModel::getFace: find face data by name */
  371. -PMDFace *PMDModel::getFace(char *name)
  372. +PMDFace *PMDModel::getFace(const char *name)
  373. {
  374. PMDFace *match = (PMDFace *) m_name2face.findNearest(name);
  375.  
  376. @@ -439,7 +451,7 @@
  377. }
  378.  
  379. /* PMDModel::getName: get name */
  380. -char *PMDModel::getName()
  381. +const char *PMDModel::getName()
  382. {
  383. return m_name;
  384. }
  385. @@ -505,13 +517,13 @@
  386. }
  387.  
  388. /* PMDModel::getComment: get comment of PMD */
  389. -char *PMDModel::getComment()
  390. +const char *PMDModel::getComment()
  391. {
  392. return m_comment;
  393. }
  394.  
  395. /* PMDModel::getModelDir: get model directory */
  396. -char *PMDModel::getModelDir()
  397. +const char *PMDModel::getModelDir()
  398. {
  399. return m_modelDir;
  400. }
  401. Index: src/lib/PMDTexture.cpp
  402. ===================================================================
  403. --- src/lib/PMDTexture.cpp (revision 39)
  404. +++ src/lib/PMDTexture.cpp (working copy)
  405. @@ -44,6 +44,53 @@
  406. #include "png.h"
  407. #include "MMDFiles.h"
  408.  
  409. +#if !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32)
  410. +#include <stdint.h>
  411. +
  412. +// XXX: "#pragma pack" seems MSVC specific but gcc understand this and works correctly.
  413. +// should use "#pragma pack"?
  414. +#pragma pack(push,1)
  415. +
  416. +typedef struct tagRGBQUAD {
  417. + uint8_t rgbBlue;
  418. + uint8_t rgbGreen;
  419. + uint8_t rgbRed;
  420. + uint8_t rgbReserved;
  421. +} RGBQUAD;
  422. +
  423. +typedef struct tagBITMAPFILEHEADER {
  424. + uint16_t bfType;
  425. + uint32_t bfSize;
  426. + uint16_t bfReserved1;
  427. + uint16_t bfReserved2;
  428. + uint32_t bfOffBits;
  429. +} BITMAPFILEHEADER;
  430. +
  431. +typedef struct tagBITMAPINFOHEADER {
  432. + uint32_t biSize;
  433. + uint32_t biWidth;
  434. + uint32_t biHeight;
  435. + uint16_t biPlanes;
  436. + uint16_t biBitCount;
  437. + uint32_t biCompression;
  438. + uint32_t biSizeImage;
  439. + uint32_t biXPelsPerMeter;
  440. + uint32_t biYPelsPerMeter;
  441. + uint32_t biClrUsed;
  442. + uint32_t biClrImportant;
  443. +} BITMAPINFOHEADER;
  444. +
  445. +typedef struct tagBITMAPCOREHEADER{
  446. + uint32_t bcSize;
  447. + uint16_t bcWidth;
  448. + uint16_t bcHeight;
  449. + uint16_t bcPlanes;
  450. + uint16_t bcBitCount;
  451. +} BITMAPCOREHEADER;
  452. +
  453. +#pragma pack(pop)
  454. +#endif
  455. +
  456. static bool checkExtension(const char *fn, const char *ext)
  457. {
  458. int len1, len2;
  459. @@ -67,10 +114,11 @@
  460. }
  461.  
  462. /* PMDTexture::loadBMP: load BMP texture */
  463. -bool PMDTexture::loadBMP(char *fileName)
  464. +bool PMDTexture::loadBMP(const char *fileName)
  465. {
  466. FILE *fp;
  467. - fpos_t size;
  468. + fpos_t fpos;
  469. + size_t size;
  470. unsigned char *data;
  471.  
  472. unsigned short bit;
  473. @@ -96,10 +144,15 @@
  474. if (!fp)
  475. return false;
  476. fseek(fp, 0, SEEK_END);
  477. - fgetpos(fp, &size);
  478. - data = (unsigned char *) malloc((size_t) size);
  479. + fgetpos(fp, &fpos);
  480. +#if defined(__linux__)
  481. + size = (size_t) fpos.__pos;
  482. +#else
  483. + size = (size_t) fpos;
  484. +#endif
  485. + data = (unsigned char *) malloc(size);
  486. fseek(fp, 0, SEEK_SET);
  487. - fread(data, 1, (size_t)size, fp);
  488. + fread(data, 1, size, fp);
  489. fclose(fp);
  490.  
  491. /* parse header */
  492. @@ -111,7 +164,7 @@
  493. fh = (BITMAPFILEHEADER *) head;
  494. body = data + fh->bfOffBits;
  495. head += sizeof(BITMAPFILEHEADER);
  496. - len = *((unsigned long *) head);
  497. + len = *((unsigned int *) head);
  498. if (len == sizeof(BITMAPCOREHEADER)) {
  499. free(data);
  500. return false;
  501. @@ -228,10 +281,11 @@
  502. }
  503.  
  504. /* PMDTexture::loadTGA: load TGA texture */
  505. -bool PMDTexture::loadTGA(char *fileName)
  506. +bool PMDTexture::loadTGA(const char *fileName)
  507. {
  508. FILE *fp;
  509. - fpos_t size;
  510. + fpos_t fpos;
  511. + size_t size;
  512. unsigned char *data;
  513.  
  514. unsigned char type;
  515. @@ -255,7 +309,12 @@
  516. if (!fp)
  517. return false;
  518. fseek(fp, 0, SEEK_END);
  519. - fgetpos(fp, &size);
  520. + fgetpos(fp, &fpos);
  521. +#if defined(__linux__)
  522. + size = (size_t) fpos.__pos;
  523. +#else
  524. + size = (size_t) fpos;
  525. +#endif
  526. data = (unsigned char *) malloc((size_t) size);
  527. fseek(fp, 0, SEEK_SET);
  528. fread(data, 1, (size_t)size, fp);
  529. @@ -334,7 +393,7 @@
  530. }
  531.  
  532. /* PMDTexture::loadPNG: load PNG texture */
  533. -bool PMDTexture::loadPNG(char *fileName)
  534. +bool PMDTexture::loadPNG(const char *fileName)
  535. {
  536. png_uint_32 imageWidth, imageHeight;
  537. int depth, color;
  538. @@ -418,7 +477,7 @@
  539. }
  540.  
  541. /* PMDTexture::loadJPG: load JPG texture */
  542. -bool PMDTexture::loadJPG(char *fileName)
  543. +bool PMDTexture::loadJPG(const char *fileName)
  544. {
  545. return false;
  546. }
  547. @@ -458,7 +517,7 @@
  548. }
  549.  
  550. /* PMDTexture::load: load from file (multi-byte character) */
  551. -bool PMDTexture::load(char *fileName)
  552. +bool PMDTexture::load(const char *fileName)
  553. {
  554. bool ret = true;
  555. size_t len;
  556. Index: src/lib/SystemTexture.cpp
  557. ===================================================================
  558. --- src/lib/SystemTexture.cpp (revision 39)
  559. +++ src/lib/SystemTexture.cpp (working copy)
  560. @@ -75,11 +75,11 @@
  561. }
  562.  
  563. /* SystemTexture::load: load system texture from current directory */
  564. -bool SystemTexture::load(char *dir)
  565. +bool SystemTexture::load(const char *dir)
  566. {
  567. int i;
  568. bool ret = true;
  569. - char *files[] = {SYSTEMTEXTURE_FILENAMES};
  570. + const char *files[] = {SYSTEMTEXTURE_FILENAMES};
  571. char buff[MMDFILES_MAXBUFLEN];
  572.  
  573. for (i = 0; i < SYSTEMTEXTURE_NUMFILES; i++) {
  574. @@ -105,4 +105,4 @@
  575. void SystemTexture::release()
  576. {
  577. clear();
  578. -}
  579. ¥ No newline at end of file
  580. +}
  581. Index: src/lib/MotionController.cpp
  582. ===================================================================
  583. --- src/lib/MotionController.cpp (revision 39)
  584. +++ src/lib/MotionController.cpp (working copy)
  585. @@ -384,6 +384,7 @@
  586. FaceMotionLink *fmlink;
  587. FaceMotion *fm;
  588. PMDFace *f;
  589. + const char centerBoneName[] = MOTIONCONTROLLER_CENTERBONENAME;
  590.  
  591. clear();
  592. m_hasCenterBoneMotion = false;
  593. @@ -405,7 +406,7 @@
  594. m_boneCtrlList[m_numBoneCtrl].bone = b;
  595. m_boneCtrlList[m_numBoneCtrl].motion = bm;
  596. m_numBoneCtrl++;
  597. - if (bm->numKeyFrame > 1 && strcmp(bm->name, MOTIONCONTROLLER_CENTERBONENAME) == 0) {
  598. + if (bm->numKeyFrame > 1 && strcmp(bm->name, centerBoneName) == 0) {
  599. /* This motion has more than 1 key frames for Center Bone, so need re-location */
  600. m_hasCenterBoneMotion = true;
  601. }
  602. Index: src/lib/PTree.cpp
  603. ===================================================================
  604. --- src/lib/PTree.cpp (revision 39)
  605. +++ src/lib/PTree.cpp (working copy)
  606. @@ -44,7 +44,7 @@
  607. #include "MMDFiles.h"
  608.  
  609. /* testBit: test a bit */
  610. -static int testBit(char *str, int slen, int bitplace)
  611. +static int testBit(const char *str, int slen, int bitplace)
  612. {
  613. int maskptr;
  614. const unsigned char mbit[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
  615. @@ -55,7 +55,7 @@
  616. }
  617.  
  618. /* testBitMax: test a bit with max bit limit */
  619. -static int testBitMax(char *str, int bitplace, int maxbitplace)
  620. +static int testBitMax(const char *str, int bitplace, int maxbitplace)
  621. {
  622. const unsigned char mbit[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
  623.  
  624. @@ -65,7 +65,7 @@
  625. }
  626.  
  627. /* getDiffPoint: return which bit differs first between two strings */
  628. -static int getDiffPoint(char *str1, char *str2)
  629. +static int getDiffPoint(const char *str1, const char *str2)
  630. {
  631. int p = 0;
  632. int bitloc;
  633. @@ -146,7 +146,7 @@
  634. }
  635.  
  636. /* PTree::add: add an entry to the tree */
  637. -void PTree::add(char *str, void *data, char *matchstr)
  638. +void PTree::add(const char *str, void *data, const char *matchstr)
  639. {
  640. int slen, bitloc;
  641. PTreeNode **p;
  642. @@ -186,7 +186,7 @@
  643. }
  644.  
  645. /* PTree::findNearest: return the nearest entry */
  646. -void * PTree::findNearest(char *str)
  647. +void * PTree::findNearest(const char *str)
  648. {
  649. PTreeNode *n;
  650. PTreeNode *branch;
  651. Index: src/lib/PMDBone.cpp
  652. ===================================================================
  653. --- src/lib/PMDBone.cpp (revision 39)
  654. +++ src/lib/PMDBone.cpp (working copy)
  655. @@ -191,7 +191,7 @@
  656. void PMDBone::setMotionIndependency()
  657. {
  658. int i;
  659. - char *names[] = {PMDBONE_ADDITIONALROOTNAME};
  660. + const char *names[] = {PMDBONE_ADDITIONALROOTNAME};
  661.  
  662. if (! m_parentBone || m_parentIsRoot) {
  663. /* if no parent bone in the model, return true */
  664. Index: src/lib/VMD.cpp
  665. ===================================================================
  666. --- src/lib/VMD.cpp (revision 39)
  667. +++ src/lib/VMD.cpp (working copy)
  668. @@ -74,7 +74,7 @@
  669. }
  670.  
  671. /* VMD::addBoneMotion: add new bone motion to list */
  672. -void VMD::addBoneMotion(char *name)
  673. +void VMD::addBoneMotion(const char *name)
  674. {
  675. BoneMotionLink *link;
  676. BoneMotion *bmNew;
  677. @@ -97,7 +97,7 @@
  678. }
  679.  
  680. /* VMD::addFaceMotion: add new face motion to list */
  681. -void VMD::addFaceMotion(char *name)
  682. +void VMD::addFaceMotion(const char *name)
  683. {
  684. FaceMotionLink *link;
  685. FaceMotion *fmNew;
  686. @@ -120,7 +120,7 @@
  687. }
  688.  
  689. /* VMD::getBoneMotion: find bone motion by name */
  690. -BoneMotion* VMD::getBoneMotion(char *name)
  691. +BoneMotion* VMD::getBoneMotion(const char *name)
  692. {
  693. BoneMotion *bm;
  694.  
  695. @@ -135,7 +135,7 @@
  696. }
  697.  
  698. /* VMD::getFaceMotion: find face motion by name */
  699. -FaceMotion* VMD::getFaceMotion(char *name)
  700. +FaceMotion* VMD::getFaceMotion(const char *name)
  701. {
  702. FaceMotion *fm;
  703.  
  704. @@ -254,10 +254,11 @@
  705. }
  706.  
  707. /* VMD::load: initialize and load from file name */
  708. -bool VMD::load(char *file)
  709. +bool VMD::load(const char *file)
  710. {
  711. FILE *fp;
  712. - fpos_t size;
  713. + fpos_t fpos;
  714. + size_t size;
  715. unsigned char *data;
  716. bool ret;
  717.  
  718. @@ -268,14 +269,19 @@
  719.  
  720. /* get file size */
  721. fseek(fp, 0, SEEK_END);
  722. - fgetpos(fp, &size);
  723. + fgetpos(fp, &fpos);
  724. +#if defined(__linux__)
  725. + size = (size_t) fpos.__pos;
  726. +#else
  727. + size = (size_t) fpos;
  728. +#endif
  729.  
  730. /* allocate memory for reading data */
  731. - data = (unsigned char *) malloc((size_t) size);
  732. + data = (unsigned char *) malloc(size);
  733.  
  734. /* read all data */
  735. fseek(fp, 0, SEEK_SET);
  736. - fread(data, 1, (size_t) size, fp);
  737. + fread(data, 1, size, fp);
  738.  
  739. /* close file */
  740. fclose(fp);
  741. @@ -290,7 +296,7 @@
  742. }
  743.  
  744. /* VMD::parse: initialize and load from data memories */
  745. -bool VMD::parse(unsigned char *data, unsigned long size)
  746. +bool VMD::parse(unsigned char *data, size_t size)
  747. {
  748. unsigned long i;
  749. size_t len = 0;
  750. @@ -304,14 +310,15 @@
  751.  
  752. /* header */
  753. VMDFile_Header *header = (VMDFile_Header *) data;
  754. - if (strncmp(header->header, "Vocaloid Motion Data 0002", 30) != 0)
  755. + if (strncmp(header->header, "Vocaloid Motion Data 0002", sizeof(header->header)) != 0)
  756. return false;
  757.  
  758. data += sizeof(VMDFile_Header);
  759.  
  760. /* bone motions */
  761. - m_numTotalBoneKeyFrame = *((unsigned long *) data);
  762. - data += sizeof(unsigned long);
  763. + // FIXME: use unsigned int instead of unsigned long for 64bit environment
  764. + m_numTotalBoneKeyFrame = *((unsigned int *) data);
  765. + data += sizeof(unsigned int);
  766.  
  767. VMDFile_BoneFrame *boneFrame = (VMDFile_BoneFrame *) data;
  768.  
  769. @@ -357,8 +364,8 @@
  770. data += sizeof(VMDFile_BoneFrame) * m_numTotalBoneKeyFrame;
  771.  
  772. /* face motions */
  773. - m_numTotalFaceKeyFrame = *((unsigned long *) data);
  774. - data += sizeof(unsigned long);
  775. + m_numTotalFaceKeyFrame = *((unsigned int *) data);
  776. + data += sizeof(unsigned int);
  777.  
  778. VMDFile_FaceFrame *faceFrame = (VMDFile_FaceFrame *) data;
  779.  
  780. Index: src/lib/PMDTextureLoader.cpp
  781. ===================================================================
  782. --- src/lib/PMDTextureLoader.cpp (revision 39)
  783. +++ src/lib/PMDTextureLoader.cpp (working copy)
  784. @@ -44,7 +44,7 @@
  785. #include "MMDFiles.h"
  786.  
  787. /* PMDTextureLoader:lookup: lookup texture in cache */
  788. -PMDTexture *PMDTextureLoader::lookup(char *fileName, bool *alreadyFailRet)
  789. +PMDTexture *PMDTextureLoader::lookup(const char *fileName, bool *alreadyFailRet)
  790. {
  791. TextureLink *tmp = m_root;
  792.  
  793. @@ -62,7 +62,7 @@
  794. }
  795.  
  796. /* PMDTextureLoader::store: add a texture to cache */
  797. -void PMDTextureLoader::store(PMDTexture *tex, char *fileName)
  798. +void PMDTextureLoader::store(PMDTexture *tex, const char *fileName)
  799. {
  800. TextureLink *newLink = new TextureLink;
  801.  
  802. @@ -109,7 +109,7 @@
  803. }
  804.  
  805. /* PMDTextureLoader::load: load texture from file name (multi-byte char) */
  806. -PMDTexture *PMDTextureLoader::load(char *fileName)
  807. +PMDTexture *PMDTextureLoader::load(const char *fileName)
  808. {
  809. PMDTexture *tex;
  810. bool already_fail;
  811. Index: src/lib/PMDModel_parse.cpp
  812. ===================================================================
  813. --- src/lib/PMDModel_parse.cpp (revision 39)
  814. +++ src/lib/PMDModel_parse.cpp (working copy)
  815. @@ -64,6 +64,7 @@
  816. unsigned long numBoneDisp;
  817.  
  818. char buf[MMDFILES_MAXBUFLEN]; /* for toon texture */
  819. + const char centerBoneName[] = MOTIONCONTROLLER_CENTERBONENAME;
  820.  
  821. unsigned char englishNameExist;
  822. char *exToonBMPName;
  823. @@ -108,6 +109,7 @@
  824. m_name = (char *) malloc(sizeof(char) * (20 + 1));
  825. strncpy(m_name, fileHeader->name, 20);
  826. m_name[20] = '¥0';
  827. +
  828. /* directory */
  829. m_modelDir = strdup(dir);
  830. /* comment */
  831. @@ -118,8 +120,9 @@
  832.  
  833. /* vertex data and bone weights */
  834. /* relocate as separated list for later OpenGL calls */
  835. - m_numVertex = *((unsigned long *) data);
  836. - data += sizeof(unsigned long);
  837. + // FIXME: unsigned long is 64bit under 64bit environment
  838. + m_numVertex = *((unsigned int *) data);
  839. + data += sizeof(unsigned int);
  840. m_vertexList = new btVector3[m_numVertex];
  841. m_normalList = new btVector3[m_numVertex];
  842. m_texCoordList = (TexCoord *) malloc(sizeof(TexCoord) * m_numVertex);
  843. @@ -141,15 +144,15 @@
  844. data += sizeof(PMDFile_Vertex) * m_numVertex;
  845.  
  846. /* surface data, 3 vertex indices for each */
  847. - m_numSurface = *((unsigned long *) data);
  848. - data += sizeof(unsigned long);
  849. + m_numSurface = *((unsigned int *) data);
  850. + data += sizeof(unsigned int);
  851. m_surfaceList = (unsigned short *) malloc(sizeof(unsigned short) * m_numSurface);
  852. memcpy(m_surfaceList, data, sizeof(unsigned short) * m_numSurface);
  853. data += sizeof(unsigned short) * m_numSurface;
  854.  
  855. /* material data (color, texture, toon parameter, edge flag) */
  856. - m_numMaterial = *((unsigned long *) data);
  857. - data += sizeof(unsigned long);
  858. + m_numMaterial = *((unsigned int *) data);
  859. + data += sizeof(unsigned int);
  860. m_material = new PMDMaterial[m_numMaterial];
  861. fileMaterial = (PMDFile_Material *) data;
  862. for (i = 0; i < m_numMaterial; i++) {
  863. @@ -167,7 +170,7 @@
  864. for (i = 0; i < m_numBone; i++) {
  865. if (!m_boneList[i].setup(&(fileBone[i]), m_boneList, m_numBone, &m_rootBone))
  866. ret = false;
  867. - if (strcmp(m_boneList[i].getName(), PMDMODEL_CENTERBONENAME) == 0)
  868. + if (strcmp(m_boneList[i].getName(), centerBoneName) == 0)
  869. m_centerBone = &(m_boneList[i]);
  870. }
  871. if (!m_centerBone && m_numBone >= 1) {
  872. @@ -222,8 +225,8 @@
  873. numBoneFrameDisp = *((unsigned char *) data);
  874. data += sizeof(unsigned char) + 50 * numBoneFrameDisp;
  875. /* indices for bones which should be displayed in each bone region */
  876. - numBoneDisp = *((unsigned long *) data);
  877. - data += sizeof(unsigned long) + (sizeof(short) + sizeof(unsigned char)) * numBoneDisp;
  878. + numBoneDisp = *((unsigned int *) data);
  879. + data += sizeof(unsigned int) + (sizeof(short) + sizeof(unsigned char)) * numBoneDisp;
  880.  
  881. /* end of base format */
  882. /* check for remaining data */
  883. @@ -294,8 +297,8 @@
  884. m_boneList[i].update();
  885.  
  886. /* Bullet Physics rigidbody data */
  887. - m_numRigidBody = *((unsigned long *) data);
  888. - data += sizeof(unsigned long);
  889. + m_numRigidBody = *((unsigned int *) data);
  890. + data += sizeof(unsigned int);
  891. if (m_numRigidBody > 0) {
  892. m_rigidBodyList = new PMDRigidBody[m_numRigidBody];
  893. fileRigidBody = (PMDFile_RigidBody *) data;
  894. @@ -311,8 +314,8 @@
  895. }
  896.  
  897. /* BulletPhysics constraint data */
  898. - m_numConstraint = *((unsigned long *) data);
  899. - data += sizeof(unsigned long);
  900. + m_numConstraint = *((unsigned int *) data);
  901. + data += sizeof(unsigned int);
  902. if (m_numConstraint > 0) {
  903. m_constraintList = new PMDConstraint[m_numConstraint];
  904. fileConstraint = (PMDFile_Constraint *) data;
  905. Index: CMakeLists.txt
  906. ===================================================================
  907. --- CMakeLists.txt (revision 0)
  908. +++ CMakeLists.txt (revision 0)
  909. @@ -0,0 +1,98 @@
  910. +cmake_minimum_required(VERSION 2.6)
  911. +
  912. +# set library version
  913. +set(MMDFILES_VERSION 1.0)
  914. +
  915. +# project configuration
  916. +project(Library_MMDFiles)
  917. +aux_source_directory(src/lib libMMDFiles_sources)
  918. +set(libMMDFiles_public_headers
  919. + include/BulletPhysics.h
  920. + include/MotionController.h
  921. + include/MotionManager.h
  922. + include/MMDFiles.h
  923. + include/PMDBone.h
  924. + include/PMDConstraint.h
  925. + include/PMDFace.h
  926. + include/PMDFile.h
  927. + include/PMDIK.h
  928. + include/PMDMaterial.h
  929. + include/PMDModel.h
  930. + include/PMDRigidBody.h
  931. + include/PMDTexture.h
  932. + include/PMDTextureLoader.h
  933. + include/PTree.h
  934. + include/SystemTexture.h
  935. + include/VMD.h
  936. + include/VMDFile.h
  937. +)
  938. +
  939. +add_library(MMDFiles SHARED ${libMMDFiles_sources} ${libMMDFiles_public_headers})
  940. +set_target_properties(MMDFiles PROPERTIES VERSION ${MMDFILES_VERSION})
  941. +set_target_properties(MMDFiles PROPERTIES SO_VERSION ${MMDFILES_VERSION})
  942. +
  943. +# project include directories
  944. +include_directories(include)
  945. +
  946. +# find zlib package
  947. +find_package(ZLIB)
  948. +if(ZLIB_FOUND)
  949. + include_directories(${ZLIB_INCLUDE_DIR})
  950. + target_link_libraries(MMDFiles ${ZLIB_LIBRARIES})
  951. +else()
  952. + message(FATAL_ERROR "Required zlib is not found.")
  953. +endif()
  954. +
  955. +# find libpng package
  956. +find_package(PNG)
  957. +if(PNG_FOUND)
  958. + include_directories(${PNG_INCLUDE_DIR})
  959. + add_definitions(${PNG_DEFINITIONS})
  960. + target_link_libraries(MMDFiles ${PNG_LIBRARIES})
  961. +else()
  962. + message(FATAL_ERROR "Required libpng is not found.")
  963. +endif()
  964. +
  965. +# find OpenGL package
  966. +find_package(OpenGL)
  967. +if(OPENGL_FOUND)
  968. + include_directories(${OPENGL_INCLUDE_DIR})
  969. + target_link_libraries(MMDFiles ${OPENGL_LIBRARIES})
  970. +else()
  971. + message(FATAL_ERROR "Required OpenGL is not found.")
  972. +endif()
  973. +
  974. +# find OpenGL Easy Extension
  975. +find_path(GLEE_INCLUDE GLee.h /usr/local/include /usr/include)
  976. +find_library(GLEE_LIBRARY GLee /usr/local/lib /usr/lib)
  977. +if(GLEE_INCLUDE AND GLEE_LIBRARY)
  978. + target_link_libraries(MMDFiles ${GLEE_LIBRARY})
  979. +else()
  980. + message(FATAL_ERROR "Required OpenGL Easy Extension is not found.")
  981. +endif()
  982. +
  983. +# find Bullet Physics via pkg-config
  984. +find_package(PkgConfig)
  985. +pkg_search_module(BULLET REQUIRED bullet)
  986. +if(BULLET_FOUND)
  987. + include_directories(${BULLET_INCLUDE_DIRS})
  988. + target_link_libraries(MMDFiles ${BULLET_LIBRARIES})
  989. + link_directories(${BULLET_LIBRARY_DIRS})
  990. +else()
  991. + message(FATAL_ERROR "Required Bullet Physics is not found.")
  992. +endif()
  993. +
  994. +# create as a framework if build on darwin environment
  995. +if(APPLE)
  996. + if(BUILD_SHARED_LIBS AND FRAMEWORK)
  997. + install(TARGETS MMDFiles DESTINATION .)
  998. + set_target_properties(MMDFiles PROPERTIES FRAMEWORK true)
  999. + set_target_properties(MMDFiles PROPERTIES PUBLIC_HEADER "${libMMDFiles_public_headers}")
  1000. + endif()
  1001. + set_target_properties(MMDFiles PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
  1002. +endif()
  1003. +
  1004. +install(TARGETS MMDFiles EXPORT MMDFiles LIBRARY DESTINATION lib)
  1005. +install(EXPORT MMDFiles DESTINATION lib/MMDFiles)
  1006. +install(DIRECTORY include/ DESTINATION include/MMDFiles PATTERN "*.h" PATTERN ".svn" EXCLUDE)
  1007. +
Add Comment
Please, Sign In to add comment