void WAN_Writer::WriteAnimationSequencesBlock() { const auto & animgroups = m_pSprite->getAnimGroups(); for( const auto & agrp : animgroups ) { for( const auto & aptr : agrp.seqsIndexes ) { auto result = m_AnimSequenceOffsets.insert( make_pair( aptr, m_outBuffer.size() ) ); if( result.second ) //If the sequence was not already written! { auto & aseq = m_pSprite->getAnimSequences()[aptr]; for( unsigned int ctfrm = 0; ctfrm < m_pSprite->getAnimSequences()[aptr].getNbFrames(); ++ctfrm ) { const auto & curfrm = aseq.getFrame(ctfrm); WriteAnAnimFrame( curfrm ); if( ctfrm == (aseq.getNbFrames() - 1) ) { //# Don't forget the null frame at the end of all sequence! WriteAnAnimFrame( AnimFrame() ); } } } //if( aptr.getNbFrames() > 0 ) //Ignore empty sequences //{ ////# Write the offsets where each sequences begins at ! (except null ones) // m_AnimSequenceOffsets.push_back( m_outBuffer.size() ); // //Write the sequence // for( unsigned int ctfrm = 0; ctfrm < aseq.getNbFrames(); ++ctfrm ) // { // const auto & curfrm = aseq.getFrame(ctfrm); // WriteAnAnimFrame( curfrm ); // if( ctfrm == (aseq.getNbFrames() - 1) ) // { // //# Don't forget the null frame at the end of all sequence! // WriteAnAnimFrame( AnimFrame() ); // } // } //} } } }
int CUnit3DLoader::ParseSub(CFileHandler& ifs, UnitModel &model,const string& filename,float3 offset,const string& treename) { string s; bool inComment=false; Animation* curAnim=0; int curAnimFrame=0; bool firstGeometryPass=false; if(geometryModels.find(treename)==geometryModels.end()){ geometryModels[treename]=new UnitModelGeometry(); UnitModelGeometry& geometry=*geometryModels[treename]; firstGeometryPass=true; geometry.normalBuffer=0; geometry.indexBuffer=0; geometry.numIndeces=0; geometry.numVerteces=0; } model.geometry=geometryModels[treename]; UnitModelGeometry& geometry=*model.geometry; geometry.radius=1; geometry.height=1; geometry.isAnimated=false; model.texCoordBuffer=0; while(ifs.Peek()!=EOF){ s=GetWord(ifs); MakeLow(s); if(s[0]=='/' && !inComment){ if(s[1]=='/'){ GetLine(ifs); continue; } if(s[1]=='*') inComment=true; } if(inComment){ for(int a=0;a<s.size()-1;++a) if(s[a]=='*' && s[a+1]=='/') inComment=false; if(inComment) continue; } if(ifs.Eof()) break; while((s.c_str()[0]=='/') || (s.c_str()[0]=='\n')){ s=GetLine(ifs); s=GetWord(ifs); MakeLow(s); if(ifs.Eof()) break; } if(s=="vertex"){ int num=atoi(GetWord(ifs).c_str()); float3 v; v.x=atof(GetWord(ifs).c_str()); v.y=atof(GetWord(ifs).c_str()); v.z=atof(GetWord(ifs).c_str()); v-=offset; if(firstGeometryPass){ if(curAnim==0){ while(geometry.vertex.size()<=num){ geometry.vertex.push_back(float3(0,0,0)); geometry.vertexNormal.push_back(float3(0,0,0)); } geometry.vertex[num]=v; } else { AnimFrame* af=&curAnim->frames[curAnimFrame]; while(af->vertex.size()<=num){ af->vertex.push_back(float3()); // model.vertexNormal.push_back(float3(0,0,0)); } af->vertex[num]=v; } } } else if(s=="quad"){ Quad q; QuadTex qt; for(int a=0;a<4;++a) q.verteces[a]=atoi(GetWord(ifs).c_str()); for(int a=0;a<8;++a) qt.texPos[0][a]=atof(GetWord(ifs).c_str()); qt.texName=GetWord(ifs); qt.teamTex=atoi(GetWord(ifs).c_str()); q.normalType=atoi(GetWord(ifs).c_str()); model.quadTex.push_back(qt); if(firstGeometryPass) geometry.quad.push_back(q); } else if(s=="tri"){ Tri t; TriTex tt; for(int a=0;a<3;++a) t.verteces[a]=atoi(GetWord(ifs).c_str()); for(int a=0;a<3;++a){ tt.texPos[0][a*2]=1-atof(GetWord(ifs).c_str()); tt.texPos[0][a*2+1]=1-atof(GetWord(ifs).c_str()); } tt.texName=GetWord(ifs); tt.teamTex=atoi(GetWord(ifs).c_str()); t.normalType=atoi(GetWord(ifs).c_str()); model.triTex.push_back(tt); if(firstGeometryPass) geometry.tri.push_back(t); } else if(s=="propeller"){ Propeller p; for(int a=0;a<3;++a) p.pos[a]=atof(GetWord(ifs).c_str()); p.size=atof(GetWord(ifs).c_str()); if(firstGeometryPass) geometry.propellers.push_back(p); } else if(s=="height"){ geometry.height=atof(GetWord(ifs).c_str()); } else if(s=="radius"){ geometry.radius=atof(GetWord(ifs).c_str()); } else if(s=="subobject"){ UnitModel* um=new UnitModel; model.subModels.push_back(um); um->name=GetWord(ifs); float3 off,rot; for(int a=0;a<3;++a) off[a]=atof(GetWord(ifs).c_str()); for(int a=0;a<3;++a) rot[a]=atof(GetWord(ifs).c_str()); um->team=model.team; char c[100]; sprintf(c,"%s%d",treename.c_str(),model.subModels.size()); ParseSub(ifs,*um,filename,off,c); um->geometry->offset=off; um->geometry->rotVector=rot; } else if(s=="endsubobject"){ return 1; } else if(s=="animation"){ string name=GetWord(ifs); if(name=="end") curAnim=0; else{ if(geometry.animations.find(name)==geometry.animations.end()){ geometry.animations[name]=new Animation; } curAnim=geometry.animations[name]; } curAnimFrame=0; geometry.isAnimated=true; } else if(s=="keyframe"){ string num=GetWord(ifs); if(num=="end"){ curAnimFrame=0; } else { curAnimFrame=atoi(num.c_str()); float length=atoi(GetWord(ifs).c_str())/25.0f*30.0f; if(curAnim){ while(curAnim->frames.size()<=curAnimFrame){ curAnim->frames.push_back(AnimFrame()); } curAnim->frames[curAnimFrame].length=length; } } } else { if(s!="") (*info) << "Unknown token " << s.c_str() << " in " << filename.c_str() << "\n"; } } return 1; }