Panda PhysX

Return to Panda Features in Development

Postby Executor » Thu Dec 04, 2008 9:29 am

Hey enn0x,
Is there a way to monitor whether a PhysActor or shape has been hit by a raycast?

I saw that the PhysShape can be set to be a trigger. Could it be done with a RayCast? I thought of creating a trigger physshape at the ray's hit point, but maybe there's a better way?
User avatar
Executor
 
Posts: 73
Joined: Tue Nov 25, 2008 6:10 am
Location: South Africa

Postby enn0x » Thu Dec 04, 2008 4:49 pm

Is there a way to monitor whether a PhysActor or shape has been hit by a raycast?


Have you seen the setPythonData/getPythonData methods available on any object that is derived from PhysObject? They allows you to assign an arbitray python object to any PhysShape, PhysActor, ....

Just iterate over the shapes returned by the raycast, get the object you have assigned to the shapes previously, and call whatever method you want on this object.

enn0x
enn0x
 
Posts: 1415
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby BMCha » Sat Dec 06, 2008 5:16 pm

I don't know if this is a bug or not. I'm currently compensating by using a large,flat,box shape, but character controllers don't seem to be colliding with planes.


EDIT: Also, I am trying to do a raycast originating from the camera. However, the ray is colliding with the character controller, and so always returns the position of the camera and a length of 0. Should I use a RaycastAll and use the second hit, or is there a better way to do this.
BMCha
 
Posts: 43
Joined: Sun Jul 13, 2008 1:32 am
Location: California, USA

Postby enn0x » Sun Dec 07, 2008 1:55 pm

I don't know if this is a bug or not. I'm currently compensating by using a large,flat,box shape, but character controllers don't seem to be colliding with planes.

Not a bug, but the way PhysX is implemented. You should use a static triangle mesh instead, like in the sample. The triangle mesh can be just two triangles, but usually you want to have an uneven ground. Or a heightfield mesh.

Also, I am trying to do a raycast originating from the camera. However, the ray is colliding with the character controller, and so always returns the position of the camera and a length of 0.

This is because you probably start the ray INSIDE the character's shape. So the character's shap is the first shape the ray hits, with distance 0.
There are several options:
- start the ray outside the capsule
- use shape groups and a PhysMask32 to disable/enable specific shape groups.
- use raycastAll, and skip the raycast hit with the *own* character's shape. Cave: the raycast hit's are not guaranteed to be sorted. Not recommended.
- Not yet supported is the way more powerful 128-bit masking system. This would be a third option.

enn0x
enn0x
 
Posts: 1415
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby Executor » Tue Dec 09, 2008 12:11 pm

I'm having trouble when removing a PhysActor with its remove() function. I get the following assertion error:

AssertionError: _error_type == ET_ok at line 750 of c:\users\rpf\desktop\physx\source\physActor.cxx


Any ideas why? I can't see anything wrong with my code. Is there anything I need to call before calling remove(), or is there a different way to remove actors?
User avatar
Executor
 
Posts: 73
Joined: Tue Nov 25, 2008 6:10 am
Location: South Africa

Postby Executor » Tue Dec 09, 2008 2:15 pm

EDIT | Reposted...
This message showed up before the next, but I posted after. Could be something with GMT differences?
User avatar
Executor
 
Posts: 73
Joined: Tue Nov 25, 2008 6:10 am
Location: South Africa

Postby enn0x » Tue Dec 09, 2008 2:29 pm

This means that your actor has been removed already by someone else, and thus _error_type is no longer "ET_OK". This could be
- because you have called remove() on another reference of this PhysActor
- you have called remove() on the scene that owns the actor. All actors get automatically invalidated this way.
- the actor has been automatically created by an controller, and you removed the controller. The automatically created objects get invalidated also.

This is exactly the same behaviour your have implemented in PandaNode (I admit that I have been cheating here - to make PhysX usage the same as core Panda3D usage).

I will add a "getErrorType" method to all objects for the next release. Then you could check before you try to remove. I have wondered for a long time if I should swallow this error and just return if the actor is already removed, but I think this leads to sloppy programming. It's better to see that something has gone wrong. But this is a rather philosophical question, and good reasons exist for both ways.

enn0x
enn0x
 
Posts: 1415
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby Executor » Wed Dec 10, 2008 5:07 pm

Ok, I've checked my code but I'm not calling remove twice. Anyway, I tried it on one of the samples, 03_Forces. I only added one line to the doScreenshot event:
def doScreenshot( self ):
base.screenshot( 'PhysX' )
self.boxActor.remove()

