Die4Ever / unreal-map-flipper

Unreal Map Flipper
https://discord.gg/daQVyAp2ds
GNU Affero General Public License v3.0
1 stars 0 forks source link

03_nyc_airfield fix texture coords #8

Closed Die4Ever closed 1 year ago

Die4Ever commented 1 year ago

image

Die4Ever commented 1 year ago

right now the trucks are the most obvious issue, because they don't loop the texture so it needs to be exact

I think if the Normal has a Y component, we need to flip the Y component of TextureU and TextureV, and might also need to invert the Pan U

unfortunately Pan seems to be in terms of texels, meaning the maximum changes

here's some WIP code:


    def AdjustTextCoord(self, Normal:int, Pan:int, TextureU:int, TextureV:int, mult_coords) -> None:
        # TODO: if normal has a Y component, we need to flip the Y component of TextureU... unless the texture is rotated? then it needs to flip the Y of TextureV
        # Pan      U=-59 V=0
        if not mult_coords:
            return
        #u = self.lines[TextureU]
        #self.lines[TextureU] = self.lines[TextureV]
        #self.lines[TextureV] = u
        #return

        match_n = poly.match(self.lines[Normal])
        match_u = poly.match(self.lines[TextureU])
        match_v = poly.match(self.lines[TextureV])

        nx = float(match_n.group(2))
        ny = float(match_n.group(4))
        nz = float(match_n.group(6))

        ux = float(match_u.group(2))
        uy = float(match_u.group(4))
        uz = float(match_u.group(6))

        vx = float(match_v.group(2))
        vy = float(match_v.group(4))
        vz = float(match_v.group(6))

        if abs(ny) >= 0.01:
            uy = -uy
            vy = -vy
            if Pan is not None:
                match_p = re.match(r'^(\s+Pan\s+)U=([^\s]+)\s+V=([^\s]+)(\s*)$', self.lines[Pan])
                panu = -int(match_p.group(2))
                panv = int(match_p.group(3))
                line = '{}U={} V={}{}'.format(match_p.group(1), panu, panv, match_p.group(4))
                self.lines[Pan] = line

        #ux *= mult_coords[0]
        #ux = 1 - abs(1-ux)
        ux = FormatPolyCoord(ux)
        #uy *= mult_coords[1]
        uy = FormatPolyCoord(uy)
        #uz *= mult_coords[2]
        uz = FormatPolyCoord(uz)

        #vx *= mult_coords[0]
        #vx = 1 - abs(1-vx)
        vx = FormatPolyCoord(vx)
        #vy *= mult_coords[1]
        vy = FormatPolyCoord(vy)
        #vz *= mult_coords[2]
        vz = FormatPolyCoord(vz)

        self.lines[TextureU] = match_u.group(1) + '{},{},{}'.format(ux,uy,uz) + match_u.group(8)
        self.lines[TextureV] = match_v.group(1) + '{},{},{}'.format(vx,vy,vz) + match_v.group(8)

        # x *= mult_coords[0] + 1
        # x = FormatPolyCoord(x)
        # y *= mult_coords[1]
        # y = FormatPolyCoord(y)
        # z *= mult_coords[2]
        # z = FormatPolyCoord(z)

        # line = match.group(1) + '{},{},{}'.format(x,y,z) + match.group(8)

        # match = poly.match(v)

        return

    def ReadPolygon(self, line:str, file, mult_coords) -> None:
        start = None
        TextureU = None
        TextureV = None
        Normal = None
        Pan = None
        while line:
            #print('ReadPolygon', line)
            stripped:str = line.strip()

            # Movers use PostScale instead of modifying vertices
            if stripped.startswith('Vertex ') and not self.IsMover():
                if not start:
                    start = len(self.lines)
                line = self.AdjustVert(line, mult_coords)

            elif stripped.startswith('TextureU'):
                TextureU = len(self.lines)
            elif stripped.startswith('TextureV'):
                TextureV = len(self.lines)
            elif stripped.startswith('Normal'):
                Normal = len(self.lines)
            elif stripped.startswith('Pan'):
                Pan = len(self.lines)
            elif stripped.startswith('Origin') and not self.IsMover():
                line = self.AdjustVert(line, mult_coords)

            self.lines.append(line)
            if stripped == 'End Polygon':
                if self.IsMover():
                    return
                self.AdjustTextCoord(Normal, Pan, TextureU, TextureV, mult_coords)
                # assert we finished with at least 3 vertices
                end = len(self.lines)-2
                #print('\nEnd Polygon', start, end)
                #print(self.lines[start:end])
                assert self.lines[end].strip().startswith('Vertex ')
                assert end-start >= 2
                if mult_coords:
                    polys = self.lines[start:end]
                    polys.reverse()
                    self.lines[start:end] = polys# MirrorList(self.lines[start:end])
                    #print(self.lines[start:end])
                self.polylist = [*range(start, end)]
                return

            line:str = file.readline()

        raise RuntimeError('unexpected end of polygon?')
Die4Ever commented 1 year ago

many have been fixed, some issues still remain

this sloped surface image

the wheels on the trucks image