ODE Middleware

Return to Code Snippets

ODE Middleware

Postby coppertop » Wed Dec 16, 2009 6:10 pm

Be aware that this code is generally meant as internal and was extracted from a larger project I'm working on. This means I can't ensure a stable API or regular updates.

The current version is 1.2.1, but you can still download the previous versions at the bottom of this post. I strongly discourage using versions earlier than 0.9 (actually, just use the most recent one, it's the best one ;) ).

Since version 1.2.0 the framework contains everything I wanted to release for now, so there will probably be only 1.2.x bug-fix releases from now on.

WARRNING: Panda 1.7.0 has a bug that causes it to leak memory when using this code. Please use it with newer snapshot builds or newer stable releases once such are available (1.7.1 and 1.7.2 are fine).

Features:
  1. World Manager, which makes it easier to use ODE with Panda and Python.,
  2. Basic classes for Static, Kinematic, Dynamic and Ray objects,
  3. Continuous Collision Detection support for fast moving small objects,
  4. Kinematic Character Controller (much more stable since 0.9),
  5. Player controller for FPP games using the KCC,
  6. Object picking and carrying for the player controller,
  7. Ray-based gun mechanics with support for automatic, semi-automatic and shotguns.
  8. Explosion mechanics and an example grenade implementation,
  9. Area Triggers,
  10. Door,
  11. Map loading example,
  12. Moving platform example,
  13. Simple bit mask generator
  14. Visualization based on FenrirWolf's code

If you want to read more about this framework, it's features and limitations, please check this file:
http://dl.dropbox.com/u/196274/odereadme_1.2.1.pdf

Changes in 1.2.1:
  • The Kinematic Character Controller now inherits from Kinematic Objects (by suggestion)

Changes in 1.2.0:
  • Added support for moving kinematic platforms. Optionally dynamic objects can serve as moving platforms for the Character Controller as well, but not for other dynamic objects. Example included;
  • Ability to easily change the size of the KCC with one intuitive method. Finally. Also the sample map was changed to correct scale;
  • Correct bouncing and sliding in CCD-enabled dynamic objects. Their velocity is no longer artificially affected after collisions;
  • Animation for smooth camera movement when going from standing to crouching and vice versa and while walking steps;
  • Additional capsule for the KCC for better object pushing;
  • Simple automatic BitMask generator;
  • Uses FenrirWolf's code for ODE visualizations. Thanks for writing and sharing it;
Changes in 1.0.1:
  • Fixed shaking when the KCC collides with TriMesh geoms (although, I still not advice using trimeshes too extensively)
  • Changed the advised bit mask setup in the sample
Changes between 1.0 and 0.9:
  • Ditched the odeGeomData class -- this made the code a lot cleaner, more optimized, and easier to use,
  • Added support for firearms,
  • Added example guns,
  • Added rayObject class,
  • Limited the use of in-place ray casting,
  • Optimizations, bugfixes

Download the current version (1.2.1) here:
http://dl.dropbox.com/u/196274/copperode_1.2.1-1.zip


To see it in action run start.sh for Linux or start.bat for Windows. Or do python main.py.

Earlier versions:
http://dl.dropbox.com/u/196274/copperode_1.2.1.zip
http://dl.dropbox.com/u/196274/copperode_1.2.0.zip
http://dl.dropbox.com/u/196274/copperode_1.0.1.zip
http://dl.dropbox.com/u/196274/copperode_1.0.zip
http://dl.dropbox.com/u/196274/copperode_0.9.zip


Hope you'll find it useful,

Coppertop
Last edited by coppertop on Sun Apr 17, 2011 9:47 am, edited 11 times in total.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby treeform » Wed Dec 16, 2009 9:09 pm

Looks like this would be a great addition to the tutorials. Care to make it more tutorial friendly?
User avatar
treeform
 
Posts: 2106
Joined: Sat May 05, 2007 5:15 pm
Location: SF, CA

Postby mindstormss » Thu Dec 17, 2009 1:29 am

control (crouch) seems to simply send the character flying upward for as long as I hold the button...but this is rather neat. Great Job. I second that this be turned into a sample program (it is almost there already!)
All human beings should try to learn before they die what they are running from, and to, and why.
  - James Thurber
User avatar
mindstormss
 
Posts: 203
Joined: Mon Jul 30, 2007 9:21 pm
Location: California

Postby rdb » Thu Dec 17, 2009 3:16 am

I'm getting this error when I run it:
Code: Select all
ODE INTERNAL ERROR 1: assertion "Stride >= (int)sizeof(dContactGeom)" failed in dCollideBTL() [collision_trimesh_box.cpp]
Aborted

I'm guessing you passed wrong arguments to OdeUtil.collide ?
This is a debug build of ODE, which probably explains why I'm getting the error and why you aren't.
rdb
 
Posts: 11118
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Postby coppertop » Thu Dec 17, 2009 6:53 am

Thanks everyone for your interest and replies. I really appreciate it.

@Treeform

I guess I could. What exactly do you mean by "more tutorial friendly"? Except for making the map look less provisional. It's the first time I put out a piece of code like that, so I'd really be thankful for more directions on this.

@mindstormss

Crouch makes you fly? That's strange... I've run the code here again, checked it and I see there is something wrong with crouching, but I don't fly... You're supposed to "fly" only when inside the ladder trigger. Can you tell me a little more about what exactly happens? Do you just take of and go up (up and away) higher and higher when control is pressed? Do I understand correct?

@RDB

Yeah, that didn't happen to me... I have the standard Panda 1.6.2 built from the Ubuntu package. I'd be very thankful though if you gave me a little direction on how to eliminate this problem - it'd be hard for me alone since I simply don't get this error. Thanks very much in advance.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby mindstormss » Thu Dec 17, 2009 12:44 pm

Yeah, when control is pressed you just continue moving at a constant velocity straight up, and upon releasing fall back down due to gravity--although it would appear that the camera moves down first for an instant (almost like one would expect when crouch is pressed). Simply tapping control gives a weird down up down bunny hop like thing.
All human beings should try to learn before they die what they are running from, and to, and why.
  - James Thurber
User avatar
mindstormss
 
Posts: 203
Joined: Mon Jul 30, 2007 9:21 pm
Location: California

Postby coppertop » Thu Dec 17, 2009 1:57 pm

This is really weird... and I cannot reproduce it :/. Crouching works as it should for me here (except that walking up stairs doesn't work when crouching ATM). It also does for a friend I just asked to check it. Very strange...
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby coppertop » Thu Dec 17, 2009 11:37 pm

Ok, time for a little update.

There's a new map (still placeholders, but more obvious, the way I personally like them, dunno if you will too ;) ).

Some bugs are fixed such as the player being unable to walk up steps when crouching. Also, now the KCC will correctly react to multiple collision contact points with the same object. I have also added a... chair. So you can sit and relax a little bit (I love Panda's sequences, intervals and so on). I'm sure some more things were fixed but I can't remember now... And I still haven't been able to reproduce the "crouching-flying" error, so I'm very curious if it will happen again with this version.

There's also more comments in the code files.

I guess that's all.

The package is under the same link: http://dl.dropbox.com/u/196274/ODE_Cust ... ork.tar.gz

Cheers,

Coppertop
Last edited by coppertop on Fri Dec 18, 2009 10:12 am, edited 2 times in total.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby adr » Fri Dec 18, 2009 12:47 am

Yea, I'll look at the code, but I'm getting that couch error too. When you press it, you just go "fly" into the air as you hold the key down. I'm using a windows OS, so that may have to do with the problem maybe? Again, I'll see what I can do.

Edit. Ok Not 100% sure, but you put 1.2 for self.crouchLevitation, so I changed it to .2 and then it seem to go down as normal, but when you hold on to it to long you'll go thow the floor or the wall. This means it's not locking after you press the key. I mean, it's still going in the loops to go down. Maybe its gravity + couch, it says I hit the floor with a -5.
Last edited by adr on Fri Dec 18, 2009 1:14 am, edited 2 times in total.
adr
 
Posts: 532
Joined: Wed Oct 12, 2005 8:26 pm
Location: USA

Postby coppertop » Fri Dec 18, 2009 12:58 am

Hmm... I actually haven't tested that on Windows, nor has anyone of my friends I sent it to, only on Linux. It would be very strange though if that was an OS-related problem, but who knows. I will have to test it there.

Adr, have you tried the new version? Is the bug still there? I haven't made much of changes to the crouching code, but again, who knows.

EDIT:

Hmm... That gives me a clue on what's wrong. The crouch levitation has to be a high value (though it does look like it's too high at the first glance, but it's not) because otherwise you won't be able to climb stairs. Once I figure out what the flying deal is of course. Anyway, my guess is that instead of setting the levitation value it increases it in every step. That might be the case. I'll dig into that, but first I must get into Windows and see if I get that glitch as well.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby adr » Fri Dec 18, 2009 1:16 am

Yea thats with the new version. If you change that value, nothing else seems to get effected other then couch. It's adding to the point where you skip a frame and go though something. Maybe you have something backwords? Like a If else statament. I'll see what happens if I make it a -1.2

Edit. K, yea making it -1.2 works, but you still go thow a wall or the floor if you hold it to long. So something keeps adding to the value and you have something flip around inside.

It could be that windows keeps sending the ctrl command while that os only sends it onces?
adr
 
Posts: 532
Joined: Wed Oct 12, 2005 8:26 pm
Location: USA

Postby coppertop » Fri Dec 18, 2009 2:06 am

Ok, checked it on Windows and fixed it. At least apparently, need confirmation. It seems like the problem was in fact OS-specific, in a way, but I think it's more probable it was some difference between the Linux and Windows Panda built that was causing the glitch. I just don't see how the system by itself could've caused it.

Anyway, the thing was that when crouching there was a collision between the footRay and the capsuleGeom. As a result the KCC thought you're lower than levitation, and pushed you upwards. Hence the "we have lift-off to the International Space Station" thing. I've added an if to the ray collision callback to check if we're not colliding with the capsule. I could've done that using masks, but that was quicker.

I've updated the package and it should work now.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby adr » Fri Dec 18, 2009 2:56 am

Other then you can't open the door while crouch and maybe naming the file testMapODE.py to just Main.py, it works great! I'm going to study it for my own game :) My collision and gravity sucks butt, but with your example I'll get it working and I hope even faster then it has been.
adr
 
Posts: 532
Joined: Wed Oct 12, 2005 8:26 pm
Location: USA

Postby coppertop » Fri Dec 18, 2009 3:21 am

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 ;).

http://dl.dropbox.com/u/196274/ODE_Cust ... ork.tar.gz
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby Nemesis#13 » Tue Jan 05, 2010 10:35 am

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
User avatar
Nemesis#13
 
Posts: 1041
Joined: Mon Aug 04, 2008 8:09 pm
Location: Germany

Postby benchang » Wed Jan 06, 2010 7:27 pm

Excellent! works great, and well commented.
User avatar
benchang
 
Posts: 202
Joined: Wed May 30, 2007 3:16 pm
Location: Troy, NY

Postby coppertop » Thu Jan 07, 2010 8:30 am

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 ;). I just don't know what I should do to get it there ATM, but it would be great.

