def _texture_fit( self, side: Side, tex_size: float, field_length: float, fizz: Fizzler, neg: Vec, pos: Vec, is_laserfield=False, ) -> None: """Calculate the texture offsets required for fitting a texture.""" if side.vaxis.vec() != -fizz.up_axis: # Rotate it rot_angle = side.normal().rotation_around() for _ in range(4): side.uaxis = side.uaxis.rotate(rot_angle) side.vaxis = side.vaxis.rotate(rot_angle) if side.vaxis.vec() == -fizz.up_axis: break else: LOGGER.warning("Can't fix rotation for {} -> {}", side.vaxis, fizz.up_axis) side.uaxis.offset = -(tex_size / field_length) * neg.dot(side.uaxis.vec()) side.vaxis.offset = -(tex_size / 128) * neg.dot(side.vaxis.vec()) # The above fits it correctly, except it's vertically half-offset. # For laserfields that's what we want, for fizzlers we want it normal. if not is_laserfield: side.vaxis.offset += tex_size / 2 side.uaxis.scale = field_length / tex_size side.vaxis.scale = 128 / tex_size side.uaxis.offset %= tex_size side.vaxis.offset %= tex_size
def apply(cat: GenCat, face: Side, tex_name: str, portalable: Portalable = None, normal: Vec = None, loc: Vec = None): """Apply directly to a face, optionally using that to retrieve the location.""" if cat is GenCat.SPECIAL or cat is GenCat.OVERLAYS: generator = GENERATORS[cat] else: if normal is None: normal = face.normal() normal.z = -normal.z generator = gen(cat, normal, portalable) if loc is None: loc = face.get_origin() face.mat = generator.get(loc, tex_name)
def apply(self, face: Side, *, change_mat=True): """Apply the template to a face.""" mat, face.uaxis, face.vaxis, face.ham_rot = self[face.normal().as_tuple()] if change_mat: face.mat = mat