It creates only one screenshot file, which means its only being called once, unless I don't know of something that keeps it from making another, but its still giving me the same error. Can you check if it does the same for you. Any other ideas?
User avatar
Executor
 
Posts: 73
Joined: Tue Nov 25, 2008 6:10 am
Location: South Africa

Postby enn0x » Thu Dec 11, 2008 2:15 pm

Hmmm.. I have not choosen my words clear enough here, sorry.

After you called remove() on an actor is is no longer *valid*. It has been destroyed, and the python object is an empty shell. This means: calling ANY other method on this actor after calling remove() will cause raise an exception. Not only calling remove() a second time - ANY other method. I payed some effort on guarding every method with an assert to achive this.

This is what happens if you modify the sample 03 like you did in the above post: You press F5 key, and self.boxActor.remove() is called. The actor is destroyed now. But there is still a task running which is called once a frame, to update the simulation and to process user input. Have a look at the code:

Code: Select all
  def updateWorld( self, task ):
    dt = globalClock.getDt( )

    self.processInput( )
    self.scene.doPhysics( dt )

    return task.cont

  def processInput( self ):
    ....
    self.boxActor.addForce( force )
    self.boxActor.addTorque( torque )

So you call addForce() AFTER calling remove() on the same actor. Raising an exception is correct here, since you can't add a force to a destroyed actor.

I suggest you do something like this in your code:
Code: Select all
    ...
    self.yourActor.remove()
    self.yourActor = None
    ...

Then you will probably get a different error message: a python traceback complaining that "None object has no method xyz." The codeline shows to you where you call a method AFTER calling remove() on your actor.

enn0x
enn0x
 
Posts: 1415
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby Executor » Thu Dec 11, 2008 3:34 pm

I was wondering if my own post was a bit confusing.

Anyway. I added the following line to my edited doScreenshot function:
Code: Select all
self.boxActor=None

And also changed the forces part to this:
Code: Select all
if self.boxActor:
   self.boxActor.addForce( force )
   self.boxActor.addTorque( torque )

Now the assertion occurs at this line: self.scene.doPhysics( dt ). I don't know how PhysX works, but if I called remove(), shouldn't my actor have been removed from the PhysScene and not be part of what doPhysics() is trying to do? You say invalidated, is doPhysics() trying to do physics calculations on my invalidated actor?

I'm sorry if I am bothering you, and thanks for the help, so far.
User avatar
Executor
 
Posts: 73
Joined: Tue Nov 25, 2008 6:10 am
Location: South Africa

Postby enn0x » Thu Dec 11, 2008 4:32 pm

This last one is a bug, but easy to fix, I even can choose between two ways to fix it. Since this is a rather serious bug I will do a new release next week (around Thuesday or Wednesday).

Of course doPhysics() should not do anything on already destroyed actors, but I am using PhysX active transforms to minimize the number of transforms to update. Updating transforms happens while PhysX simulates the scene, in two different threads. This saves a lot of time, but it means that the active transform list which I get from PhysX is the active transform list from the previous simulation step. This list might contain removed actors.

enn0x
enn0x
 
Posts: 1415
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby Executor » Thu Dec 11, 2008 6:04 pm

Ah, thanks. I'm waiting with anticipation.
User avatar
Executor
 
Posts: 73
Joined: Tue Nov 25, 2008 6:10 am
Location: South Africa

Panda PhysX (0.4.3)

Postby enn0x » Thu Dec 18, 2008 2:37 am

http://enn0x.p3dp.com/libpandaphysx_0.4.3.zip

Mainly a bugfix release, but cloth simulation has been added also (currently only for windows).

* Adds simulation of clothes (ALPHA stage, API may change in future releases!).
* setSharpness() has moved from PhysBoxController to PhysController.
* Fixed a bug in the controller callback implementations.
* Fixed a bug in the controller creation (actor had NULL pointer as name).
* Fixed a bug with removing actors.
* Replaces set/getPythonData with them more flexible set/getPythonTag system.
* Updated some of the samples.
* Add some variants of PhysActor.addForce/addTorque.
* Add methods to set/get linear and angular momentum on PhysActor.

(see included file doc/RELEASE-NOTES.txt)

The included binaries are built for Panda3D-1.5.4.
Many thanks to all who helped finding bugs. :-)

enn0x
enn0x
 
Posts: 1415
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby jrose » Fri Dec 19, 2008 3:04 pm