Thanks again and enjoy.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Amazing!

Postby powerpup118 » Sun Apr 18, 2010 12:07 am

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 :P
User avatar
powerpup118
 
Posts: 325
Joined: Sat Apr 17, 2010 11:59 pm

Postby coppertop » Sun Apr 18, 2010 6:30 am

Thank you very much for your work.

I'm glad you like it :).

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

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:
Code: Select all
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.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby powerpup118 » Sun Apr 18, 2010 1:08 pm

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

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:

Code: Select all
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:

Code: Select all
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)
User avatar
powerpup118
 
Posts: 325
Joined: Sat Apr 17, 2010 11:59 pm

Postby coppertop » Sun Apr 18, 2010 1:34 pm

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.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby Insy_Shrouded » Fri May 14, 2010 8:32 pm

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.
User avatar
Insy_Shrouded
 
Posts: 3
Joined: Thu May 13, 2010 7:21 am
Location: Russian Federation

Postby powerpup118 » Fri May 14, 2010 8:44 pm

Hi,

Insy_Shrouded wrote:- when lamp is switched off, FPS meter shows ~120, when I switch a lamp on - framerate drops to ~58-60.


~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
User avatar
powerpup118
 
Posts: 325
Joined: Sat Apr 17, 2010 11:59 pm

