void CGuiWidget::ParseBaseInfo(CGuiFrame* frame, CInputStream& in, const CGuiWidgetParms& parms) { CGuiWidget* parent = frame->FindWidget(parms.x8_parentId); bool a = in.readBool(); if (a) xf4_workerId = in.readInt16Big(); zeus::CVector3f trans; trans.readBig(in); zeus::CMatrix3f orient; orient.readBig(in); x80_transform = zeus::CTransform(orient, trans); ReapplyXform(); zeus::CVector3f rotCenter; rotCenter.readBig(in); SetRotationCenter(rotCenter); ParseMessages(in, parms); ParseAnimations(in, parms); if (a) if (!parent->AddWorkerWidget(this)) { Log.report(logvisor::Warning, "Warning: Discarding useless worker id. Parent is not a compound widget."); xf4_workerId = -1; } parent->AddChildWidget(this, false, true); }
void CLoadMD2::ConvertDataStructures(t3DModel *pModel) { int j = 0, i = 0; // Like the previous function, not a lot was changed her from the last tutorial. // Since we are dealing with multiple key frames, we need to pretty much do the // same things for each frame. This entails adding a for loop to go through // every frame. We use index 'i' into the m_pFrames array to set each key frame. // This is one tricky thing in the middle of this for loop though, since we only // need to save the face and texture information once, this is only calculated // once and stored in the first frame of animation. We can then reference the // polygon information for every other frame from the first frame. That way // we don't copy the same information for every key frame, which would make a huge // memory footprint. // Initialize the model structure first before assigning data to it memset(pModel, 0, sizeof(t3DModel)); // Set the number of objects to our number of frames since pObjects will // hold the key frames. pModel->numOfObjects = m_Header.numFrames; // Create our animation list and store it in our model ParseAnimations(pModel); // Go through every key frame and store it's vertices info in our pObject list. for (i=0; i < pModel->numOfObjects; i++) { // Create a local object to store the first frame of the animation's data t3DObject currentFrame = {0}; // Assign the vertex, texture coord and face count to our new structure currentFrame.numOfVerts = m_Header.numVertices; currentFrame.numTexVertex = m_Header.numTexCoords; currentFrame.numOfFaces = m_Header.numTriangles; // Allocate memory for the vertices, texture coordinates and face data. currentFrame.pVerts = new CVector3 [currentFrame.numOfVerts]; // Go through all of the vertices and assign them over to our structure for (j=0; j < currentFrame.numOfVerts; j++) { currentFrame.pVerts[j].x = m_pFrames[i].pVertices[j].vertex[0]; currentFrame.pVerts[j].y = m_pFrames[i].pVertices[j].vertex[1]; currentFrame.pVerts[j].z = m_pFrames[i].pVertices[j].vertex[2]; } // We can now free the old vertices stored in this frame of animation // since we have them stored in the pObject list of our model. delete m_pFrames[i].pVertices; // Now comes the tricky part, since we only need to store the UV coordinates // and face indices once, we only do this on the first frame. If the // current frame is past the first frame, we just add the current frame // as it is to our list, then continue to the next frame. If we are // on the first frame, we still need to store the UV and face information. // This will only go in the first frame, and will be referenced from the // remaining frames when we animate the model. // Check if we are past the first key frame if(i > 0) { // Here we add the current object (or frame) to our list object list pModel->pObject.push_back(currentFrame); continue; // Go on to the next key frame } // We will only get here ONE because we just need this information // calculated for the first key frame. // Allocate memory for our UV coordinates and face information currentFrame.pTexVerts = new CVector2 [currentFrame.numTexVertex]; currentFrame.pFaces = new tFace [currentFrame.numOfFaces]; // Go through all of the uv coordinates and assign them over to our structure. // The UV coordinates are not normal uv coordinates, they have a pixel ratio of // 0 to 256. We want it to be a 0 to 1 ratio, so we divide the u value by the // skin width and the v value by the skin height. This gives us our 0 to 1 ratio. // For some reason also, the v coordinate is flipped upside down. We just subtract // the v coordinate from 1 to remedy this problem. for(j=0; j < currentFrame.numTexVertex; j++) { currentFrame.pTexVerts[j].x = m_pTexCoords[j].u / float(m_Header.skinWidth); currentFrame.pTexVerts[j].y = 1 - m_pTexCoords[j].v / float(m_Header.skinHeight); } // Go through all of the face data and assign it over to OUR structure for(j=0; j < currentFrame.numOfFaces; j++) { // Assign the vertex indices to our face data currentFrame.pFaces[j].vertIndex[0] = m_pTriangles[j].vertexIndices[0]; currentFrame.pFaces[j].vertIndex[1] = m_pTriangles[j].vertexIndices[1]; currentFrame.pFaces[j].vertIndex[2] = m_pTriangles[j].vertexIndices[2]; // Assign the texture coord indices to our face data currentFrame.pFaces[j].coordIndex[0] = m_pTriangles[j].textureIndices[0]; currentFrame.pFaces[j].coordIndex[1] = m_pTriangles[j].textureIndices[1]; currentFrame.pFaces[j].coordIndex[2] = m_pTriangles[j].textureIndices[2]; } // Here we add the current object (or frame) to our list object list pModel->pObject.push_back(currentFrame); } }
/** 将各帧数据保存在模型结构中 */ void CMD2Loader::ConvertDataStructures(t3DModel *pModel) { int j = 0, i = 0; /** 分配内存 */ memset(pModel, 0, sizeof(t3DModel)); /** 设置对象数目为关键帧数目 */ pModel->numOfObjects = m_Header.numFrames; /** 产生动作信息 */ ParseAnimations(pModel); /** 将各帧顶点数据添加到模型对象链表中 */ for (i=0; i < pModel->numOfObjects; i++) { /** 保存第一帧数据 */ t3DObject currentFrame = {0}; /** 指定顶点 纹理坐标和面的个数 */ currentFrame.numOfVerts = m_Header.numVertices; currentFrame.numTexVertex = m_Header.numTexCoords; currentFrame.numOfFaces = m_Header.numTriangles; /** 分配内存 */ currentFrame.pVerts = new Vector3 [currentFrame.numOfVerts]; /** 循环处理所有顶点 */ for (j=0; j < currentFrame.numOfVerts; j++) { currentFrame.pVerts[j].x = m_pFrames[i].pVertices[j].vertex[0]; currentFrame.pVerts[j].y = m_pFrames[i].pVertices[j].vertex[1]; currentFrame.pVerts[j].z = m_pFrames[i].pVertices[j].vertex[2]; } /** 释放内存 */ delete m_pFrames[i].pVertices; /** 检查是否超过第一帧 */ if(i > 0) { /** 将该帧添加到模型对象中 */ pModel->pObject.push_back(currentFrame); continue; } /** 分配内存 */ currentFrame.pTexVerts = new Vector2 [currentFrame.numTexVertex]; currentFrame.pFaces = new tFace [currentFrame.numOfFaces]; /** 处理纹理坐标 */ for(j=0; j < currentFrame.numTexVertex; j++) { currentFrame.pTexVerts[j].x = m_pTexCoords[j].u / float(m_Header.skinWidth); currentFrame.pTexVerts[j].y = 1 - m_pTexCoords[j].v / float(m_Header.skinHeight); } /** 保存面数据信息 */ for(j=0; j < currentFrame.numOfFaces; j++) { /** 为面顶点坐标索引赋值 */ currentFrame.pFaces[j].vertIndex[0] = m_pTriangles[j].vertexIndices[0]; currentFrame.pFaces[j].vertIndex[1] = m_pTriangles[j].vertexIndices[1]; currentFrame.pFaces[j].vertIndex[2] = m_pTriangles[j].vertexIndices[2]; /** 为面顶点纹理坐标索引赋值 */ currentFrame.pFaces[j].coordIndex[0] = m_pTriangles[j].textureIndices[0]; currentFrame.pFaces[j].coordIndex[1] = m_pTriangles[j].textureIndices[1]; currentFrame.pFaces[j].coordIndex[2] = m_pTriangles[j].textureIndices[2]; } /** 将该帧添加到模型中 */ pModel->pObject.push_back(currentFrame); } }