How can I convert all GeomNodes to CollideNodes from an egg model that was converted by dae2egg?
Below was my attempt. Is this a fixable issue with the dae2egg converter? If so, I would like to know before I go writing my own (using pyCollada and pyxb for a quick turn around).
I drew a simple cylinder in sketchup and exported as .dae (attached). I then converted it using dae2egg (also attached) with the simple command: C:\Panda3D-1.8.0\bin\dae2egg cylinder.dae cylinder.egg
I converted all GeomNodes into CollideNodes as in the code provided here:
[url]GeomNode vs CollisionPolygon]
So, for the simple case of smiley.egg this works wonderfully, the CollideNodes perfectly resemble the location and shape of the GeomNodes. But, for my simple cylinder.egg this is not the case. Although the GeomNodes of the cylinder load and display correctly, the CollisionNodes do not.
from direct.showbase.ShowBase import ShowBase
from panda3d.core import CollisionTraverser
from panda3d.core import CollisionHandlerQueue,CollisionRay
from panda3d.core import CollisionNode
from panda3d.core import CollisionPolygon
from panda3d.core import NodePath
from panda3d.core import GeomVertexReader
from panda3d.core import BitMask32
from panda3d.core import PointLight
from panda3d.core import Point3
def geoms_to_collisions(incomingNode):
parent = NodePath('cGeomConversionParent')
for c in incomingNode.findAllMatches('**/+GeomNode'):
geomNode = c.node()
for i in range(geomNode.getNumGeoms()):
geom = geomNode.getGeom(i)
vdata = geom.getVertexData()
cChild = CollisionNode(c.getName())
for i in range(geom.getNumPrimitives()):
prim = geom.getPrimitive(i)
vertex = GeomVertexReader(vdata, 'vertex')
prim = prim.decompose()
for p in range(prim.getNumPrimitives()):
s = prim.getPrimitiveStart(p)
e = prim.getPrimitiveEnd(p)
v = []
for i in range(s, e):
vi = prim.getVertex(i)
vertex.setRow(vi)
v.append(vertex.getData3f())
colPoly = CollisionPolygon(*v)
cChild.addSolid(colPoly)
parent.attachNewNode (cChild)
return parent
ShowBase()
base.cTrav = CollisionTraverser()
#this works:
model = loader.loadModel('smiley')
#this doesn't
#model = loader.loadModel('cylinder.egg')
#model.reparentTo(render)
model.setPos(0, 25, 0)
#model.setCollideMask(BitMask32.bit(0))
model_NP = geoms_to_collisions(model)
model_NP.set_pos(0,25,0)
model_NP.reparentTo(render)
interior_test_ray = render.attachNewNode("interior_root")
inside_ray = CollisionRay() # Create the ray
inside_ray.setOrigin(0,0,0) # Set its origin
inside_ray.setDirection(1,0,0) # And its direction
rayCol = CollisionNode('insideRay') # Create and name the node
rayCol.addSolid(inside_ray) # Add the ray
rayCol.setFromCollideMask(BitMask32.bit(0)) # Set its bitmasks
rayCol.setIntoCollideMask(BitMask32.all_off())
insideColNp = interior_test_ray.attachNewNode(rayCol)
cRayHandler = CollisionHandlerQueue()
base.cTrav.addCollider(insideColNp, cRayHandler)
base.cTrav.showCollisions(render)
insideColNp.show()
insideColNp.posInterval(5, Point3(5, 25, -2), startPos=Point3(-10, 25, 1), fluid=1).loop()
redPointLight = render.attachNewNode( PointLight( "PointLight" ) )
render.setLight( redPointLight )
run()
not_working_model.zip (5.04 KB)