Mercurial > hg > Game > Cerium
changeset 1365:a5797dff2262 draft
add base64 encoder.
author | Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 20 Jan 2012 09:49:47 +0900 |
parents | f53e986715fa |
children | 6e388be03bb1 |
files | Renderer/Engine/SceneGraphRoot.cc Renderer/Engine/base64_de.cc |
diffstat | 2 files changed, 99 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraphRoot.cc Fri Jan 20 07:34:02 2012 +0900 +++ b/Renderer/Engine/SceneGraphRoot.cc Fri Jan 20 09:49:47 2012 +0900 @@ -366,9 +366,11 @@ polylist_count = 0; vcsum = 0; + limit = 0; vmember = 0; + images_flag=0; } int polylist; int library_images; @@ -398,10 +400,15 @@ char *name; char *tex_picname; + + int images_flag; + int vcsum; int limit; int vmember; -}; +}; + + static texture_list list[TABLE_SIZE]; @@ -486,7 +493,7 @@ } SceneGraph* -decode_points(collada_state *s, TaskManager *manager){ +decode_points(collada_state *s, TaskManager *manager, SceneGraphPtr sg){ int *vertexp; vertexp = new int[s->vcsum]; for (int i=0;i<s->vcsum;i++){ @@ -551,16 +558,19 @@ */ int count = s->vcsum / 3; //polygonの作成 - SceneGraphPtr sg = new SceneGraph(manager); sg->pp_num = (count + MAX_SIZE_TRIANGLE - 1) / MAX_SIZE_TRIANGLE; sg->pp = new PolygonPack[sg->pp_num]; for (int i = 0;i < sg->pp_num; i++ ){ - PolygonPackPtr pp = sg->pp; + PolygonPackPtr pp = sg->pp; TrianglePackPtr tri = pp[i].tri; // TrianglePack の size のチェック int tri_size = (count < MAX_SIZE_TRIANGLE) ? count : MAX_SIZE_TRIANGLE ; pp[i].info.size = tri_size; + /* default texture peste */ + if (s->images_flag==0) { + get_texpic("collada_file/default.jpg", sg, (xmlNodePtr)NULL, manager); + } int k = 0; int m = 0; int n = 0; @@ -603,9 +613,8 @@ } sg->c_xyz[0] = sg->c_xyz[1] = sg->c_xyz[2] = 0; - int tex_id = 0; - sgid_hash.sg_hash_regist(s->name, tex_id); - //get_texpic(s->tex_picname, sg, cur , manager); + //int tex_id = 0; + //sgid_hash.sg_hash_regist(s->name, tex_id); delete []vertexp; delete []vertex_table; @@ -618,7 +627,7 @@ } static void -xml_walk(xmlNodePtr cur, struct collada_state *s, LIST_P list,SceneGraphRoot *root) +xml_walk(xmlNodePtr cur, struct collada_state *s, LIST_P list,SceneGraphPtr sg, SceneGraphRoot *root) { int in_polylist=0; printf("name = %s, child:%s\n", (char *)cur->name, (char *)cur->children); @@ -633,8 +642,10 @@ s->library_images=1;// library_images is wrote at texture image name. only use one image file } else if (s->library_images && !xmlStrcmp(cur->name, (xmlChar*)"init_from")) { s->tex_picname = (char*)xmlGetProp(cur, (xmlChar*)"init_from"); + get_texpic(s->tex_picname, sg, cur , root->tmanager); printf("------------------%s",s->tex_picname); s->library_images=0; + s->images_flag=1; } else if (!s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input")) { char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic"); if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"POSITION")) { @@ -671,7 +682,7 @@ s->name = (char*)xmlGetProp(cur, (xmlChar*)"id"); } for (cur=cur->children; cur; cur=cur->next){ - xml_walk(cur,s,list,root); + xml_walk(cur,s,list,sg,root); } } @@ -699,12 +710,13 @@ /* node analyze */ struct collada_state s; + SceneGraphPtr sg = new SceneGraph(manager); for (cur=cur->children; cur; cur=cur->next){ LIST list; init_list(&list); - xml_walk(cur,&s,&list,this); + xml_walk(cur,&s,&list,sg,this); } - registSceneGraph(decode_points(&s,manager)); + registSceneGraph(decode_points(&s,manager,sg)); xmlFreeDoc(doc); }
--- a/Renderer/Engine/base64_de.cc Fri Jan 20 07:34:02 2012 +0900 +++ b/Renderer/Engine/base64_de.cc Fri Jan 20 09:49:47 2012 +0900 @@ -10,6 +10,7 @@ int nlen; }; +const char* szB64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; unsigned char CtoNum(int c) { @@ -89,3 +90,78 @@ return 0; } + +/*const char *encode(const char *infile, int outfile) +{ + int i,j,outfile_; + char *outputString; + + if (outfile==-1) + outfile_ = strlen(infile); + else + outfile_ = outfile; + + outputString = new char[(int)((double)(outfile_)*1.5)+10]; + for(i = 0,j = 0; i < (outfile_ - (outfile_ % 3)); i+=3) + { + outputString[j] = szB64[(infile[i] & 0xfc) >> 2]; + outputString[j+1] = szB64[((infile[i] &0x03) << 4)|((infile[i+1] & 0xf0) >> 4)]; + outputString[j+2] = szB64[((infile[i+1] & 0x0f) <<2 )|((infile[i+2] & 0xc0) >> 6)]; + outputString[j+3] = szB64[(infile[i+2] & 0x3f)]; + j += 4; + } + i = outfile_-(outfile_ % 3); + switch(outfile_ % 3) + { + case 2: + { + outputString[j] = szB64[(infile[i] & 0xfc) >> 2]; + outputString[j+1] = szB64[((infile[i] &0x03) << 4)|((infile[i+1] & 0xf0) >> 4)]; + outputString[j+2] = szB64[((infile[i+1] & 0x0f) <<2 )]; + outputString[j+3] = szB64[64]; // Pad + outputString[j+4] = '\0'; + } + break; + case 1: + { + outputString[j] = szB64[(infile[i] & 0xfc) >> 2]; + outputString[j+1] = szB64[((infile[i] &0x03) << 4)]; + outputString[j+2] = szB64[64]; // Pad + outputString[j+3] = szB64[64]; // Pad + outputString[j+4] = '\0'; + } + break; + } + outputString[j+4] = '\0'; + return outputString; + +}*/ +void encode(istream& istr, ostream& ostr) +{ + int iRet=76; + int i; + char c[3]; + + i = 0; + while(!istr.eof()) + { + c[0] = c[1] = c[2] = '\0'; + istr.read(c,3); + + ostr << szB64[(c[0] & 0xfc) >> 2]; + i++; if(i >= iRet && iRet != -1){ ostr << endl; i = 0; } + ostr << szB64[((c[0] &0x03) << 4) | ((c[1] & 0xf0) >> 4)]; + i++; if(i >= iRet && iRet != -1){ ostr << endl; i = 0; } + if(istr.gcount() == 1) + ostr << szB64[64]; + else + ostr << szB64[((c[1] & 0x0f) <<2 ) | ((c[2] & 0xc0) >> 6)]; + i++; if(i >= iRet && iRet != -1){ ostr << endl; i = 0; } + if(istr.gcount() == 3) + ostr << szB64[(c[2] & 0x3f)]; + else + ostr << szB64[64]; + i++; if(i >= iRet && iRet != -1){ ostr << endl; i = 0; } + } + ostr.flush(); +}