/* ================ idRestoreGame::ReadRenderEntity ================ */ void idRestoreGame::ReadRenderEntity( renderEntity_t& renderEntity ) { int i; int index; ReadModel( renderEntity.hModel ); ReadInt( renderEntity.entityNum ); ReadInt( renderEntity.bodyId ); ReadBounds( renderEntity.bounds ); // callback is set by class's Restore function renderEntity.callback = NULL; renderEntity.callbackData = NULL; ReadInt( renderEntity.suppressSurfaceInViewID ); ReadInt( renderEntity.suppressShadowInViewID ); ReadInt( renderEntity.suppressShadowInLightID ); ReadInt( renderEntity.allowSurfaceInViewID ); ReadVec3( renderEntity.origin ); ReadMat3( renderEntity.axis ); ReadMaterial( renderEntity.customShader ); ReadMaterial( renderEntity.referenceShader ); ReadSkin( renderEntity.customSkin ); ReadInt( index ); renderEntity.referenceSound = gameSoundWorld->EmitterForIndex( index ); for( i = 0; i < MAX_ENTITY_SHADER_PARMS; i++ ) { ReadFloat( renderEntity.shaderParms[ i ] ); } for( i = 0; i < MAX_RENDERENTITY_GUI; i++ ) { ReadUserInterface( renderEntity.gui[ i ] ); } // idEntity will restore "cameraTarget", which will be used in idEntity::Present to restore the remoteRenderView renderEntity.remoteRenderView = NULL; renderEntity.joints = NULL; renderEntity.numJoints = 0; ReadFloat( renderEntity.modelDepthHack ); ReadBool( renderEntity.noSelfShadow ); ReadBool( renderEntity.noShadow ); ReadBool( renderEntity.noDynamicInteractions ); ReadBool( renderEntity.weaponDepthHack ); ReadInt( renderEntity.forceUpdate ); ReadInt( renderEntity.timeGroup ); ReadInt( renderEntity.xrayIndex ); }
/* ================ idRestoreGame::ReadRenderLight ================ */ void idRestoreGame::ReadRenderLight( renderLight_t &renderLight ) { int index; int i; ReadMat3( renderLight.axis ); ReadVec3( renderLight.origin ); ReadInt( renderLight.suppressLightInViewID ); ReadInt( renderLight.allowLightInViewID ); ReadBool( renderLight.noShadows ); ReadBool( renderLight.noSpecular ); ReadBool( renderLight.pointLight ); ReadBool( renderLight.parallel ); ReadVec3( renderLight.lightRadius ); ReadVec3( renderLight.lightCenter ); ReadVec3( renderLight.target ); ReadVec3( renderLight.right ); ReadVec3( renderLight.up ); ReadVec3( renderLight.start ); ReadVec3( renderLight.end ); // only idLight has a prelightModel and it's always based on the entityname, so we'll restore it there // ReadModel( renderLight.prelightModel ); renderLight.prelightModel = NULL; ReadInt( renderLight.lightId ); ReadMaterial( renderLight.shader ); for( i = 0; i < MAX_ENTITY_SHADER_PARMS; i++ ) { ReadFloat( renderLight.shaderParms[ i ] ); } ReadInt( index ); renderLight.referenceSound = gameSoundWorld->EmitterForIndex( index ); }
int Struct3D_Master::ReadAppearance(FILE * file, int *LineNum) /*************************************************************/ { char line[1024], *text; int err = 1; while ( GetLine(file, line, LineNum, 512) ) { text = strtok(line, " \t\n\r"); if ( * text == '}' ) { err = 0; break; } if ( stricmp (text, "material" ) == 0 ) { ReadMaterial(file, LineNum ); } else { printf ("ReadAppearance error line %d <%s> \n", *LineNum, text); break; } } return err; }
int AseFile::ReadMaterial_List() { char temp[255]; do { if( !fgets(temp, 255, file) )return 0; if( EqualString( temp, "*MATERIAL ") ) { if( !ReadMaterial(atoi(temp)) )return 0; } // else if( EqualString( temp, "*MATERIAL_COUNT ") ) numOfMat=atoi(temp); else ReadUnknown( temp); }while(!FindBracketClose( temp)); // while temp not contain '}' return 1; }
/* =================== idRestoreGame::ReadContactInfo =================== */ void idRestoreGame::ReadContactInfo( contactInfo_t &contactInfo ) { ReadInt( (int &)contactInfo.type ); ReadVec3( contactInfo.point ); ReadVec3( contactInfo.normal ); ReadFloat( contactInfo.dist ); ReadInt( contactInfo.contents ); ReadMaterial( contactInfo.material ); ReadInt( contactInfo.modelFeature ); ReadInt( contactInfo.trmFeature ); ReadInt( contactInfo.entityNum ); ReadInt( contactInfo.id ); }
//*************************************************************************** void ReadMaterials(scene_t *scene,void *chunkmain) { header_t **temp; uint nMATERIALS=0,Q; material_t *material; //��������������������������������������������������������������������������� temp=ColectMaterials(chunkmain,&nMATERIALS); material=scene->materials=malloc(sizeof(material_t)*(nMATERIALS+1)); // +1 coz there is default material too scene->nmaterials=nMATERIALS+1; memcpy(material,&default_material,sizeof(material_t)); for(Q=0; Q!=nMATERIALS; Q++) ReadMaterial(temp[Q],&material[Q+1]); free(temp); }
bool bgParserASE::Read() { bool hr = true; TCHAR szWordArray[2][MAX_PATH * 4]; // m_ASE 데이터 초기화 ZeroMemory(&m_pModel->m_Scene, sizeof(SceneInfo)); m_pModel->m_MaterialList.clear(); m_pModel->m_ObjectList.clear(); // 파일 앞부분 1회만 등장하는 섹션 읽기 IF_FALSE_RETURN(FindWord(_T("*SCENE"))); IF_FALSE_RETURN(ReadScene()); IF_FALSE_RETURN(FindWord(_T("*MATERIAL_LIST"))); IF_FALSE_RETURN(ReadMaterial()); // 여러번 등장하는 섹션 반복해서 읽기 _tcscpy(szWordArray[0], _T("*GEOMOBJECT")); _tcscpy(szWordArray[1], _T("*HELPEROBJECT")); while (!feof(m_pFile)) { switch (FindWordArray(szWordArray, 2)) { case 0: IF_FALSE_RETURN(ReadGeomObject()); break; case 1: IF_FALSE_RETURN(ReadHelperObject()); break; case -1: // 찾는 단어 없음 (파일의 끝) { ConvertToModel(); // 읽은 데이터를 모델용 데이터로 컨버팅 LinkNode(); // 노드 관계 연결 OperationTM(); // 노드 관계에 따른 행렬 연산 } break; default: // 나머지 (배열 요소가 2개이므로 나올 수 없음) return false; break; } } return hr; }
/* ================ ReadMaterialList ================ */ static void ReadMaterialList( Lexer &lexer ) { lexer.ExpectToken("{"); const char *p; const Token *token; int numMaterials; while ( (token = lexer.ReadToken()) != OG_NULL ) { p = token->GetString(); if ( !p || !*p ) continue; if ( String::Icmp( p, "}" ) == 0 ) return; if ( String::Icmp( p, "*" ) != 0 ) lexer.Error( Format("expected *, got '$*'") << p ); if ( lexer.CheckToken( "MATERIAL_COUNT" ) ) numMaterials = lexer.ReadInt(); else if ( lexer.CheckToken( "MATERIAL" ) ) ReadMaterial( lexer ); else if ( !SkipUnknown(lexer) ) break; } }
int XFileLoader::ReadMeshMaterials(istream& s) { vector<int> materialIndices; int nMaterialIndices; int nMaterials; XFileToken t = XFileToken::NextToken(s); if (t.m_type == XFileToken::Identifier) { //m_meshes[meshIdx].m_name = t.m_content; t = XFileToken::NextToken(s); } if (t.m_type != XFileToken::LeftBrace) THROW_EXCEPTION_T("Parsing error", ParsingException); ReadMember(s, nMaterials); ReadMember(s, nMaterialIndices); materialIndices.resize(nMaterialIndices); ReadArray(s, materialIndices.begin(), materialIndices.end()); SkipToken(s, XFileToken::Semicolon); unsigned int materialIdx = UINT_MAX; while (true) { t = XFileToken::NextToken(s); if (t.m_type == XFileToken::Identifier) { if (t.m_content == "Material" && materialIdx == UINT_MAX) materialIdx = ReadMaterial(s); else SkipDataObject(s); } else if (t.m_type == XFileToken::LeftBrace) SkipDataReference(s); else if (t.m_type == XFileToken::RightBrace) break; else THROW_EXCEPTION_T("Parsing error", ParsingException); } return materialIdx; }
// 读取3ds物体主编辑Chunk UINT C3DSModel::ReadEdit(UINT n) { UINT count = 0; tChunk chunk = {0}; while(count < n) { ReadChunk(&chunk); switch(chunk.ID) { case EDIT_MAT: ReadMaterial(chunk.length-6); break; case EDIT_OBJECT: ReadObject(chunk.length-6); break; default: fseek(m_FilePtr, chunk.length-6, SEEK_CUR); break; } count += chunk.length; } return count; }
HRESULT FileReader::ReadObjFile(std::string filename, //.obj filename ID3D11Buffer* vertBuff, //mesh vertex buffer ID3D11Device* device, ID3D11DeviceContext* deviceContext, std::vector<std::vector<GraphicHelper::SimpleVertex>> &vertices, std::vector<Material> &outMaterials, std::vector<ID3D11ShaderResourceView*> &textureViews ) { HRESULT hr = S_OK; std::vector<Group> groups; Group tempGroup; std::vector<std::string> accMaterialNames; std::vector<XMFLOAT3> temp_vertices; std::vector<XMFLOAT2> temp_uvs; std::vector<XMFLOAT3> temp_normals; char matFileName[128]; FILE * file; fopen_s(&file,filename.c_str(), "r"); if( file == NULL ) { printf("Impossible to open the file !\n"); return false; } while(true) { char lineHeader[128]; // read the first word of the line int res = fscanf_s(file, "%s", lineHeader, _countof(lineHeader)); if (res == EOF) { break; // EOF = End Of File. Quit the loop. } if ( strcmp( lineHeader, "v" ) == 0 ) { XMFLOAT3 vertex; fscanf_s(file, "%f %f %f\n", &vertex.x, &vertex.y, &vertex.z ); temp_vertices.push_back(vertex); } else if(strcmp( lineHeader, "vt" ) == 0 ) { XMFLOAT2 uv; fscanf_s(file, "%f %f\n", &uv.x, &uv.y ); temp_uvs.push_back(uv); // else : parse lineHeader } else if ( strcmp( lineHeader, "vn" ) == 0 ) { XMFLOAT3 normal; fscanf_s(file, "%f %f %f\n", &normal.x, &normal.y, &normal.z ); temp_normals.push_back(normal); } else if ( strcmp( lineHeader, "f" ) == 0 ) { //std::string vertex1, vertex2, vertex3; unsigned int vertexIndex[3], uvIndex[3], normalIndex[3]; int matches = fscanf_s(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", &vertexIndex[0], &uvIndex[0], &normalIndex[0], &vertexIndex[1], &uvIndex[1], &normalIndex[1], &vertexIndex[2], &uvIndex[2], &normalIndex[2] ); if (matches != 9){ printf("File can't be read by our simple parser : ( Try exporting with other options\n"); return false; } tempGroup.vertexIndices.push_back(vertexIndex[0]); tempGroup.vertexIndices.push_back(vertexIndex[1]); tempGroup.vertexIndices.push_back(vertexIndex[2]); tempGroup.uvIndices.push_back(uvIndex[0]); tempGroup.uvIndices.push_back(uvIndex[1]); tempGroup.uvIndices.push_back(uvIndex[2]); tempGroup.normalIndices.push_back(normalIndex[0]); tempGroup.normalIndices.push_back(normalIndex[1]); tempGroup.normalIndices.push_back(normalIndex[2]); } else if( strcmp( lineHeader, "mtllib" ) == 0 ) { int outp = fscanf_s(file, "%s\n", matFileName, _countof(matFileName)); if(outp != 1) { return false; //I guess? } } else if( strcmp( lineHeader, "usemtl" ) == 0 ) { char temp[128]; int outp = fscanf_s(file, "%s\n", temp, _countof(temp)); if(outp != 1) { return false; //I guess? } tempGroup.materialName = temp; } else if( strcmp( lineHeader, "g" ) == 0 ) { char temp[128]; int outp = fscanf_s(file, "%s\n", temp, _countof(temp)); if(outp != 1) { return false; //I guess? } if(tempGroup.groupName == "") //if first group { tempGroup.groupName = temp; } else { groups.push_back(tempGroup); tempGroup.normalIndices.clear(); tempGroup.uvIndices.clear(); tempGroup.vertexIndices.clear(); tempGroup.materialName = ""; tempGroup.groupName = temp; } } else if( strcmp( lineHeader, "s" ) == 0 ) { //save side (could be averaged) } } groups.push_back(tempGroup); for (int i = 0; i < groups.size(); i++) { if(groups[i].vertexIndices.size() > 0) { std::vector<GraphicHelper::SimpleVertex> tempVerticeList; std::vector <XMFLOAT3> out_vertices; std::vector <XMFLOAT2> out_uvs; std::vector <XMFLOAT3> out_normals; for(unsigned int j = 0; j< groups[i].vertexIndices.size(); j++) { unsigned int vertexIndex = groups[i].vertexIndices[j]; XMFLOAT3 vertex = temp_vertices[vertexIndex - 1]; out_vertices.push_back(vertex); } for(unsigned int j = 0; j<groups[i].normalIndices.size(); j++) { unsigned int normalIndex = groups[i].normalIndices[j]; XMFLOAT3 normal = temp_normals[normalIndex - 1]; out_normals.push_back(normal); } for(unsigned int j = 0; j<groups[i].uvIndices.size(); j++) { unsigned int uvIndex = groups[i].uvIndices[j]; XMFLOAT2 uv = temp_uvs[uvIndex - 1]; out_uvs.push_back(uv); } for (int j = 0; j < out_vertices.size(); j++) { GraphicHelper::SimpleVertex temp; temp.Pos = out_vertices[j]; temp.Norm = out_normals[j]; temp.Tex = out_uvs[j]; tempVerticeList.push_back(temp); } accMaterialNames.push_back(groups[i].materialName); vertices.push_back(tempVerticeList); } } hr = ReadMaterial(device,matFileName,accMaterialNames,outMaterials,textureViews); fclose(file); return hr; }
bool L3DS::Read3DS() { LChunk mainchunk; LChunk edit; edit.id = EDIT3DS; mainchunk = ReadChunk(); if (mainchunk.id != MAIN3DS) { fprintf(stderr, "L3DS::Read3DS - wrong file format"); return false; } if (!FindChunk(edit, mainchunk)) return false; LChunk obj; LChunk ml; GotoChunk(edit); obj.id = MAT_ENTRY; while (FindChunk(obj, edit)) { ReadMaterial(obj); SkipChunk(obj); } GotoChunk(edit); obj.id = EDIT_OBJECT; { while (FindChunk(obj, edit)) { ReadASCIIZ(m_objName, 99); ml = ReadChunk(); if (ml.id == OBJ_TRIMESH) ReadMesh(ml); else if (ml.id == OBJ_LIGHT) ReadLight(ml); else if (ml.id == OBJ_CAMERA) ReadCamera(ml); SkipChunk(obj); } } // read the keyframer data here to find out correct object orientation LChunk keyframer; keyframer.id = KFDATA; LChunk objtrack; objtrack.id = OBJECT_NODE_TAG; GotoChunk(mainchunk); if (FindChunk(keyframer, mainchunk)) { // keyframer chunk is present GotoChunk(keyframer); while (FindChunk(objtrack, keyframer)) { ReadKeyframeData(objtrack); SkipChunk(objtrack); } } for (uint i=0; i<m_meshes.size(); i++) m_meshes[i].Optimize(m_optLevel); m_pos = 0; strcpy(m_objName, ""); return true; }
// expect wavelength in m int SetReflectivity(struct ElementType *ep, double wavelength) { double f1, f2, a, rho, energy, nt, delta, beta, ac, sinag, cosag, Rs, Rp; int z, myreturn; COMPLEX cn, cn2, cwu, crs, cts, crp, ctp, c1, c2, c3, csinag; char *material; struct ReflecType *rp; material= ep->MDat.material; rp= (struct ReflecType *)&ep->reflec; #ifdef DEBUG printf("debug: SetReflectivity called, material= >%s<, file= %s\n", material, __FILE__); #endif if (!(wavelength > 0.0)) { fprintf(stderr, "error SetReflectivity: wavelength not defined (%f)- return"); return 0; } energy= 1240e-9/ wavelength; myreturn= ReadMaterial(material, &z, &a, &rho); myreturn &= ReadHenke(material, energy, &f1, &f2); nt= 1e6* rho * NA / a; // Teilchendichte (1/m^3), rho is in (g/cm^3) delta= RE * pow(wavelength, 2) * nt * f1 / (2.0 * PI); beta = RE * pow(wavelength, 2) * nt * f2 / (2.0 * PI); ac = acos(1.0 - delta); // critical (grazing) angle in rad complex_in(&cn, (1.0- delta), beta); // complex index of refraction sinag= ep->geo.cosa; // sin(grazing angle) grazing angle in rad cosag= ep->geo.sina; // sin <-> cos change for grazing angle // we calculate the compex reflectivity and transmission coefficients // transmission coefficients not used so far complex_x (&cn, &cn, &cn2); // n^2 complex_in (&c1, pow(cosag, 2.0), 0.0); // cos(theta))^2 saved in c1 complex_minus(&cn2, &c1, &c2); // c2= n2- c1 complex_pow (&c2, 0.5, &cwu); // wu= sqrt(c2) complex_in (&csinag, sinag, 0.0); // sin(theta) saved in csinag complex_minus(&csinag, &cwu, &c1); // zehler in c1 complex_plus (&csinag, &cwu, &c2); // nenner in c2 complex_div (&c1, &c2, &crs); // calc crs complex_in (&c1, (2* sinag), 0.0); // zehler in c1 complex_div(&c1, &c2, &cts); // calc cts complex_x (&cn2, &csinag, &c3); // c3 complex_minus(&c3, &cwu, &c1); // zehler in c1 complex_plus (&c3, &cwu, &c2); // nenner in c2 complex_div (&c1, &c2, &crp); // calc crp complex_in (&c1, 2.0, 0.0); // 2.0 in c1 complex_x (&c1, &cn, &c3); // 2n in c3 complex_x (&c3, &csinag, &c1); // zaehler in c1 complex_div(&c1, &c2, &ctp); // calc ctp Rs= pow(crs.re, 2)+ pow(crs.im, 2); // abs()^2 Rp= pow(crp.re, 2)+ pow(crp.im, 2); // abs()^2; rp->runpol= 0.5 * (Rs + Rp); // fill double ryamp, rypha, rzamp, rzpha, runpol; switch (ep->GDat.azimut) /* vertikal 0; nach links 1; nach unten 2 ; nach rechts 3 */ { case 0: case 2: rp->ryamp= sqrt(pow(crp.re, 2)+ pow(crp.im, 2)); rp->rypha= atan2(crp.im, crp.re); rp->rzamp= sqrt(pow(crs.re, 2)+ pow(crs.im, 2)); rp->rzpha= atan2(crs.im, crs.re); break; case 1: case 3: rp->rzamp= sqrt(pow(crp.re, 2)+ pow(crp.im, 2)); rp->rzpha= atan2(crp.im, crp.re); rp->ryamp= sqrt(pow(crs.re, 2)+ pow(crs.im, 2)); rp->rypha= atan2(crs.im, crs.re); break; default: fprintf(stderr, "error in file %s- azimut >>%d<<out of range\n", __FILE__, ep->GDat.azimut); exit(-1); } return myreturn; } // SetReflectivity