[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
Chipmunk Physics • View topic - [SOLVED]MeshCollider in Unity?

[SOLVED]MeshCollider in Unity?

Chipmunk2D Bindings for the Unity3D engine

[SOLVED]MeshCollider in Unity?

Postby compass3 » Fri Aug 30, 2013 4:40 pm

Hi,

I just bought the Chipmunk2D for Unity yesterday. The Chipmunk2D is very good, I find it works better than PhysX.

However I can not find a lot functions in Chipmunk2D manual. For example, the cpPolyValidate function. I was trying to use the function to make Chipmunk2D work well with concave polygon. But since I can not find the function, I probably will need to implement the calculation by myself.

Is the function exist in the library(May be I just did not find it)? Or is there any functions that provide similar usages?
Will the Chipmunk2D team made it available in future for Unity?

Thanks! :D
Last edited by compass3 on Wed Sep 04, 2013 3:16 pm, edited 1 time in total.
compass3
 
Posts: 37
Joined: Fri Aug 30, 2013 4:27 pm

Re: cpPolyValidate in Unity?

Postby compass3 » Fri Aug 30, 2013 5:03 pm

I think I can just compare the Length of vert and hull, if different, the original polygon is concave. Am I right?
:lol:
compass3
 
Posts: 37
Joined: Fri Aug 30, 2013 4:27 pm

Re: cpPolyValidate in Unity?

Postby compass3 » Fri Aug 30, 2013 7:29 pm

unfortunately, the method above is not correct. Even I compared all the vertices in vert and hull I still get incorrect result.
compass3
 
Posts: 37
Joined: Fri Aug 30, 2013 4:27 pm

Re: cpPolyValidate in Unity?

Postby compass3 » Fri Aug 30, 2013 9:08 pm

sorry, may be I made a mistake. Check every vertices should work.
compass3
 
Posts: 37
Joined: Fri Aug 30, 2013 4:27 pm

Re: cpPolyValidate in Unity?

Postby slembcke » Sun Sep 01, 2013 11:01 am

Hey compass3.

So I didn't expose the cpPolyValidate() function to Unity because I didn't think people would actually want to use it. Chipmunk automatically creates a convex hull out of your input points like Unity does when using convex mesh colliders.

So there are two things that cpPolyValidate() does. It checks that the points are convex, that the points have a clockwise winding. When creating a polygon shape from a bunch of points, the hull property will contain be exactly that, the set of convex points with a clockwise winding. The point it picks for the first vertex is the hull is the leftmost one, ties are broken by picking the bottommost.

If you just want to check for concavity, then comparing the arrays' sizes is sufficient. Comparing the winding is harder since you need to figure out which is the first vertex in the hull array. Alternatively, if the array sizes are the same, you can just compare the first three vertexes in the array to check the winding. Check if the 2D cross product analog is positive or negative. (Do a 3D cross product and only look at the z-value) I forget which direction is which off the top of my head though.

All said and done... it might just be easiest to port cpPolyValidate() to Unity. It's a pretty short function, so it would only take a minute or two. https://github.com/slembcke/Chipmunk2D/ ... ape.c#L150
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: cpPolyValidate in Unity?

Postby compass3 » Tue Sep 03, 2013 7:08 am

compass3
 
Posts: 37
Joined: Fri Aug 30, 2013 4:27 pm

Re: cpPolyValidate in Unity?

Postby compass3 » Tue Sep 03, 2013 7:11 am

By the way, I detect if the polygon is convex by compare array length and each element of _vert[] and _hull. I think it is just the way similar as you mentioned. It works well. Thanks. :D
compass3
 
Posts: 37
Joined: Fri Aug 30, 2013 4:27 pm

Re: cpPolyValidate in Unity?

Postby compass3 » Tue Sep 03, 2013 7:56 am

It is also possible because of each polyshape is a monobehaviour. And I attached too much monobehaviour as component to a game object, which slow down the game. Thanks.
compass3
 
Posts: 37
Joined: Fri Aug 30, 2013 4:27 pm

Re: cpPolyValidate in Unity?

Postby slembcke » Tue Sep 03, 2013 10:51 am

So creating a lot of poly colliders from triangles isn't very efficient. Each individual shape has a pretty high cost, and polys are the most expensive shape type to use. A better solution for that is to outline your mesh using segment colliders. You need fewer of them and they are cheaper computationally. In either case, adding a radius to the polys or segments will increase the performance (10% or so is common) and smoothness of the collisions at corners and cracks.

The downside is that it does make your shapes hollow and it is possible to get stuff inside of them if they are moving fast enough or small enough to pass through in a single timestep.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: cpPolyValidate in Unity?

Postby compass3 » Wed Sep 04, 2013 2:50 pm

Last edited by compass3 on Wed Sep 04, 2013 2:55 pm, edited 1 time in total.
compass3
 
Posts: 37
Joined: Fri Aug 30, 2013 4:27 pm

Next

Return to Chipmunk2D for Unity

Who is online

Users browsing this forum: No registered users and 0 guests