ODE Middleware


#14

Ok, another update than, into version 0.2.2.

Fixed the problem with not being able to use objects when crouching (or more precisely when holding control). And changed the name of the starter file to main.py :wink:.

dl.dropbox.com/u/196274/ODE_Cust … ork.tar.gz


#15

finally found some time to test this.

it looks and feel great!
thank you very much for sharing

i hope this will become an official sample one day


#16

Excellent! works great, and well commented.


#17

Thanks for your opinions guys, I really appreciate them. Please tell me if there’s anything you’d like to see added there, not to mention if you find any bugs of course.

I have nothing against this code ending up as an official sample, I’m really all for that obviously :wink:. I just don’t know what I should do to get it there ATM, but it would be great.

Thanks again and enjoy.


#18

I really like your work!

particularly, the way you implemented the world manager is very interesting!

Thank you very much for your work.

On a side note, I am trying to learn how to add new objects with physics, using your world manager…

I want to add a box (just the default panda3d box mesh provided with the SDK) and have it roll and react to the character, you get my point, some standard physics.

I am pretty sure I would use Dynamic instead of Kinematic, correct?

Here’s what I’ve done:
used self.worldManager.setGeomData(boxGeom, boxData)

and this works well, I can jump and hit into the box (I’ve placed it in the air)

However, it’s static. No matter what I’ve tried it refuses to fall due to gravity, or to react when I jump and hit into it.

How do I do this? I thought it’d be simple, but I suppose I’m missing something obvious :stuck_out_tongue:


#19

I’m glad you like it :slight_smile:.

Yeah, perhaps I should have made an example of that in the package… Don’t know why I haven’t, so maybe I’ll update it with some boxes.

Anyway, yes, the box, or any other object that you want to be animated by ODE rather than by hand, should be Dynamic. But that’s the default setting when you look at setGeomData method.

It’s actually quite simple to do. You haven’t provided much information (a complete piece of code where you setup stuff would be very helpful next time), but I think I can see what’s wrong.

Instead of setGeomData(boxGeom, boxData) you should have used this:

self.worldManager.setGeomData(boxGeom, boxData, boxModel)

If you take a look into the odeWorldManager code you’ll see that this method takes 4 arguments: geom, data, object, kinematic. Geom is the OdeGeom, data is OdeGeomData and object is the visible 3D model. Kinematic is obviously a switch between kinematic and dynamic.

If you don’t add a value for the “object” argument the code will not crash however, since that’s the way you can add Static objects which are not animated in any way – neither by you nor by ODE. Objects such as walls (you can see setGeomData with None as object argument in main.py when I setup the static environment). In such objects the positions of graphical representation and collision body don’t need to be updated every frame since they do not change. But you need to remember about this, since if you forget the “object” argument you will end up with static objects by accident and no error to warn you (if you want such error you can modify the setGeomData() method to request the object argument and remember to set is to None for Statics).

Try this and let me know if it works.


#20

Hi, and thank you for such a detailed reply!
Sorry about forgetting to post a snippet, I was tired… annd… well yes :smiley:

I tired as you suggested however still no go, so here is my cube.py file, and I just plugged it into main.py (included with your example) by the following code:

box = loader.loadModel("box")  #load model
box.reparentTo(render)         #reparent to render
box.setPos(0, -7, 3)           #set pos because I changed map
cube(self.worldManager, box)   #make a cube (see cube.py)

that’s how its being called. and for the class:

class cube():
	def __init__(self, worldManager, model):
		self.worldManager = worldManager
		self.cubeNP = model

		self.cubemesh = OdeTriMeshData(self.cubeNP, True)	
		self.cubeGeom = OdeTriMeshGeom(self.worldManager.space, self.cubemesh)
		#self.cubeGeom = OdeBoxGeom(self.worldManager.space, 1, 1, 1)
		self.cubeGeom.setPosition(self.cubeNP.getPos(render))
		self.cubeGeom.setQuaternion(self.cubeNP.getQuat(render))

		self.cubeData = odeGeomData()
		self.cubeData.name = "cube"

		self.worldManager.setGeomData(self.cubeGeom, self.cubeData, self.cubeNP)

I’m still lookin’ to see where I’ve went wrong… :wink:

Thanks!

EDIT: fixed cube class (I forgot to change it back to TRI mesh)


#21

Seems to me like you didn’t set an OdeBody for that cube. Remember that my code is one thing, but you need to create an OdeBody with OdeMass to have an actual Dynamic object. You do that exactly the same way as described in the Panda Manual. The OdeWorldManager only makes the rest of the process automatic (updating positions of 3d models and stuff), but creation of an OdeBody is your job.


#22

Greetings!
I’ve just started using p3d so I search through forum looking for examples to study.

Just tried your code - seems cool for me since it could be a good base for making a game!

I’ve experienced some problems:

  • while walking on the roof player sometime’s shifts forward for some distance.
  • when lamp is switched off, FPS meter shows ~120, when I switch a lamp on - framerate drops to ~58-60.
  • player walk’s through the desk sometimes
    I’ve used panda 1.7.0 and directx9 windowed rendering

Other stuff works fine, I think, and I’d like to thank you for the code.


#23

Hi,

~I could be wrong about this, but I think it’s correct~

the reason you see a drop from ~120 FPS to the mid 50s is because lighting requires shaders, which will cut the FPS down to about 50 on most graphics cards, but note that you can probably do infinite lighting without losing the 50 FPS you did before, also your graphics card (if any) may likely have little to no shader support, which may also cause the problem


#24

I think I’ll try to add more light sources to test…btw, should there be shadows in this sample?

