I’m using 414 dev build for windows.
1)
I have made simple model in blender and exported to *.egg file, however when I load it, in debug mode I can see it really rescalled/smaller than the visual model is itself.
Is it how it should be done?
Please pay attention to what loader.loadModel() returns. It is a NodePath to a small tree of nodes, usually having a ModelNode as root, and then one or more GeomNodes. You can test this yourself:
The PandaNodes and thus the GeomNodes might have transforms relative to the root of the subtree loaded with loader.loadModel!
If you just pick the GeomNodes, fetch the Geoms from them, and feed the Geoms to the BulletTriangleMesh then you will loose information about these transforms, since the Geom itself does not know anything about a transform.
Also if you have more than one GeomNodes or more than one Geom within a GeomNode then you will loose them, since you explicitly fetch the first GeomNode, and from this first GeomNode the first Geom!
So what you might want to do is (pseudocode!):
np = loader.loadModel(path)
loop over all NodePath's to GeomNodes (gnp) within np:
ts = get transformState of gnp relative to np
loop over all Geoms (geom) within gnp.node()
shape = create mesh shape from geom
body.addShape(shape, ts) # <-- pass TransformState!
I’m having some issues about model mesh to Bullet Triangle Mesh (& -Shape), I tried your pseudocode and I can’t get it work, the following code (in C++) creates shape but apparently unscaled:
Note: If you uncomment the line brbn_floor-> … then you will get an half-well working, but when you reparent model to physics node, the model changes (Transform values are powered, I think).
Variable base is just a class with WindowFramework * and PandaFramework * pointers.
Function get_physics_world() is just a static variable allocator:
Can you PM me a download link for this model (zipped egg), or send it via email? Of course I wont re-use/re-sell/… the model and delete it once the question is ansered.
sigh Another file hosting service I can not use. Guys, there is Panda3D Projects (p3dp), why do you always use those sign-in-with-your-email-to-download-a-file hosters.
The floor.egg seems weired indeed. Just try this (Python) code:
np = loader.loadModel('floor.egg')
np.ls()
for geomNP in np.findAllMatches('**/+GeomNode'):
geomNode = geomNP.node()
print geomNP.getTransform(np)
for geom in geomNode.getGeoms():
print geom.getVertexData()
No Bullet stuff in here, just plain Panda3D. Anyway, the output will show vertices at (1,1,1), (-1,1,1) etc. Not what I would expect after looking at the .egg file. I can’t explain what is going on here. In order to get an explanation I think we need rdb or drwr.
But I know what helps: flatten light after loading
By the way, you don’t need a new shape for each geom. And if you are not using the Panda3D internal collision system you probably have no use for the contained Panda3D collision solids. You could try to export without the " { Polyset keep descend }". Maybe this way you can get rid of the in the .egg file (which causes this effect).
This is the code I used for loading. It’s Python, but I guess you can translate to C++:
np = loader.loadModel('floor.egg')
np.reparentTo(render)
np.flattenLight()
mesh = BulletTriangleMesh()
for geomNP in np.findAllMatches('**/+GeomNode'):
geomNode = geomNP.node()
ts = geomNP.getTransform(np)
for geom in geomNode.getGeoms():
mesh.addGeom(geom, ts)
shape = BulletTriangleMeshShape(mesh, False)
floor = BulletRigidBodyNode('floor')
floor.addShape(shape)
floorNP = render.attachNewNode(floor)
floorNP.setPos(0, 0, 0)
floorNP.setCollideMask(BitMask32.allOn())
world.attachRigidBody(floor)
Actually, I modified YABEE plugin for automatic adding of " { Polyset keep descend }" and I forgot it . Anyway I couldn’t get it work, so I rebuilded entire land from scratch without resizing and did mesh transforms only. After exporting without “…”, it worked!.
I’ll look for more stylish solution, but for now it’s ok.
Thanks again .
Hey enn0x I tried your code to automatically create a mesh of my model (the box.egg that comes with panda) but for some reason when I create it using the triangle mesh it does not collide with my BulletPlaneShape anymore, it just goes straight through it. Any idea why? If I used a boxshape for the same model it works fine.
Just for the record: using a triangle mesh for anything but a static environment is highly discouraged. Either use primitives (box!) or a convex hull shape.
Hm, when I was reading the manual in the entry of Convex Hull Shapes I read “elastic membrane” and I thought it was refering to the kind of membrane of a drum and it was used to simulate vibrations and I skiped to the Triangle Meshes.
So I’m now trying to use Convex Hull Shapes. But it’s not working as I expected. I think when I create the shape it’s not getting all the geoms of my model.
You see the “(0)” twice in the code you have cited? This is where you access the first elements of something. Now look at your own post of 07 Apr. There you will see how to pick up all geoms. Also have a look at the manual section on the Panda3D scene graph and how Panda3D stores geometry - it won’t be time wasted if you want to code with Panda3D.
shape = BulletConvexHullShape()
for geomNP in model.findAllMatches('**/+GeomNode'):
geomNode = geomNP.node()
for geom in geomNode.getGeoms():
shape.addGeom(geom)
I actually tried this too before. This seems to be working on simpler models, but anything more complex and it doesn’t get all the geometry. In the teapot.egg model included in panda it doesn’t get the handle, the funnel and the lid of the model. On the panda.egg it only gets the glasses and part of one hand as can be seen in the screenshots below:
(in the teapot screeshot there is a plane shape in the background, ignore the line behind the teapot)
I don’t see anything wrong while looking at the debug wire-frames of the box.egg model but it behaves very oddly when colliding with a plane which leads me to think that the rigid body in this model is also not being made properly.
Using
findAllMatches(’**/+GeomNode;+h+s+i’):
doesn’t help either.