From 9da4cb7157ca034b547561b5a889215066b751df Mon Sep 17 00:00:00 2001 From: Kan <70838508+kan6868@users.noreply.github.com> Date: Fri, 11 Jul 2025 08:30:53 +0700 Subject: [PATCH 1/2] Add needHull to Outline body --- external/b2Separator-cpp/b2Separator.cpp | 6 ++++-- external/b2Separator-cpp/b2Separator.h | 2 +- librtt/Rtt_LuaLibPhysics.cpp | 8 +++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/external/b2Separator-cpp/b2Separator.cpp b/external/b2Separator-cpp/b2Separator.cpp index 10188a874..82594dd79 100644 --- a/external/b2Separator-cpp/b2Separator.cpp +++ b/external/b2Separator-cpp/b2Separator.cpp @@ -36,7 +36,9 @@ bool b2Separator::SeparateAndCreateFixtures( b2Body *body, FixtureCreator_t fixture_creator, b2Vec2Vector &vertices_vec, b2Vec2 &translate, - b2Vec2 &scale ) + b2Vec2 &scale, + bool needHull + ) { bool vertices_added = false; @@ -97,7 +99,7 @@ bool b2Separator::SeparateAndCreateFixtures( b2Body *body, DEBUG_PRINT( "*** Fixture %03d : Vertex %03d : x, y: %f, %f\n", i, j, v.x, v.y ); } - bool ok = polyShape.Set( &( vertices[ 0 ] ), (int)m ); + bool ok = polyShape.Set( &( vertices[ 0 ] ), (int)m, needHull); if( ! ok ) { // Set() failed. Skip this polygon. diff --git a/external/b2Separator-cpp/b2Separator.h b/external/b2Separator-cpp/b2Separator.h index 0ae551620..7a3849506 100644 --- a/external/b2Separator-cpp/b2Separator.h +++ b/external/b2Separator-cpp/b2Separator.h @@ -46,7 +46,7 @@ class b2Separator { FixtureCreator_t fixture_creator, b2Vec2Vector &vertices_vec, b2Vec2 &translate, - b2Vec2 &scale ); + b2Vec2 &scale, bool needHull); /** * Checks whether the vertices in verticesVec can be properly distributed into the new fixtures (more specifically, it makes sure there are no overlapping segments and the vertices are in clockwise order). diff --git a/librtt/Rtt_LuaLibPhysics.cpp b/librtt/Rtt_LuaLibPhysics.cpp index 46dde3db8..556c1866c 100644 --- a/librtt/Rtt_LuaLibPhysics.cpp +++ b/librtt/Rtt_LuaLibPhysics.cpp @@ -1752,6 +1752,12 @@ InitializeFixtureUsing_Outline( lua_State *L, b2Body *body, float meter_per_pixels_scale ) { + + lua_getfield(L, lua_arg_index, "needHull"); + bool needHull = (lua_isboolean(L, -1) && + lua_toboolean(L, -1)); + lua_pop(L, 1); + lua_getfield( L, lua_arg_index, "outline" ); if( lua_istable( L, -1 ) ) { @@ -1870,7 +1876,7 @@ InitializeFixtureUsing_Outline( lua_State *L, _FixtureCreator, vertexList, translate, - scale ); + scale, needHull); if( ! ok ) { DEBUG_PRINT( "SeparateAndCreateFixtures() failed to add any fixtures." ); From 3a54ca9af44d3ff6f340da799f749396e2265051 Mon Sep 17 00:00:00 2001 From: Kan <70838508+kan6868@users.noreply.github.com> Date: Fri, 11 Jul 2025 08:31:12 +0700 Subject: [PATCH 2/2] Add needHull to shape body --- librtt/Rtt_LuaLibPhysics.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/librtt/Rtt_LuaLibPhysics.cpp b/librtt/Rtt_LuaLibPhysics.cpp index 556c1866c..bd5f1ec51 100644 --- a/librtt/Rtt_LuaLibPhysics.cpp +++ b/librtt/Rtt_LuaLibPhysics.cpp @@ -2105,6 +2105,11 @@ InitializeFixtureUsing_Shape( lua_State *L, b2Body *body, float meter_per_pixels_scale ) { + lua_getfield(L, lua_arg_index, "needHull"); + bool needHull = (lua_isboolean(L, -1) && + lua_toboolean(L, -1)); + lua_pop(L, 1); + lua_getfield( L, lua_arg_index, "shape" ); if ( lua_istable( L, -1 ) ) { @@ -2134,7 +2139,7 @@ InitializeFixtureUsing_Shape( lua_State *L, b2PolygonShape polygonDef; bool ok = polygonDef.Set( &vertexList[ 0 ], - (int)vertexList.size() ); + (int)vertexList.size(), needHull); if( ok ) { InitializeFixtureFromLua( L,