Revisión | 4a64760e680a7918feb59e688c818f02492d101e (tree) |
---|---|
Tiempo | 2012-09-11 14:46:07 |
Autor | angeart <angeart@git....> |
Commiter | angeart |
GenerateJSONの追加
エッジのコンフィグ追加
@@ -103,6 +103,7 @@ void FieldPlayer::LoadModel(const tstring& name) | ||
103 | 103 | } else { |
104 | 104 | SetModel(ResourceManager::LoadModelFromName(name)); |
105 | 105 | } |
106 | + ResourceManager::SetModelEdgeSize(model_handle_.handle()); | |
106 | 107 | } |
107 | 108 | |
108 | 109 | void FieldPlayer::SetModel(const ModelHandle& model) |
@@ -28,6 +28,7 @@ void ConfigManager::Load(const std::string& filename) | ||
28 | 28 | max_local_storage_size_ = pt.get<int>("max_local_storage_size", 512000); |
29 | 29 | upnp_ = pt.get<bool>("upnp", false); |
30 | 30 | udp_port_ = pt.get<uint16_t>("udp_port", 39391); |
31 | + model_edge_size_ = pt.get<float>("edge_size",1.0f); | |
31 | 32 | |
32 | 33 | } |
33 | 34 |
@@ -98,3 +99,8 @@ bool ConfigManager::shader_depth_field() const | ||
98 | 99 | { |
99 | 100 | return shader_depth_field_; |
100 | 101 | } |
102 | + | |
103 | +float ConfigManager::model_edge_size() const | |
104 | +{ | |
105 | + return model_edge_size_; | |
106 | +} | |
\ No newline at end of file |
@@ -33,6 +33,8 @@ class ConfigManager | ||
33 | 33 | bool shader_shadow_; |
34 | 34 | bool shader_depth_field_; |
35 | 35 | |
36 | + float model_edge_size_; | |
37 | + | |
36 | 38 | public: |
37 | 39 | bool fullscreen() const; |
38 | 40 | int screen_width() const; |
@@ -50,6 +52,8 @@ class ConfigManager | ||
50 | 52 | bool shader_shadow() const; |
51 | 53 | bool shader_depth_field() const; |
52 | 54 | |
55 | + float model_edge_size() const; | |
56 | + | |
53 | 57 | private: |
54 | 58 | ManagerAccessorPtr manager_accessor_; |
55 | 59 | }; |
@@ -0,0 +1,360 @@ | ||
1 | +#include "GenerateJSON.hpp" | |
2 | + | |
3 | +namespace | |
4 | +{ | |
5 | + int ADFUNC_DXconvAnsiToWide(int destsize, WCHAR* wstrDest, const CHAR* strSrc ) | |
6 | + { | |
7 | + // 引数の*がNULLの場合はエラー | |
8 | + if( strSrc==NULL ) | |
9 | + return 0; | |
10 | + int ct = strlen(strSrc) + 1; | |
11 | + if( wstrDest == NULL ) | |
12 | + return MultiByteToWideChar( CP_ACP, 0, strSrc, ct, NULL, 0 ); | |
13 | + int nResult = MultiByteToWideChar( CP_ACP, 0, strSrc, ct, wstrDest, destsize ); | |
14 | + wstrDest[destsize-1] = 0; | |
15 | + | |
16 | + if( nResult == 0 ) | |
17 | + return 0; | |
18 | + return nResult; | |
19 | + } | |
20 | + | |
21 | + TCHAR* _ftot_s( TCHAR* pString, size_t Size, float Value, int FracDigits ) | |
22 | + { | |
23 | + if( pString == NULL ) | |
24 | + goto _error; | |
25 | + TCHAR* pSource = pString; | |
26 | + if( *(long*)&Value < 0 ) | |
27 | + { | |
28 | + if( (size_t)( pString - pSource ) >= Size ) | |
29 | + goto _error; | |
30 | + *pString++ = '-'; | |
31 | + *(long*)&Value ^= 0x80000000; | |
32 | + } | |
33 | + TCHAR* pBegin = pString; | |
34 | + int Integer = (int)Value; | |
35 | + for( int i = 10; i <= Integer; i *= 10, pString++ ); | |
36 | + if( (size_t)( pString - pSource ) >= Size ) | |
37 | + goto _error; | |
38 | + TCHAR* pCode = pString++; | |
39 | + *pCode-- = '0' + (char)( Integer % 10 ); | |
40 | + for( int i = Integer / 10; i != 0; i /= 10 ) | |
41 | + *pCode-- = '0' + (char)( i % 10 ); | |
42 | + if( FracDigits > 0 ) | |
43 | + { | |
44 | + if( (size_t)( pString - pSource ) >= Size ) | |
45 | + goto _error; | |
46 | + *pString++ = '.'; | |
47 | + while( FracDigits-- > 1 ) | |
48 | + { | |
49 | + Value -= Integer; | |
50 | + Integer = (int)( Value *= 10.0f ); | |
51 | + if( (size_t)( pString - pSource ) >= Size ) | |
52 | + goto _error; | |
53 | + *pString++ = '0' + (char)Integer; | |
54 | + } | |
55 | + Integer = (int)( ( Value - Integer ) * 10.0f + 0.5f ); | |
56 | + if( Integer < 10 ) | |
57 | + { | |
58 | + if( (size_t)( pString - pSource ) >= Size ) | |
59 | + goto _error; | |
60 | + *pString++ = '0' + (char)Integer; | |
61 | + } | |
62 | + else | |
63 | + { | |
64 | + pCode = pString - 1; | |
65 | + if( (size_t)( pString - pSource ) >= Size ) | |
66 | + goto _error; | |
67 | + *pString++ = '0'; | |
68 | + do | |
69 | + { | |
70 | + if( *pCode == '.' ) | |
71 | + pCode--; | |
72 | + if( *pCode != '9' ) | |
73 | + { | |
74 | + *pCode += 1; | |
75 | + break; | |
76 | + } | |
77 | + else | |
78 | + *pCode = '0'; | |
79 | + if( pCode == pBegin ) | |
80 | + { | |
81 | + if( (size_t)( pString - pSource ) >= Size ) | |
82 | + goto _error; | |
83 | + TCHAR* pEnd = pString++; | |
84 | + while( pEnd-- != pCode ) | |
85 | + *( pEnd + 1 ) = *pEnd; | |
86 | + *pCode = '1'; | |
87 | + } | |
88 | + } while( *pCode-- == '0' ); | |
89 | + } | |
90 | + } | |
91 | + if( (size_t)( pString - pSource ) >= Size ) | |
92 | + goto _error; | |
93 | + *pString = '\0'; | |
94 | + return pSource; | |
95 | +_error: | |
96 | + __debugbreak(); | |
97 | + return NULL; | |
98 | + } | |
99 | + | |
100 | + BOOL DeleteDirectory( LPCTSTR lpPathName ) | |
101 | + { | |
102 | + // 入力値チェック | |
103 | + if( NULL == lpPathName ) | |
104 | + { | |
105 | + return FALSE; | |
106 | + } | |
107 | + | |
108 | + // ディレクトリ名の保存(終端に'\'がないなら付ける) | |
109 | + TCHAR szDirectoryPathName[_MAX_PATH]; | |
110 | + _tcsncpy_s( szDirectoryPathName, _MAX_PATH, lpPathName, _TRUNCATE ); | |
111 | + if( '\\' != szDirectoryPathName[_tcslen(szDirectoryPathName) - 1] ) | |
112 | + { // 一番最後に'\'がないなら付加する。 | |
113 | + _tcsncat_s( szDirectoryPathName, _MAX_PATH, _T("\\"), _TRUNCATE ); | |
114 | + } | |
115 | + | |
116 | + // ディレクトリ内のファイル走査用のファイル名作成 | |
117 | + TCHAR szFindFilePathName[_MAX_PATH]; | |
118 | + _tcsncpy_s( szFindFilePathName, _MAX_PATH, szDirectoryPathName, _TRUNCATE ); | |
119 | + _tcsncat_s( szFindFilePathName, _MAX_PATH, _T("*"), _TRUNCATE ); | |
120 | + | |
121 | + // ディレクトリ内のファイル走査開始 | |
122 | + WIN32_FIND_DATA fd; | |
123 | + HANDLE hFind = FindFirstFile( szFindFilePathName, &fd ); | |
124 | + if( INVALID_HANDLE_VALUE == hFind ) | |
125 | + { // 走査対象フォルダが存在しない。 | |
126 | + return FALSE; | |
127 | + } | |
128 | + | |
129 | + do | |
130 | + { | |
131 | + //if( '.' != fd.cFileName[0] ) | |
132 | + if( 0 != _tcscmp( fd.cFileName, _T(".") ) // カレントフォルダ「.」と | |
133 | + && 0 != _tcscmp( fd.cFileName, _T("..") ) ) // 親フォルダ「..」は、処理をスキップ | |
134 | + { | |
135 | + TCHAR szFoundFilePathName[_MAX_PATH]; | |
136 | + _tcsncpy_s( szFoundFilePathName, _MAX_PATH, szDirectoryPathName, _TRUNCATE ); | |
137 | + _tcsncat_s( szFoundFilePathName, _MAX_PATH, fd.cFileName, _TRUNCATE ); | |
138 | + | |
139 | + if( FILE_ATTRIBUTE_DIRECTORY & fd.dwFileAttributes ) | |
140 | + { // ディレクトリなら再起呼び出しで削除 | |
141 | + if( !DeleteDirectory( szFoundFilePathName ) ) | |
142 | + { | |
143 | + FindClose( hFind ); | |
144 | + return FALSE; | |
145 | + } | |
146 | + } | |
147 | + else | |
148 | + { // ファイルならWin32API関数を用いて削除 | |
149 | + if( !DeleteFile( szFoundFilePathName ) ) | |
150 | + { | |
151 | + FindClose( hFind ); | |
152 | + return FALSE; | |
153 | + } | |
154 | + } | |
155 | + } | |
156 | + } while( FindNextFile( hFind, &fd ) ); | |
157 | + | |
158 | + FindClose( hFind ); | |
159 | + | |
160 | + return RemoveDirectory( lpPathName ); | |
161 | + } | |
162 | + | |
163 | +}; | |
164 | + | |
165 | +JsonGen::JsonGen() | |
166 | +{ | |
167 | + HANDLE hFind,hPmdFind,hTxtFind; // Directory Pmd Text | |
168 | + WIN32_FIND_DATA win32fd_dir,win32fd_pmd,win32fd_txt; // Directory Pmd Text | |
169 | + TCHAR tcsTmpPath[MAX_PATH] = {0}; | |
170 | + TCHAR tcsTmpPath_Pmd[MAX_PATH] = {0}; | |
171 | + TCHAR tcsTmpDir[MAX_PATH] = {0}; | |
172 | + | |
173 | + std::vector<std::wstring> pmd_paths; | |
174 | + std::wstring prejson; | |
175 | + DxLib::VECTOR prePos = {0},curPos = {0},lclPos = {0}; | |
176 | + DxLib::MATRIX chglcl = {0}; | |
177 | + | |
178 | + char pmd_model_name_[256] = {0}; | |
179 | + char pmd_author_name_[256] = {0}; | |
180 | + | |
181 | + int exist_num_pmd_ = 0; | |
182 | + | |
183 | + int model_handle_ = 0; | |
184 | + | |
185 | + FILE *json_file = 0; | |
186 | + | |
187 | + // resources/models/内検索 列挙 | |
188 | + hFind = FindFirstFile(_T("\\resources\\models\\?*"), &win32fd_dir); | |
189 | + | |
190 | + if (hFind == INVALID_HANDLE_VALUE) { | |
191 | + return; | |
192 | + } | |
193 | + | |
194 | + do { | |
195 | + if (win32fd_dir.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && | |
196 | + _tcscmp(win32fd_dir.cFileName,_T("."))!=0 && | |
197 | + _tcscmp(win32fd_dir.cFileName,_T(".."))!=0 && | |
198 | + _tcscmp(win32fd_dir.cFileName,_T(".svn"))!=0) { | |
199 | + _tcscpy_s(tcsTmpDir,_T("\\resources\\models\\")); | |
200 | + _tcscat_s(tcsTmpDir,win32fd_dir.cFileName); | |
201 | + _tcscat_s(tcsTmpDir,_T("\\")); | |
202 | + | |
203 | + ZeroMemory(tcsTmpPath,MAX_PATH); | |
204 | + _tcscpy_s(tcsTmpPath,tcsTmpDir); | |
205 | + _tcscat_s(tcsTmpPath,_T("info.json")); | |
206 | + | |
207 | + // info.jsonが存在しない場合、pmdに従って作成 | |
208 | + if(!PathFileExists(tcsTmpPath)) | |
209 | + { | |
210 | + ZeroMemory(tcsTmpPath_Pmd,MAX_PATH); | |
211 | + _tcscpy_s(tcsTmpPath_Pmd,tcsTmpDir); | |
212 | + _tcscat_s(tcsTmpPath_Pmd,_T("*.pmd")); | |
213 | + hPmdFind = FindFirstFile(tcsTmpPath_Pmd, &win32fd_pmd); | |
214 | + if(hPmdFind < 0) | |
215 | + { | |
216 | + FindClose(hPmdFind); | |
217 | + continue; | |
218 | + } | |
219 | + | |
220 | + TCHAR cur_dir[MAX_PATH]; | |
221 | + ZeroMemory(cur_dir,MAX_PATH); | |
222 | + GetCurrentDirectory(MAX_PATH,cur_dir); | |
223 | + bool flag = false; | |
224 | + for(int k = MAX_PATH - 1;k != 0;--k) | |
225 | + { | |
226 | + if( cur_dir[k] == _T('\\') ) | |
227 | + { | |
228 | + cur_dir[k] = 0; | |
229 | + break; | |
230 | + } | |
231 | + } | |
232 | + do { | |
233 | + std::wstring tmp_path = cur_dir; | |
234 | + tmp_path += _T("\\resources\\models\\"); | |
235 | + tmp_path += win32fd_dir.cFileName; | |
236 | + tmp_path += _T("\\"); | |
237 | + tmp_path += win32fd_pmd.cFileName; | |
238 | + pmd_paths.push_back(tmp_path); | |
239 | + } while (FindNextFile(hPmdFind, &win32fd_pmd)); | |
240 | + FindClose(hPmdFind); | |
241 | + | |
242 | + for(int i = 0;i < pmd_paths.size();++i){ | |
243 | + char pmd_info[PMDINFO_SIZE+1]; | |
244 | + int fd = _topen(pmd_paths[i].c_str(),O_RDONLY); | |
245 | + read(fd,pmd_info,PMDINFO_SIZE); | |
246 | + close(fd); | |
247 | + | |
248 | + // モデル名取得 | |
249 | + strcpy_s(pmd_model_name_,pmd_info+7); | |
250 | + | |
251 | + int cnt = 7 + strlen(pmd_info+7); | |
252 | + while(cnt < PMDINFO_SIZE){ | |
253 | + if(!strncmp("モデリング",pmd_info+cnt,10))break; | |
254 | + else ++cnt; | |
255 | + } | |
256 | + if(cnt == PMDINFO_SIZE) | |
257 | + { | |
258 | + strcpy_s(pmd_author_name_,"Unknown"); | |
259 | + }else{ | |
260 | + for(cnt;cnt<PMDINFO_SIZE && (*(pmd_info+cnt) != 0x46 && *(pmd_info+cnt-1) != 0x81);++cnt); | |
261 | + int tmp_str_cnt = 1; | |
262 | + for(tmp_str_cnt;cnt+tmp_str_cnt<PMDINFO_SIZE && (*(pmd_info+cnt+tmp_str_cnt) != 0x0a && *(pmd_info+cnt+tmp_str_cnt) != 0x20);++tmp_str_cnt); | |
263 | + // 作者取得 | |
264 | + strncpy_s(pmd_author_name_,pmd_info+cnt+1,tmp_str_cnt-1); | |
265 | + } | |
266 | + | |
267 | + TCHAR tmp_mv1_path[MAX_PATH] = {0}; | |
268 | + _tcscpy_s(tmp_mv1_path,pmd_paths[i].c_str()); | |
269 | + | |
270 | + model_handle_ = MV1LoadModel( tmp_mv1_path ); | |
271 | + int tex_num = MV1GetTextureNum( model_handle_ ); | |
272 | + int frame_num = MV1GetFrameNum( model_handle_ ); | |
273 | + | |
274 | + | |
275 | + // ボーンに基づいたモデルの高さ設定 | |
276 | + for(int j = 0;j < frame_num;++j) | |
277 | + { | |
278 | + curPos = MV1GetFramePosition( model_handle_, j ); | |
279 | + chglcl = MV1GetFrameLocalMatrix( model_handle_, j ); | |
280 | + lclPos.x = chglcl.m[3][0]; | |
281 | + lclPos.y = chglcl.m[3][1]; | |
282 | + lclPos.z = chglcl.m[3][2]; | |
283 | + | |
284 | + if( prePos.y < curPos.y && | |
285 | + lclPos.x == curPos.x && | |
286 | + lclPos.y == curPos.y && | |
287 | + lclPos.z == curPos.z)prePos = curPos; | |
288 | + } | |
289 | + | |
290 | + // JSONの構築 | |
291 | + prejson = _T("{\n\t\"name\": \"char:"); | |
292 | + size_t tmp_w_s_m = ADFUNC_DXconvAnsiToWide(0,0,pmd_model_name_); | |
293 | + TCHAR *tmp_w_m = new TCHAR[tmp_w_s_m + 1]; | |
294 | + ADFUNC_DXconvAnsiToWide(tmp_w_s_m,tmp_w_m,pmd_model_name_); | |
295 | + prejson += tmp_w_m; | |
296 | + prejson += _T(":"); | |
297 | + size_t tmp_w_s_a = ADFUNC_DXconvAnsiToWide(0,0,pmd_author_name_); | |
298 | + TCHAR *tmp_w_a = new TCHAR[tmp_w_s_a + 1]; | |
299 | + ADFUNC_DXconvAnsiToWide(tmp_w_s_a,tmp_w_a,pmd_author_name_); | |
300 | + prejson += tmp_w_a; | |
301 | + prejson += _T("式\",\n\t\"character\":\n\t\t{\n\t\t\t\"height\":"); | |
302 | + TCHAR tmp_f[32]; | |
303 | + _ftot_s(tmp_f,32,floor(prePos.y*2)/10.0f,2); | |
304 | + prejson += tmp_f; | |
305 | + prejson += _T(",\n\t\t\t\"motions\":\n\t\t\t\t{\n\t\t\t\t\t\"stand\":\"basic_stand.vmd\",\n\t\t\t\t\t\"walk\": \t\"basic_walk.vmd\",\n\t\t\t\t\t\"run\":\t\"basic_run.vmd\"\n\t\t\t\t}\n\t\t}\n}"); | |
306 | + TCHAR tmp_dir[MAX_PATH]; | |
307 | + _tcscpy_s(tmp_dir,_T("\\resources\\models\\")); | |
308 | + _tcscat_s(tmp_dir,tmp_w_a); | |
309 | + _tcscat_s(tmp_dir,_T("式")); | |
310 | + _tcscat_s(tmp_dir,tmp_w_m); | |
311 | + _tcscat_s(tmp_dir,_T("\\")); | |
312 | + _wmkdir(tmp_dir); | |
313 | + delete [] tmp_w_m; | |
314 | + delete [] tmp_w_a; | |
315 | + TCHAR json_path[MAX_PATH]; | |
316 | + _tcscpy_s(json_path,tmp_dir); | |
317 | + _tcscat_s(json_path,_T("info.json")); | |
318 | + _tfopen_s(&json_file,json_path, _T("w, ccs=UTF-8")); | |
319 | + fseek(json_file, 0, SEEK_SET); | |
320 | + _ftprintf_s(json_file,prejson.c_str()); | |
321 | + fclose(json_file); | |
322 | + TCHAR tmp_src[MAX_PATH]; | |
323 | + TCHAR tmp_cpy[MAX_PATH]; | |
324 | + | |
325 | + // テクスチャのコピー | |
326 | + for(int t = 0;t < tex_num;++t) | |
327 | + { | |
328 | + _tcscpy_s(tmp_src,tcsTmpDir); | |
329 | + _tcscat_s(tmp_src,MV1GetTextureName( model_handle_, t)); | |
330 | + _tcscpy_s(tmp_cpy,tmp_dir); | |
331 | + _tcscat_s(tmp_cpy,MV1GetTextureName( model_handle_, t)); | |
332 | + CopyFile(tmp_src,tmp_cpy,TRUE); | |
333 | + } | |
334 | + TCHAR tmp_txt_f[MAX_PATH]; | |
335 | + _tcscpy_s(tmp_txt_f,tcsTmpDir); | |
336 | + _tcscat_s(tmp_txt_f,_T("*.txt")); | |
337 | + hTxtFind = FindFirstFile(tmp_txt_f,&win32fd_txt); | |
338 | + do{ | |
339 | + _tcscpy_s(tmp_src,tcsTmpDir); | |
340 | + _tcscat_s(tmp_src,win32fd_txt.cFileName); | |
341 | + _tcscpy_s(tmp_cpy,tmp_dir); | |
342 | + _tcscat_s(tmp_cpy,win32fd_txt.cFileName); | |
343 | + CopyFile(tmp_src,tmp_cpy,TRUE); | |
344 | + }while(FindNextFile(hTxtFind, &win32fd_txt)); | |
345 | + FindClose(hTxtFind); | |
346 | + TCHAR tmp_type[128] = {0}; | |
347 | + _tsplitpath(pmd_paths[i].c_str(),NULL,NULL,tmp_cpy,tmp_type); | |
348 | + _tcscat_s(tmp_cpy,tmp_type); | |
349 | + _tcscpy_s(tmp_type,tmp_dir); | |
350 | + _tcscat_s(tmp_type,tmp_cpy); | |
351 | + CopyFile(pmd_paths[i].c_str(),tmp_type,TRUE); | |
352 | + } | |
353 | + | |
354 | + DeleteDirectory(tcsTmpDir); | |
355 | + } | |
356 | + } | |
357 | + } while (FindNextFile(hFind, &win32fd_dir)); | |
358 | + | |
359 | + FindClose(hFind); | |
360 | +} | |
\ No newline at end of file |
@@ -0,0 +1,21 @@ | ||
1 | +#pragma once | |
2 | + | |
3 | +#include <io.h> | |
4 | +#include <fcntl.h> | |
5 | +#include <vector> | |
6 | +#include <string> | |
7 | +#include <math.h> | |
8 | +#include <Windows.h> | |
9 | +#include <shlwapi.h> | |
10 | +#include <DxLib.h> | |
11 | + | |
12 | +#pragma comment(lib, "shlwapi.lib") | |
13 | + | |
14 | +#define PMDINFO_SIZE 0x11A | |
15 | + | |
16 | +class JsonGen | |
17 | +{ | |
18 | +public: | |
19 | + JsonGen(); | |
20 | + virtual ~JsonGen(){}; | |
21 | +}; | |
\ No newline at end of file |
@@ -79,6 +79,8 @@ class ResourceManager { | ||
79 | 79 | static void RequestModelFromName(const tstring&); |
80 | 80 | static bool IsCachedModelName(const tstring&); |
81 | 81 | static const std::vector<std::string>& GetModelNameList(); |
82 | + static void SetModelEdgeSize(int handle); | |
83 | + static void set_model_edge_size(float edge_size); | |
82 | 84 | |
83 | 85 | private: |
84 | 86 | static tstring NameToFullPath(const tstring& name); |
@@ -92,7 +94,7 @@ class ResourceManager { | ||
92 | 94 | static std::unordered_map<tstring, tstring> model_names_; |
93 | 95 | static std::unordered_map<tstring, ModelHandle> model_handles_; |
94 | 96 | static std::vector<std::string> model_name_list_; |
95 | - | |
97 | + static float model_edge_size_; | |
96 | 98 | }; |
97 | 99 | |
98 | 100 | class ImageHandle { |