Permalink
Browse files
fix shoddy texture mapping in Shape.lathe()
- Loading branch information
Showing
with
10 additions
and
10 deletions.
-
+9
−9
pi3d/Shape.py
-
+1
−1
pi3d/shaders/shadowcast.fs
|
|
@@ -708,14 +708,11 @@ def _lathe(self, path, sides=12, rise=0.0, loops=1.0): |
|
|
pr = (pi / self.sides) * 2.0 |
|
|
rdiv = rise / rl |
|
|
|
|
|
# Find largest and smallest y of the path used for stretching the texture |
|
|
miny = path[0][1] |
|
|
maxy = path[s-1][1] |
|
|
for p in range(s): |
|
|
if path[p][1] < miny: |
|
|
miny = path[p][1] |
|
|
if path[p][1] > maxy: |
|
|
maxy = path[p][1] |
|
|
# Find length of the path |
|
|
path_len = 0.0 |
|
|
for p in range(1, s): |
|
|
path_len += ((path[p][0] - path[p-1][0])**2 + |
|
|
(path[p][1] - path[p-1][1])**2)**0.5 |
|
|
|
|
|
verts = [] |
|
|
norms = [] |
|
|
@@ -725,12 +722,15 @@ def _lathe(self, path, sides=12, rise=0.0, loops=1.0): |
|
|
opx = path[0][0] |
|
|
opy = path[0][1] |
|
|
|
|
|
tcy = 0.0 |
|
|
for p in range(s): |
|
|
|
|
|
px = path[p][0] * 1.0 |
|
|
py = path[p][1] * 1.0 |
|
|
|
|
|
tcy = 1.0 - ((py - miny) / (maxy - miny)) |
|
|
if p > 0: |
|
|
tcy += ((path[p][0] - path[p-1][0])**2 + |
|
|
(path[p][1] - path[p-1][1])**2)**0.5 / path_len |
|
|
|
|
|
# Normalized 2D vector between path points |
|
|
if p == 0: |
|
|
|
|
|
@@ -6,7 +6,7 @@ varying vec4 position; |
|
|
vec4 pack (float depth) |
|
|
{ |
|
|
const vec4 bitSh = vec4(256.0 * 256.0, 256.0, 1.0, 0.0); |
|
|
const vec4 bitMsk = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0); |
|
|
const vec4 bitMsk = vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0); |
|
|
vec4 comp = fract(depth * bitSh); |
|
|
comp -= comp.xxyz * bitMsk; |
|
|
return comp; |
|
|
|