Hello,
I made a Lod and using it for a while now at small games, Atm i am building a bigger game and walked into processing issues.
I made a blend with 500 trees and 3000 flowers, if i run this without Lod i am at a steady 60 fps, as soon as i use the Lod it goes down to 40 fps. I solved it by delaying the LoD by 30 ticks and it runs at 60 fps again.
But is this normal? i know 3500 objects are a lot to go trough but i thought that the Lod should be able to handle it.
This is my Lod, what do you think? did i build it the wrong way or are the amount of objects just the bottleneck?
#
# LoD by cotax
#
# Place a property on the object that needs LoD, call it lod_mesh and put the origional mesh name in it.
# Now duplicate it as much as you like.
# Make a low poly mesh, call that mesh: origionalname_far (so put _far behind the origional mesh name).
# You can use the property on the low poly instead of the high one, easier to work with ;).
# (only 1 mesh type needs a property, either the high one or low one depending on what you place in the main scene)
# Use the update_lod_list(cont) to update the list when needed
def lod(cont):
own = cont.owner
if not 'lod_list' in own:
update_lod_list(cont)
for obj in own['lod_list']:
distance = own.getDistanceTo(obj)
mesh_name = obj['lod_mesh']
# get LOD distances
min, max = set_distances(mesh_name)
if distance <= min:
visible(obj, True)
change_mesh(obj, mesh_name)
elif distance > min and distance <= max:
visible(obj, True)
change_mesh(obj, mesh_name + '_far')
else:
visible(obj, False)
def update_lod_list(cont):
own = cont.owner
own['lod_list'] = [obj for obj in own.scene.objects if 'lod_mesh' in obj]
def set_distances(mesh_name):
if mesh_name == 'tree_green_leaves':
min = 75.0 # high mesh
max = 125.0 # low mesh
elif mesh_name == 'flower_red' or 'flower_blue':
min = 20.0 # high mesh
max = 40.0 # low mesh
else:
min = 10.0
max = 20.0
return min, max
def visible(obj, state):
if state == True:
if obj.visible == False:
obj.restoreDynamics()
obj.visible = True
elif state == False:
if obj.visible == True:
obj.suspendDynamics()
obj.visible = False
def change_mesh(obj, mesh_name):
mesh = obj.meshes[0].name
if mesh != mesh_name:
obj.replaceMesh(mesh_name)