Thanks for the great library. Would you recommend using force fields for modeling buoyancy or is there a better way I'm missing?
jrose
 
Posts: 4
Joined: Sun Dec 14, 2008 3:28 pm

Postby enn0x » Mon Dec 22, 2008 12:00 pm

To be honest I have been wondering myself how to do buoancy. the tricky part if when only part of a shape is submerged. Then the upward force depends on the submerged fraction of the total volume.

Force field will either apply the full force or none, depending on the center of the shape (I think...). So you will get an constant up-and-down oszilation.

One way would be to split up the total shape in subshapes/actors. Another would be to append a number of points (?) from which you estimate the submerged volume, and then apply buoyancy forces yourself each frame.

PhysX has a feature in preparation which will solve this and other features of fluids: fluid heighfields. So I guess the best is to wait until this feature is released by NVIDIA.

enn0x
enn0x
 
Posts: 1415
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby jrose » Tue Dec 23, 2008 10:42 am

Makes sense, guess I'll put in a placeholder non-physics object for now, thanks for the feedback.
jrose
 
Posts: 4
Joined: Sun Dec 14, 2008 3:28 pm

Postby olala » Tue Dec 30, 2008 1:52 am

hello.
I wanna try this physic engine,too.
Then I tried your lastest code.
I ran 01_Basic.py(and another.) then I get this error.
Code: Select all
Assertion failed: error == NXCE_NO_ERROR at line 230 of c:\users\rpf\desktop\phy
sx\source\physEngine.cxx
Traceback (most recent call last):
  File "01_Basics.py", line 176, in <module>
    world = World( )
  File "01_Basics.py", line 55, in __init__
    base.setBackgroundColor( 0, 0, 0.3, 1 )
  File "C:\Panda3D-1.5.4\direct\src\showbase\ShowBase.py", line 1615, in setBack
groundColor
    color = VBase4(r, g, b, a)
AssertionError: error == NXCE_NO_ERROR at line 230 of c:\users\rpf\desktop\physx
\source\physEngine.cxx


I use Panda3D-1.5.4. , ageia_physx_7.07.24 and NVIDIA PhysX SDK 2.8.0, 2.8.1
Does I miss something?
Help me please.
olala
 
Posts: 41
Joined: Sun Jul 27, 2008 12:42 am

Postby enn0x » Tue Dec 30, 2008 7:51 am

There has been an error when initializing the PhysX SDK. There are several reasons why this could happen, for example not finding the system software, or two applications trying to grab the same hardware, or a version mismatch.

The error should have been reported on the console, somwhere ABOVE the assert. The output is category "error", so if you don't turn off every output manually then you will see it.

By the way: you need the SDK only if you want to compile yourself.

enn0x
enn0x
 
Posts: 1415
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby olala » Tue Dec 30, 2008 11:53 am

Oh!!~
I tried remove SDK and install older version of PhysX.
(PhysX_8.04.25_SystemSoftware.exe )

It 's work well.
Thank you very much enn0x. :wink:
olala
 
Posts: 41
Joined: Sun Jul 27, 2008 12:42 am

Postby enn0x » Tue Dec 30, 2008 12:59 pm

Ok, seems like the installed system software has been to old.

Just to make sure: did you see this line on the console, or has there been another error type?
Code: Select all
:physx(debug): Error when setting up the PhysX system: NXCE_WRONG_VERSION


enn0x
enn0x
 
Posts: 1415
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby Executor » Sat Jan 24, 2009 11:31 am

Edit | Nevermind, found the SFDisableRaycasting flag to get a raycast to ignore a certain shape...
User avatar
Executor
 
Posts: 73
Joined: Tue Nov 25, 2008 6:10 am
Location: South Africa

Postby BMCha » Sat Jan 24, 2009 3:09 pm

enn0x, would it be possible for you to add some functions to add forces to a character controller? It would help with part of a project I'm working on, and currently the functions that set force on actors don't work as the controller is not dynamic.
BMCha
 
Posts: 43
Joined: Sun Jul 13, 2008 1:32 am
Location: California, USA

Postby Executor » Tue Jan 27, 2009 7:41 am

How can I get the surface normal of the hit surface when doing a raycast?
I'm trying to place a decal on the hit surface. Any ideas how to get the correct angles for the decal?
User avatar
Executor
 
Posts: 73
Joined: Tue Nov 25, 2008 6:10 am
Location: South Africa

Postby BMCha » Tue Jan 27, 2009 10:51 am

PhysRaycastHit.getImpactNormal() should work.
BMCha
 
