1

First off, this is what I'm trying to do: enter image description here

The blue lines are the texture boundaries, the red line is a "slice" I am putting across the polygon (the slice can be variable).

What I'm trying to do is make a cut across the top of my polygon, and making the checkers on the side match up. Because the texture is repeating, it seems it should be possible to convert UV into a matching U, so that my new wall can be U,0 to U,height on the side wall.

The texture itself is very simple:

enter image description here

I had a premise that I could take the UV coordinate, and collide it with the texture boundaries in the direction of the cut plane normal, like so:

enter image description here

But that produces the staggered checkers visible in the first image, and I want them to match up.

After I cut the polygon, I "build" the wall across the hole that is left after the cut. I thought I might be able to just figure out the U at the cut's start, and then increase it by the distance to the next point. From the test, it looks like that doesn't work, but I'm not even getting a good conversion from UV to U in the first place.

Is there a way to solve this?

(Note: Currently there is not a vertex at every checker boundary. For full precision I imagine I'm going to have to do that-- but I'm trying to attain stage 1 make even the starting point match up first)

For completeness, this is the code I'm using to try to convert a UV coordinate into U-only:

(theUV = current UV coordinate at the top, theFacing = normal of the slice, theRect = rectangle at texture boundaries around the UV coordinate)

float CheckerizeUV(Point theUV, Point theFacing, Rect theRect)
{
    Line aGoLine;
    aGoLine.mPos[0]=theUV;
    aGoLine.mPos[1]=theUV+theFacing*theRect.MajorAxis()*2;

    theRect=theRect.Expand(.0001f);

    float aResult=theUV.mU;
    Point aHit;
    for (int aCount=0;aCount<4;aCount++) 
    {
        Line aL=theRect.GetSideClockwise(aCount,false);
        if (gMath.GetLineIntersection(aGoLine,aL,&aHit)) 
        {
            aResult=aL.GetPercentAt(aHit)*aL.Len();
            switch(aCount)
            {
                //
                // What is the .25 with mX that's all through here???
                //
                case 0:
                    aResult+=aL.mPos[0].mX-.25f;
                    aResult+=Snap(aHit.mY,.5f);
                    break;
                case 1:
                    aResult+=aL.mPos[0].mY;
                    aResult+=Snap(aHit.mX+.25f,.5f); // Checker swapped
                    break;
                case 2:
                    aResult+=aL.mPos[0].mX+.25f;
                    aResult+=Snap(aHit.mY,.5f); // Add .5 because the checker is swapped here
                    break;
                case 3:
                    aResult+=aL.mPos[0].mY;
                    aResult+=Snap(aHit.mX-.25f,.5f); // Checker swapped
                    break;
            }
            break;
        }
    }
    return aResult;
}

float CheckerizeUV(Point theUV, Point theFacing)
{
    Point aUL=theUV.Floor();
    Point aLR=theUV.Ceil();
    Rect aRect;
    aRect=aRect.Union(aUL);
    aRect=aRect.Union(aLR);
    return CheckerizeUV(theUV,theFacing,aRect);
}
KiraHoneybee
  • 495
  • 3
  • 12

0 Answers0