Game Development Community

PhysX 3.x Plugin

by Timmy01 · in Torque 3D Professional · 10/28/2013 (5:11 am) · 500 replies

Update:
If you wish to follow this than please check here github.com/ChrisCalef/Torque3D/tree/physx3_advanced_WIP
#21
01/24/2014 (8:04 pm)
I haven't had a chance to look into the bugs yet. First I need to justify PhysX 3.3 for my game, since it will take time to integrate it and make sure it's stable. My progress on cloth is increasing those chances greatly.

Speaking of which. Update time! I'm on a roll, at this rate I should be able to release something by the end of the weekend. I got my bone idea working pretty well.

I took my mesh from the previous video and I added two bones. I named one of them "Cloth" and the other one "NotCloth". Here's a screenshot of the weight painted for Cloth:
i.imgur.com/h5RxxtV.png
And here's the weight paint for the other bone, "NotCloth":
i.imgur.com/iuRjxd2.png
The ClothShape will look for a bone named "Cloth", if it finds it it will take over the vertex buffers and overwrite those vertices with data from PhysX. It's pretty simple, the only downside is animations don't work, so that's the limitation preventing me from using this on characters, but I'll find a solution. Without further ado, here's a video of the above mesh in action ( I rotated the cloth so it would be more interesting ):


#22
01/24/2014 (9:25 pm)
That's really awesome mate ;-)

My own project that i developed this plugin for is a tank game and i'm pretty happy with the performance of Physx 3.3 so far. I did the majority of my testing with Physx 3.2 though and only upgraded to 3.3 recently. As stated previously though the plugin i use has a quite a few differences to this one i posted here (all project specific).

One day if i get really excited i'll replace the torque default vehicles with Physx one's because the vehicle classes in physx 3 is pretty good.
#23
01/25/2014 (10:21 am)
Here's a more real world example of how it can be used:

Wooden house, add a banner, weight the banner to the cloth bone ( no texture because I'm too lazy to UV map it. ):
i.imgur.com/IQ6Z6Mz.png
And video with collisions enabled (video skips a bit due to me having a lot of programs running):

They kind of suck at the moment, but I am affecting the cloth as I walk through it. I've been reading through UDK's documentation on cloth and I'm going to use a similar system. That is, in the datablock you'll be able to specify which bones are cloth bones, rather than relying on naming the bone "Cloth".
#24
01/27/2014 (6:46 am)
Well congratulations, PhysXInfo.com featured this thread on their Facebook page, and since then I guess it got more and more "known".
Anw seems like you have managed to add Torque 3D to Nvidia's list of "common" engines.
When I signed up for a new account I was met with:
* Game Engine (if any): []Unreal4 []Unreal3 []UDK []Unity []Torque 3d []Internal Tech []Other

Again, congratulations T3D seems to be one of Nvidia's "Top5" because of you lol.

Edit:
Here have an image
imageshack.com/a/img827/7392/m3fj.jpg
#25
01/27/2014 (12:40 pm)
haha I think you can thank Andrew for that with all his videos ;-) Anything that gets Torque3D noticed is a good thing. Although Torque3D has supported PhysX 2.8 for quite some time now.

I will remove my copyright messages soon from the code and change it to GG so at some stage in the not so distant future a pull request can be made.

@Andrew:
Personally I would vote for naming the bone "Cloth" simply because it would be more consistent with the naming structure torque uses for other parts of the mesh but that is neither here nor there.


#26
01/27/2014 (2:58 pm)
Ok updated the repo with GG copyright in place now and also enabled the onDebugDraw method.

For anyone who missed it the repo can be found here github.com/rextimmy/Torque3D just remember you want the development branch.

Andrew is currently doing some nice work on the cloth system and he has released the initial code here gist.github.com/andr3wmac/8552604. Do note though this is not the weighted vertex version seen above, I am not sure if he is making that one public or not?

Physx 3.3 plugin known bugs:
* First bullet you fire causes a FPS drop. Still investigating this.

