Ejemplo n.º 1
0
void MakeContourFaces(Mesh * mesh, ContourPoint * v0, ContourPoint * v1, FlowLinePoint *v0child, FlowLinePoint *v1child)
{
    if (v0 == NULL || v1 == NULL || v0child == NULL || v1child == NULL ||
            v0child->stitchTarget == NULL || v1child->stitchTarget == NULL)
        return;

    // check if the flowlines cross
    if (!ParamPointCC::ConvexInChart(v0->vertex->GetData().sourceLoc, v0child->vertex->GetData().sourceLoc, v1child->vertex->GetData().sourceLoc, v1->vertex->GetData().sourceLoc))
        //  if (!ParamPointCC::SameSide(v0->vertex->GetData().sourceLoc, v0child->vertex->GetData().sourceLoc,
        //			    v1->vertex->GetData().sourceLoc, v1child->vertex->GetData().sourceLoc) &&
        //      !ParamPointCC::SameSide(v1->vertex->GetData().sourceLoc, v1child->vertex->GetData().sourceLoc,
        //			    v0->vertex->GetData().sourceLoc, v0child->vertex->GetData().sourceLoc))
    {
        printf("WARNING: CROSSING FLOWLINES/NON-CONVEX FLOWLINE QUAD\n");
        return;
    }

    assert(v0->vertex->GetData().facing == CONTOUR && v1->vertex->GetData().facing == CONTOUR &&
           v0child->vertex->GetData().facing != CONTOUR && v1child->vertex->GetData().facing != CONTOUR);

    // find the common face that they came from
    MeshFace * commonFace = NULL;
    if (v0->sourceEdge->GetLeftFace() != NULL && (v0->sourceEdge->GetLeftFace() == v1->sourceEdge->GetLeftFace() ||
            v0->sourceEdge->GetLeftFace() == v1->sourceEdge->GetRightFace()))
        commonFace = v0->sourceEdge->GetLeftFace();
    else if (v0->sourceEdge->GetRightFace() != NULL && (v0->sourceEdge->GetRightFace() == v1->sourceEdge->GetLeftFace() ||
             v0->sourceEdge->GetRightFace() == v1->sourceEdge->GetRightFace()))
        commonFace = v0->sourceEdge->GetRightFace();

    assert(commonFace != NULL);

    double v0ind = GetEdgeIndex(commonFace, v0);
    double v1ind = GetEdgeIndex(commonFace, v1);
    int v0Cind = GetVertexIndex(commonFace, v0child->stitchTarget);
    int v1Cind = GetVertexIndex(commonFace, v1child->stitchTarget);

    for(int i=0; i<4; i++)
        printf("v[%d] = %s\n", i, FacingToString(commonFace->GetVertex(i)->GetData().facing));

    assert(v0ind != v1ind);
    assert(v0Cind >= 0 && v0Cind <= 3 && v1Cind >= 0 && v1Cind <= 3);

    if (v0ind == 3.5 && v0Cind == 0)
        v0Cind = 4;
    if (v1ind == 3.5 && v1Cind == 0)
        v1Cind = 4;


    printf("v0: %08X, v1: %08X, v0ind: %f, v1ind: %f, v0Cind: %d, v1Cind: %d\n",
           v0, v1, v0ind, v1ind, v0Cind, v1Cind);

    assert(v0child->vertex->GetEdge(v1child->vertex) == NULL &&
           v1child->vertex->GetEdge(v0child->vertex) == NULL);


    if (v0ind > v0Cind)
    {
        if ( v1ind < v1Cind)
        {
            printf("A: %08X, B: %08X\n", v0->vertex->GetEdge(v1->vertex), v1->vertex->GetEdge(v0->vertex));
            NewFaceDebug(mesh, v0->vertex, v1->vertex, v1child->vertex);
            NewFaceDebug(mesh, v0->vertex, v1child->vertex, v0child->vertex);

            //	  int vIDa[3] = { v0->vertex->GetID(), v1->vertex->GetID(), v1child->vertex->GetID() };
            //	  int vIDb[3] = { v0->vertex->GetID(), v1child->vertex->GetID(), v0child->vertex->GetID() };
            //	  NewFaceDebug(mesh, 3, vIDa);
            //	  NewFaceDebug(mesh, 3, vIDb);
            //	  newFaces.push_back(FaceRec(v0->vertex, v1->vertex, v1child->vertex));
            //	  newFaces.push_back(FaceRec(v0->vertex, v1child->vertex, v0child->vertex));
        }
        else
            printf("WARNING: SKIPPING MESSED-UP TRIANGLE\n");
    }
    else
    {
        if (v1ind > v1Cind)
        {
            printf("C: %08X, D: %08X\n", v0->vertex->GetEdge(v1->vertex), v1->vertex->GetEdge(v0->vertex));
            NewFaceDebug(mesh, v1->vertex, v0->vertex, v0child->vertex);
            NewFaceDebug(mesh, v1->vertex, v0child->vertex, v1child->vertex);

            //	  int vIDa[3] = { v1->vertex->GetID(), v0->vertex->GetID(), v0child->vertex->GetID() };
            //	  int vIDb[3] = { v1->vertex->GetID(), v0child->vertex->GetID(), v1child->vertex->GetID() };
            //	  NewFaceDebug(mesh, 3, vIDa);
            //	  NewFaceDebug(mesh, 3, vIDb);
            //	  newFaces.push_back(FaceRec(v1->vertex, v0->vertex, v0child->vertex));
            //	  newFaces.push_back(FaceRec(v1->vertex, v0child->vertex, v1child->vertex));
        }
        else
            printf("WARNING: SKIPPING MESSED-UP TRIANGLE\n");
    }
}
Ejemplo n.º 2
0
Vector2d* Edge::GetVertex(int vertex) {
	return GetGlobalVertex(GetVertexIndex(vertex));
}
Ejemplo n.º 3
0
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;
		}
	}
}