Posts: 43
Joined: Sun Jul 13, 2008 1:32 am
Location: California, USA

Postby enn0x » Tue Jan 27, 2009 1:21 pm

@Executor:
BMCha is right, hit.getImpactNormal() should return the surface normal at the impact point. However, it is a "smoothed" normal . So far I don't support a way to ask for either a smoothed normal or the real face normal. I will put this on my todo list.

@BMCha:
I'm afraid this is not possible, because the actor created by a controller is a kinematic actor. The error messages you see are not from my code but from the PhysX SDK itself. Setting forces on a static or kinematic actor is not allowed. Only dynamic actors can bemoved with forces. To move around a kinematic actor you must use move(). The PhysX SDK documentation has some more explanation on the different actor types. So here is what you can do:

(1) Create a dynamic actor and write you own controller code, for moving it around with forces. It's hard, especially if you want to have all the features that PhysX controller offer, but possible. Look at the Newton, Ode or Bullet examples for how to implement a controller.

(2) Depending on how complex your forces are you can calculate a velocity change from your forces, and use actor.move() or controller.setLocalSpeed() accordingly.

enn0x
enn0x
 
Posts: 1415
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby Executor » Thu Feb 05, 2009 7:48 am

I am trying to create a convexmesh nxb file for an object within a map that I created with 3dmax. Heres the code:

Code: Select all
import direct.directbase.DirectStart
from pandac.PandaModules import Filename
from libpandaphysx import PhysKitchen

fname = 'map01'

map=loader.loadModel( 'models/%s.egg' % fname )
np=map.find("*/object")

status=PhysKitchen( ).cookConvexMesh( np, Filename( 'models/%s.nxb' % fname ) )
print 'Kitchen status for mesh:', status


I get the following assertion:
AssertionError: meshDesc.isValid() at line 241 of c:\development\physx\source\physKitchen.cxx


If it can't find the object it gives an assertion that says something about isEmpty(). So I believe that it does find the object but its not in the same 'form' as when using the loader to load a model and then the kitchen says that the mesh is missing. I have also reparented the found nodepath to the render node and the object does get rendered, which means that the mesh can't be missing.

Any idea how I can get it to work or a reason why its not?
User avatar
Executor
 
Posts: 73
Joined: Tue Nov 25, 2008 6:10 am
Location: South Africa

Postby enn0x » Thu Feb 05, 2009 2:10 pm

The egg model has already been read and vertices collected from it at the time when the assert is raised. So this is not the problem. Still, the NxMeshDesc created from these vertices seems to be invalid. Thi sis checked before attempting to cook the mesh.

One idea would be that the mesh contains more than 256 vertices. Convex meshes are restricted to a max of 256 vertices.

If this is not the problem I would like to see the egg or bam file. Maybe I can figure out what is going wrong with this mesh.

enn0x
enn0x
 
Posts: 1415
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby enn0x » Tue Feb 10, 2009 10:47 am

http://enn0x.p3dp.com/libpandaphysx_0.4.4.zip

Just a maintenance release. Focus has been on strengthening collision and interaction filtering as well as enabeling the visual remote debugger.

* Add one-way interactions between dynamic objects using dominance groups.
* Adds support for the Visual Remote Debugger.
* Adds support for actor groups and actor group filtering.
* Adds support for 128-bit mask for collision filtering.
* Adds raycast methods for axis aligned bounding boxes.
* Additional parameter to raycastClosest/Any methods for smoothed normals.
* Adds preliminary(!) implementations for vehicles.

(see included file doc/RELEASE-NOTES.txt)

The included binaries are built for Panda3D-1.5.4. Please note that the vehcile classes are not yet ready for being used. I have just been too lazy to remove them for the release.

ennox
enn0x
 
Posts: 1415
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby BMCha » Sat Feb 14, 2009 1:38 am

enn0x, I noticed in the raycast sample that the ray originates from the box, how were you able to prevent it from immidiately colliding with the box?
BMCha
 
Posts: 43
Joined: Sun Jul 13, 2008 1:32 am
Location: California, USA

Postby enn0x » Sat Feb 14, 2009 10:50 am

By utilizing an oddity of PhysX collision detection system. Box shapes won't collide from the "inside". It won't work with sphere shapes or capsule shapes. Hmm... considering this I think I provided a bad example. I should have used actor groups or shape groups to explicitly filter collision detection.

enn0x
enn0x
 
Posts: 1415
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

PreviousNext

Return to Panda Features in Development

Who is online

Users browsing this forum: No registered users and 3 guests