From 56213ca2daca30531fa1804327c5b58e1846aff2 Mon Sep 17 00:00:00 2001 From: pokepetter Date: Fri, 9 Feb 2024 09:53:50 +0100 Subject: [PATCH] added material setter to Entity so you can set shader, texture, texture_scale, texture_offset, color and shader inputs all at once by using a dict. this makes it easier to reuse materials across entitites. --- ursina/entity.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ursina/entity.py b/ursina/entity.py index 166a9583..1fce4443 100644 --- a/ursina/entity.py +++ b/ursina/entity.py @@ -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: @@ -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.