About videocard - it’s an old device(2006), but it understands shader model 1…I think=)…at least it has Hardware T&L support…


#25

This is probably caused by the room’s trimesh. ODE is quite sensitive in this regard, so the models for trimeshing must be very nice and clean, otherwise you get strange results sometimes. I will update the map asap with a better version.

That’s related to lighting and shaders. When you look into the main.py file you’ll see that there’s render.setShaderAuto(). If you disable that you’ll get much better performance at the price of much worse looking flashlight effect. There might be a way to deal with that to some extend (you will always get a frame drop), but I haven’t looked into that yet.
On faster graphic cards it obviously shouldn’t be an issue.

Oh… That’s interesting. Can you provide more details in what situations this happens? It might be, again, related to trimesh – with ODE it’s much better to use in-engine shapes. I used the trimesh extensively in this sample only because I needed a working environment quickly up and running for codding.

No, this is not supposed to look pretty :wink:. There aren’t even static shadows there.


#26

About walking through desk:
It happens accidentally… but I’d like to note 2 cases(when it happens more, I think):

-when player stands up from chair
-when player approaches desk at an angle(I mean at an angle to desk’s bounding box’s sides or something)

I’m sorry but I don’t have my explanation of that :frowning:


#27

That’s actually just an animation. If you look into the code for standing up you’ll see, that it’s just the way camera is moved around with simple Panda intervals set on it. You can tune that as much as you want. The actual ode character controller doesn’t take part in this, it’s just an animation.

Seems like I just forgot to make a collider for it ;D. No idea how I missed that… Anyway, I updated it and should be fine now. Hit me back on the result.


#28

Hi,

first of all this is a great script, thank you very much.

I have got a problem adding a Cube:

this is my code

""" 
Create a box
"""

box = loader.loadModel("box")
box.setPos(0,0,7)
box.reparentTo(render)
box.flattenLight()

	 
boxBody = OdeBody(self.worldManager.world)
M = OdeMass()
M.setBox(50000, 1, 1, 1)
boxBody.setMass(M)
boxBody.setPosition(box.getPos(render))
boxBody.setQuaternion(box.getQuat(render))
# Create a BoxGeom
boxMesh = OdeTriMeshData(box, True)    
boxGeom = OdeTriMeshGeom(self.worldManager.space, boxMesh)	
boxGeom.setCollideBits(BitMask32(0x00000122))
boxGeom.setCategoryBits(BitMask32(0x0000111))
boxGeom.setBody(boxBody)
boxData=odeGeomData()
boxData.name = "box"
boxData.isTrigger = False
boxData.surfaceFriction = 0.0

self.worldManager.setGeomData(boxGeom, boxData, box)

So there is a cobe added and it is controlled by gravity but, as it hits the ground the box goes crazy and slips on the ground, rotates and is becoming faster and faster till it slips away…

What did I do wrong =/

I also tryed a OdeBoxGeom but that isn’t effected by anything… it just shakes a bit.

Thanks in advance,
blenderkid


#29

My first thought would be that’s because you set the surfaceFriction to zero. Try changing it to a higher value and tell me if it helps.


#30

I’ve tried with friction = 10 / 100 / 1000 and all the same… =(


#31

Ok, here’s a working version:

""" 
Create a box 
""" 

box = loader.loadModel("box") 
box.setPos(0,-6.0,2.0) 
box.reparentTo(render) 
#box.flattenLight() -- don't use.
    
boxBody = OdeBody(self.worldManager.world) 
M = OdeMass()
M.setBoxTotal(5.0, 1.0, 1.0, 1.0)
boxBody.setMass(M) 
boxBody.setPosition(box.getPos(render)) 
boxBody.setQuaternion(box.getQuat(render)) 

# Create a BoxGeom 
boxGeom = OdeBoxGeom(self.worldManager.space, Vec3(1.0, 1.0, 1.0))
boxGeom.setCollideBits(BitMask32(0x00000122)) 
boxGeom.setCategoryBits(BitMask32(0x0000111)) 
boxGeom.setBody(boxBody) 

boxData = odeGeomData()
boxData.name = "box"
boxData.isTrigger = False
boxData.surfaceFriction = 0.1

self.worldManager.setGeomData(boxGeom, boxData, box)

And a little bit of explanation.

I use setBoxTotal because it feels better for me, but I’ve tried setBox and it should work as well (with correct values).

Don’t use flattenLight. I don’t know why, and I don’t know if it’s the fault of my code of whatever else, but it seems to produce completely unstable results.

Also, for dynamic stuff try to use meshes that have centers in the middle. The “box” mesh that comes with Panda (with that colorful texture) doesn’t, so to see the difference you can use this: dl.dropbox.com/u/196274/companion_cube.egg

And try to use built in shapes for dynamic stuff. In some cases it might not make any difference, but trimesh is not the best (not the most stable) choice here.

Check it and inform me of the result.


#32

Ok, thank you very much it does not have any crazy behaviour anymore, but the cube still slips on the ground, is that intented to be so?

Thanks in advance
blenderkid


#33

You mean that it slides like on an ice rink? That’s a matter of friction set.

I just noticed that this version only takes the ground’s friction into consideration. I’m not sure why ATM (since both are added to the contact), so for now just set your ground’s friction to a higher value while I investigate on the problem.

FIY, I’m planning a major update to this code. The new version will make it easier to add stuff and bring some other nice features. But there’s still some things I need to cross off my to-do list before I can extract the updated framework from the rest of my code and upload it. So just stay tuned.

Also, remember that this is still a work in progress, so keep informing me of any glitches you happen to find.

Thanx for your interest in this code, have fun with it.

Coppertop