Help! Collision Detection


#1

I‘m studying the collision detection today, after reading the manual I know that I can create CollisionSolids (like collisionsphere) for collision detection and the examples run successfully. However, I need to detect the collision of two given models (.egg file), and the known collisionsolids(sphere, tube and so on) can not perfectly cover the model.
Unluckily, I found that I can’t straightly use my model Nodepath as the CollisionNode(I use PT(CollisionNode) basecol = DCAST(CollisionNode, base.node()), but there is an error that attempt to cast pointer from model to CollisionNode).
So, is there anyway to transform my loaded model to a collision solid to be detected? It can be of great benefit. Or may I need to creat lots of collision solids and combine them to cover my model? that sounds too complicated. I found that some egg file have the definition , but my given egg files don’t have such tags.
Please help!


#2

The easy way would be to add the collision tags to the .egg ( {Polyset keep descent} to get a copy of the visible geometry as a collision mesh), you can also list all the triangles from the mesh and add them one by one to a collision mesh. I know how to do that from Python, but not using c++, sorry.


#3

Thank you for your response, but I’m unfamiliar with the.egg files, so can you tell me more about how to add the collision tags? I open my .egg file in VS2017, it looks like this


do you know where should I add the collision tags?
(I’m so sorry that I’m really new to panda3d and .egg files, grateful for your kind help)


#4

Under the <Group> tag, for example:

<Group> base {
  <Collide> { Polyset keep descend }
  <Transform> {
  ...

Please note that arbitrary geometry like this can only be used as “into” solid, not as “from” solid.


#5

Thank you, I have added the sentence in the correct position in my base.egg file now. But I’m sorry I’m still confused what should I do next.
base = window->load_model(render, “base.egg”);
PT(PandaNode) basecol = DCAST(PandaNode, base.node());
NodePath self = base.attach_new_node(basecol);
I use such codes by imitating the example for creating own collision solids, but it seems not work at all. (Meanwhile, the created collisionsphere attached to the NodePath base can work well).
I think I’m wrong with the codes, but I don’t know the correct way, and I’m sorry I can’t find available reference, can you give me an example?
By the way, you say this can only be used as “into”, so if I want use a modelroot NodePath to be an “from” solid, how should I do?


#6

Or if Bullet or ODE can realize such effort?
I need to use my loaded model to be the collision node both for “into” and “from”,
the computational complexity can be ignored , please help.


#7

Oh, I’m sorry I forgot to save my change in the base.egg file. it’s stupid.
After saving, now it works well!
Thank you so much for your help,


#8

However, it can’t work for “from” solid, which results in the error !collider.is_empty() && collider.node()->is_collision_node(),
but I really need to use my model as the “from” solid, so can you help me?


#9

oh, I have successfully use bullet to transform my model to a bulletrigidbody, it looks normally now, thanks so much for your help!