Skip to content

Commit

Permalink
added material setter to Entity so you can set shader, texture, textu…
Browse files Browse the repository at this point in the history
…re_scale, texture_offset, color and shader inputs all at once by using a dict. this makes it easier to reuse materials across entitites.
  • Loading branch information
pokepetter committed Feb 9, 2024
1 parent 1a66a3e commit 56213ca
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ursina/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,13 @@ def shader_input_setter(self, value):
for key, value in value.items():
self.set_shader_input(key, value)

def material_setter(self, value): # a way to set shader, texture, texture_scale, texture_offset and shader inputs in one go
for name in ('shader', 'texture', 'texture_scale', 'texture_offset'):
if name in value:
setattr(self, name, value[name])

self.shader_input = {key: value for key, value in value.items() if key not in ('shader', 'texture', 'texture_scale', 'texture_offset')}


def texture_setter(self, value): # set model with texture='texture_name'. requires a model to be set beforehand.
if value is None and self.texture:
Expand Down Expand Up @@ -879,7 +886,7 @@ def bounds(self):


def get_position(self, relative_to=scene): # get position relative to on other Entity. In most cases, use .position instead.
return self.getPos(relative_to)
return Vec3(*self.getPos(relative_to))


def set_position(self, value, relative_to=scene): # set position relative to on other Entity. In most cases, use .position instead.
Expand Down

0 comments on commit 56213ca

Please sign in to comment.