Game Development Community

Guide how to use new PhysicsShape class in Beta1.1

by Zealander · in Torque 3D Professional · 02/14/2010 (2:21 pm) · 15 replies

Hi all.

There was questions how to use PhysicsShape class.

So, first of all build Torque3D for PhysX(in my case) or Bullet(did not try, maybe someone will try and report)

Then add new cs file(physicsShapes/Pallet.cs in my case) in datablocks folder with content like this

datablock PhysicsShapeData(Pallet)
{
category = "PhysicsShapes";
shapeName = "art/shapes/physicsShapes/pallet.DAE";

emap = true; //Do not know is it necessary...

mass = 100;
dynamicFriction = 0.5;
staticFriction = 0.5;
restitution = 0.1;
linearDamping = 1;
angularDamping = 1;
linearSleepThreshold =1;
angularSleepThreshold = 1;
waterDampingScale = 1;
buoyancyDensity = 0;

//simType = 3; // Do not want to hardcode here, better use constant or default client server simType
};

then add the code to the end of datablockExec.cs file

// Load the physics shape datablocks
exec("./physicsShapes/Pallet.cs");

Possible problems:

1. Your model has be created with collision mesh inside.

To avoid this problem just create it for your model file or create bounds instead of this mesh by this way:

create Pallet.cs file in your folder with Pallet.DAE with content

singleton TSShapeConstructor(PalletDAE)
{
baseShape = "./Pallet.DAE";
loadLights = "0";

};
function PalletDAE::onLoad(%this)
{
%this.addMesh("cube", "bounds", "Col-1");
}

Then place a physicsShape to the scene, press F11 and enjoy!!!

It works at least with PhysX!



#1
02/14/2010 (5:28 pm)
Thanks for the post...I plan on giving Bullet a try in the next few days...I'll let you know how it goes
#2
02/15/2010 (11:51 am)
Thanks,

I am looking for more information on what changes on the modeling side and what has or is planned on being implemented. I was thinking Bullet required a collapsed model which would change the way I have everything setup, but getting frustrated waiting to download the new Physx SDK. Rather annoying.
#3
02/15/2010 (1:07 pm)
Randy, if you go to the Nvidia forums and politely nudge a moderator with a comment like this: "we need access ASAP or we'll choose Bullet or Havok"..you should be allowed access within a day or 2.
#4
02/15/2010 (1:24 pm)
:) Already posted something along that line..

I went to buy a Ford the other day and they said come back in 30 days and we will let you test drive one, so i guess it's the new going thing now:)
#5
02/15/2010 (4:30 pm)
Happen to know if the PhysXStream file (Which I'm assuming is the only way to make destructible objects) can still be loaded with this method?
#6
02/15/2010 (4:43 pm)
No, it does not work with physics streams now, but it will work in the future, details here http://www.torquepowered.com/community/forums/viewthread/110887.

Or you need to extract PhysXStream reader manually from PxMultiActor, i did it, it is not hard. It works for dynamic and static actors, but i did not test it for more complicated stuff like ragdolls yet. It has to work.
#7
02/15/2010 (4:54 pm)
This may seem like a stupid question, but how do you actually select the physics library that Torque3D uses? I looked at the Physics demo and managed to add Physics support to my own project by copying the defines and adding the additional libraries source files to my VC project, but the demo had defines for both Bullet physics and PhysX physics as well as compiled both Bullet and PhysX into the engine simultaneously. As far as I can tell both physics implementations are being used in my project just now and they work. I would really like to set it to use Bullet and figure out how to do destructible meshes with it since I don't have a license for Maya or 3DSMax and Nvidia will probably never release a PhysX plugin for Blender.
#8
02/15/2010 (5:01 pm)
I just added all files from physics/physX folder to the project and Preprocessor definitions TORQUE_PHYSICS_ENABLED
TORQUE_PHYSICS_PHYSX, thats all.

Maybe you can select physics by this definitions.
#9
02/15/2010 (5:12 pm)
If that's the case then my project is indeed using both PhysX and Bullet simultaneously and works just fine. Somehow I doubt it's actually doing that though so perhaps the engine prefers PhysX over Bullet when it finds both options.
#10
02/15/2010 (5:37 pm)
:) Intresting, plus you have inner Torque physics engine too, because shells are bouncing in my project and debris is not redone to PhysX or Bullet still.

Use Vesual debuggers to ensure they both are running, to enable PhysX debugger add last line of the code to game/scripts/client/init.cs

function initClient()
{
echo("n--------- Initializing " @ $appName @ ": Client Scripts ---------");

// Make sure this variable reflects the correct state.
$Server::Dedicated = false;

// Game information used to query the master server
$Client::GameTypeQuery = $appName;
$Client::MissionTypeQuery = "Any";

// enable Physx Visual Debugger
physXRemoteDebuggerConnect();

then you have to run PhysX remote debugger before your application.

and you will exactly know is PhysX running or not. Sadly, there isn't the same call for bullet yet.
#11
02/15/2010 (5:51 pm)
I know it's working because I stuck a pallet into my level, fired a missile at it, and watched it fly off into the ocean. It was probably the best laugh I've had in a long time. PhysicsShape is definitely a huge step forward for T3D's pluggable physics system though.
#12
02/16/2010 (3:47 am)
so.. a standalone physx tool for T3D may be well received ?
I can add this to my spring development list if no-one else has anything planned in this area.
#13
02/18/2010 (6:57 pm)
Ok... some more secrets with physics.

If you link both PhysX and Bullet by adding them to your project.conf:

<?php

// Configure Torque 3D
Torque3D::beginConfig( "win32", "MyDemo" );

   includeModule( 'bullet' );
   includeModule( 'physx' );
           
Torque3D::endConfig();

?>

You can then switch between Bullet and Physics by doing either: physicsInit( Bullet ) or physicsInit( PhysX ) at the console. Note this doesn't work while the game is running... you should do it from the main mentu.

The PhysicsShape, all collision representations, and the Player controller all work in both Bullet and PhysX. We'll be adding cloth, destructables, and other objects in the future.

We also added new "hints" into the TSShape collision system for physics. If you create your DAE to have a "Collision-1" marker node then a "Colbox-1" as the name for the collision mesh... that tells the system to use a box primitive for physics collision and not a convex. We support "Colbox", "Colsphere", "Colcapsule", and "Colmesh" as hints to build a box, sphere, capsule, or triangle mesh primitives.
#14
02/18/2010 (11:37 pm)
Tom... Good info.. Helps understand things quicker, before we have time to get down and dirty in the code:)

Got my Nvidia account updated, so now need a cron job to log into once a week:)
#15
02/21/2010 (9:20 pm)
Wasn't able to successfully switch to bullet in the physx demo

I created a PhysicsShape object shaped like a brick using the datablock properties from the beginning of this thread, and it behaved similarly to the PxMultiActor objects in the physx demo in Physx mode.

But when I switched to Bullet mode using physicsInit(Bullet), the bricks did not react to gravity or projectiles and pretty much only moved if I placed them within one another, whereby they would smoothly separate until they no long touched each other.

edit:
I figured it out. You have to set the linearDamping and angularDamping values to less than one in the PhysicsShape datablock for PhysicsShape objects to react to outside forces in Bullet mode.