Do get testing everyone so we can hopefully see this make it into T3D once it is decided who from the community is "taking over" from Dave Wyand (see this thread if you missed it www.garagegames.com/community/forums/viewthread/136026/2#comment-853805 )

*Edit:
Updated original post with information about the plugin.
#27
01/27/2014 (3:28 pm)
My cloth shape system is almost ready to begin testing/public contribution, I'm just sorting out the details on how it will work. I've abandoned the bone system and I have a mesh-name based system almost working. The problem I ran into with the bones only is that if you want multiple cloth objects as part of one shape, weighting them all to the cloth bone causes problems trying to distinguish where one piece ends and the other begins.

Instead, I'm making it work the same way collision shapes and lod works. You make multiple meshs inside the shape with names like cloth-0 cloth-1 cloth-2, etc and each one is treated as a piece of cloth. Within that cloth mesh, it expects 2 bones, the first bone specifies movable vertices, the second specifies fixed vertices.

Regarding the copyright notice, I think we should at least stick a list of authors at the top. We're putting in the time to make it, I think we at least deserve credit when someone goes looking through the source :P

Even though this is named development, this is where I've been moving the stuff that works:
github.com/andr3wmac/Torque3D/tree/development

I've updated the readme to include some basic instructions on getting PhysX 3.3 running and in the My Projects folder you'll find a working project with some maps for testing things out. (Pretend you don't see the test particles level - that's top secret for now ;) My vertex cloth is not in there either, I hope to add it tonight though.
#28
01/27/2014 (5:56 pm)
If you play around with the demo you'll notice a movement problem with the player. He bobs up and down while moving, and his jumping ability is sporadic at best. It's been in all the PhysX 3.3 copies I've tried. I starting looking for the problem and I suspect is comes from the Px3Player::findContact function. Probably due to the fact PhysX 3.3 doesn't have skin sizes anymore, and some of the math seems to include skin sizes. I've tried to tackle it a few times but it just gets worse. Perhaps a rewrite is required? It seems the ported code is not working right.

When looking into this function it lead me the question of why the player class would use PhysX for collision data at all? I suppose performance, especially when offloaded to a capable GPU. Regardless, especially in the case of the game I'm working on I'd like PhysX to be an optional enhancement. My hope is to add PhysX as an option that can be turned on/off. With PhysX disabled cloth would appear static or fall back on an animation or something of that nature.

So, I've added a PhysicsCollision option to the player class. There's various spots in the player class where it chooses to either use Torque's collision or collision through the Physics plugin if it's available. In these cases if PhysicsCollision is false, it will use torque's collision despite the available PhysX. The character is still represented in PhysX and updated with movement information but there's no feedback from PhysX that can affect the player, only other physics enabled objects. In my initial tests it's fixed all the movement issues, without having any drawbacks. It's obviously just a band-aid for now, but I think adding options like these will allow people to enhance their projects with PhysX without potentially compromising what they already have, which has been a concern of mine from the start. It's for this reason and because of the existing bug I propose it defaults to false. Once we get it working, if someone wishes to enhance collision in the player class they could enable it in the datablock.

Thoughts?
#29
01/27/2014 (7:21 pm)
Ok everyone I have merged Andrew's cloth code into the repository and Andrew has also put up a nice guide on how to enable the physx 3 plugin too. Check here github.com/rextimmy/Torque3D/tree/development

@Andrew:
Yeah you are right the character controller is problematic, these problems have been introduced when I changed over to Physx 3.3 from 3.2 as there was a few API changes. I'll have a play around with it tonight and hopefully get it back working ok because it was exactly the same as the physx 2.8 plugin before the upgrade. The skin width is specified on the character controller with PxControllerDesc::contactOffset which I will add back in (not sure why I left that out actually). Having said that I believe the problem runs deeper than that. I'll report back with any findings.
#30
01/28/2014 (12:21 pm)
Woo! I got it working the way I was hoping. This method seems the most flexible and it works in a similar fashion to collision methods and LOD. You just need to name the cloth meshes following the scheme of Cloth-0, Cloth-1, Cloth-2, etc. It's not case sensitive either. It requires two bones to be created, all verts weighted to the first one are loose cloth, all verts to the second bone are fixed.

Below is a screenshot of the testing model in blender, note the 3 different cloth meshes and their different amount of vertices. This obviously translates directly into the quality of the cloth you get. If you create a cloth with more vertices it will look nicer, but it would also be slower to simulate. I have yet to notice any dip in FPS but I haven't done a proper stress test yet.

i.imgur.com/dcQQt02.pngi.imgur.com/8bchm07.png
And here is a video of it in action:

I'm going to clean the code up and sort out any remaining bugs, as well review my changes to the TSSkinMesh class to try and have as little impact on the external engine code as possible. Unfortunately it can't be entirely avoided, as my cloth code overwrites the vertex buffer of the mesh. I'm quite confident I'll have it online tonight now that it's working. I'll also include some .blend files in the test project folder to use as examples as well.
#31
01/28/2014 (3:41 pm)
Nice work, looks great :-)

While i see your concern with the TSSkinMesh class if it's not breaking any current interfaces than all is sweet.
#32
01/28/2014 (4:33 pm)
The vehicle class i am porting over from my tank project will work differently to the current vehicle stuff in T3D, the current way requires one wheel to be created separately and that is placed via helper node positions. I don't like this way and I do it differently.

Screenshot of a tank chassis in blender:

