void AssimpParser::ParseModel(aiNode* node, std::shared_ptr<SceneNode> sceneNode) { std::shared_ptr<SceneNode> newNode = std::shared_ptr<SceneNode>(new SceneNode(std::string(node->mName.C_Str()))); for(int i=0; i<node->mNumMeshes; i++) { int meshIndex = node->mMeshes[i]; aiMesh* mesh = scene->mMeshes[meshIndex]; std::shared_ptr<SceneMesh> newMesh = std::shared_ptr<SceneMesh>(new SceneMesh()); newNode->AddMesh(newMesh); ParseMesh(newMesh, mesh); } if(sceneNode != nullptr) { sceneNode->AddChild(newNode); } for(int i=0; i<node->mNumChildren; i++) { aiNode* child = node->mChildren[i]; ParseModel(child, newNode); } }
CModel* CManagerModel::Load(string Path) { for (auto it = mModelIndex.begin();it != mModelIndex.end(); it++) { if (FSys.AliasAdd("Models",Path) == it->Path) { cout << "ManagerModel: Returning Allocated Buffer.\n"; return it->Model; } } cout << "ManagerModel: Allocating New Buffer\n"; CModel *Ret_Model = new CModel; Path = FSys.AliasAdd("Models",Path); XMLDocument doc; if (doc.LoadFile(Path.c_str()) == XML_SUCCESS) { XMLElement *Geo = doc.RootElement()->FirstChildElement("library_geometries")->FirstChildElement("geometry"); XMLElement *XMLMesh = Geo->FirstChildElement("mesh"); while (Geo != NULL) { while (XMLMesh != NULL) { XMLMesh = ParseMesh(XMLMesh,Ret_Model); } Geo = Geo->NextSiblingElement(); } cout << "Returned Valid Model.\n"; Ret_Model->Finalize(); mModelIndex.push_back(ModelPack(Ret_Model,Path)); return Ret_Model; } else { Warning("Failed to load model: "+Path,true); } return NULL; }
VOID ParseSubDiv( KFbxSubdiv* pFbxSubD, ExportFrame* pParentFrame ) { if( !g_pScene->Settings().bExportMeshes ) return; if( pFbxSubD == NULL ) { return; } const CHAR* strName = pFbxSubD->GetName(); if( strName == NULL || strName[0] == '\0' ) strName = pParentFrame->GetName().SafeString(); DWORD dwLevelCount = (DWORD)pFbxSubD->GetLevelCount(); ExportLog::LogMsg( 2, "Parsing subdivision surface \"%s\" with %d levels", strName, dwLevelCount ); if( dwLevelCount == 0 ) { ExportLog::LogWarning( "Subdivision surface \"%s\" has no levels.", strName ); return; } KFbxMesh* pLevelMesh = NULL; DWORD dwCurrentLevel = dwLevelCount - 1; while( pLevelMesh == NULL && dwCurrentLevel > 0 ) { pLevelMesh = pFbxSubD->GetMesh( dwCurrentLevel ); if( pLevelMesh == NULL ) { --dwCurrentLevel; } } if( pLevelMesh == NULL ) { pLevelMesh = pFbxSubD->GetBaseMesh(); } assert( pLevelMesh != NULL ); ExportLog::LogMsg( 3, "Parsing level %d", dwCurrentLevel ); CHAR strSuffix[32]; sprintf_s( strSuffix, "_level%d", dwCurrentLevel ); ParseMesh( pLevelMesh, pParentFrame, TRUE, strSuffix ); }
void DaeParser::ParseGeometry (Parser::Iterator iter) { Parser::Iterator mesh_iter = iter->First ("mesh"); if (!mesh_iter) return; if (mesh_iter->NextNamesake ()) raise_parser_exception (mesh_iter->NextNamesake (), "Only one 'mesh' tag allowed"); //разбор меша Mesh mesh; const char* id = get<const char*> (*iter, "id"); mesh.SetId (id); ParseMesh (mesh_iter, mesh); //добавление меша в библиотеку model.Meshes ().Insert (id, mesh); }
/* =============== R_LoadSurfaces =============== */ static void R_LoadSurfaces( lump_t *surfs, lump_t *verts, lump_t *indexLump ) { dsurface_t *in; msurface_t *out; mapVert_t *dv; int *indexes; int count; int numFaces, numMeshes, numTriSurfs, numFlares; int i; numFaces = 0; numMeshes = 0; numTriSurfs = 0; numFlares = 0; in = (dsurface_t *)(fileBase + surfs->fileofs); if (surfs->filelen % sizeof(*in)) ri.Error (ERR_DROP, "LoadMap: funny lump size in %s",s_worldData.name); count = surfs->filelen / sizeof(*in); dv = (mapVert_t *)(fileBase + verts->fileofs); if (verts->filelen % sizeof(*dv)) ri.Error (ERR_DROP, "LoadMap: funny lump size in %s",s_worldData.name); indexes = (int *)(fileBase + indexLump->fileofs); if ( indexLump->filelen % sizeof(*indexes)) ri.Error (ERR_DROP, "LoadMap: funny lump size in %s",s_worldData.name); out = (struct msurface_s *) ri.Hunk_Alloc ( count * sizeof(*out), qtrue ); s_worldData.surfaces = out; s_worldData.numsurfaces = count; // new bit, the face code on our biggest map requires over 15,000 mallocs, which was no problem on the hunk, // bit hits the zone pretty bad (even the tagFree takes about 9 seconds for that many memblocks), // so special-case pre-alloc enough space for this data (the patches etc can stay as they are)... // int iFaceDataSizeRequired = 0; for ( i = 0 ; i < count ; i++, in++) { switch ( LittleLong( in->surfaceType ) ) { case MST_PLANAR: int sfaceSize = ( int ) &((srfSurfaceFace_t *)0)->points[LittleLong(in->numVerts)]; sfaceSize += sizeof( int ) * LittleLong(in->numIndexes); iFaceDataSizeRequired += sfaceSize; break; } } in -= count; // back it up, ready for loop-proper // since this ptr is to hunk data, I can pass it in and have it advanced without worrying about losing // the original alloc ptr... // byte *pFaceDataBuffer = (byte *)ri.Hunk_Alloc( iFaceDataSizeRequired, qtrue ); // now do regular loop... // for ( i = 0 ; i < count ; i++, in++, out++ ) { switch ( LittleLong( in->surfaceType ) ) { case MST_PATCH: ParseMesh ( in, dv, out); numMeshes++; break; case MST_TRIANGLE_SOUP: ParseTriSurf( in, dv, out, indexes ); numTriSurfs++; break; case MST_PLANAR: ParseFace( in, dv, out, indexes, pFaceDataBuffer ); numFaces++; break; case MST_FLARE: ParseFlare( in, dv, out, indexes ); numFlares++; break; default: ri.Error( ERR_DROP, "Bad surfaceType" ); } } ri.Printf( PRINT_ALL, "...loaded %d faces, %i meshes, %i trisurfs, %i flares\n", numFaces, numMeshes, numTriSurfs, numFlares ); }
void PartSysParser::ParseEmitter(const TabFileRecord& record) { auto systemName = record[COL_PARTSYS_NAME].AsString(); auto& system = mSpecs[tolower(systemName)]; // Create it on demand if (!system) { system = std::make_shared<PartSysSpec>(systemName); } // Add the emitter auto emitter = system->CreateEmitter(record[COL_EMITTER_NAME].AsString()); ParseOptionalFloat(record, COL_DELAY, "Delay", [&] (float value) { emitter->SetDelay(value / 30.0f); }); ParseLifespan(record, emitter); ParseParticleLifespan(record, emitter); ParseParticleRate(record, emitter); ParseOptionalEnum<PartSysEmitterSpace>(record, COL_EMITTER_SPACE, "emitter space", EmitterSpaceMapping, [&](auto space) { emitter->SetSpace(space); }); ParseEmitterNodeName(record, emitter); ParseOptionalEnum<PartSysCoordSys>(record, COL_EMITTER_COORD_SYS, "emitter coord sys", CoordSysMapping, [&](auto coordSys) { emitter->SetCoordSys(coordSys); }); ParseOptionalEnum<PartSysCoordSys>(record, COL_EMITTER_OFFSET_COORD_SYS, "emitter offset coord sys", CoordSysMapping, [&](auto coordSys) { emitter->SetOffsetCoordSys(coordSys); }); ParseOptionalEnum<PartSysParticleType>(record, COL_PARTICLE_TYPE, "particle type", ParticleTypeMapping, [&](PartSysParticleType type) { emitter->SetParticleType(type); }); ParseOptionalEnum<PartSysBlendMode>(record, COL_BLEND_MODE, "blend mode", BlendModeMapping, [&](auto mode) { emitter->SetBlendMode(mode); }); ParseMaterial(record, emitter); ParseOptionalEnum<PartSysCoordSys>(record, COL_PARTICLE_POS_COORD_SYS, "particle pos coord sys", CoordSysMapping, [&](auto coordSys) { emitter->SetParticlePosCoordSys(coordSys); }); ParseOptionalEnum<PartSysCoordSys>(record, COL_PARTICLE_VELOCITY_COORD_SYS, "particle velocity coord sys", CoordSysMapping, [&](auto coordSys) { emitter->SetParticleVelocityCoordSys(coordSys); }); ParseOptionalEnum<PartSysParticleSpace>(record, COL_PARTICLE_SPACE, "particle space", ParticleSpaceMapping, [&](auto space) { emitter->SetParticleSpace(space); }); ParseMesh(record, emitter); // Parse the bounding box ParseOptionalFloat(record, COL_BB_LEFT, "bb left", [&](float val) { emitter->SetBoxLeft(val); }); ParseOptionalFloat(record, COL_BB_TOP, "bb top", [&](float val) { emitter->SetBoxTop(val); }); ParseOptionalFloat(record, COL_BB_RIGHT, "bb right", [&](float val) { emitter->SetBoxRight(val); }); ParseOptionalFloat(record, COL_BB_BOTTOM, "bb bottom", [&](float val) { emitter->SetBoxBottom(val); }); for (int paramId = 0; paramId <= part_attractorBlend; paramId++) { int colIdx = 22 + paramId; auto col = record[colIdx]; if (col) { bool success; std::unique_ptr<PartSysParam> param(ParserParams::Parse((PartSysParamId) paramId, col, emitter->GetLifespan(), emitter->GetParticleLifespan(), success)); if (success) { emitter->SetParam((PartSysParamId)paramId, param); } else { logger->warn("Unable to parse particle system param {} for particle system {} and emitter {} with value {}", paramId, systemName, emitter->GetName(), col.AsString()); } } } }
char *PROJECT::Load(char *filename, DISPLAY *disp) { long error = 0; struct IFFHandle *iff; struct ContextNode *cn; char *err; OBJECT *where = NULL; int dir = INSERT_HORIZ; // there is currently no active camera read camera[0] = 0; iff = AllocIFF(); if (!iff) return errors[ERR_MEM]; #ifdef __AMIGA__ iff->iff_Stream = Open(filename, MODE_OLDFILE); #else iff->iff_Stream = Open_(filename, MODE_OLDFILE); #endif if (!(iff->iff_Stream)) { IFFCleanup(iff); return errors[ERR_OPEN]; } InitIFFasDOS(iff); error = OpenIFF(iff, IFFF_READ); if (error) { IFFCleanup(iff); return errors[ERR_IFFPARSE]; } error = ParseIFF(iff, IFFPARSE_RAWSTEP); if (error) { IFFCleanup(iff); return errors[ERR_IFFPARSE]; } cn = CurrentChunk(iff); if(!cn) { IFFCleanup(iff); return errors[ERR_IFFPARSE]; } if((cn->cn_ID != ID_FORM) || (cn->cn_Type != ID_RSCN)) { IFFCleanup(iff); return errors[ERR_NORSCNFILE]; } while(!error || error == IFFERR_EOC) { error = ParseIFF(iff, IFFPARSE_RAWSTEP); if(error != IFFERR_EOC) { // Get a pointer to the context node describing the current context cn = CurrentChunk(iff); if (cn) { switch (cn->cn_ID) { case ID_VERS: if(!ReadULONG(iff,&rscn_version,1)) { IFFCleanup(iff); return errors[ERR_RSCNFILE]; } if(rscn_version > VERSION) { IFFCleanup(iff); return errors[ERR_WRONGVERS]; } break; case ID_FORM: switch(cn->cn_Type) { case ID_GNRL: err = ParseGeneral(iff,disp); if(err) { IFFCleanup(iff); return err; } break; case ID_FRAM: err = ParseFrame(iff); if(err) { IFFCleanup(iff); return err; } break; case ID_SRFS: err = ParseSurfaces(iff); if(err) { IFFCleanup(iff); return err; } break; case ID_CAMR: where = ParseCamera(iff, where, dir); if(!where) { IFFCleanup(iff); return errors[ERR_RSCNFILE]; } dir = INSERT_HORIZ; break; case ID_SPHR: where = ParseSphere(iff, where, dir); if(!where) { IFFCleanup(iff); return errors[ERR_RSCNFILE]; } dir = INSERT_HORIZ; break; case ID_PLAN: where = ParsePlane(iff, where, dir); if(!where) { IFFCleanup(iff); return errors[ERR_RSCNFILE]; } dir = INSERT_HORIZ; break; case ID_PLGT: case ID_SLGT: case ID_DLGT: where = ParseLight(iff, where, dir, cn->cn_Type); if(!where) { IFFCleanup(iff); return errors[ERR_RSCNFILE]; } dir = INSERT_HORIZ; break; case ID_MESH: where = ParseMesh(iff, where, dir); if(!where) { IFFCleanup(iff); return errors[ERR_RSCNFILE]; } dir = INSERT_HORIZ; break; case ID_EXTN: where = ParseExternal(iff, where, dir); if(!where) { IFFCleanup(iff); return errors[ERR_RSCNFILE]; } dir = INSERT_HORIZ; break; case ID_BOX: where = ParseBox(iff, where, dir); if(!where) { IFFCleanup(iff); return errors[ERR_RSCNFILE]; } dir = INSERT_HORIZ; break; case ID_CYLR: where = ParseCylinder(iff, where, dir); if(!where) { IFFCleanup(iff); return errors[ERR_RSCNFILE]; } dir = INSERT_HORIZ; break; case ID_CONE: where = ParseCone(iff, where, dir); if(!where) { IFFCleanup(iff); return errors[ERR_RSCNFILE]; } dir = INSERT_HORIZ; break; case ID_CSG: where = ParseCSG(iff, where, dir); if(!where) { IFFCleanup(iff); return errors[ERR_RSCNFILE]; } dir = INSERT_HORIZ; break; case ID_SOR: where = ParseSOR(iff, where, dir); if(!where) { IFFCleanup(iff); return errors[ERR_RSCNFILE]; } dir = INSERT_HORIZ; break; case ID_HIER: dir = INSERT_VERT; break; } break; } } } else { cn = CurrentChunk(iff); if (cn) { if((cn->cn_ID == ID_FORM) && (cn->cn_Type == ID_HIER)) { if(dir == INSERT_HORIZ) { while(where->GetPrev()) where = (OBJECT*)where->GetPrev(); if(where->GoUp()) where = (OBJECT*)where->GoUp(); } else dir = INSERT_HORIZ; } } } } if (error != IFFERR_EOF) { return errors[ERR_IFFPARSE]; } IFFCleanup(iff); // we have to set the active camera disp->camera = (CAMERA*)GetObjectByName(camera); if(!disp->camera) err = errors[ERR_NOCAMERA]; else err = NULL; // and translate track names to track objects // and the surface names to surface pointers TranslateNames(); return err; }
HRESULT DirectXMesh::CreateDirectXMesh(const MeshModel &m) { HRESULT hr; std::vector<Vertex> vertices; std::vector<Face> faces; ParseMesh(m, vertices, faces); WriteToFile(vertices, faces); return D3D_OK; /* DWORD numFaces = faces.size(); DWORD numVertices = vertices.size(); PD(L"number of vertices: ", numVertices); PD(L"number of faces: ", numFaces); D3DVERTEXELEMENT9 localVertDecl[MAX_FVF_DECL_SIZE] = { {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0}, D3DDECL_END() }; hr = D3DXCreateMesh(numFaces, numVertices, D3DXMESH_MANAGED | D3DXMESH_32BIT, localVertDecl, pd3d9Device, &mMesh); PD(hr, L"create mesh"); if(FAILED(hr)) return hr; LOCAL_VERTEX *pVertices = NULL; hr = mMesh->LockVertexBuffer(0, (void**)&pVertices); PD(hr, L"lock vertex buffer"); if(FAILED(hr)) return hr; for ( DWORD i = 0; i < numVertices; ++i ) { pVertices[i].pos = D3DXVECTOR3(vertices[i].x, vertices[i].y, vertices[i].z); } hr = mMesh->UnlockVertexBuffer(); PD(hr, L"unlock vertex buffer"); if(FAILED(hr)) return hr; DWORD* pIndices = NULL; hr = mMesh->LockIndexBuffer(0, (void**)&pIndices); PD(hr, L"lock index buffer"); if(FAILED(hr)) return hr; for ( DWORD i = 0; i < numFaces; i++ ) { pIndices[3 * i] = faces[i].vertices[0]; pIndices[3 * i + 1] = faces[i].vertices[1]; pIndices[3 * i + 2] = faces[i].vertices[2]; } hr = mMesh->UnlockIndexBuffer(); PD(hr, L"unlock index buffer"); if(FAILED(hr)) return hr; DWORD* pAdjacency = new DWORD[numFaces * 3]; hr = mMesh->GenerateAdjacency(1e-6f, pAdjacency); PD(hr, L"generate adjacency"); if(FAILED(hr)) return hr; hr = D3DXComputeNormals(mMesh, pAdjacency); PD(hr, L"compute normals"); if(FAILED(hr)) return hr; delete [] pAdjacency; return D3D_OK; */ }
void LoadTextXFile(const char *pText) { const char *pTok = GetNextToken(pText, &pText); while(pTok) { if(!MFString_Compare(pTok, "Header")) { SkipToken(pText, "{"); int maj = GetInt(pText, &pText); int min = GetInt(pText, &pText); int flag = GetInt(pText, &pText); // printf("XFile V%d.%d, 0x%X\n", maj, min, flag); pTok = GetNextToken(pText, &pText); while(MFString_Compare(pTok, "}")) { pTok = GetNextToken(pText, &pText); } } else if(!MFString_Compare(pTok, "Frame")) { pText = ParseFrame(pText, MFMatrix::identity, -1); } else if(!MFString_Compare(pTok, "Mesh")) { gMeshChunks.push(XMeshChunk::Create(MFMatrix::identity, pText, "")); SkipSection(pText); } else if(!MFString_Compare(pTok, "AnimationSet")) { gAnimSets.push(pText); SkipSection(pText); } else if(!MFString_Compare(pTok, "template")) { // const char *pName = GetNextToken(pText, &pText); SkipSection(pText); } else { MFDebug_Warn(4, MFStr("Unknown token '%s'\n", pTok)); SkipSection(pText); } pTok = GetNextToken(pText, &pText); } int a; for(a=0; a<gMeshChunks.size(); a++) { ParseMesh(gMeshChunks[a].pMesh, gMeshChunks[a].mat, gMeshChunks[a].frameName); } for(a=0; a<gAnimSets.size(); a++) { ParseAnimationSet(gAnimSets[a]); } gMeshChunks.clear(); }
bool MD5MeshParser::Parse() { while (Advance(false)) { switch (m_currentLine[0]) { #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING case 'M': // MD5Version if (m_currentLine.GetWord(0) != "MD5Version") UnrecognizedLine(); break; case 'c': // commandline if (m_currentLine.GetWord(0) != "commandline") UnrecognizedLine(); break; #endif case 'j': // joints #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING if (!m_currentLine.StartsWith("joints {")) { UnrecognizedLine(); break; } #endif if (!ParseJoints()) { Error("Failed to parse joints"); return false; } break; case 'm': // mesh { #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING if (m_currentLine != "mesh {") { UnrecognizedLine(); break; } #endif if (m_meshIndex >= m_meshes.size()) { #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING Warning("More meshes than registred"); #endif m_meshes.push_back(Mesh()); } if (!ParseMesh()) { NazaraError("Failed to parse mesh"); return false; } m_meshIndex++; break; } case 'n': // num[Frames/Joints] { unsigned int count; if (std::sscanf(&m_currentLine[0], "numJoints %u", &count) == 1) { #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING if (!m_joints.empty()) Warning("Joint count is already defined"); #endif m_joints.resize(count); } else if (std::sscanf(&m_currentLine[0], "numMeshes %u", &count) == 1) { #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING if (!m_meshes.empty()) Warning("Mesh count is already defined"); #endif m_meshes.resize(count); } #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING else UnrecognizedLine(); #endif break; } default: #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING UnrecognizedLine(); #endif break; } } return true; }