Hi, is there a way to calculate the number of objects appearing on a scene while the game engine is running?
I need this because i want to see in realtime if the LOD system and the occluders work correctly.
LOD switches meshes it does not change the number of objects.
Occluders hide object, it does not change the number of objects. You can check that in wireframe mode as you can see through objects.
You are absolutely right, i didnt spell my question correctly! I just need a “realtime poly counter” for a very large open world map i am trying to make. Is there a script for this?
As soon as i make my game more functional i will post it in the works in progress section.
You are absolutely right, i didnt spell my question correctly! I just need a “realtime poly counter” for a very large open world map i am trying to make. Is there a script for this?
[ATTACH=CONFIG]426721[/ATTACH]
As soon as i make my game more functional i will post it in the works in progress section. Appropriate credits will be posted very soon.
LOD, depending on the implementation does change the number of objects (not the integrated LOD system tough). And about the original question you should be able to count them with the following functions:
from bge import logic, types
def objectsInScene(scene):
return len(scene.objects)
def polygonsInScene(scene):
c = 0
for obj in scene.objects:
if type(obj) != types.KX_GameObject: continue
c += obj.meshes[0].numPolygons
return c
It think it is a valid assumption that “the LOD system” means the build-in LOD.
Btw. I do not know LOD implementation that removes objects. You might refer to object culling (which can indeed be combined with LOD systems).
Back to the question:
No, I do not know a way to count visible faces or visible objects.
My best bet is to log when the average frame rate gets below the frame rate you want.
I think* we can use pointInsideFrustum to inaccurately test what objects are in view, should be enough for debug properties to display the property, try this
from bge import logic,types
def Polygon_on_Screen():
own = logic.getCurrentController().owner
scene = logic.getCurrentScene()
sceneObj = scene.objects
cam = scene.active_camera
own['Polygon_on_Screen'] = 0
for obj in sceneObj:
if isinstance(obj,types.KX_GameObject):
if (cam.pointInsideFrustum(obj.worldPosition)):
for mesh in obj.meshes:
own['Polygon_on_Screen'] += mesh.numPolygons
Edit:@farhani
your game looks and feels like assassin creed, are you making a similar game? It’d be awesome to see parkour in bge
I decided to test the object’s vertex position with pointInsideFrustum instead, though not direct but an ambiguous approach to polycount, you should still get more accurate readings and ideas of what’s being rendered on screen
Edit: script updated
from bge import logic,types
def Vertex_on_Screen():
own = logic.getCurrentController().owner
scene = logic.getCurrentScene()
sceneObj = scene.objects
cam = scene.active_camera
own['Vertex_on_Screen'] = 0
objGen = (obj for obj in sceneObj if isinstance(obj,types.KX_GameObject) if obj.visible)
for obj in objGen:
transform = obj.worldTransform
for mesh in obj.meshes:
for m_index in range(len(mesh.materials)):
for v_index in range(mesh.getVertexArrayLength(m_index)):
vertex = mesh.getVertex(m_index, v_index)
co = transform*vertex.XYZ
if (cam.pointInsideFrustum(co)):
own['Vertex_on_Screen'] += 1
Edit:@farhani
your game looks and feels like assassin creed, are you making a similar game? It’d be awesome to see parkour in bge[/QUOTE]
Thats exactly what i am trying to create! A parkour game, as i havent seen any for the BGE and i love these games.
Thanks for the script. Can you please show me how to display the script’s result in the debug properties?
I spend all my time designing the world and the particles. This is a really huge map (30 km long) and needs a lot of time to place everything properly.
I need the script to “stabilize” the number of faces appearing on the screen on every spot on the map.
I use the built-in LOD system in addition with linked group instances (rendered particle systems) and radar sensors (at the center of each terrain tile (250m long each) to add or end these groups.
@farhani
the script needs the property from the logic brick > Add Game Property > name it Vertex_on_Screen > set integer as value and remember the “I” besides it must also be enabled and then you go up to Game > Show Debug Properties
I don’t think the python script can help “stabilize” anything at all, it only display vertices that are currently on screen, in fact the script will SLOW your cpu down to a crawl when you’re facing a dense scene
Sounds like what you need is a glsl script that can do some fancy culling/instancing that open world games needed but that’s beyond me currently