Created
December 29, 2010 16:47
-
-
Save hkrn/758722 to your computer and use it in GitHub Desktop.
Library_MMDFiles の POSIX (といっても実作業の環境上 MacOSX と Linux での確認だけど) で共有ライブラリを作成できるようにするためのパッチです。64bit にも対応します。ライセンスは MMDAgent と同じく修正 BSD ライセンスです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# build libGLee (OpenGL easy extension) | |
# | |
cmake_minimum_required(VERSION 2.6) | |
project(GLee) | |
add_library(GLee SHARED GLee.c GLee.h) | |
# link against Foundation.framework | |
if(APPLE) | |
find_library(FOUNDATION Foundation) | |
target_link_libraries(GLee ${FOUNDATION}) | |
set_target_properties(GLee PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib") | |
endif() | |
# find OpenGL package | |
find_package(OpenGL) | |
if(OPENGL_FOUND) | |
include_directories(${OPENGL_INCLUDE_DIR}) | |
target_link_libraries(GLee ${OPENGL_LIBRARIES}) | |
else() | |
message(FATAL_ERROR "Required OpenGL is not found.") | |
endif() | |
install(TARGETS GLee LIBRARY DESTINATION lib) | |
install(FILES GLee.h DESTINATION include) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: include/MMDFiles.h | |
=================================================================== | |
--- include/MMDFiles.h (revision 39) | |
+++ include/MMDFiles.h (working copy) | |
@@ -50,7 +50,12 @@ | |
#define MMDFILES_DEG(a) (a * (180.0f / 3.1415926f)) | |
#define MMDFILES_MAXBUFLEN 1024 | |
+ | |
+#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) | |
#define MMDFILES_DIRSEPARATOR '¥¥' | |
+#else | |
+#define MMDFILES_DIRSEPARATOR '/' | |
+#endif | |
#include "btBulletDynamicsCommon.h" | |
Index: include/MotionManager.h | |
=================================================================== | |
--- include/MotionManager.h (revision 39) | |
+++ include/MotionManager.h (working copy) | |
@@ -109,16 +109,16 @@ | |
~MotionManager(); | |
/* startMotion: start a motion */ | |
- bool startMotion(VMD *vmd, char *name, bool full, bool once, bool enableSmooth, bool enableRePos); | |
+ bool startMotion(VMD *vmd, const char *name, bool full, bool once, bool enableSmooth, bool enableRePos); | |
/* startMotionSub: initialize a motion */ | |
void startMotionSub(VMD *vmd, MotionPlayer *m); | |
/* swapMotion: swap a motion, keeping parameters */ | |
- bool swapMotion(VMD *vmd, char *name); | |
+ bool swapMotion(VMD *vmd, const char *name); | |
/* deleteMotion: delete a motion */ | |
- bool deleteMotion(char *name); | |
+ bool deleteMotion(const char *name); | |
/* update: apply all motion players */ | |
bool update(double frame); | |
Index: include/PMDTexture.h | |
=================================================================== | |
--- include/PMDTexture.h (revision 39) | |
+++ include/PMDTexture.h (working copy) | |
@@ -57,16 +57,16 @@ | |
private: | |
/* loadBMP: load BMP texture */ | |
- bool loadBMP(char *fileName); | |
+ bool loadBMP(const char *fileName); | |
/* loadTGA: load TGA texture */ | |
- bool loadTGA(char *fileName); | |
+ bool loadTGA(const char *fileName); | |
/* loadPNG: load PNG texture */ | |
- bool loadPNG(char *fileName); | |
+ bool loadPNG(const char *fileName); | |
/* loadJPG: load JPG texture */ | |
- bool loadJPG(char *fileName); | |
+ bool loadJPG(const char *fileName); | |
/* initialize: initialize texture */ | |
void initialize(); | |
@@ -83,7 +83,7 @@ | |
~PMDTexture(); | |
/* load: load from file name */ | |
- bool load(char *fileName); | |
+ bool load(const char *fileName); | |
/* getID: get OpenGL texture ID */ | |
GLuint getID(); | |
Index: include/PMDModel.h | |
=================================================================== | |
--- include/PMDModel.h (revision 39) | |
+++ include/PMDModel.h (working copy) | |
@@ -39,8 +39,6 @@ | |
/* POSSIBILITY OF SUCH DAMAGE. */ | |
/* ----------------------------------------------------------------- */ | |
-#define PMDMODEL_CENTERBONENAME "センター" | |
- | |
#define PMDMODEL_MINBONEWEIGHT 0.0001f | |
#define PMDMODEL_MINFACEWEIGHT 0.001f | |
@@ -151,10 +149,10 @@ | |
bool load(const char *file, BulletPhysics *bullet, SystemTexture *systex); | |
/* getBone: find bone data by name */ | |
- PMDBone *getBone(char *name); | |
+ PMDBone *getBone(const char *name); | |
/* getFace: find face data by name */ | |
- PMDFace *getFace(char *name); | |
+ PMDFace *getFace(const char *name); | |
/* getChildBoneList: return list of child bones, in decent order */ | |
int getChildBoneList(PMDBone **bone, unsigned short boneNum, PMDBone **childBoneList, unsigned short childBoneNumMax); | |
@@ -190,7 +188,7 @@ | |
PMDBone *getCenterBone(); | |
/* getName: get model name */ | |
- char * getName(); | |
+ const char *getName(); | |
/* getNumVertex: get number of vertics */ | |
unsigned long getNumVertex(); | |
@@ -223,10 +221,10 @@ | |
float getMaxHeight(); | |
/* getComment: get comment of PMD */ | |
- char *getComment(); | |
+ const char *getComment(); | |
/* getModelDir: get model directory */ | |
- char *getModelDir(); | |
+ const char *getModelDir(); | |
/* updateBone: update bones */ | |
void updateBone(); | |
Index: include/SystemTexture.h | |
=================================================================== | |
--- include/SystemTexture.h (revision 39) | |
+++ include/SystemTexture.h (working copy) | |
@@ -65,7 +65,7 @@ | |
~SystemTexture(); | |
/* load: load system texture from current directory */ | |
- bool load(char *dir); | |
+ bool load(const char *dir); | |
/* getTextureID: get toon texture ID */ | |
unsigned int getTextureID(int i); | |
Index: include/MotionController.h | |
=================================================================== | |
--- include/MotionController.h (revision 39) | |
+++ include/MotionController.h (working copy) | |
@@ -42,7 +42,7 @@ | |
#define MOTIONCONTROLLER_BONESTARTMARGINFRAME 20.0f /* frame lengths for bone motion smoothing at loop head */ | |
#define MOTIONCONTROLLER_FACESTARTMARGINFRAME 6.0f /* frame lengths for face motion smoothing at loop head */ | |
-#define MOTIONCONTROLLER_CENTERBONENAME "センター" | |
+#define MOTIONCONTROLLER_CENTERBONENAME { 0x83, 0x5a, 0x83, 0x93, 0x83, 0x5e, 0x81, 0x5b } | |
/* MotionControllerBoneElement: motion control element for bone */ | |
typedef struct _MotionControllerBoneElement { | |
Index: include/PTree.h | |
=================================================================== | |
--- include/PTree.h (revision 39) | |
+++ include/PTree.h (working copy) | |
@@ -86,8 +86,8 @@ | |
void release(); | |
/* add: add an entry to the tree */ | |
- void add(char *str, void *data, char *matchStr); | |
+ void add(const char *str, void *data, const char *matchStr); | |
/* findNearest: return the nearest entry */ | |
- void *findNearest(char *str); | |
+ void *findNearest(const char *str); | |
}; | |
Index: include/PMDFile.h | |
=================================================================== | |
--- include/PMDFile.h (revision 39) | |
+++ include/PMDFile.h (working copy) | |
@@ -92,7 +92,7 @@ | |
float ambient[3]; /* ambient color */ | |
unsigned char toonID; /* toon index: 0xff -> toon0.bmp, other -> toon(val+1).bmp */ | |
unsigned char edgeFlag; /* 1 if edge should be drawn */ | |
- unsigned long numSurfaceIndex; /* number of surface indices for this material */ | |
+ unsigned int numSurfaceIndex; /* number of surface indices for this material */ | |
char textureFile[20]; /* texture file name */ | |
} PMDFile_Material; | |
@@ -117,7 +117,7 @@ | |
/* PMDFile_Face_Vertex: face vertex element */ | |
typedef struct { | |
- unsigned long vertexID; /* vertex index of this model to be controlled */ | |
+ unsigned int vertexID; /* vertex index of this model to be controlled */ | |
/* if base face, this is index for model vertex index */ | |
/* if not base, this is index for base face vertices */ | |
float pos[3]; /* position to be placed if this face rate is 1.0 */ | |
@@ -126,7 +126,7 @@ | |
/* PMDFile_Face: face element */ | |
typedef struct { | |
char name[20]; /* name of this face */ | |
- unsigned long numVertex; /* number of vertices controlled by this face */ | |
+ unsigned int numVertex; /* number of vertices controlled by this face */ | |
unsigned char type; /* face type (PMD_FACE_TYPE) */ | |
} PMDFile_Face; | |
@@ -153,8 +153,8 @@ | |
/* Bulletphysics Constraint element */ | |
typedef struct { | |
char name[20]; /* name of this constraint */ | |
- unsigned long bodyIDA; /* ID of body A */ | |
- unsigned long bodyIDB; /* ID of body B */ | |
+ unsigned int bodyIDA; /* ID of body A */ | |
+ unsigned int bodyIDB; /* ID of body B */ | |
float pos[3]; /* position (x, y, z), relative to related bone */ | |
float rot[3]; /* rotation (x, y, z), in radian */ | |
float limitPosFrom[3]; /* position move limit from (x, y, z) */ | |
Index: include/VMD.h | |
=================================================================== | |
--- include/VMD.h (revision 39) | |
+++ include/VMD.h (working copy) | |
@@ -102,16 +102,16 @@ | |
float m_maxFrame; /* max frame */ | |
/* addBoneMotion: add new bone motion to list */ | |
- void addBoneMotion(char *name); | |
+ void addBoneMotion(const char *name); | |
/* addFaceMotion: add new face motion to list */ | |
- void addFaceMotion(char *name); | |
+ void addFaceMotion(const char *name); | |
/* getBoneMotion: find bone motion by name */ | |
- BoneMotion * getBoneMotion(char *name); | |
+ BoneMotion * getBoneMotion(const char *name); | |
/* getFaceMotion: find face motion by name */ | |
- FaceMotion * getFaceMotion(char *name); | |
+ FaceMotion * getFaceMotion(const char *name); | |
/* setInterpolationTable: set up motion interpolation parameter */ | |
void setInterpolationTable(BoneKeyFrame *bf, char ip[]); | |
@@ -131,10 +131,10 @@ | |
~VMD(); | |
/* load: initialize and load from file name */ | |
- bool load(char *file); | |
+ bool load(const char *file); | |
/* parse: initialize and load from data memories */ | |
- bool parse(unsigned char *data, unsigned long size); | |
+ bool parse(unsigned char *data, size_t size); | |
/* getTotalKeyFrame: get total number of key frames */ | |
unsigned long getTotalKeyFrame(); | |
Index: include/VMDFile.h | |
=================================================================== | |
--- include/VMDFile.h (revision 39) | |
+++ include/VMDFile.h (working copy) | |
@@ -51,7 +51,7 @@ | |
/* VMDFile_BoneFrame: bone motion element structure for VMD file reading */ | |
typedef struct _VMDFile_BoneFrame { | |
char boneName[15]; /* bone name */ | |
- unsigned long keyFrame; /* key frame */ | |
+ unsigned int keyFrame; /* key frame */ | |
float pos[3]; /* position (x, y, z) */ | |
float rot[4]; /* rotation (x, y, z, w) */ | |
char interpolation[64]; /* interpolation parameters */ | |
@@ -60,7 +60,7 @@ | |
/* VMDFile_FaceFrame: face motion element structure for VMD file reading */ | |
typedef struct _VMDFile_FaceFrame { | |
char faceName[15]; /* face name */ | |
- unsigned long keyFrame; /* key frame */ | |
+ unsigned int keyFrame; /* key frame */ | |
float weight; /* weight (0.0 - 1.0) */ | |
} VMDFile_FaceFrame; | |
Index: include/PMDTextureLoader.h | |
=================================================================== | |
--- include/PMDTextureLoader.h (revision 39) | |
+++ include/PMDTextureLoader.h (working copy) | |
@@ -55,10 +55,10 @@ | |
bool m_hasError; /* true then some error occured at texture loading */ | |
/* lookup: lookup texture in cache */ | |
- PMDTexture *lookup(char *fileName, bool *alreadyFailRet); | |
+ PMDTexture *lookup(const char *fileName, bool *alreadyFailRet); | |
/* store: add a texture to cache */ | |
- void store(PMDTexture *tex, char *fileName); | |
+ void store(PMDTexture *tex, const char *fileName); | |
/* initialize: initialize texture loader */ | |
void initialize(); | |
@@ -75,7 +75,7 @@ | |
~PMDTextureLoader(); | |
/* load: load texture from file name (multi-byte char) */ | |
- PMDTexture *load(char *fileName); | |
+ PMDTexture *load(const char *fileName); | |
/* getErrorTextureString: get newline-separated list of error textures */ | |
void getErrorTextureString(char *buf, int maxlen); | |
Index: src/lib/MotionManager.cpp | |
=================================================================== | |
--- src/lib/MotionManager.cpp (revision 39) | |
+++ src/lib/MotionManager.cpp (working copy) | |
@@ -136,7 +136,7 @@ | |
} | |
/* MotionManager::startMotion start a motion */ | |
-bool MotionManager::startMotion(VMD * vmd, char *name, bool full, bool once, bool enableSmooth, bool enableRePos) | |
+bool MotionManager::startMotion(VMD * vmd, const char *name, bool full, bool once, bool enableSmooth, bool enableRePos) | |
{ | |
MotionPlayer *m, *tmp1, *tmp2; | |
@@ -242,7 +242,7 @@ | |
} | |
/* MotionManager::swapMotion: swap a motion, keeping parameters */ | |
-bool MotionManager::swapMotion(VMD * vmd, char * name) | |
+bool MotionManager::swapMotion(VMD * vmd, const char * name) | |
{ | |
MotionPlayer *m; | |
@@ -268,7 +268,7 @@ | |
} | |
/* MotionManager::deleteMotion: delete a motion */ | |
-bool MotionManager::deleteMotion(char *name) | |
+bool MotionManager::deleteMotion(const char *name) | |
{ | |
MotionPlayer *m; | |
Index: src/lib/PMDModel.cpp | |
=================================================================== | |
--- src/lib/PMDModel.cpp (revision 39) | |
+++ src/lib/PMDModel.cpp (working copy) | |
@@ -278,17 +278,29 @@ | |
fgetpos(fp, &size); | |
/* allocate memory for reading data */ | |
+#if defined(__linux) || defined(__linux__) || defined(linux) | |
+ data = (unsigned char *) malloc((size_t) size.__pos); | |
+#else | |
data = (unsigned char *) malloc((size_t) size); | |
+#endif | |
/* read all data */ | |
fseek(fp, 0, SEEK_SET); | |
+#if defined(__linux) || defined(__linux__) || defined(linux) | |
+ fread(data, 1, (size_t) size.__pos, fp); | |
+#else | |
fread(data, 1, (size_t) size, fp); | |
+#endif | |
/* close file */ | |
fclose(fp); | |
/* initialize and load from the data memories */ | |
+#if defined(__linux) || defined(__linux__) || defined(linux) | |
+ ret = parse(data, (unsigned long) size.__pos, bullet, systex, dir); | |
+#else | |
ret = parse(data, (unsigned long) size, bullet, systex, dir); | |
+#endif | |
/* release memory for reading */ | |
free(data); | |
@@ -298,7 +310,7 @@ | |
} | |
/* PMDModel::getBone: find bone data by name */ | |
-PMDBone *PMDModel::getBone(char *name) | |
+PMDBone *PMDModel::getBone(const char *name) | |
{ | |
PMDBone *match = (PMDBone *) m_name2bone.findNearest(name); | |
@@ -309,7 +321,7 @@ | |
} | |
/* PMDModel::getFace: find face data by name */ | |
-PMDFace *PMDModel::getFace(char *name) | |
+PMDFace *PMDModel::getFace(const char *name) | |
{ | |
PMDFace *match = (PMDFace *) m_name2face.findNearest(name); | |
@@ -439,7 +451,7 @@ | |
} | |
/* PMDModel::getName: get name */ | |
-char *PMDModel::getName() | |
+const char *PMDModel::getName() | |
{ | |
return m_name; | |
} | |
@@ -505,13 +517,13 @@ | |
} | |
/* PMDModel::getComment: get comment of PMD */ | |
-char *PMDModel::getComment() | |
+const char *PMDModel::getComment() | |
{ | |
return m_comment; | |
} | |
/* PMDModel::getModelDir: get model directory */ | |
-char *PMDModel::getModelDir() | |
+const char *PMDModel::getModelDir() | |
{ | |
return m_modelDir; | |
} | |
Index: src/lib/PMDTexture.cpp | |
=================================================================== | |
--- src/lib/PMDTexture.cpp (revision 39) | |
+++ src/lib/PMDTexture.cpp (working copy) | |
@@ -44,6 +44,53 @@ | |
#include "png.h" | |
#include "MMDFiles.h" | |
+#if !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32) | |
+#include <stdint.h> | |
+ | |
+// XXX: "#pragma pack" seems MSVC specific but gcc understand this and works correctly. | |
+// should use "#pragma pack"? | |
+#pragma pack(push,1) | |
+ | |
+typedef struct tagRGBQUAD { | |
+ uint8_t rgbBlue; | |
+ uint8_t rgbGreen; | |
+ uint8_t rgbRed; | |
+ uint8_t rgbReserved; | |
+} RGBQUAD; | |
+ | |
+typedef struct tagBITMAPFILEHEADER { | |
+ uint16_t bfType; | |
+ uint32_t bfSize; | |
+ uint16_t bfReserved1; | |
+ uint16_t bfReserved2; | |
+ uint32_t bfOffBits; | |
+} BITMAPFILEHEADER; | |
+ | |
+typedef struct tagBITMAPINFOHEADER { | |
+ uint32_t biSize; | |
+ uint32_t biWidth; | |
+ uint32_t biHeight; | |
+ uint16_t biPlanes; | |
+ uint16_t biBitCount; | |
+ uint32_t biCompression; | |
+ uint32_t biSizeImage; | |
+ uint32_t biXPelsPerMeter; | |
+ uint32_t biYPelsPerMeter; | |
+ uint32_t biClrUsed; | |
+ uint32_t biClrImportant; | |
+} BITMAPINFOHEADER; | |
+ | |
+typedef struct tagBITMAPCOREHEADER{ | |
+ uint32_t bcSize; | |
+ uint16_t bcWidth; | |
+ uint16_t bcHeight; | |
+ uint16_t bcPlanes; | |
+ uint16_t bcBitCount; | |
+} BITMAPCOREHEADER; | |
+ | |
+#pragma pack(pop) | |
+#endif | |
+ | |
static bool checkExtension(const char *fn, const char *ext) | |
{ | |
int len1, len2; | |
@@ -67,10 +114,11 @@ | |
} | |
/* PMDTexture::loadBMP: load BMP texture */ | |
-bool PMDTexture::loadBMP(char *fileName) | |
+bool PMDTexture::loadBMP(const char *fileName) | |
{ | |
FILE *fp; | |
- fpos_t size; | |
+ fpos_t fpos; | |
+ size_t size; | |
unsigned char *data; | |
unsigned short bit; | |
@@ -96,10 +144,15 @@ | |
if (!fp) | |
return false; | |
fseek(fp, 0, SEEK_END); | |
- fgetpos(fp, &size); | |
- data = (unsigned char *) malloc((size_t) size); | |
+ fgetpos(fp, &fpos); | |
+#if defined(__linux__) | |
+ size = (size_t) fpos.__pos; | |
+#else | |
+ size = (size_t) fpos; | |
+#endif | |
+ data = (unsigned char *) malloc(size); | |
fseek(fp, 0, SEEK_SET); | |
- fread(data, 1, (size_t)size, fp); | |
+ fread(data, 1, size, fp); | |
fclose(fp); | |
/* parse header */ | |
@@ -111,7 +164,7 @@ | |
fh = (BITMAPFILEHEADER *) head; | |
body = data + fh->bfOffBits; | |
head += sizeof(BITMAPFILEHEADER); | |
- len = *((unsigned long *) head); | |
+ len = *((unsigned int *) head); | |
if (len == sizeof(BITMAPCOREHEADER)) { | |
free(data); | |
return false; | |
@@ -228,10 +281,11 @@ | |
} | |
/* PMDTexture::loadTGA: load TGA texture */ | |
-bool PMDTexture::loadTGA(char *fileName) | |
+bool PMDTexture::loadTGA(const char *fileName) | |
{ | |
FILE *fp; | |
- fpos_t size; | |
+ fpos_t fpos; | |
+ size_t size; | |
unsigned char *data; | |
unsigned char type; | |
@@ -255,7 +309,12 @@ | |
if (!fp) | |
return false; | |
fseek(fp, 0, SEEK_END); | |
- fgetpos(fp, &size); | |
+ fgetpos(fp, &fpos); | |
+#if defined(__linux__) | |
+ size = (size_t) fpos.__pos; | |
+#else | |
+ size = (size_t) fpos; | |
+#endif | |
data = (unsigned char *) malloc((size_t) size); | |
fseek(fp, 0, SEEK_SET); | |
fread(data, 1, (size_t)size, fp); | |
@@ -334,7 +393,7 @@ | |
} | |
/* PMDTexture::loadPNG: load PNG texture */ | |
-bool PMDTexture::loadPNG(char *fileName) | |
+bool PMDTexture::loadPNG(const char *fileName) | |
{ | |
png_uint_32 imageWidth, imageHeight; | |
int depth, color; | |
@@ -418,7 +477,7 @@ | |
} | |
/* PMDTexture::loadJPG: load JPG texture */ | |
-bool PMDTexture::loadJPG(char *fileName) | |
+bool PMDTexture::loadJPG(const char *fileName) | |
{ | |
return false; | |
} | |
@@ -458,7 +517,7 @@ | |
} | |
/* PMDTexture::load: load from file (multi-byte character) */ | |
-bool PMDTexture::load(char *fileName) | |
+bool PMDTexture::load(const char *fileName) | |
{ | |
bool ret = true; | |
size_t len; | |
Index: src/lib/SystemTexture.cpp | |
=================================================================== | |
--- src/lib/SystemTexture.cpp (revision 39) | |
+++ src/lib/SystemTexture.cpp (working copy) | |
@@ -75,11 +75,11 @@ | |
} | |
/* SystemTexture::load: load system texture from current directory */ | |
-bool SystemTexture::load(char *dir) | |
+bool SystemTexture::load(const char *dir) | |
{ | |
int i; | |
bool ret = true; | |
- char *files[] = {SYSTEMTEXTURE_FILENAMES}; | |
+ const char *files[] = {SYSTEMTEXTURE_FILENAMES}; | |
char buff[MMDFILES_MAXBUFLEN]; | |
for (i = 0; i < SYSTEMTEXTURE_NUMFILES; i++) { | |
@@ -105,4 +105,4 @@ | |
void SystemTexture::release() | |
{ | |
clear(); | |
-} | |
¥ No newline at end of file | |
+} | |
Index: src/lib/MotionController.cpp | |
=================================================================== | |
--- src/lib/MotionController.cpp (revision 39) | |
+++ src/lib/MotionController.cpp (working copy) | |
@@ -384,6 +384,7 @@ | |
FaceMotionLink *fmlink; | |
FaceMotion *fm; | |
PMDFace *f; | |
+ const char centerBoneName[] = MOTIONCONTROLLER_CENTERBONENAME; | |
clear(); | |
m_hasCenterBoneMotion = false; | |
@@ -405,7 +406,7 @@ | |
m_boneCtrlList[m_numBoneCtrl].bone = b; | |
m_boneCtrlList[m_numBoneCtrl].motion = bm; | |
m_numBoneCtrl++; | |
- if (bm->numKeyFrame > 1 && strcmp(bm->name, MOTIONCONTROLLER_CENTERBONENAME) == 0) { | |
+ if (bm->numKeyFrame > 1 && strcmp(bm->name, centerBoneName) == 0) { | |
/* This motion has more than 1 key frames for Center Bone, so need re-location */ | |
m_hasCenterBoneMotion = true; | |
} | |
Index: src/lib/PTree.cpp | |
=================================================================== | |
--- src/lib/PTree.cpp (revision 39) | |
+++ src/lib/PTree.cpp (working copy) | |
@@ -44,7 +44,7 @@ | |
#include "MMDFiles.h" | |
/* testBit: test a bit */ | |
-static int testBit(char *str, int slen, int bitplace) | |
+static int testBit(const char *str, int slen, int bitplace) | |
{ | |
int maskptr; | |
const unsigned char mbit[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; | |
@@ -55,7 +55,7 @@ | |
} | |
/* testBitMax: test a bit with max bit limit */ | |
-static int testBitMax(char *str, int bitplace, int maxbitplace) | |
+static int testBitMax(const char *str, int bitplace, int maxbitplace) | |
{ | |
const unsigned char mbit[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; | |
@@ -65,7 +65,7 @@ | |
} | |
/* getDiffPoint: return which bit differs first between two strings */ | |
-static int getDiffPoint(char *str1, char *str2) | |
+static int getDiffPoint(const char *str1, const char *str2) | |
{ | |
int p = 0; | |
int bitloc; | |
@@ -146,7 +146,7 @@ | |
} | |
/* PTree::add: add an entry to the tree */ | |
-void PTree::add(char *str, void *data, char *matchstr) | |
+void PTree::add(const char *str, void *data, const char *matchstr) | |
{ | |
int slen, bitloc; | |
PTreeNode **p; | |
@@ -186,7 +186,7 @@ | |
} | |
/* PTree::findNearest: return the nearest entry */ | |
-void * PTree::findNearest(char *str) | |
+void * PTree::findNearest(const char *str) | |
{ | |
PTreeNode *n; | |
PTreeNode *branch; | |
Index: src/lib/PMDBone.cpp | |
=================================================================== | |
--- src/lib/PMDBone.cpp (revision 39) | |
+++ src/lib/PMDBone.cpp (working copy) | |
@@ -191,7 +191,7 @@ | |
void PMDBone::setMotionIndependency() | |
{ | |
int i; | |
- char *names[] = {PMDBONE_ADDITIONALROOTNAME}; | |
+ const char *names[] = {PMDBONE_ADDITIONALROOTNAME}; | |
if (! m_parentBone || m_parentIsRoot) { | |
/* if no parent bone in the model, return true */ | |
Index: src/lib/VMD.cpp | |
=================================================================== | |
--- src/lib/VMD.cpp (revision 39) | |
+++ src/lib/VMD.cpp (working copy) | |
@@ -74,7 +74,7 @@ | |
} | |
/* VMD::addBoneMotion: add new bone motion to list */ | |
-void VMD::addBoneMotion(char *name) | |
+void VMD::addBoneMotion(const char *name) | |
{ | |
BoneMotionLink *link; | |
BoneMotion *bmNew; | |
@@ -97,7 +97,7 @@ | |
} | |
/* VMD::addFaceMotion: add new face motion to list */ | |
-void VMD::addFaceMotion(char *name) | |
+void VMD::addFaceMotion(const char *name) | |
{ | |
FaceMotionLink *link; | |
FaceMotion *fmNew; | |
@@ -120,7 +120,7 @@ | |
} | |
/* VMD::getBoneMotion: find bone motion by name */ | |
-BoneMotion* VMD::getBoneMotion(char *name) | |
+BoneMotion* VMD::getBoneMotion(const char *name) | |
{ | |
BoneMotion *bm; | |
@@ -135,7 +135,7 @@ | |
} | |
/* VMD::getFaceMotion: find face motion by name */ | |
-FaceMotion* VMD::getFaceMotion(char *name) | |
+FaceMotion* VMD::getFaceMotion(const char *name) | |
{ | |
FaceMotion *fm; | |
@@ -254,10 +254,11 @@ | |
} | |
/* VMD::load: initialize and load from file name */ | |
-bool VMD::load(char *file) | |
+bool VMD::load(const char *file) | |
{ | |
FILE *fp; | |
- fpos_t size; | |
+ fpos_t fpos; | |
+ size_t size; | |
unsigned char *data; | |
bool ret; | |
@@ -268,14 +269,19 @@ | |
/* get file size */ | |
fseek(fp, 0, SEEK_END); | |
- fgetpos(fp, &size); | |
+ fgetpos(fp, &fpos); | |
+#if defined(__linux__) | |
+ size = (size_t) fpos.__pos; | |
+#else | |
+ size = (size_t) fpos; | |
+#endif | |
/* allocate memory for reading data */ | |
- data = (unsigned char *) malloc((size_t) size); | |
+ data = (unsigned char *) malloc(size); | |
/* read all data */ | |
fseek(fp, 0, SEEK_SET); | |
- fread(data, 1, (size_t) size, fp); | |
+ fread(data, 1, size, fp); | |
/* close file */ | |
fclose(fp); | |
@@ -290,7 +296,7 @@ | |
} | |
/* VMD::parse: initialize and load from data memories */ | |
-bool VMD::parse(unsigned char *data, unsigned long size) | |
+bool VMD::parse(unsigned char *data, size_t size) | |
{ | |
unsigned long i; | |
size_t len = 0; | |
@@ -304,14 +310,15 @@ | |
/* header */ | |
VMDFile_Header *header = (VMDFile_Header *) data; | |
- if (strncmp(header->header, "Vocaloid Motion Data 0002", 30) != 0) | |
+ if (strncmp(header->header, "Vocaloid Motion Data 0002", sizeof(header->header)) != 0) | |
return false; | |
data += sizeof(VMDFile_Header); | |
/* bone motions */ | |
- m_numTotalBoneKeyFrame = *((unsigned long *) data); | |
- data += sizeof(unsigned long); | |
+ // FIXME: use unsigned int instead of unsigned long for 64bit environment | |
+ m_numTotalBoneKeyFrame = *((unsigned int *) data); | |
+ data += sizeof(unsigned int); | |
VMDFile_BoneFrame *boneFrame = (VMDFile_BoneFrame *) data; | |
@@ -357,8 +364,8 @@ | |
data += sizeof(VMDFile_BoneFrame) * m_numTotalBoneKeyFrame; | |
/* face motions */ | |
- m_numTotalFaceKeyFrame = *((unsigned long *) data); | |
- data += sizeof(unsigned long); | |
+ m_numTotalFaceKeyFrame = *((unsigned int *) data); | |
+ data += sizeof(unsigned int); | |
VMDFile_FaceFrame *faceFrame = (VMDFile_FaceFrame *) data; | |
Index: src/lib/PMDTextureLoader.cpp | |
=================================================================== | |
--- src/lib/PMDTextureLoader.cpp (revision 39) | |
+++ src/lib/PMDTextureLoader.cpp (working copy) | |
@@ -44,7 +44,7 @@ | |
#include "MMDFiles.h" | |
/* PMDTextureLoader:lookup: lookup texture in cache */ | |
-PMDTexture *PMDTextureLoader::lookup(char *fileName, bool *alreadyFailRet) | |
+PMDTexture *PMDTextureLoader::lookup(const char *fileName, bool *alreadyFailRet) | |
{ | |
TextureLink *tmp = m_root; | |
@@ -62,7 +62,7 @@ | |
} | |
/* PMDTextureLoader::store: add a texture to cache */ | |
-void PMDTextureLoader::store(PMDTexture *tex, char *fileName) | |
+void PMDTextureLoader::store(PMDTexture *tex, const char *fileName) | |
{ | |
TextureLink *newLink = new TextureLink; | |
@@ -109,7 +109,7 @@ | |
} | |
/* PMDTextureLoader::load: load texture from file name (multi-byte char) */ | |
-PMDTexture *PMDTextureLoader::load(char *fileName) | |
+PMDTexture *PMDTextureLoader::load(const char *fileName) | |
{ | |
PMDTexture *tex; | |
bool already_fail; | |
Index: src/lib/PMDModel_parse.cpp | |
=================================================================== | |
--- src/lib/PMDModel_parse.cpp (revision 39) | |
+++ src/lib/PMDModel_parse.cpp (working copy) | |
@@ -64,6 +64,7 @@ | |
unsigned long numBoneDisp; | |
char buf[MMDFILES_MAXBUFLEN]; /* for toon texture */ | |
+ const char centerBoneName[] = MOTIONCONTROLLER_CENTERBONENAME; | |
unsigned char englishNameExist; | |
char *exToonBMPName; | |
@@ -108,6 +109,7 @@ | |
m_name = (char *) malloc(sizeof(char) * (20 + 1)); | |
strncpy(m_name, fileHeader->name, 20); | |
m_name[20] = '¥0'; | |
+ | |
/* directory */ | |
m_modelDir = strdup(dir); | |
/* comment */ | |
@@ -118,8 +120,9 @@ | |
/* vertex data and bone weights */ | |
/* relocate as separated list for later OpenGL calls */ | |
- m_numVertex = *((unsigned long *) data); | |
- data += sizeof(unsigned long); | |
+ // FIXME: unsigned long is 64bit under 64bit environment | |
+ m_numVertex = *((unsigned int *) data); | |
+ data += sizeof(unsigned int); | |
m_vertexList = new btVector3[m_numVertex]; | |
m_normalList = new btVector3[m_numVertex]; | |
m_texCoordList = (TexCoord *) malloc(sizeof(TexCoord) * m_numVertex); | |
@@ -141,15 +144,15 @@ | |
data += sizeof(PMDFile_Vertex) * m_numVertex; | |
/* surface data, 3 vertex indices for each */ | |
- m_numSurface = *((unsigned long *) data); | |
- data += sizeof(unsigned long); | |
+ m_numSurface = *((unsigned int *) data); | |
+ data += sizeof(unsigned int); | |
m_surfaceList = (unsigned short *) malloc(sizeof(unsigned short) * m_numSurface); | |
memcpy(m_surfaceList, data, sizeof(unsigned short) * m_numSurface); | |
data += sizeof(unsigned short) * m_numSurface; | |
/* material data (color, texture, toon parameter, edge flag) */ | |
- m_numMaterial = *((unsigned long *) data); | |
- data += sizeof(unsigned long); | |
+ m_numMaterial = *((unsigned int *) data); | |
+ data += sizeof(unsigned int); | |
m_material = new PMDMaterial[m_numMaterial]; | |
fileMaterial = (PMDFile_Material *) data; | |
for (i = 0; i < m_numMaterial; i++) { | |
@@ -167,7 +170,7 @@ | |
for (i = 0; i < m_numBone; i++) { | |
if (!m_boneList[i].setup(&(fileBone[i]), m_boneList, m_numBone, &m_rootBone)) | |
ret = false; | |
- if (strcmp(m_boneList[i].getName(), PMDMODEL_CENTERBONENAME) == 0) | |
+ if (strcmp(m_boneList[i].getName(), centerBoneName) == 0) | |
m_centerBone = &(m_boneList[i]); | |
} | |
if (!m_centerBone && m_numBone >= 1) { | |
@@ -222,8 +225,8 @@ | |
numBoneFrameDisp = *((unsigned char *) data); | |
data += sizeof(unsigned char) + 50 * numBoneFrameDisp; | |
/* indices for bones which should be displayed in each bone region */ | |
- numBoneDisp = *((unsigned long *) data); | |
- data += sizeof(unsigned long) + (sizeof(short) + sizeof(unsigned char)) * numBoneDisp; | |
+ numBoneDisp = *((unsigned int *) data); | |
+ data += sizeof(unsigned int) + (sizeof(short) + sizeof(unsigned char)) * numBoneDisp; | |
/* end of base format */ | |
/* check for remaining data */ | |
@@ -294,8 +297,8 @@ | |
m_boneList[i].update(); | |
/* Bullet Physics rigidbody data */ | |
- m_numRigidBody = *((unsigned long *) data); | |
- data += sizeof(unsigned long); | |
+ m_numRigidBody = *((unsigned int *) data); | |
+ data += sizeof(unsigned int); | |
if (m_numRigidBody > 0) { | |
m_rigidBodyList = new PMDRigidBody[m_numRigidBody]; | |
fileRigidBody = (PMDFile_RigidBody *) data; | |
@@ -311,8 +314,8 @@ | |
} | |
/* BulletPhysics constraint data */ | |
- m_numConstraint = *((unsigned long *) data); | |
- data += sizeof(unsigned long); | |
+ m_numConstraint = *((unsigned int *) data); | |
+ data += sizeof(unsigned int); | |
if (m_numConstraint > 0) { | |
m_constraintList = new PMDConstraint[m_numConstraint]; | |
fileConstraint = (PMDFile_Constraint *) data; | |
Index: CMakeLists.txt | |
=================================================================== | |
--- CMakeLists.txt (revision 0) | |
+++ CMakeLists.txt (revision 0) | |
@@ -0,0 +1,98 @@ | |
+cmake_minimum_required(VERSION 2.6) | |
+ | |
+# set library version | |
+set(MMDFILES_VERSION 1.0) | |
+ | |
+# project configuration | |
+project(Library_MMDFiles) | |
+aux_source_directory(src/lib libMMDFiles_sources) | |
+set(libMMDFiles_public_headers | |
+ include/BulletPhysics.h | |
+ include/MotionController.h | |
+ include/MotionManager.h | |
+ include/MMDFiles.h | |
+ include/PMDBone.h | |
+ include/PMDConstraint.h | |
+ include/PMDFace.h | |
+ include/PMDFile.h | |
+ include/PMDIK.h | |
+ include/PMDMaterial.h | |
+ include/PMDModel.h | |
+ include/PMDRigidBody.h | |
+ include/PMDTexture.h | |
+ include/PMDTextureLoader.h | |
+ include/PTree.h | |
+ include/SystemTexture.h | |
+ include/VMD.h | |
+ include/VMDFile.h | |
+) | |
+ | |
+add_library(MMDFiles SHARED ${libMMDFiles_sources} ${libMMDFiles_public_headers}) | |
+set_target_properties(MMDFiles PROPERTIES VERSION ${MMDFILES_VERSION}) | |
+set_target_properties(MMDFiles PROPERTIES SO_VERSION ${MMDFILES_VERSION}) | |
+ | |
+# project include directories | |
+include_directories(include) | |
+ | |
+# find zlib package | |
+find_package(ZLIB) | |
+if(ZLIB_FOUND) | |
+ include_directories(${ZLIB_INCLUDE_DIR}) | |
+ target_link_libraries(MMDFiles ${ZLIB_LIBRARIES}) | |
+else() | |
+ message(FATAL_ERROR "Required zlib is not found.") | |
+endif() | |
+ | |
+# find libpng package | |
+find_package(PNG) | |
+if(PNG_FOUND) | |
+ include_directories(${PNG_INCLUDE_DIR}) | |
+ add_definitions(${PNG_DEFINITIONS}) | |
+ target_link_libraries(MMDFiles ${PNG_LIBRARIES}) | |
+else() | |
+ message(FATAL_ERROR "Required libpng is not found.") | |
+endif() | |
+ | |
+# find OpenGL package | |
+find_package(OpenGL) | |
+if(OPENGL_FOUND) | |
+ include_directories(${OPENGL_INCLUDE_DIR}) | |
+ target_link_libraries(MMDFiles ${OPENGL_LIBRARIES}) | |
+else() | |
+ message(FATAL_ERROR "Required OpenGL is not found.") | |
+endif() | |
+ | |
+# find OpenGL Easy Extension | |
+find_path(GLEE_INCLUDE GLee.h /usr/local/include /usr/include) | |
+find_library(GLEE_LIBRARY GLee /usr/local/lib /usr/lib) | |
+if(GLEE_INCLUDE AND GLEE_LIBRARY) | |
+ target_link_libraries(MMDFiles ${GLEE_LIBRARY}) | |
+else() | |
+ message(FATAL_ERROR "Required OpenGL Easy Extension is not found.") | |
+endif() | |
+ | |
+# find Bullet Physics via pkg-config | |
+find_package(PkgConfig) | |
+pkg_search_module(BULLET REQUIRED bullet) | |
+if(BULLET_FOUND) | |
+ include_directories(${BULLET_INCLUDE_DIRS}) | |
+ target_link_libraries(MMDFiles ${BULLET_LIBRARIES}) | |
+ link_directories(${BULLET_LIBRARY_DIRS}) | |
+else() | |
+ message(FATAL_ERROR "Required Bullet Physics is not found.") | |
+endif() | |
+ | |
+# create as a framework if build on darwin environment | |
+if(APPLE) | |
+ if(BUILD_SHARED_LIBS AND FRAMEWORK) | |
+ install(TARGETS MMDFiles DESTINATION .) | |
+ set_target_properties(MMDFiles PROPERTIES FRAMEWORK true) | |
+ set_target_properties(MMDFiles PROPERTIES PUBLIC_HEADER "${libMMDFiles_public_headers}") | |
+ endif() | |
+ set_target_properties(MMDFiles PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib") | |
+endif() | |
+ | |
+install(TARGETS MMDFiles EXPORT MMDFiles LIBRARY DESTINATION lib) | |
+install(EXPORT MMDFiles DESTINATION lib/MMDFiles) | |
+install(DIRECTORY include/ DESTINATION include/MMDFiles PATTERN "*.h" PATTERN ".svn" EXCLUDE) | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment