polygon budget widget

Here’s a little something for people that create models for games. It’s a widget that displays in the 3D window and keeps track of the current triangle count of a mesh with respect to a polygon ‘budget’. It’s inspired by similar tools in 3D Max et al.

The widget is only visible out of edit mode so that it doesn’t slow down modelling. For models with tens of thousands of faces the interface will slow when the script is running, but then a games model probably wouldn’t have that kind of face count.

Usage:
1 - Run the script
2 - Create a mesh object and go to the Logic buttons. Give the object an integer property named ‘budget’ and set it to the desired value.
3 - Get modelling…

Preview:
http://www.flippyneck.com/wip/pb_preview.jpg

The script:
http://www.flippyneck.com/wip/polybudget.py

A very nice script. I also like how it draws in the 3d window the info. I am looking at your code and I’m not quite sure how you did all of that.

It looks like I need to hone up on my python because you have some stuff in there that I would like to use in some scripts.

But again…terrific script.

Good stuff! I’ll have to give this a shot.

nice tool. It deserve a place in the official toolset.
8)

I’ve just fixed a small bug that caused lots of script links to be created if you hit the ‘show’ button in the GUI over and over. The link in the first post points to the correct file if you want to download the update.

PopeStewart - It’s fairly easy to draw in the 3D window. Take the snippet below and copy it to a Text file in your .blend. Call it ‘DrawTest.py’ or similar. Then create a scene script link to 'DrawTest.py’with a ‘Redraw’ event to see it working. The polybudget code is a little more complex as it creates the script links automatically via the GUI.

import Blender
from Blender import Draw
from Blender.BGL import *

glLoadIdentity()
glColor3f(1,0,0)
glRasterPos2i(10,30)
Draw.Text('This is a test...')

Wow…that is really easy.

I think that confused me a little and where I need to hit the books on python is


if __name__ == '__main__':
	init_dict = {"CACHE_EDIT_MODE": True,
				"TRI_CACHE": 0,
				"CACHE_SELECTED_OB": None}	
	Registry.SetKey("polybudget", init_dict)		
	Draw.Register(launcherGui, event, bevent)

PopeStewart -

if __name__ == '__main__':

:expressionless: Whoops, I’m guessing this was the bit that confused you. Actually this line isn’t really necessary; I’ve been doing some non-Blender Python recently and got used to starting scripts like this.

init_dict = {"CACHE_EDIT_MODE": True, 
            "TRI_CACHE": 0, 
            "CACHE_SELECTED_OB": None}    
   Registry.SetKey("polybudget", init_dict)  

This just initialises some persistent values in the Blender Registry to stop the script from calculating the triangle count on every redraw.

Draw.Register(launcherGui, event, bevent) 

Starts the GUI loop