Depends on the context. There’s a reason why both interfaces are available. Usually, the collision surfaces should more-or-less match the geometry of the world, which usually means it makes sense to define the collision surfaces in Blender, at the same time you’re defining the world. For dynamic objects like your avatars, though, it might make more sense to create a CollisionSphere of the appropriate size at runtime.
I think the Panda3D manual explains this. Let us know if you have any more specific questions.
The answer to “what’s the best type of collision solid” is always the same: whatever solid can be made to fit your desired shape. CollisionPolygons are always the worst choice, and often the only choice.
If you can figure out a way to model your maze out of sphere and tubes, go for it. Otherwise, use polygons.
when you model and object in blender, and you make a copy of that object and make it a collision octree, how do you set up that collision octree (same as a collision polygon, right?) up in blender?
The term “octree” refers to a particular hierarchical structure of the scene graph, not to any one particular solid type. You can arrange your solids in an octree by building a good hierarchy for them. Don’t put too many solids in any one level, and make sure that each level is a parent of a reasonably small group of children, which are located close to each other physically.
The idea is to minimize the number of bounding-volume tests that Panda has to perform when it walks the hierarchy looking for collisions. Each node has an automatic bounding volume that includes all of the node’s children. When Panda looks for collisions, it has to test the bounding volume of each node first against the “from” object. If the “from” object lies completely outside the node’s bounding volume, then Panda knows that it also lies completely outside of the bounding volume of each of the node’s children, and it doesn’t have to visit the node’s children at all.
So, if your nodes are cleverly arranged so that all of a node’s children are smaller nodes that are grouped physically together, you can maximize the chance that Panda will be able to eliminate large parts of the scene graph from testing.
The “octree” structure is just an automatic way to arrange your solids in a scene graph that approximates this ideal structure. You can also arrange your solids in this kind of structure by hand.
So wait, i’m confused. I was rereeading the Panda Manual and ran into a few questions.
First off, setting up a collision mesh, what’s the difference between a “from” and an "into " collision mesh?
Also, setting up a actor, say you put a collision sphere around it. If you wanted to mold it to the actor (for example, a zombie) so that if you hit the area around the zombie with a sword, it wouldn’t take damage, but if you hit the zombie itself it would. How’d you do that?
The CollisionTraversers page explains these two concepts in considerable detail.
A sphere can’t be molded to fit a shape; it is always a sphere. If you want your collision mesh to closely follow the shape of your actor, you can’t use just a big CollisionSphere, but you might be able to get away with smaller spheres and tubes parented to the various joints of your actor. But if you insist that it exactly follow your actor, you will almost certainly need to use the very expensive collide-with-visible-geometry feature. In short, Panda’s collision system wasn’t designed with collisions of this level of fidelity in mind. You can probably make it work, but you might be better off with some other system instead.
I have a question. In my little project, I am trying to make a collision solid form polygons. Also I want to make it visible so I can adjust and debug accordingly. So…I made this:
from pandac.PandaModules import loadPrcFileData
loadPrcFileData("","window-title Maze Daze" )
loadPrcFileData("", "model-path /c/Documents and Settings/Owner/My Documents/Project B.A.M-Chaos Reigns/models_egg/")
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *
import direct.directbase.DirectStart
from direct.actor.Actor import Actor
Actor1=render.attachNewNode("mc")
maze=loader.loadModel("testlvlgroop.egg")
maze.setPos(0,0,0)
maze.setScale(1,1,1)
#maze.reparentTo(render)
coll=render.attachNewNode(CollisionNode("smack"))
c=CollisionPolygon(Point3(4,0,-5), Point3(-4,0,-5), Point3(4,4,-5), Point3(-4,-4,-5))
coll.node().addSolid(c)
co=CollisionPolygon(Point3(4,0,5), Point3(-4,0,5), Point3(4,4,5), Point3(-4,-4,5))
coll.node().addSolid(co)
coll.show()
run()
from pandac.PandaModules import loadPrcFileData
loadPrcFileData("","window-title FU(Alpha)" )
loadPrcFileData("", "model-path /c/Documents and Settings/Owner/My Documents/Project B.A.M-Chaos Reigns/models_egg/")
import sys
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *
import math
import direct.directbase.DirectStart
from direct.actor.Actor import Actor
from pandac.PandaModules import CollisionTraverser,CollisionNode
enviro=loader.loadModel("lelvl")
enviro.setPos(0,0,0)
enviro.reparentTo(render)
wall=enviro.find('**/wall_collide')
wall.show()
render.setShaderAuto()
run()
and got this:
Traceback (most recent call last):
File "C:\Documents and Settings\Owner\My Documents\Project B.A.M-Chaos Reigns\Code\game1\src\game1.py", line 18, in <module>
wall.show()
AssertionError: !is_empty() at line 1916 of c:\p\p3d\panda3d-1.6.2\panda\src\pgraph\nodePath.I
Well, I don’t know. It’s your model. Why were you looking for a node called “wall_collide” in the first place? What did you expect to find, and what did you plan to do with it when you found it?
From the name, I’m guessing you expected it to be a collision node that corresponds to the walls. Did you put such an object in the model when you created it?
If you don’t have any specific plans for a “wall_collide” node already, then don’t look for one.
Sorry for the sheer repeatedness of this. I think I got it now. Thank you for the help David, I really apeciate it.
What I did was I made a copy of the model in the file and named it “coll”. Then, I set it up as a colision bounds in Blender then exported them both in one file. then i called it as previously shown. Is that how its done?
so I was wondering what code I need to use to make the collision geometry visible for troubleshooting as well as so that it works correctly.
would i do something like this?
from pandac.PandaModules import Vec3,Vec4,BitMask32
wall=enviro.find('**/coll')
wall.node().setIntoCollideMask(BitMask32.bit(0))
wall.show()