Skip to content

Commit

Permalink
Merge branch 'pokepetter:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
PaologGithub authored Nov 24, 2024
2 parents 8261a2b + c596d90 commit 8c0b700
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repo and install as develop like this. Make sure you have [git](https://git-scm.

```
git clone https://github.com/pokepetter/ursina.git
python setup.py develop
pip install --editable .
```


Expand All @@ -43,6 +43,11 @@ pip install ursina[extras]


On some systems you might have to use pip3 instead of pip in order to use Python 3 and not the old Python 2.
To use a specific Python version, use:
```
python3.xx -m pip install ursina
```
Where 3.xx is the version you want to target.


## Dependencies
Expand Down
11 changes: 7 additions & 4 deletions ursina/duplicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ def duplicate(entity, copy_children=True, *args, **kwargs): # use a for loop ins
for name in entity.attributes:
if name == 'model':
continue
elif name == 'collider' and entity.collider and entity.collider.name:
if name == 'collider' and entity.collider and entity.collider.name:
# TODO: currently only copies colliders set with strings, not custom colliders.
e.collider = entity.collider.name

elif name == 'scripts':
continue
if name == 'scripts':
for script in entity.scripts:
e.add_script(copy(script))
continue

else:
if hasattr(entity, name):
setattr(e, name, getattr(entity, name))

e.shader_input = entity.shader_input

for c in entity.children:
clone = duplicate(c, copy_children=False)
clone.world_parent = e
Expand Down Expand Up @@ -72,7 +75,7 @@ def duplicate(entity, copy_children=True, *args, **kwargs): # use a for loop ins
# e2 = duplicate(e)
# e2.y += 1.5

e = Button(parent=scene, scale=1, text='yolo')
e = Button(parent=scene, scale=1, text='yolo', texture='shore', texture_scale=Vec2(2), color=color.gray)
# e.c = Entity(parent=e, model='cube', scale=.5, y=.5, color=color.azure)
e2 = duplicate(e, x=1.25)
# print(e.text_entity.z, e2.text_entity.z)
Expand Down
8 changes: 6 additions & 2 deletions ursina/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,10 @@ def set_shader_input(self, name, value):
if isinstance(value, Texture):
value = value._texture # make sure to send the panda3d texture to the shader

super().set_shader_input(name, value)

try:
super().set_shader_input(name, value)
except:
raise Exception(f'Incorrect input to shader: {name} {value}')

def shader_input_getter(self):
return self._shader_inputs
Expand All @@ -726,6 +728,8 @@ def shader_input_setter(self, value):


def material_setter(self, value): # a way to set shader, texture, texture_scale, texture_offset and shader inputs in one go
if value is None:
raise ValueError('material can not be set to None')
_shader = value.get('shader', None)
if _shader is not None:
self.shader = _shader
Expand Down
2 changes: 1 addition & 1 deletion ursina/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def clear(self, regenerate=True):
if regenerate:
self.generate()

def save(self, name='', folder:Path=Func(getattr, application, 'compressed_models_folder'), flip_faces=False, vertex_decimal_limit=5, color_decimal_limit=4):
def save(self, name='', folder:Path=Func(getattr, application, 'models_compressed_folder'), flip_faces=False, vertex_decimal_limit=5, color_decimal_limit=4):
if callable(folder):
folder = folder()
if not folder.exists():
Expand Down
4 changes: 2 additions & 2 deletions ursina/mesh_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def get_blender(blend_file): # try to get a matching blender version in case
return application.blender_paths['default']


def blend_to_obj(blend_file:Path, out_folder=Func(getattr, application, 'compressed_models_folder'), export_mtl=True):
def blend_to_obj(blend_file:Path, out_folder=Func(getattr, application, 'models_compressed_folder'), export_mtl=True):
if callable(out_folder):
out_folder = out_folder()

Expand Down Expand Up @@ -459,7 +459,7 @@ def blend_to_obj_fast(model_name=None, write_to_disk=False):

return file_content

def ursina_mesh_to_obj(mesh, name='', out_path=Func(getattr, application, 'compressed_models_folder'), max_decimals=5, flip_faces=True):
def ursina_mesh_to_obj(mesh, name='', out_path=Func(getattr, application, 'models_compressed_folder'), max_decimals=5, flip_faces=True):
if callable(out_path):
out_path = out_path()

Expand Down
15 changes: 10 additions & 5 deletions ursina/scripts/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ def combine(combine_parent, analyze=False, auto_destroy=True, ignore=[], ignore_
cols.extend((e.color, ) * len(e.model.vertices))

if include_normals:
rotation_scale_matrix = vertex_to_world_matrix.getUpper3() # get the rotation and scaling part of the matrix
normal_to_world_matrix = rotation_scale_matrix
normal_to_world_matrix.invertInPlace()
normal_to_world_matrix.transposeInPlace()

if e.model.normals: # if has normals
norms.extend(e.model.normals)
norms.extend([Vec3(*normal_to_world_matrix.xform(Vec3(*n)))for n in e.model.normals])
else:
norms.extend((Vec3.up, ) * len(e.model.vertices))

Expand Down Expand Up @@ -96,11 +101,12 @@ def combine(combine_parent, analyze=False, auto_destroy=True, ignore=[], ignore_
from ursina import *
app = Ursina()

from ursina.shaders import lit_with_shadows_shader
from ursina.shaders import lit_with_shadows_shader, normals_shader
Entity.default_shader = lit_with_shadows_shader
# Entity.default_shader = normals_shader

p = Entity(texture='brick')
e1 = Entity(parent=p, model='sphere', y=1.5, color=color.pink)
e1 = Entity(parent=p, model='sphere', y=1.5, color=color.pink, rotation_y=90)
e2 = Entity(parent=p, model='cube', color=color.yellow, x=1, origin_y=-.5, texture='brick')
e3 = Entity(parent=e2, model='cube', color=color.yellow, y=2, scale=.5, texture='brick', texture_scale=Vec2(3,3), texture_offset=(.1,.1))
e4 = Entity(parent=p, model='plane', color=color.lime, scale=10, texture='brick', texture_scale=Vec2(5,5))
Expand All @@ -110,10 +116,9 @@ def input(key):
from time import perf_counter
t = perf_counter()
p.combine(include_normals=True)
# p.model.generate_normals(smooth=False)
p.shader = lit_with_shadows_shader
# p.shader = normals_shader
p.texture='brick'
print(p.model.normals)
print('combined in:', perf_counter() - t)


Expand Down

0 comments on commit 8c0b700

Please sign in to comment.