Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poor optimizations in the physics engine #7690

Closed
bkeys opened this issue Jan 31, 2017 · 17 comments
Closed

Poor optimizations in the physics engine #7690

bkeys opened this issue Jan 31, 2017 · 17 comments

Comments

@bkeys
Copy link
Contributor

bkeys commented Jan 31, 2017

Operating system or device - Godot version:
Fedora 25 (Linux)

Issue description:
Collision shapes on even simple meshes can cause serious performance hits on the smallest collisions. Here is a video of a car of mine colliding with my roads, which collision shape seems to be that of a cube, at the least a very simple mesh

It is common also for after the performance hit for the mesh to seemingly teleport elsewhere and collide right though objects.
output

Steps to reproduce:
I can create a simple scene (using non default objects like the cube), say a car and a much simpler map, and I will get similar behavior

@bkeys
Copy link
Contributor Author

bkeys commented Jan 31, 2017

Personally I understand why Godot has it's own physics engine; but I think the best long term solution to issues like this would be to eventually migrate to Bullet physics, or allow it as an option.

@razcore-rad
Copy link
Contributor

So can you provide a minimal example?

@bkeys
Copy link
Contributor Author

bkeys commented Jan 31, 2017

https://notabug.org/bkeys/DMUX/archive/master.tar.gz
In JoinGameButton.gd you can swap out which scene it loads with the castle scene, the castle scene has the same (all be it less fatal) issue.

@DriNeo
Copy link

DriNeo commented Feb 1, 2017

On your other issue about meshes, I saw an image of your truck. This image shows a over complicated collision shape.
I assume it was generated directly from the truck mesh.
I suggest to modelize a simple shape in order to generate the collision shape truck, then you can delete this mesh from the scene and keep a clean collision shape.
Maybe it's not the main solution but this is an easy optimization to do.

@Zylann
Copy link
Contributor

Zylann commented Mar 15, 2017

Just for reference, I just added collision meshes to my terrain plugin using the trimesh collision helper, and it worked like a charm: https://www.youtube.com/watch?v=531szCVfZPw
I didn't do a bunnymark benchmark on this but Cubes vs Mesh has decent performance. Maybe performance is only slow with Mesh vs Mesh?

@DjPale
Copy link

DjPale commented Aug 20, 2017

I started testing Godot 3.0 alpha1, and I can confirm that mesh-to-mesh collisions on even simple shapes gives a noticable lag. I used some of the assets from Kenney which are fairly simple, and added

  • Import an OBJ file from a Kenney pack and create a new scene for the obj-file
  • Select the mesh and use the function Create Convex Static Body
  • Change type of StaticBody to RigidBody
  • Reorganize hierarchy so that the root node in the object scene is the RigidBody, and the Mesh + Collisionshape are children of the physics node
  • When colliding with other objects of this type - there is a noticable visual jitter / frame drop

image

image

@Zireael07
Copy link
Contributor

Curious about the reorganizing hierarchy step. Does the jitter happen if the hierarchy is left as-is? Or if you have a Spatial as the root?

@DriNeo
Copy link

DriNeo commented Aug 20, 2017

I never reproduced this issue with primitive collision shapes (boxes, capsules...).

@DjPale
Copy link

DjPale commented Aug 20, 2017

I couldn't find a good way organizing it so that the mesh followed the body in this case. I had some troubles with the scene since it was inhereted and the mesh would be duplicated. Not completely sure why the generation function generates children for a mesh - seems kinda useless to me?

@DjPale
Copy link

DjPale commented Aug 20, 2017

Just built the latest version from git 30 mins ago and it was worse - may have to do with some a lot of messages with WARNING: AudioDriverRtAudio::callback: RtAudio output underflow! At: drivers\rtaudio\audio_driver_rtaudio.cpp:57 several times per second.

@DjPale
Copy link

DjPale commented Aug 20, 2017

Running latest code (35d5724) on Windows 10.
Notice the extreme lag spikes when colliding with other objects. There is also a small heightened edge on the roads themselves that causes some intererence.

If anyone's interested-here's the project:
Alpha-1-Test.zip

racing-lag

@reduz
Copy link
Member

reduz commented Aug 20, 2017 via email

@DjPale
Copy link

DjPale commented Aug 21, 2017

@reduz thanks for the reply! I also used this scene when testing the version 14c11fb97a1916759915e0e706d25a440b4f21da from the godot fork created by @AndreaCatania and switched to the Bullet-engine, but it had worse issues with collision shapes, and I experienced other periodic lags. As an example - the pylons just tunneled through the road at the beginning using the Bullet engine implementation. (It also didn't handle the huge static collision shape which is a simple scaled plate - but I now the old Godot saying - you shouldn't scale collision shapes).

So the best build I have tested for now is the "official" Alpha1. It might be a crap scene, and I have very limited experience with 3D in general - but consider this a "naive" approach to creating a 3D scene with pre-exiting assets 😄

Also, personally I have no idea how I would start constructing a simple collision shape for pre-existing meshes - it seems like a near impossible task in the editor without any tooling for assistance (like you have in 2D editors). I would probably need to do this in a 3D program?

@DriNeo
Copy link

DriNeo commented Aug 22, 2017

@DjPale In this case I created a simple shape in Wings 3D software, who is very easy to learn and to use. Then I use Godot mesh menu to create the collision shape from this mesh.

@AndreaCatania
Copy link
Contributor

@DjPale I've fixed the problem with scaled objects. Now The ground is working correctly.
The freezing that you mention with Bullet physics engine in reality are not a "Freeze", but is a problem in your GDscript. You are controlling the rotation of a rigid body in a wrong way. To know more about it and how to fix this problem check my answer on here: #10013 (comment)

@DjPale
Copy link

DjPale commented Aug 25, 2017

@AndreaCatania re-compiled your branch, works like a charm! I also used set_angular_velocity in _integrate_forces and there are no lag anymore when using the Bullet engine 👍

@kubecz3k
Copy link
Contributor

kubecz3k commented Nov 5, 2017

According to previous comment and the fact that bullet is now merged I think this one can be closed :)

@kubecz3k kubecz3k closed this as completed Nov 5, 2017
@kubecz3k kubecz3k added this to the 3.0 milestone Nov 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants