void ModelLoader::ReadBinObj(const tstring& assetName) { //LAYOUT //DWord : #meshes //Word: nameLength //buffer: name //DWord : #vert //vector3: pos, vector3: norm, vector3 tan, vector2: tex : vertex //DWord : #triangles //DWord, DWord, DWord : triangle //... string name(assetName.cbegin(), assetName.cend()); UserStream stream(name.c_str(), true); DWORD meshes = stream.readDword(); for (DWORD m = 0; m < meshes; ++m) { WORD nameLength = stream.readWord(); char* name = new char[nameLength]; stream.readBuffer(name, nameLength); string tempname(name); tempname = tempname.substr(0, nameLength); delete name; m_pCurrentMesh = m_pCurrentModel->AddMesh(tstring(tempname.cbegin(), tempname.cend())); m_VPNTTData.clear(); DWORD vertices = stream.readDword(); for (DWORD v = 0; v < vertices; ++v) { Vector3 pos = stream.readVector3(); Vector3 norm = stream.readVector3(); Vector3 tan = stream.readVector3(); Vector2 tex = stream.readVector2(); m_VPNTTData.push_back(VertexPosNormTanTex(pos, norm, tan, tex)); } DWORD indices = stream.readDword() * 3; m_IndexData.clear(); for (DWORD i = 0; i < indices; ++i) { DWORD index = stream.readDword(); m_IndexData.push_back(index); } m_pCurrentMesh->SetVertices(m_VPNTTData); m_pCurrentMesh->SetIndices(m_IndexData); } }
void ModelLoader::ReadBinSBObj(const tstring& assetName) { //LAYOUT //Word: nameLength //buffer: name //DWord : #vert //vector3: pos, vector3: norm, vector2: tex, DWORD tetra, Vector3 bc : vertex //DWord : #triangles //DWord, DWord, DWord : triangle string filename(assetName.cbegin(), assetName.cend()); UserStream stream(filename.c_str(), true); WORD nameLength = stream.readWord(); char* name = new char[nameLength]; stream.readBuffer(name, nameLength); string tempname(name); delete name; m_pCurrentSBMesh->SetName(tstring(tempname.cbegin(), tempname.cend())); m_VPNTTData.clear(); vector<DWORD> tetraData; vector<Vector3> bcData; DWORD numVertices = stream.readDword(); for (DWORD v = 0; v < numVertices; ++v) { Vector3 pos = stream.readVector3(); Vector3 norm = stream.readVector3(); Vector2 tex = stream.readVector2(); DWORD tetra = stream.readDword(); Vector3 bc = stream.readVector3(); m_VPNTTData.push_back(VertexPosNormTanTex(pos, norm, Vector3(), tex)); tetraData.push_back(tetra); bcData.push_back(bc); } DWORD tris = stream.readDword(); m_IndexData.clear(); for (DWORD i = 0; i < tris * 3; ++i) { DWORD index = stream.readDword(); m_IndexData.push_back(index); } m_pCurrentSBMesh->SetVertices(m_VPNTTData); m_pCurrentSBMesh->SetIndices(m_IndexData); m_pCurrentSBMesh->SetTetra(tetraData); m_pCurrentSBMesh->SetBaryCentricCoords(bcData); }