i.imgur.com/9T87GqO.png
Basically you create your vehicle and just skin each wheel and name it appropriately and the code searches through and finds the node names,the above video uses WD_L or WD_R meaning WheelDrive_Left or WheelDrive_Right but i'll change this to be a little more friendly. You don't need to create a collision shape in the mesh for the wheels as it does that automatically from the supplied width and radius. I'll post more details when it get's further along.


#33
01/28/2014 (7:36 pm)
That's looking awesome! And easy to use as well. You should rename the video to something like "Torque3D PhysX 3.3 - Vehicle Chassis Test" so they all group together and come up when you search for physx 3.3 on youtube.

I've squashed all the bugs I'm aware of in my cloth system, so I'm preparing to push it now.
#34
01/28/2014 (8:57 pm)
My cloth shape code has just been pushed. It's world editor friendly and I've added a PhysX 3.3 category with cloth plane and shape. You can just add an empty cloth shape, then pick the shape file and place it. I haven't moved any of these changes into the templates yet so you can only use the world editor in the testPhysX sample project.

All meshes in the shape other than the cloth currently lack collision. That's my next task. I'm hoping to have the objects have the ability to either be static or able to be knocked around and still have the cloth stay with them. Nvidia included this nice little function called setTargetPose() that generates acceleration in the cloth due to the position change so it shouldn't be too difficult. This will lay the groundwork for character clothing.

I've included a test level to showcase the cloth and the .blend files for the two cloth objects are in "My Projects/testPhysX/blender sources/". I figure we should follow suit to how nVidia put together their SDK and include a set of open source samples for each feature so people can try working code and build off of it.

This was my one complaint about the Pacific demo. While it was great looking and showcased the engines features, it didn't really help all that much with teaching people to use the features it was showcasing.
#35
01/28/2014 (9:41 pm)
Yeah couldn't agree more, while it's always nice to see what the product your using is capable of it's far more useful for learning purposes how these features are actually used.

Hey while i'm posting, does anyone reading here have a nice car model they wouldn't mind donating so i can use for the vehicle part of this project? While i can use the cheetah that ships with the T3D as a base, i would prefer a nice looking car for demonstration purposes, doesn't have to be rigged or anything like as i can take care of that.
#36
01/29/2014 (2:24 am)
I have also started work on adding support for this plugin to the T3D project manager/auto project building. I'll keep everyone updated on this too.

I think the current development branch the px3Cloth* files in the testPhysx3 project point to the wrong directory, i'll fix this up tomorrow unless andrew beats me to it.

Everyone else do try this plugin out and report any problems or anything else you find, even feature requests are fine :-)
#37
01/29/2014 (6:25 pm)
Sample project has been moved to it's own repository:
github.com/andr3wmac/Torque3D-PhysX-Samples

Which mean's you can also now download just the samples binaries. You can try them out without needing to sign up for the Nvidia developer program. Link here:
github.com/andr3wmac/Torque3D-PhysX-Samples/archive/master.zip

I've updated my cloth quite a bit. In the pursuit of collision with the rest of the mesh I ended up building cloth support right into TSStatic. It seemed foolish to have a Px3Static class that was 15 lines of code when I could just move it right into TSStatic. So, now it's an option "enableCloth" and it runs through a generic PhysicsCloth class created using the physics manager. If PhysX3 is removed, it won't break the TSStatic class. If the mesh is setup correctly, just browse to it under meshes in the world editor, double click, place it, check off "enableCloth" and when you play the scene it will be waving around. TSStatic features like Visible Mesh collision and Collision Mesh are still supported. Scale is currently not working.

I've also added an "enablePhysicsRep" option to the TSStatic class. It defaults to true because it only needs to be disabled in certain scenarios. This option is useful to disable if you don't want the cloth colliding with the mesh. Especially useful if parts of the cloth mesh are inside the non-cloth mesh parts, as PhysX will push these out when the scene simulates.

The second reason I've added it is because I plan to spread the option across everything in the engine that has a PhysicsRep automatically created. So, once a scene is created, you could go through each item and turn off their physics representations. If your player isn't using PhysicsCollision then it won't have any impact on collision. It will, however, reduce the complexity of the physics scene. This is especially useful if you're only using PhysX for cloth, as having a physics representation of the terrain and all the static objects is useless if the cloth never touches it.
#38
01/29/2014 (7:01 pm)
I uploaded a few fixes etc to add support for physx 3 plugin with the project manager. Should make it very simple now for people to test and try out the plugin.
#39
01/30/2014 (5:48 am)
I have forked the project manager too as i had to make a few small changes to better support the physx3 plugin. It can be found here github.com/rextimmy/Torque3D-ProjectManager/tree/development
#40
01/30/2014 (6:34 am)
Hey - just a note: First bullet fired causes a hit in Torque no matter which physics system you're using. Can't imagine why though.