hi
i have a problem with my first script: it is cpu ultraintensive.
cpu monitor is 98-100% every second when i launch it till i close it.
i think i am doing something wrong.
normally the examples i downloaded are getting no more than 60%.
for example Glow-Filter/Tut-Glow-Advanced.py is no more than 45%.
this is my code:
from pandac.PandaModules import NodePath, TextNode, Point3
from direct.task import Task
from math import pi, sin, cos, sqrt, atan, tan, radians
from direct.showbase.ShowBase import ShowBase
import deliciousapi
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
# base node
node = NodePath("Sprite" )
node.reparentTo(render)
node.showBounds()
self.node = node
self.create_tags(node)
self.tags_in_grid()
def foo(task):
self.centerTrackball(self.node)
return Task.cont
taskMgr.add(foo, "SpinCameraTask")
self.useTrackball()
def centerTrackball(self, where):
bounds = where.getBounds()
center = bounds.getCenter()
radius = bounds.getRadius()
lens = self.camLens
fov = lens.getFov()
distance = radius / tan(radians(min(fov[0], fov[1]) / 2.0))
self.camera.setPos(bounds.getCenter())
self.camera.setY(base.camera, -distance)
def create_tags(self, parent):
print 'create_tags > call delicious api'
self.tags = []
self.text_width = 0
#dapi = deliciousapi.DeliciousAPI()
#_tags = dapi.get_tags_of_user('nootropic.kint')
_tags = eval( str(open("cashed_tags.log").read()) )
print len(_tags)
for k,v in _tags.items():
c = self.getCard(parent, k, v)
if c:
self.tags.append( c )
self.text_width += c.getWidth()
self.tag_min_count = min( _tags.values() )
self.tag_max_count = max( _tags.values() )
def tags_in_grid(self, leading = 1):
column = sqrt( self.text_width + (leading)*len(self.tags) )
x = y = z = 0
for c in self.tags:
if x>column:
x = 0
z += leading
x+= 3
c.nodePath.setPos(x, y, z)
x += c.getWidth()
def getCard(self, parent, string, count):
try:
str(string)
except UnicodeEncodeError:
print 'MyApp::getCard() - handling UnicodeEncodeError: ', string
return None
else:
tag = Tag(string, count)
tag.attachToScenegraph(parent)
return tag
class Tag:
def __init__(self, string, count):
self.string = string
self.count = count
text = TextNode('node name')
text.setText(string) #"Every day in every way I'm getting better and better.")
self.textNode = text
self.nodePath = None
def attachToScenegraph(self, parent):
nodePath = parent.attachNewNode(self.textNode)
self.nodePath = nodePath
return nodePath
def getWidth(self): return self.textNode.getWidth()
def getHeight(self): return self.textNode.getHeight()
app = MyApp()
app.run()
print 'am i here?'
it is a simple tag cloud (i have to implement some 3d deformation, i’m on this project only from few days) and now i’m testing it with 1284 tags.
ok 1284 could be a big number but it is only static text… nothing complicated IMHO…
and for my project i want to do more than one visualization 1284*n …
where am i wrong?
are there some smart ways to do it? mayebe TextNode is not the better tool for visualizing tags?
if you want to test it i can give you the test-file of my tags, but i simply done something like:
$ python
>>> f = open('somefile.log', 'w')
>>> d = { 'hudge_dict_here':12345 }
>>> f.write(str(d))
>>> f.close()
ps: any other kind of advice on writing panda3d-code is nicly excpeted