MCPcopy Create free account
hub / github.com/apple/ml-pointersect / __init__

Method __init__

plib/uv_mapping.py:10–40  ·  view source on GitHub ↗

Args: texture: (h, w, dim) for example, an rgb image, a displacement map, a bump map, etc mode: 'wrap': used when 1 <= uv or uv <= 0. 'edge': used when no wrapping is needed

(
            self,
            texture: np.ndarray,
            mode: str = 'wrap',
    )

Source from the content-addressed store, hash-verified

8
9class UVMap:
10 def __init__(
11 self,
12 texture: np.ndarray,
13 mode: str = 'wrap',
14 ):
15 """
16 Args:
17 texture:
18 (h, w, dim) for example, an rgb image, a displacement map, a bump map, etc
19 mode:
20 'wrap': used when 1 <= uv or uv <= 0.
21 'edge': used when no wrapping is needed
22 """
23 self.texture = texture
24 self.texture_height = self.texture.shape[0]
25 self.texture_width = self.texture.shape[1]
26 self.mode = mode
27
28 # handle padding
29 pad_widths = [[0, 0]] * self.texture.ndim
30 pad_widths[0] = [1, 1]
31 pad_widths[1] = [1, 1]
32 padded_texture = np.pad(self.texture, pad_width=pad_widths, mode=mode)
33
34 # create interpolator for the texture
35 ys = np.linspace(-1, self.texture_height, self.texture_height + 2) # 0, 1, ..., h-1
36 xs = np.linspace(-1, self.texture_width, self.texture_width + 2) # 0, 1, ..., w-1
37 # yg, xg = np.meshgrid(ys, xs, indexing='ij')
38 self.interpolator = RegularGridInterpolator(
39 (ys, xs), padded_texture, method='linear', bounds_error=True)
40 # image grid defined on 0..h-1
41
42 def __call__(self, uv: np.ndarray):
43 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected