void BinaryConverter::LoadAnimations(Serializer::Reader &rd) { //load channels and PRS keys const Uint32 numAnims = rd.Int32(); for (Uint32 i = 0; i < numAnims; i++) { const std::string animName = rd.String(); const double duration = rd.Double(); Animation *anim = new Animation(animName, duration); const Uint32 numChans = rd.Int32(); for (Uint32 j = 0; j < numChans; j++) { const std::string tgtName = rd.String(); MatrixTransform* tgtNode = dynamic_cast<MatrixTransform*>(m_model->m_root->FindNode(tgtName)); anim->m_channels.push_back(AnimationChannel(tgtNode)); auto& chan = anim->m_channels.back(); for (Uint32 numKeys = rd.Int32(); numKeys > 0; numKeys--) { const double ktime = rd.Double(); const vector3f kpos = rd.Vector3f(); chan.positionKeys.push_back(PositionKey(ktime, kpos)); } for (Uint32 numKeys = rd.Int32(); numKeys > 0; numKeys--) { const double ktime = rd.Double(); const Quaternionf krot = rd.RdQuaternionf(); chan.rotationKeys.push_back(RotationKey(ktime, krot)); } for (Uint32 numKeys = rd.Int32(); numKeys > 0; numKeys--) { const double ktime = rd.Double(); const vector3f kscale = rd.Vector3f(); chan.scaleKeys.push_back(ScaleKey(ktime, kscale)); } } m_model->m_animations.push_back(anim); } }
GeomTree::GeomTree(Serializer::Reader &rd) { m_numVertices = rd.Int32(); m_numEdges = rd.Int32(); m_numTris = rd.Int32(); m_radius = rd.Double(); m_aabb.max = rd.Vector3d(); m_aabb.min = rd.Vector3d(); m_aabb.radius = rd.Double(); const Uint32 numAabbs = rd.Int32(); m_aabbs.resize(numAabbs); for (Uint32 iAabb = 0; iAabb < numAabbs; ++iAabb) { m_aabbs[iAabb].max = rd.Vector3d(); m_aabbs[iAabb].min = rd.Vector3d(); m_aabbs[iAabb].radius = rd.Double(); } m_edges.resize(m_numEdges); for (Sint32 iEdge = 0; iEdge < m_numEdges; ++iEdge) { m_edges[iEdge].Load(rd); } m_vertices.resize(m_numVertices); for (Sint32 iVert = 0; iVert < m_numVertices; ++iVert) { m_vertices[iVert] = rd.Vector3f(); } const int numIndicies(m_numTris * 3); m_indices.resize(numIndicies); for (Sint32 iIndi = 0; iIndi < numIndicies; ++iIndi) { m_indices[iIndi] = rd.Int16(); } m_triFlags.resize(m_numTris); for (Sint32 iTri = 0; iTri < m_numTris; ++iTri) { m_triFlags[iTri] = rd.Int32(); } // activeTris = tris we are still trying to put into leaves std::vector<int> activeTris; activeTris.reserve(m_numTris); // So, we ignore tris with flag >= 0x8000 for (int i = 0; i<m_numTris; i++) { if (m_triFlags[i] >= IGNORE_FLAG) continue; activeTris.push_back(i * 3); } // regenerate the aabb data Aabb *aabbs = new Aabb[activeTris.size()]; for (unsigned int i = 0; i<activeTris.size(); i++) { const vector3d v1 = vector3d(m_vertices[m_indices[activeTris[i] + 0]]); const vector3d v2 = vector3d(m_vertices[m_indices[activeTris[i] + 1]]); const vector3d v3 = vector3d(m_vertices[m_indices[activeTris[i] + 2]]); aabbs[i].min = aabbs[i].max = v1; aabbs[i].Update(v2); aabbs[i].Update(v3); } m_triTree.reset(new BVHTree(activeTris.size(), &activeTris[0], aabbs)); delete[] aabbs; // int *edgeIdxs = new int[m_numEdges]; memset(edgeIdxs, 0, sizeof(int)*m_numEdges); for (int i = 0; i<m_numEdges; i++) { edgeIdxs[i] = i; } m_edgeTree.reset(new BVHTree(m_numEdges, edgeIdxs, &m_aabbs[0])); }