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

Convex decomposition in 2d produces bad shapes #189

Open
hakolao opened this issue Apr 23, 2024 · 2 comments
Open

Convex decomposition in 2d produces bad shapes #189

hakolao opened this issue Apr 23, 2024 · 2 comments

Comments

@hakolao
Copy link
Contributor

hakolao commented Apr 23, 2024

Convex decomposition with params produces bad shapes.

I would like to use triangle colliders, because they provide better shapes (for dynamic bodies), but they break completely with ccd enabled, which is necessary to prevent objects going within terrain. Therefore, I use convex decomposition instead. However, that sometimes produces really bad shapes.

I haven't found a combination of parameters which would fix this.

ColliderBuilder::convex_decomposition_with_params(
            &contours,
            &indices,
            &VHACDParameters {
                resolution: 32,
               FillMode::FloodFill {
                detect_cavities: true,
                detect_self_intersections: true,
              },
                ..Default::default()
            },
        )

Contour input:
image

Resulting collider:
image

Test data:

contour
[[0.1388889, 0.12962963],
[0.1388889, 0.11111111],
[0.1388889, 0.0925926],
[0.1388889, 0.074074075],
[0.1388889, 0.055555556],
[0.1388889, 0.037037037],
[0.1388889, 0.018518519],
[0.1388889, 0.0],
[0.1388889, -0.018518519],
[0.1388889, -0.037037037],
[0.1388889, -0.055555556],
[0.1388889, -0.074074075],
[0.1388889, -0.0925926],
[0.1388889, -0.11111111],
[0.1388889, -0.12962963],
[0.1388889, -0.14814815],
[0.12962963, -0.1574074],
[0.11111111, -0.1574074],
[0.0925926, -0.1574074],
[0.074074075, -0.1574074],
[0.055555556, -0.1574074],
[0.037037037, -0.1574074],
[0.018518519, -0.1574074],
[0.0, -0.1574074],
[-0.018518519, -0.1574074],
[-0.037037037, -0.1574074],
[-0.055555556, -0.1574074],
[-0.074074075, -0.1574074],
[-0.0925926, -0.1574074],
[-0.11111111, -0.1574074],
[-0.12962963, -0.1574074],
[-0.14814815, -0.1574074],
[-0.1574074, -0.14814815],
[-0.1574074, -0.12962963],
[-0.1574074, -0.11111111],
[-0.1574074, -0.0925926],
[-0.1574074, -0.074074075],
[-0.1574074, -0.055555556],
[-0.1574074, -0.037037037],
[-0.1574074, -0.018518519],
[-0.1574074, 0.0],
[-0.1574074, 0.018518519],
[-0.1574074, 0.037037037],
[-0.1574074, 0.055555556],
[-0.1574074, 0.074074075],
[-0.1574074, 0.0925926],
[-0.1574074, 0.11111111],
[-0.1574074, 0.12962963],
[-0.14814815, 0.1388889],
[-0.12962963, 0.1388889],
[-0.11111111, 0.1388889],
[-0.0925926, 0.1388889],
[-0.074074075, 0.1388889],
[-0.055555556, 0.1388889],
[-0.037037037, 0.1388889],
[-0.018518519, 0.1388889],
[0.0, 0.1388889],
[0.018518519, 0.1388889],
[0.037037037, 0.1388889],
[0.055555556, 0.1388889],
[0.074074075, 0.1388889],
[0.0925926, 0.1388889],
[0.11111111, 0.1388889],
[0.12962963, 0.1388889],
[0.1388889, 0.12962963]]

indices
[[0, 1],
[1, 2],
[2, 3],
[3, 4],
[4, 5],
[5, 6],
[6, 7],
[7, 8],
[8, 9],
[9, 10],
[10, 11],
[11, 12],
[12, 13],
[13, 14],
[14, 15],
[15, 16],
[16, 17],
[17, 18],
[18, 19],
[19, 20],
[20, 21],
[21, 22],
[22, 23],
[23, 24],
[24, 25],
[25, 26],
[26, 27],
[27, 28],
[28, 29],
[29, 30],
[30, 31],
[31, 32],
[32, 33],
[33, 34],
[34, 35],
[35, 36],
[36, 37],
[37, 38],
[38, 39],
[39, 40],
[40, 41],
[41, 42],
[42, 43],
[43, 44],
[44, 45],
[45, 46],
[46, 47],
[47, 48],
[48, 49],
[49, 50],
[50, 51],
[51, 52],
[52, 53],
[53, 54],
[54, 55],
[55, 56],
[56, 57],
[57, 58],
[58, 59],
[59, 60],
[60, 61],
[61, 62],
[62, 63],
[63, 64]]

@hakolao
Copy link
Contributor Author

hakolao commented Apr 23, 2024

The shape is correct with

FillMode::FloodFill {
                    detect_cavities: false,
                    detect_self_intersections: false,
                }

image.

But I can only use it for the initial state of the object (which can deform). For this particular object this isn't an issue though.

FillMode::SurfaceOnly gives the same result as the reported example.

@hakolao
Copy link
Contributor Author

hakolao commented Apr 23, 2024

Kinda helps if i simplify the contours (to be less lines).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant