Instancing many object

Hello, i create a basic totalwar like game, and i have a problem for generate a big army.

i want to generate 40k soldiers, for make this i can create a model for far unit that represent 1000 soldiers for example.

But I would like to know what other options are with panda3d.

i make an exemple with cube, i use the Advanced Instancing

and i call a flattenstrong at the end, but flattenstrong “not work”, the function work, but with or without flattenstrong, i have same fps, why ?
if I’ve understood correctly, the aim of flattenstrong is to merge several objects into 1 and reduce drawcall.
But maybe I’m using it wrong.

from direct.showbase.ShowBase import ShowBase
from panda3d.core import load_prc_file_data, NodePath


class Application(ShowBase):
    def __init__(self):
        super().__init__()
        base.setFrameRateMeter(True)

        box = self.loader.load_model("box.egg")

        box.setPos(0, 0, 0)
        chorusline = NodePath('chorusline')
        for y in range(10):
            for i in range(200):
                placeholder = chorusline.attachNewNode("mybox")
                placeholder.setPos(i * 3, y * 3, 0)
                box.instanceTo(placeholder)
        chorusline.flattenStrong()
        chorusline.reparentTo(render)

Application().run()

an other way, it’s possible to create a 2d object for far unit ?
it’s a shame to create “complex” 3d objects just to draw a far army in 2d.

for near soldiers, i use lod, my issue is only for far unit, what is best way.

First of all, welcome to the forum! I hope that you find your time here to be positive! :slight_smile:

As to your questions:

Hmm… Well, I have a few thoughts here:

If I recall correctly, models that are loaded from files often have a certain type of node at the top of their internal structures, and “flattenStrong” doesn’t go beyond that certain type of node.

As a result, such models tend to remain unaffected by a call to “flattenStrong”.

If this is (part of) the problem that you’re seeing, then you might be able to work around it: instead of using the loaded model itself, it might be worth trying to use the first child-node of the loaded model (i.e. box.getChild(0)).

However:

Hmm… I’m not sure that the code that you have there will do quite what you want it to do.

For one thing, the result of a call to “flattenStrong” is, ideally, a single, merged node–I imagine that individual animations will no longer work on this unified model.

For another, the sort of instancing that you seem to be using there isn’t the sort of instancing that’s used to reduce draw-calls.

Instead, it’s a type of instancing that is (amongst other things) useful for reducing the work required of the CPU for animation.

The sort of instancing that would reduce draw-calls would, I think, likely involve shaders.

I don’t know offhand whether Panda has any specific tools for aiding this sort of instancing.

Either way, it might be worth searching the forum to find out what other people have done.

Otherwise, while I’m not sure that these next are likely to help much with the sheer number of objects that you have in mind, you could try looking into the use of the RigidBodyCombiner, or clever use of MeshDrawer.

See these manual pages for more:
https://docs.panda3d.org/1.10/python/optimization/rigid-body-combiner
https://docs.panda3d.org/1.10/python/programming/internal-structures/other-manipulation/meshdrawer

I mean, at distance there isn’t going to be much visible difference, after all. So why not use a more-efficient 2D version when far away?

It is possible. Panda has the “LODNode” class for this purpose, I believe.

See this manual page for more:
https://docs.panda3d.org/1.10/python/programming/scene-graph/level-of-detail

hello, than you, meshdrawer make that i want !

1 Like