Postby Insy_Shrouded » Fri May 14, 2010 9:14 pm

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...
User avatar
Insy_Shrouded
 
Posts: 3
Joined: Thu May 13, 2010 7:21 am
Location: Russian Federation

Postby coppertop » Sat May 15, 2010 6:00 am

while walking on the roof player sometime's shifts forward for some distance.

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.

when lamp is switched off, FPS meter shows ~120, when I switch a lamp on - framerate drops to ~58-60.

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.

player walk's through the desk sometimes

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.

btw, should there be shadows in this sample?

No, this is not supposed to look pretty ;). There aren't even static shadows there.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby Insy_Shrouded » Sun May 16, 2010 9:10 am

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 :(
User avatar
Insy_Shrouded
 
Posts: 3
Joined: Thu May 13, 2010 7:21 am
Location: Russian Federation

Postby coppertop » Sun May 16, 2010 2:10 pm

when player stands up from chair

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.

when player approaches desk at an angle(I mean at an angle to desk's bounding box's sides or something)

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.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby blenderkid » Mon Jul 19, 2010 4:44 am

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
Code: Select all
"""
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
blenderkid
 
Posts: 85
Joined: Sat Jun 20, 2009 4:15 am
Location: Germany

Postby coppertop » Mon Jul 19, 2010 5:41 am

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.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby blenderkid » Mon Jul 19, 2010 6:24 am

I've tried with friction = 10 / 100 / 1000 and all the same... =(
blenderkid
 
Posts: 85
Joined: Sat Jun 20, 2009 4:15 am
Location: Germany

Next

Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest

cron