一、makehuman
是开源的人体变形软件。
二、makehuman相关网址
http://www.makehuman.org/
· 可以下载最新的release版本,以及最新的python源代码;
http://sourceforge.net/projects/makehuman/files/MakeHuman%20Source/MakeHuman_091/
makehuman 0.9.X 纯C++版本 linux下。
三、相关了解:
软件makehuman(简称mh), 在0.9版本之前均为纯C编程,linux平台下,在1.0发布后,开始采用C与python混合编程,目前版本1.0.2采用的纯python编程。
四、将mh 0.9版本改写为window平台下,visual studio 2010中的c++编程,主要修改的代码如下:
1、linux下直接可以用 #include<dirent.h>, 但windows下面没有,所以需要类似该功能添加如下dirent.h以及dirent.cpp文件。
// dirent.h
#ifndef _SYS_DIRENT_H
#define _SYS_DIRENT_H
#include <windows.h>
typedef struct _dirdesc {
int dd_fd; /** file descriptor associated with directory */
long dd_loc; /** offset in current buffer */
long dd_size; /** amount of data returned by getdirentries */
char *dd_buf; /** data buffer */
int dd_len; /** size of data buffer */
long dd_seek; /** magic cookie returned by getdirentries */
HANDLE hFind;
} DIR;
# define __dirfd(dp) ((dp)->dd_fd)
DIR *opendir (const char *);
struct dirent *readdir (DIR *);
void rewinddir (DIR *);
int closedir (DIR *);
#include <sys/types.h>
struct dirent
{
long d_ino; /* inode number*/
off_t d_off; /* offset to this dirent*/
unsigned short d_reclen; /* length of this d_name*/
unsigned char d_type; /* the type of d_name*/
char d_name[1]; /* file name (null-terminated)*/
};
#endif参考博文http://www.cnblogs.com/lanxuezaipiao/p/3420025.html ,不过改了部分代码,支持循环遍历。
// dirent.c
#include <stdio.h>
#include <windows.h>
#include "dirent.h"
//
//static HANDLE hFind;
DIR *opendir(const char *name)
{
DIR *dir;
WIN32_FIND_DATA FindData;
char namebuf[512];
sprintf(namebuf, "%s\\*.*",name);
dir = (DIR *)malloc(sizeof(DIR));
dir->hFind = FindFirstFile(namebuf, &FindData );
if(dir->hFind == INVALID_HANDLE_VALUE)
{
printf("FindFirstFile failed (%d)\n", GetLastError());
return 0;
}
if(!dir)
{
printf("DIR memory allocate fail\n");
return 0;
}
/*memset(dir, 0, sizeof(DIR)); */
//dir->dd_fd = 0; // simulate return
return dir;
}
struct dirent *readdir( DIR *d)
{
int i;
//static struct dirent dirent;
BOOL bf;
WIN32_FIND_DATA FileData;
if(!d)
{
return 0;
}
bf = FindNextFile(d->hFind, &FileData);
//fail or end
if(!bf)
{
return 0;
}
struct dirent *dirent = (struct dirent *)malloc(sizeof(struct dirent)+sizeof(FileData.cFileName));
for(i = 0; i < 256; i++)
{
dirent->d_name[i] = FileData.cFileName[i];
if(FileData.cFileName[i] == '\0') break;
}
dirent->d_reclen = i;
dirent->d_reclen = FileData.nFileSizeLow;
//check there is file or directory
if(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
dirent->d_type = 2;
}
else
{
dirent->d_type = 1;
}
return dirent;
}
int closedir(DIR *d)
{
if(!d) return -1;
d->hFind=0;
free(d);
return 0;
} 2、需要添加png.h以及libpng.lib
五、运行效果截图
本文是关于开源人体变形软件makehuman的学习笔记,重点讲述如何将0.9版本移植到Windows平台,涉及dirent.h头文件的替换及libpng库的添加,最终实现makehuman在Windows下的运行。


被折叠的 条评论
为什么被折叠?



