// **************************************************************************** // Constructor: Atom::Atom // // Arguments: // line the line of text in a PDB file // // Programmer: Jeremy Meredith // Creation: March 23, 2006 // // Modifications: // Brad Whitlock, Fri Jun 2 13:15:47 PST 2006 // Added Jeremy's fix for yet another style of ATOM line. // // Jeremy Meredith, Mon Aug 28 17:58:02 EDT 2006 // Changed the scanning to (a) match the PDB spec document more // effectively, (b) be faster, and (c) handle some missing elements // (short lines) better. // // Jeremy Meredith, Wed Oct 17 11:27:10 EDT 2007 // Added compound support. // // **************************************************************************** eavlPDBImporter::Atom::Atom(const char *line, int cmpnd) { char record[7]; int len = strlen(line); ScanString(line, len, 1, 6, record); ScanInt (line, len, 7, 11, &serial); ScanString(line, len, 13, 16, name); ScanChar (line, len, 17, &altloc); ScanString(line, len, 18, 20, resname); ScanChar (line, len, 22, &chainid); ScanInt (line, len, 23, 26, &resseq); ScanChar (line, len, 27, &icode); ScanFloat (line, len, 31, 38, &x); ScanFloat (line, len, 39, 46, &y); ScanFloat (line, len, 47, 54, &z); ScanFloat (line, len, 55, 60, &occupancy); ScanFloat (line, len, 61, 66, &tempfactor); ScanString(line, len, 73, 76, segid); ScanString(line, len, 77, 78, element); ScanString(line, len, 79, 80, charge); // Left-justify element names if (element[0] == ' ') { element[0] = element[1]; element[1] = '\0'; } if((atomicnumber = ElementNameToAtomicNumber(element)) < 0) { // We have a weird file that does not keep the element name in // the place designated by the ATOM record. Files like this seem // to use the space for a line number. Check columns 12,13 // for the atom number. if(line[12] == ' ' || (line[12] >= '0' && line[12] <= '9')) { element[0] = line[13]; element[1] = '\0'; } else if (line[13] >= '0' && line[13] <= '9') { element[0] = line[12]; element[1] = '\0'; } else { element[0] = line[12]; element[1] = line[13]; } atomicnumber = ElementNameToAtomicNumber(element); if (atomicnumber < 0 && element[1] != '\0') { element[1] = '\0'; atomicnumber = ElementNameToAtomicNumber(element); } if (atomicnumber < 0) { char msg[2000]; snprintf(msg, 2000, "Unknown element name <%s> in line: %s", element, line); THROW(eavlException, msg); } } // Shift spaces out of the resname. if(resname[0] == ' ') { if(resname[1] == ' ') { resname[0] = resname[2]; resname[1] = '\0'; } else { resname[0] = resname[1]; resname[1] = resname[2]; resname[2] = '\0'; } } // Look up the residue number from the name. if((residuenumber = ResiduenameToNumber(resname)) < 0) { residuenumber = 0; } backbone = false; if (strcmp(name, " N ")==0 || strcmp(name, " C ")==0 || strcmp(name, " CA ")==0) { backbone = true; } compound = cmpnd; }
void sXSILoader::ScanMatLib(sInt indent) { sChar chunk[XSISIZE]; sChar name[XSISIZE]; sChar texname[256]; sChar buffer[XSISIZE]; sChar pname[XSISIZE]; sChar tname[XSISIZE]; sChar tsup[2][XSISIZE]; sInt texena[2]; sXSIMaterial *mat; sXSITexture *tex; sInt i,max; sInt pcount,ccount; sInt ival; sF32 fval; ScanInt(); while(*Scan!=0 && *Scan!='}' && !Error) { ScanChunk(indent,chunk,name); if(sCmpString(chunk,"SI_Material")==0) { mat = new sXSIMaterial; sCopyString(mat->Name,name,sizeof(mat->Name)); mat->Flags |= 0; Materials->Add(mat); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanInt(); ScanFloat(); ScanFloat(); ScanFloat(); sScanSpace(Scan); while(*Scan!=0 && *Scan!='}' && !Error) { ScanChunk(indent+1,chunk,name); if(sCmpString(chunk,"SI_Texture2D")==0) { ScanString(texname,sizeof(texname)); ScanInt(); ScanInt(); ScanInt(); ScanInt(); ScanInt(); ScanInt(); ScanInt(); ScanInt(); ScanInt(); ScanInt(); ScanInt(); ScanInt(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanInt(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); EndChunk(); if(mat->Tex[0] == 0) { tex = FindTexture(texname); if(tex) mat->Tex[0] = tex; } } else { SkipChunk(); } sScanSpace(Scan); } EndChunk(); } else if(sCmpString(chunk,"XSI_Material")==0) { mat = new sXSIMaterial; sCopyString(mat->Name,name,sizeof(mat->Name)); mat->TFlags[0] = 0; mat->TFlags[1] = 0; mat->Flags |= 0; sDPrintF("%08x:<%s>\n",Scan,name); Materials->Add(mat); max = ScanInt(); for(i=0;i<max;i++) { ScanString(buffer,sizeof(buffer)); ScanString(buffer,sizeof(buffer)); } sScanSpace(Scan); tsup[0][0]=0; tsup[0][1]=0; texena[0] = 0; texena[1] = 0; while(*Scan!=0 && *Scan!='}' && !Error) { ScanChunk(indent+1,chunk,name); if(sCmpString(chunk,"XSI_Shader")==0) { ScanString(buffer,sizeof(buffer)); ScanInt(); pcount = ScanInt(); ccount = ScanInt(); for(i=0;i<pcount;i++) { ScanString(pname,sizeof(pname)); ScanString(tname,sizeof(tname)); if(sCmpString(tname,"STRING")==0) { ScanString(buffer,sizeof(buffer)); if(sCmpString(pname,"tspace_id1")==0) sCopyString(tsup[0],buffer,sizeof(tsup[0])); if(sCmpString(pname,"tspace_id" )==0) sCopyString(tsup[0],buffer,sizeof(tsup[0])); if(sCmpString(pname,"tspace_id2")==0) sCopyString(tsup[1],buffer,sizeof(tsup[1])); } else if(sCmpString(tname,"FLOAT")==0) { fval = ScanFloat(); ival = sRange<sInt>(255*fval,255,0); if(sCmpString(pname,"Ambient.red")==0) mat->Ambient.r = ival; if(sCmpString(pname,"Ambient.green")==0) mat->Ambient.g = ival; if(sCmpString(pname,"Ambient.blue")==0) mat->Ambient.b = ival; if(sCmpString(pname,"Diffuse.red")==0) mat->Diffuse.r = ival; if(sCmpString(pname,"Diffuse.green")==0) mat->Diffuse.g = ival; if(sCmpString(pname,"Diffuse.blue")==0) mat->Diffuse.b = ival; if(sCmpString(pname,"Specular.red")==0) mat->Specular.r = ival; if(sCmpString(pname,"Specular.green")==0) mat->Specular.g = ival; if(sCmpString(pname,"Specular.blue")==0) mat->Specular.b = ival; if(sCmpString(pname,"Shininess")==0) mat->Specularity = fval; } else if(sCmpString(tname,"INTEGER")==0) { ival = ScanInt(); } else if(sCmpString(tname,"BOOLEAN")==0) { ival = ScanInt(); if(ival!=0) { // if(sCmpString(pname,"WrapS1")==0) mat->TFlags[0] |= sMTF_TILE; // if(sCmpString(pname,"WrapT1")==0) mat->TFlags[0] |= sMTF_TILE; if(sCmpString(pname,"Refmap1")==0) mat->TFlags[0] |= sMTF_UVENVI; if(sCmpString(pname,"Texture_1_Enable")==0) texena[0]=1; // if(sCmpString(pname,"WrapS2")==0) mat->TFlags[1] |= sMTF_TILE; // if(sCmpString(pname,"WrapT2")==0) mat->TFlags[1] |= sMTF_TILE; if(sCmpString(pname,"Refmap2")==0) mat->TFlags[1] |= sMTF_UVENVI; if(sCmpString(pname,"Texture_2_Enable")==0) texena[1]=1; } else { if(sCmpString(pname,"Enable_Ambient")==0) mat->Ambient = 0xffffffff; if(sCmpString(pname,"Enable_Diffuse")==0) mat->Diffuse = 0xffffffff; if(sCmpString(pname,"Enable_Specular")==0) mat->Specular = 0xffffffff; if(sCmpString(pname,"Enable_Shininess")==0) mat->Specularity = 0; // if(sCmpString(pname,"Enable_Lighting")==0) mat->Flags &= ~sMF_LIGHTMASK; } } else { Error = sTRUE; } } for(i=0;i<ccount;i++) { ScanString(pname,sizeof(pname)); ScanString(buffer,sizeof(buffer)); ScanString(tname,sizeof(tname)); if(sCmpString(tname,"IMAGE")==0) { if((sCmpString(pname,"Texture_1")==0 || sCmpString(pname,"tex")==0) && texena[0]) { if(mat->Tex[0] == 0 && (tsup[0][0]!=0 || (mat->TFlags[0]&sMTF_UVMASK)==sMTF_UVENVI) && TSCount<sXSI_MAXTS) { tex = FindTexture(buffer); if(tex) { mat->Tex[0] = tex; mat->Mode = sMBM_TEX; sCopyString(TSName[TSCount],tsup[0],XSISIZE); mat->TUV[0] = TSCount++; } } } if(sCmpString(pname,"Texture_2")==0 && texena[1]) { if(mat->Tex[1] == 0 && (tsup[1][0]!=0 || (mat->TFlags[1]&sMTF_UVMASK)==sMTF_UVENVI) && TSCount<sXSI_MAXTS) { tex = FindTexture(buffer); if(tex) { mat->Tex[1] = tex; mat->Mode = sMBM_MUL; // mat->TFlags[1] = sMTF_FILTER|sMTF_MIPMAP;//|sMTF_UVENVI; sCopyString(TSName[TSCount],tsup[1],XSISIZE); mat->TUV[1] = TSCount++; } } } } } sScanSpace(Scan); while(*Scan!=0 && *Scan!='}' && !Error) { ScanChunk(indent+1,chunk,name); SkipChunk(); sScanSpace(Scan); } EndChunk(); } else { SkipChunk(); } sScanSpace(Scan); } if((mat->TFlags[1] & sMTF_UVMASK)==0) mat->TFlags[1] |= sMTF_UV1; if(mat->Specularity>0.0001f || mat->Ambient!=0xffffffff || mat->Diffuse != 0xffffffff || mat->Specular != 0xffffffff) { // mat->Flags = (mat->Flags & (~sMF_LIGHTMASK)) | sMF_LIGHTMAT; // sDPrintF("extlight: %08x %08x %08x\n",mat->Diffuse.Color,mat->Ambient.Color,mat->Specular.Color); } else { // mat->Flags |= sMF_COLBOTH; } mat->TFlags[0] |= sMTF_FILTERMIN | sMTF_FILTERMAG | sMTF_MIPMAP; mat->TFlags[1] |= sMTF_FILTERMIN | sMTF_FILTERMAG | sMTF_MIPMAP; EndChunk(); } else { SkipChunk(); } sScanSpace(Scan); } EndChunk(); }
void sXSILoader::ScanMesh(sInt indent,sXSIModel *model) { sChar buffer[256]; sChar chunk[XSISIZE]; sChar name[XSISIZE]; sChar *cmd; sInt supports,i,j,k,max; sInt fcount; sInt vcount; sXSICluster *cluster; sInt cr,cg,cb,ca; sInt set,set2; sInt PosCount; sVector *Pos; sInt NormCount; sVector *Norm; sInt ColorCount; sU32 *Color; sInt UVCount[sXSI_MAXUV]; sF32 *UV[sXSI_MAXUV]; sChar UVName[sXSI_MAXUV][XSISIZE]; // init shape holder PosCount = 0; Pos = 0; NormCount = 0; Norm = 0; ColorCount = 0; Color = 0; for(i=0;i<sXSI_MAXUV;i++) { UVCount[i] = 0; UV[i] = 0; } while(*Scan!=0 && *Scan!='}' && !Error) { ScanChunk(indent,chunk,name); if(sCmpString(chunk,"SI_Shape")==0) { supports = ScanInt(); ScanString(buffer,sizeof(buffer)); if(sCmpString(buffer,"ORDERED")!=0) Error = sTRUE; for(i=0;i<supports && !Error;i++) { max = ScanInt(); ScanString(buffer,sizeof(buffer)); if(sCmpString(buffer,"POSITION")==0) { sVERIFY(Pos==0); PosCount = max; Pos = new sVector[max]; for(j=0;j<max;j++) { Pos[j].x = ScanFloat(); Pos[j].y = ScanFloat(); Pos[j].z = ScanFloat(); } } else if(sCmpString(buffer,"NORMAL")==0) { sVERIFY(Norm==0); NormCount = max; Norm = new sVector[max]; for(j=0;j<max;j++) { Norm[j].x = ScanFloat(); Norm[j].y = ScanFloat(); Norm[j].z = ScanFloat(); } } else if(sCmpString(buffer,"COLOR")==0) { sVERIFY(Color==0); ColorCount = max; Color = new sU32[max]; for(j=0;j<max;j++) { cr = sRange<sInt>(ScanFloat()*255,255,0); cg = sRange<sInt>(ScanFloat()*255,255,0); cb = sRange<sInt>(ScanFloat()*255,255,0); ca = sRange<sInt>(ScanFloat()*256,255,0); Color[j] = (ca<<24)|(cb<<16)|(cg<<8)|(cr); } } else if(sCmpString(buffer,"TEX_COORD_UV")==0) { set = 0; sVERIFY(UV[set]==0); UVCount[set] = max; UV[set] = new sF32[max*2]; for(j=0;j<max;j++) { UV[set][j*2+0] = ScanFloat(); UV[set][j*2+1] = 1.0f-ScanFloat(); } } else if(sCmpMem(buffer,"TEX_COORD_UV",12)==0) { j=12; set = 0; while(buffer[j]>='0' && buffer[j]<='9') set = set*10 + (buffer[j++]-'0'); sVERIFY(set>=0 && set<sXSI_MAXUV); sVERIFY(UV[set]==0); ScanString(UVName[set],sizeof(UVName[set])); UVCount[set] = max; UV[set] = new sF32[max*2]; for(j=0;j<max;j++) { UV[set][j*2+0] = ScanFloat(); UV[set][j*2+1] = 1.0f-ScanFloat(); } } else { Error = sTRUE; } } EndChunk(); } else if(sCmpString(chunk,"SI_PolygonList")==0) { cluster = new sXSICluster; fcount = ScanInt(); sCopyString(buffer,"|POSITION|",sizeof(buffer)); i = sGetStringLen(buffer); ScanString(buffer+i,sizeof(buffer)-i); #if DUMPCHUNK sDPrintF(" %s",buffer); #endif ScanString(name,sizeof(name)); cluster->Material = FindMaterial(name); vcount = ScanInt(); cluster->VertexCount = vcount; cluster->IndexCount = vcount; cluster->Vertices = new sXSIVertex[vcount]; cluster->Faces = new sInt[vcount*2]; model->Clusters->Add(cluster); j = 0; for(i=0;i<fcount;i++) { max = ScanInt(); cluster->Vertices[j].Init(); cluster->Faces[j*2+0] = max; cluster->Faces[j*2+1] = j; j++; for(k=1;k<max;k++) { cluster->Vertices[j].Init(); cluster->Faces[j*2+0] = 0; cluster->Faces[j*2+1] = j; j++; } } sVERIFY(j==vcount); cmd = buffer; while(!Error && *cmd) { if(sCmpMem(cmd,"|POSITION",9)==0) { cmd+=9; sVERIFY(Pos); for(i=0;i<vcount;i++) { j = ScanInt(); cluster->Vertices[i].Pos = Pos[j]; cluster->Vertices[i].Index = j; } } else if(sCmpMem(cmd,"|NORMAL",7)==0) { cmd+=7; sVERIFY(Norm); for(i=0;i<vcount;i++) { j = ScanInt(); cluster->Vertices[i].Normal = Norm[j]; cluster->Vertices[i].Normal.Init(0,0,0,1); } } else if(sCmpMem(cmd,"|COLOR",6)==0) { cmd+=6; sVERIFY(Color); for(i=0;i<vcount;i++) { j = ScanInt(); cluster->Vertices[i].Color = Color[j]; } } else if(sCmpMem(cmd,"|TEX_COORD_UV",13)==0) { cmd+=13; set = 0; if(*cmd>='0' && *cmd<='9') { while(*cmd>='0' && *cmd<='9') set = set*10 + ((*cmd++)-'0'); sVERIFY(set>=0 && set<sXSI_MAXUV); sVERIFY(UV[set]) for(set2=0;set2<4;set2++) if(sCmpString(TSName[cluster->Material->TUV[set2]],UVName[set])==0) break; } else { set2 = 0; } for(i=0;i<vcount;i++) { j = ScanInt(); if(set2>=0 && set2<2) { cluster->Vertices[i].UV[set2][0] = 0.0f;// UV[set][j*2+0]; cluster->Vertices[i].UV[set2][1] = 0.0f;// UV[set][j*2+1]; } } } else {
void Lexer::ScanNumber() { PushBack(*--tp); ScanInteger(10); char ch = PeekAtChar(); // If they both read the same number of characters or the integer ended // in a radix specifier then we got ourselves an integer but we'll need // to check its in range later. // switch (ch) { case 'r': { if (m_tokenType != SmallIntegerConst) return; if (m_integer >= 2 && m_integer <= 36) { // Probably a short or long integer with a leading radix. *tp++ = NextChar(); char* startSuffix = tp; int radix = m_integer; ScanInteger(radix); if (tp == startSuffix) { m_integer = radix; tp--; PushBack(ch); } } } break; case 's': // A ScaledDecimal *tp++ = NextChar(); // We must read over the trailing scale (optional) while (isdigit(PeekAtChar())) *tp++ = NextChar(); m_tokenType = ScaledDecimalConst; break; case '.': // Its probably a floating value but might actually // be the end of statement ScanFloat(); if (PeekAtChar() == 's') { // Its a scaled decimal - include any trailing digits *tp++ = NextChar(); while (isdigit(PeekAtChar())) *tp++ = NextChar(); m_tokenType = ScaledDecimalConst; } break; case 'e': { // Allow old St-80 exponent form, such as 1e6 ScanExponentInteger(); } default: break; }; }