//----------------------------------------------------------------------------- // Purpose: // Input : pSolid - // pList - // Output : //----------------------------------------------------------------------------- static BOOL _CheckLightmapSizeOnDisplacement( CMapSolid *pSolid, CListBox *pList ) { // // check all faces with the displacement parameter for proper // lightmap size // int faceCount = pSolid->GetFaceCount(); for( int i = 0; i < faceCount; i++ ) { // // check for faces with a displacement map // CMapFace *pFace = pSolid->GetFace( i ); if( !pFace->HasDisp() ) continue; // // check the lightmap extents // if( !pFace->ValidLightmapSize() ) { AddError( pList, ErrorInvalidLightmapSizeOnDisplacement, i, pSolid ); break; } } return TRUE; }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- static void FixInvalidLightmapSizeOnDisplacement( MapError *pError ) { CMapSolid *pSolid = ( CMapSolid* )pError->pObjects[0]; // // check and fix all displacement faces of the solid with improper lightmap // extents // int faceCount = pSolid->GetFaceCount(); for( int i = 0; i < faceCount; i++ ) { CMapFace *pFace = pSolid->GetFace( i ); if( !pFace->HasDisp() ) continue; // find the bad surfaces if( pFace->ValidLightmapSize() ) continue; // adjust the lightmap scale pFace->AdjustLightmapScale(); } }
void CSSolid::FromMapSolid(CMapSolid *p, bool bSkipDisplacementFaces) { // so we can pass NULL (default) or another solid (to copy): CMapSolid *pSolid; if(p) pSolid = p; else pSolid = m_pMapSolid; m_nFaces = 0; m_nEdges = 0; m_nVertices = 0; // Create vertices, edges, faces. int nSolidFaces = pSolid->GetFaceCount(); for(int i = 0; i < nSolidFaces; i++) { CMapFace *pSolidFace = pSolid->GetFace(i); if (bSkipDisplacementFaces) { if (pSolidFace->HasDisp()) continue; } // Add a face CSSFace *pFace = AddFace(); memcpy(pFace->PlanePts, pSolidFace->plane.planepts, sizeof(Vector) * 3); pFace->texture = pSolidFace->texture; pFace->normal = pSolidFace->plane.normal; pFace->m_nFaceID = pSolidFace->GetFaceID(); // Displacement. if ( pSolidFace->HasDisp() ) { pFace->m_hDisp = EditDispMgr()->Create(); CMapDisp *pDisp = EditDispMgr()->GetDisp( pFace->m_hDisp ); CMapDisp *pSolidDisp = EditDispMgr()->GetDisp( pSolidFace->GetDisp() ); pDisp->CopyFrom( pSolidDisp, false ); } // Convert vertices and edges int nFacePoints = pSolidFace->nPoints; Vector *pFacePoints = pSolidFace->Points; SSHANDLE hLastVertex = 0; // valid IDs start at 1 SSHANDLE hThisVertex, hFirstVertex; for(int pt = 0; pt <= nFacePoints; pt++) { int iVertex; if(pt < nFacePoints) { // YWB: Change leniency from 1.0 down to 0.1 iVertex = GetVertexIndex(pFacePoints[pt], 0.1f); if (iVertex == -1) { // not found - add the vertex CSSVertex *pVertex = AddVertex(&iVertex); pVertex->pos = pFacePoints[pt]; } // assign this vertex handle hThisVertex = m_Vertices[iVertex].id; if (pt == 0) hFirstVertex = hThisVertex; } else { // connect last to first hThisVertex = hFirstVertex; } if (hLastVertex) { // create the edge from the last vertex to current vertex. // first check to see if this edge already exists.. int iEdge = GetEdgeIndex(hLastVertex, hThisVertex); CSSEdge *pEdge; if (iEdge == -1) { // not found - add new edge pEdge = AddEdge(&iEdge); pEdge->hvStart = hLastVertex; pEdge->hvEnd = hThisVertex; // make sure edge center is valid: CalcEdgeCenter(pEdge); } else { pEdge = &m_Edges[iEdge]; } // add the edge to the face pFace->Edges[pFace->nEdges++] = pEdge->id; // set edge's face array if(!pEdge->Faces[0]) pEdge->Faces[0] = pFace->id; else if(!pEdge->Faces[1]) pEdge->Faces[1] = pFace->id; else { // YWB try filling in front side // rather than ASSERT(0) crash pEdge->Faces[0] = pFace->id; AfxMessageBox("Edge with both face id's already filled, skipping..."); } } hLastVertex = hThisVertex; } } }