void XFileUtils::LoadChild( GLoadCallback& call, ID3DXFileEnumObject* pObject ) { { SIZE_T numChild = 0; pObject->GetChildren(&numChild); for (SIZE_T i = numChild - 1; i >= 0 && i < numChild; --i) { ID3DXFileData* pFileData = nullptr; pObject->GetChild(i, &pFileData); m_LoadStack.push_back(pFileData); } } while (!m_LoadStack.empty()) { ID3DXFileData* pLoadFileData = m_LoadStack.back(); m_LoadStack.pop_back(); int ss = m_LoadStack.size(); GUID gGuid = { 0 }; pLoadFileData->GetType(&gGuid); call.Excute(gGuid, pLoadFileData); SIZE_T numChild = 0; pLoadFileData->GetChildren(&numChild); for (SIZE_T i = numChild - 1; i >= 0 && i < numChild; --i) { ID3DXFileData* pInsertFileData = nullptr; pLoadFileData->GetChild(i, &pInsertFileData); m_LoadStack.push_back(pInsertFileData); } } }
bool XFileUtils::LoadFrameHierarchy( ID3DXFileEnumObject* pFileData, IDirect3DDevice9* pDevice, GFrameContainer** pNewFrameContainer) { GFrameContainer* pFrameContainer = new GFrameContainer(); SIZE_T numChild = 0; pFileData->GetChildren(&numChild); struct FrameFD { GFrame* pFrame; ID3DXFileData* pFileData; }; //读取用栈 std::vector<FrameFD> FrameStack; //框架GUID const GUID& frameGuid = _XTemplate("Frame"); //创建根框架 GFrame* pRootFrame = new GFrame(); pRootFrame->Name = GROOTFRAME; pFrameContainer->m_pRootFrames = pRootFrame; pFrameContainer->InsertFrame(pRootFrame); //得到第一层 框架 //********************************* { GFrame* pPreSiblingFrame = nullptr; for (size_t i = 0; i < numChild; ++i) { ID3DXFileData* pTopFileData = nullptr; GFrame* pTopChild = nullptr; pFileData->GetChild(i, &pTopFileData); GUID cguid; pTopFileData->GetType(&cguid); if (cguid == frameGuid) { if (!LoadFrame(pTopFileData, pDevice, &pTopChild)) return false; if (pRootFrame->pFrameFirstChild == nullptr) { pRootFrame->pFrameFirstChild = pTopChild; pFrameContainer->InsertFrame(pTopChild); pPreSiblingFrame = pTopChild; } else { pPreSiblingFrame->pFrameSibling = pTopChild; pPreSiblingFrame = pTopChild; } FrameFD fd; fd.pFileData = pTopFileData; fd.pFrame = pTopChild; FrameStack.push_back(fd); } } } //********************************* //得到第一层 框架 while (!FrameStack.empty()) { //上一个兄弟节点 GFrame* pPreSiblingFrame = nullptr; //栈弹出 FrameFD fd = FrameStack.back(); FrameStack.pop_back(); GFrame* pParentFrame = fd.pFrame; ID3DXFileData* pParentFileData = fd.pFileData; //得到孩子个数 SIZE_T numChild = 0; pParentFileData->GetChildren(&numChild); //开始解析该节点的孩子 for (size_t i = 0; i < numChild; ++i) { //读取孩子 ID3DXFileData* pChildFileData = nullptr; pParentFileData->GetChild(i, &pChildFileData); GFrame* pChildFrame = nullptr; //解析该 孩子框架,失败进入条件返回 false GUID cguid; pChildFileData->GetType(&cguid); if (cguid != frameGuid) continue; if (!LoadFrame(pChildFileData, pDevice, &pChildFrame)) { char DebugText[512] = { 0 }; sprintf_s(DebugText, "LoadFrame Error: %s \n", pParentFrame->Name.c_str()); OutputDebugStringA(DebugText); continue; } if (pPreSiblingFrame == nullptr) { //如果是第一个孩子节点,则将pFirstChild指向该节点, //并将preSiblingFrame指针指向它, 并压入解析用栈 pParentFrame->pFrameFirstChild = pChildFrame; pPreSiblingFrame = pChildFrame; } else { //上一个兄弟节点指针连接, preSiblingFrame指针往下移 pPreSiblingFrame->pFrameSibling = pChildFrame; pPreSiblingFrame = pChildFrame; } FrameFD tmp_fd; tmp_fd.pFrame = pChildFrame; tmp_fd.pFileData = pChildFileData; FrameStack.push_back(tmp_fd); pFrameContainer->InsertFrame(pChildFrame); } } *pNewFrameContainer = pFrameContainer; return true; }
void XFileUtils::PrintAll( ID3DXFileEnumObject* pObject, std::ostream& os) { std::vector<size_t> stack_depth; //保存节点深度 { SIZE_T numChild = 0; pObject->GetChildren(&numChild); for (SIZE_T i = numChild - 1; i >= 0 && i < numChild; --i) { ID3DXFileData* pFileData = nullptr; pObject->GetChild(i, &pFileData); m_LoadStack.push_back(pFileData); stack_depth.push_back(1); } } while (!m_LoadStack.empty()) { ID3DXFileData* pLoadFileData = m_LoadStack.back(); m_LoadStack.pop_back(); size_t depth = stack_depth.back(); stack_depth.pop_back(); int ss = m_LoadStack.size(); GUID gGuid = { 0 }; char name[128] = { 0 }; SIZE_T nameLen = 128; pLoadFileData->GetType(&gGuid); pLoadFileData->GetName(name, &nameLen); const std::string& typeName = getStringFromGuid(gGuid); { for (size_t i = 0; i < depth - 1; ++i) os.write(" ", 2); if (pLoadFileData->IsReference()) { os.write("[", 1); } os.write(typeName.c_str(), typeName.size()); os.write(" ", 1); os.write(name, strlen(name)); if (pLoadFileData->IsReference()) { os.write("]", 1); os.write("\n", 1); continue; } os.write("\n", 1); } SIZE_T numChild = 0; pLoadFileData->GetChildren(&numChild); for (SIZE_T i = numChild - 1; i >= 0 && i < numChild; --i) { ID3DXFileData* pInsertFileData = nullptr; pLoadFileData->GetChild(i, &pInsertFileData); m_LoadStack.push_back(pInsertFileData); stack_depth.push_back(depth + 1); } } }