Skip to content

Commit

Permalink
added option for also including normals with combine().
Browse files Browse the repository at this point in the history
  • Loading branch information
pokepetter committed Jun 4, 2024
1 parent a174990 commit 43c410f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ursina/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,10 +913,10 @@ def add_script(self, class_instance):
return class_instance


def combine(self, analyze=False, auto_destroy=True, ignore=[]):
def combine(self, analyze=False, auto_destroy=True, ignore=[], ignore_disabled=True, include_normals=False):
from ursina.scripts.combine import combine

self.model = combine(self, analyze, auto_destroy, ignore)
self.model = combine(self, analyze, auto_destroy, ignore, ignore_disabled, include_normals)
return self.model


Expand Down
20 changes: 14 additions & 6 deletions ursina/scripts/combine.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from ursina import *


def combine(combine_parent, analyze=False, auto_destroy=True, ignore=[], ignore_disabled=True):
def combine(combine_parent, analyze=False, auto_destroy=True, ignore=[], ignore_disabled=True, include_normals=False):
if not combine_parent.children:
print_warning('Error, trying to combine children of entity with no children.', combine_parent.children)
return

verts = []
tris = []
norms = []
Expand Down Expand Up @@ -52,9 +56,6 @@ def combine(combine_parent, analyze=False, auto_destroy=True, ignore=[], ignore_
o += len(e.model.vertices)
tris += new_tris

# if e.model.normals:
# norms += e.model.normals

if e.model.uvs:
uvs.extend([(uv * e.texture_scale) + e.texture_offset for uv in e.model.uvs])
else:
Expand All @@ -64,6 +65,12 @@ def combine(combine_parent, analyze=False, auto_destroy=True, ignore=[], ignore_
cols.extend([Color(*vcol) * e.color for vcol in e.model.colors])
else:
cols.extend((e.color, ) * len(e.model.vertices))

if include_normals:
if e.model.colors: # if has normals
norms.extend(e.model.normals)
else:
norms.extend((Vec3.up, ) * len(e.model.vertices))


if auto_destroy and e != combine_parent:
Expand Down Expand Up @@ -104,11 +111,12 @@ def input(key):
p.texture='brick'
print('combined in:', perf_counter() - t)

p.combine()
print('----------', p.children)
# p.combine(include_normals=True)
# p.y=2
# p.model.save()
# ursinamesh_to_obj(p.model, name='combined_model_test', out_path=application.asset_folder)
print(p.model.vertices[0].__class__)
# print('----combined model:', repr(p.model))

EditorCamera()
app.run()

0 comments on commit 43c410f

Please sign in to comment.