Skip to content

Commit

Permalink
fixed TrailRenderer not working because Pipe wasn't clearing uvs on .…
Browse files Browse the repository at this point in the history
…generate().
  • Loading branch information
pokepetter committed Dec 24, 2024
1 parent 9bd4dc4 commit b809d60
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
19 changes: 14 additions & 5 deletions ursina/models/procedural/pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ def __init__(self, base_shape=Quad, origin=(0,0), path=((0,0,0),(0,1,0)), thickn
if callable(base_shape):
base_shape = base_shape()

self.base_shape = base_shape
if isinstance(base_shape, Mesh):
self.base_shape = base_shape.vertices
elif isinstance(base_shape, (list, tuple)):
self.base_shape = base_shape
else:
raise ValueError(f'base_shape must be Mesh/list/tuple, not {type(base_shape)}')

self.origin = origin
self.path = path
self.thicknesses = thicknesses
Expand All @@ -23,18 +29,18 @@ def __init__(self, base_shape=Quad, origin=(0,0), path=((0,0,0),(0,1,0)), thickn


def generate(self):
shape = self.base_shape.vertices
# make the base shape and rotate it
if not self.prev:
self.prev = Entity(position=self.path[0], scale=self.thicknesses[0], origin=self.origin, enabled=False)
for p in shape:
for p in self.base_shape:
Entity(parent=self.prev, position=Vec3(p), scale=(.05, .05, .05), color=color.yellow, enabled=False)

self.prev.look_at(self.path[1])
self.curr = duplicate(self.prev)

verts = []
self.colors = []
self.uvs = []

# cap start
if self.cap_ends:
Expand All @@ -59,8 +65,8 @@ def generate(self):
if i+1 < len(self.path):
self.curr.look_at(self.path[i+1])

if i == len(self.path)-1 and self.path[0] == self.path[-1]: # if the first and last point are the same, make the end math the rotation of the start.
self.curr.look_at(self.path[1])
if i == len(self.path)-1 and len(self.path) > 2 and self.path[0] == self.path[-1]: # if the first and last point are the same, make the end math the rotation of the start.
self.curr.look_at(self.path[2])

# for debugging sections
# clone = duplicate(e)
Expand Down Expand Up @@ -138,6 +144,9 @@ def generate(self):
path.append(path[0])
# thicknesses = ((1,1), (.5,.5), (.75,.75), (.5,.5), (1,1))
e = Entity(model=Pipe(path=path, cap_ends=False), texture='shore')
color_gradient = [color.magenta, color.cyan.tint(-.5), color.clear]
color_gradient = color_gradient[::-1]

# print(e.model.colors)
print(len(e.model.vertices), len(e.model.colors))
# e.model.colorize()
Expand Down
7 changes: 4 additions & 3 deletions ursina/prefabs/trail_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ def __init__(self, size=[1,.01], segments=8, min_spacing=.05, fade_speed=0, colo
color_gradient = color_gradient[::-1]

self.renderer = Entity(
model = Pipe(
base_shape = Quad(segments=0, scale=size),
model=Pipe(
base_shape=Quad(segments=0, scale=size),
path=[Vec3(0,0,i) for i in range(2)],
color_gradient=color_gradient,
static=False,
cap_ends=False,
look_at=True,
),
)
self._t = 0
Expand Down Expand Up @@ -59,7 +60,7 @@ def on_destroy(self):

trail_renderers = []
for i in range(1):
tr = TrailRenderer(size=[1,1], segments=8, min_spacing=.05, fade_speed=0, parent=player, color_gradient=[color.magenta, color.cyan.tint(-.5), color.clear])
tr = TrailRenderer(size=[1,1], segments=8, min_spacing=.2, fade_speed=0, parent=player, color_gradient=[color.magenta, color.cyan.tint(-.5), color.clear])
trail_renderers.append(tr)

def update():
Expand Down

0 comments on commit b809d60

Please sign in to comment.