# Optimize egg for collision (octrees?)

Hi guys, a quick one

How to easily convert/optimize an egg file for collision using octrees?

I’ve seen some discussion about this in the forum, especially talking about ocquadtree and so on, but still can’t find a short summary on how to merely use this to optimize an egg file.

Could you please provide basic hint.

Thanks

if you already saw the discussions about it, you propably have spotted treeforms eggoctree script,too.
it does exactly what you’r looking for.

Hi Thomas,

As far as I’ve understood from reading the discussions the eggoctree script was somewhat buggy and the recommended one is ocquadtreefy.py which i’m trying to use (unsuccesfully ) the following way :

``````import sys, getopt
import math
from   pandac.PandaModules import *
import direct.directbase.DirectStart
from   pandac.PandaModules import Filename

def main():
egg = EggData()

ed = EggData()
ed.setCoordinateSystem(egg.getCoordinateSystem())

## find nodes ???? in a hierarchical Group structure???

octreeNode = octreefy(eggGeomNode,type='colpoly', maxDensity=64, verbose=1);
ed.writeEgg(Filename('file_octree.egg'))

if __name__ == "__main__":
import os
main()``````

The issue is what node parameters (geomNode ???) are expected by octreefy… and how to provide them

BTW This is an excerpt of my file.egg

``````<Group> pipo {
/* <Dart> { 1 } */
<Group> groundPlane_transform {}
<Collide> { Polyset keep descend }
<Group> Model {
<Group> Terrain {
<Group> Mesh1 {
<VertexPool> Mesh1Shape.verts {``````
1. you use a class for a function which is well. not what it was designed for.
2. the line ed.setCoordinateSystem is out of indentation
3. i see no imports of anything so pretty much every line should throw an error.
4. if you just want to convert a model there is no need for run(). you don’t even need a class or a function for that.

i recommend to fresh up your python basics and then try again.
posting the error you get from running a certain piece of code is always a good idea. the interpreter error usualy gives good hints where to start looking for mistakes.

Ok,

Obviously the imports are part of it and the idents are fine too (don’t forget that entering code into the forum editor sometimes shifts the ident !), see modified code…
anyway let’s leave the ocquadtreefy.py on a side for the time being…

So, as per your prior suggestion I tried the eggOctree.py grabbed from github.com/treeform/eggOctree

I used merely:

``python eggOctree.py -v -o file_octree.egg file.egg``

The only message I’m getting is:

``processing file.egg``

And at completion there is no file generated !!!
no trace of any file_octree.egg

Seems that the vertexPool is not found. Is that related to the egg file???

Ok, coming back on this question :

-> Should an eggfile have a specific structure in order to be octreefyed with eggOctree.py?

-> if yes, what kind of pre-processing is suggested?

BTW This is an excerpt of my file.egg that refuses to get processed…

``````<Group> pipo {
/* <Dart> { 1 } */
<Group> groundPlane_transform {}
<Collide> { Polyset keep descend }
<Group> Model {
<Group> Terrain1 {
<Group> Mesh1 {
<VertexPool> Mesh1Shape.verts {
.......
<Group> Mesh2 {
<VertexPool> Mesh2Shape.verts {
.......
<Group> Terrain2 {
.......``````

Well, you get the idea: a bunch of embedded Groups