Frame rate drop down using NodePath.setPos()
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Panda3D |
Invalid
|
Undecided
|
David Rose |
Bug Description
FORUM TOPIC REFERENCE: http://
OPERATING SYSTEM: Windows 7 home premium 32 bit, service pack 1, 4Gb ram, Video card: nVidia GTX260.
TESTED WITH "1.8.0" and with "Panda3D-
THE PROBLEM:
I'm creating many objects (about 100000) not linked to "render" node. See this code:
--- CODE: -------
from direct.
from panda3d.core import *
class MyApp(ShowBase):
def __init__(self):
# Load the environment model.
theBarrel = self.loader.
cache = NodePath("cache")
for x in range(NUM_
for y in range(NUM_
app = MyApp()
app.run()
--- CODE: -------
I create many object instances attached to a main node called "cache". "cache" node is NOT attached to "render".
If I set the position of "placeholder" as (x, 0, 0) or (1, 1, 1) or (99, 11, 22) or (1, 9999, -9999) etc.... the program works.
If I set the position as (x, y, 1) the frame rate drops down incredibly (from 700fps to 150fps).
It seems there is a problem related to the 3D position of the placeholder. The problem is evident when I set the object position using at least two coordinates modified (in the previous case I use both "x" and "y").
This is a critical problem for me, in fact I need to create a big scenario off the "render" node (using "cache" node), then I will move the nodes from "cache" node to "render" node based on player position (imagine a scenario divided in sectors).
I made some tests using "pstats" and seems my program spend so much time in "app" task! It's crazy, since I have no background tasks, no heavy calculation. Furthermore my "cache" node is not rendered at all!
UPDATE: I noticed the problem is probably related to NodePath(), in fact even the following code has the same problem:
from direct.
from panda3d.core import *
--- CODE: -------
class MyApp(ShowBase):
def __init__(self):
# Load the environment model.
theBarrel = self.loader.
cache = NodePath("cache")
for x in range(NUM_
for y in range(NUM_
app = MyApp()
app.run()
--- CODE: -------
Thank you!
Short answer: add "transform-cache 0" to your Config.prc file.
Long answer: It's not a bug; it's just a misusage of Panda's transform cache. Because Transforms (4x4 matrices) can be relatively expensive to operate on--to multiply, invert, and/or decompose--and to make implicit coordinate-space transforms between nodes more efficient, Panda stores every Transform in the world in a reusable cache. This allows nodes that share the same transforms to reuse the same computations over and over again, instead of having to recompute them each time.
But when you create many thousands of nodes, each with a unique Transform; and you don't actually use those Transforms for any computations (or at least, not right away), then the overhead for maintaining that cache will dwarf any potential savings from the cache. In this case, you're better off not having a cache at all.
If you set "transform-cache 0" in your Config.prc file you tell Panda not to create a cache of Transforms, but rather to make each computation on-demand.
David