Skip to content

Commit 9c7559e

Browse files
committed
Allow polygon collision to be optionally disabled
1 parent 413bac2 commit 9c7559e

36 files changed

+58
-7
lines changed

.sconsign.dblite

0 Bytes
Binary file not shown.
Binary file not shown.

project/examples/7_classic_platformer/main.tscn

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ sources/1 = SubResource("TileSetAtlasSource_qdrbb")
5656
metadata/_edit_horizontal_guides_ = [352.0]
5757

5858
[node name="QWorldNode" type="QWorldNode" parent="."]
59+
debug_renderer = false
5960
enable_debug_mouse_interactions = true
6061

6162
[node name="background" type="ColorRect" parent="."]
@@ -132,22 +133,21 @@ data_uv_maps = Array[PackedInt32Array]([PackedInt32Array(0, 1, 3), PackedInt32Ar
132133

133134
[node name="Water" type="QSoftBodyNode" parent="."]
134135
rigidity = 0.01
135-
shape_matching = true
136-
shape_matching_rate = 0.02
137136
use_custom_gravity = true
138137
position = Vector2(640, 480)
139138

140139
[node name="QMeshAdvancedNode" type="QMeshAdvancedNode" parent="Water"]
141-
enable_springs = false
140+
disable_polygon_for_collisions = true
142141
enable_vector_rendering = true
143142
fill_color = Color(0.146318, 0.398419, 0.80446, 0.803922)
144143
enable_stroke = true
145144
enable_curved_corners = true
146-
curve_length = 5.0
145+
curve_length = 4.0
146+
enable_particle_rendering = false
147147
data_particle_positions = PackedVector2Array(-73, -20, -25, -20, 31, -20, 87, -20, 151, -20, -72, 16, -24, 16, 32, 16, 88, 16, 152, 16, -72, 56, -24, 56, 32, 56, 88, 56, 152, 56, -72, 104, -24, 104, 32, 104, 88, 104, 152, 104)
148-
data_particle_radius = PackedFloat32Array(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5)
148+
data_particle_radius = PackedFloat32Array(18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18)
149149
data_particle_is_internal = PackedByteArray("AAAAAAAAAQEBAAABAQEAAAAAAAA=")
150-
data_particle_is_enabled = PackedByteArray("AAEBAQAAAQEBAAABAQEAAAAAAAA=")
150+
data_particle_is_enabled = PackedByteArray("AAEBAQAAAAEBAAAAAQEAAAAAAAA=")
151151
data_particle_is_lazy = PackedByteArray("AAEBAQAAAQEBAAABAQEAAAAAAAA=")
152152
data_springs = Array[PackedInt32Array]([PackedInt32Array(0, 1), PackedInt32Array(1, 2), PackedInt32Array(2, 3), PackedInt32Array(3, 4), PackedInt32Array(4, 9), PackedInt32Array(9, 14), PackedInt32Array(14, 19), PackedInt32Array(15, 10), PackedInt32Array(10, 5), PackedInt32Array(5, 0)])
153153
data_internal_springs = Array[PackedInt32Array]([PackedInt32Array(0, 6), PackedInt32Array(1, 7), PackedInt32Array(1, 5), PackedInt32Array(1, 6), PackedInt32Array(2, 8), PackedInt32Array(2, 6), PackedInt32Array(2, 7), PackedInt32Array(3, 9), PackedInt32Array(3, 7), PackedInt32Array(3, 8), PackedInt32Array(4, 8), PackedInt32Array(6, 5), PackedInt32Array(5, 11), PackedInt32Array(7, 6), PackedInt32Array(6, 12), PackedInt32Array(6, 10), PackedInt32Array(6, 11), PackedInt32Array(8, 7), PackedInt32Array(7, 13), PackedInt32Array(7, 11), PackedInt32Array(7, 12), PackedInt32Array(9, 8), PackedInt32Array(8, 14), PackedInt32Array(8, 12), PackedInt32Array(8, 13), PackedInt32Array(9, 13), PackedInt32Array(11, 10), PackedInt32Array(10, 16), PackedInt32Array(12, 11), PackedInt32Array(11, 17), PackedInt32Array(11, 15), PackedInt32Array(11, 16), PackedInt32Array(13, 12), PackedInt32Array(12, 18), PackedInt32Array(12, 16), PackedInt32Array(12, 17), PackedInt32Array(14, 13), PackedInt32Array(13, 19), PackedInt32Array(13, 17), PackedInt32Array(13, 18), PackedInt32Array(14, 18), PackedInt32Array(16, 15), PackedInt32Array(17, 16), PackedInt32Array(18, 17), PackedInt32Array(19, 18)])
384 Bytes
Binary file not shown.
344 Bytes
Binary file not shown.

src/QuarkPhysics/qareabody.os

384 Bytes
Binary file not shown.

src/QuarkPhysics/qbody.os

384 Bytes
Binary file not shown.

src/QuarkPhysics/qcollision.os

608 Bytes
Binary file not shown.

src/QuarkPhysics/qjoint.os

240 Bytes
Binary file not shown.

src/QuarkPhysics/qmanifold.os

312 Bytes
Binary file not shown.

src/QuarkPhysics/qmesh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void QMesh::UpdateCollisionBehavior()
6666
return;
6767

6868

69-
if(GetPolygonParticleCount()>0){
69+
if(GetPolygonParticleCount()>0 && disablePolygonForCollisions==false){
7070
if(ownerBody->simulationModel==QBody::SimulationModels::RIGID_BODY){
7171
collisionBehavior=CollisionBehaviors::POLYGONS;
7272
}else{

src/QuarkPhysics/qmesh.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct QMesh
6767
QBody *ownerBody=nullptr;
6868
CollisionBehaviors collisionBehavior=CollisionBehaviors::CIRCLES;
6969
vector<vector<int>> UVMaps=vector<vector<int>>();
70+
bool disablePolygonForCollisions=false;
7071

7172
bool collisionBehaviorNeedsUpdate=false;
7273

@@ -242,6 +243,15 @@ struct QMesh
242243
}
243244
return collisionBehavior;
244245
}
246+
/** Returns whether the polygon is disabled for collisions.
247+
248+
The polygon defined for the mesh is disabled during collision behavior determination and
249+
is not used in collisions. As a result, collisions are handled by the particles.
250+
The polygon can optionally be used for rendering purposes and other external
251+
purposes in the related simulation. */
252+
bool GetPolygonForCollisionsDisabled(){
253+
return disablePolygonForCollisions;
254+
}
245255

246256

247257
//General Set Methods
@@ -269,6 +279,20 @@ struct QMesh
269279
rotation=value;
270280
return this;
271281
}
282+
283+
/** Sets whether the polygon is disabled for collisions.
284+
* The polygon defined for the mesh is disabled during collision behavior determination and
285+
* is not used in collisions. As a result, collisions are handled by the particles.
286+
* The polygon can optionally be used for rendering purposes and other external
287+
* purposes in the related simulation.
288+
* @param value The boolean value to set.
289+
* @return QMesh* A pointer to mesh itself.
290+
*/
291+
QMesh *SetPolygonForCollisionsDisabled(bool value){
292+
disablePolygonForCollisions=value;
293+
collisionBehaviorNeedsUpdate=true;
294+
return this;
295+
}
272296

273297

274298

src/QuarkPhysics/qmesh.os

-2.8 KB
Binary file not shown.

src/QuarkPhysics/qparticle.os

384 Bytes
Binary file not shown.

src/QuarkPhysics/qraycast.os

232 Bytes
Binary file not shown.

src/QuarkPhysics/qrigidbody.os

384 Bytes
Binary file not shown.

src/QuarkPhysics/qsoftbody.os

384 Bytes
Binary file not shown.

src/QuarkPhysics/qspring.os

384 Bytes
Binary file not shown.

src/QuarkPhysics/qworld.os

384 Bytes
Binary file not shown.

src/qareabody_node.os

768 Bytes
Binary file not shown.

src/qbody_node.os

760 Bytes
Binary file not shown.

src/qjoint_object.os

760 Bytes
Binary file not shown.

src/qmesh_advanced_node.os

688 Bytes
Binary file not shown.

src/qmesh_circle_node.os

768 Bytes
Binary file not shown.

src/qmesh_node.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ void QMeshNode::on_post_enter_tree() {
586586
}
587587
set_mesh_position(get_position());
588588
set_mesh_rotation(get_rotation());
589+
590+
//Re-Set Properties of Mesh Object
591+
meshObject->SetPolygonForCollisionsDisabled(disablePolygonForCollisions);
592+
589593
if(ownerBodyNode==nullptr){
590594
QBodyNode *bodyNode=QBodyNode::type_cast(get_parent());
591595
if(bodyNode!=nullptr){
@@ -773,12 +777,14 @@ void QMeshNode::_bind_methods()
773777
ClassDB::bind_method(D_METHOD("get_owner_body_node"),&QMeshNode::get_owner_body_node );
774778
ClassDB::bind_method(D_METHOD("get_springs_enabled"),&QMeshNode::get_springs_enabled );
775779
ClassDB::bind_method(D_METHOD("get_polygons_enabled"),&QMeshNode::get_polygons_enabled );
780+
ClassDB::bind_method(D_METHOD("get_polygon_for_collision_disabled"),&QMeshNode::get_polygon_for_collision_disabled );
776781
//Set
777782
ClassDB::bind_method(D_METHOD("set_mesh_position"),&QMeshNode::set_mesh_position );
778783
ClassDB::bind_method(D_METHOD("set_mesh_global_position"),&QMeshNode::set_mesh_global_position );
779784
ClassDB::bind_method(D_METHOD("set_mesh_rotation"),&QMeshNode::set_mesh_rotation );
780785
ClassDB::bind_method(D_METHOD("set_springs_enabled","value"),&QMeshNode::set_springs_enabled );
781786
ClassDB::bind_method(D_METHOD("set_polygons_enabled","value"),&QMeshNode::set_polygons_enabled );
787+
ClassDB::bind_method(D_METHOD("set_polygon_for_collision_disabled","value"),&QMeshNode::set_polygon_for_collision_disabled );
782788
//Particle Operations
783789
ClassDB::bind_method(D_METHOD("add_particle","particle_object"),&QMeshNode::add_particle );
784790
ClassDB::bind_method(D_METHOD("remove_particle","particle_object"),&QMeshNode::remove_particle );
@@ -894,6 +900,8 @@ void QMeshNode::_bind_methods()
894900

895901

896902
//Props
903+
ADD_PROPERTY( PropertyInfo(Variant::BOOL , "disable_polygon_for_collisions"), "set_polygon_for_collision_disabled","get_polygon_for_collision_disabled" );
904+
897905
ADD_PROPERTY( PropertyInfo(Variant::BOOL , "enable_springs"), "set_springs_enabled","get_springs_enabled" );
898906
ADD_PROPERTY( PropertyInfo(Variant::BOOL , "enable_polygons"), "set_polygons_enabled","get_polygons_enabled" );
899907

@@ -1021,6 +1029,11 @@ float QMeshNode::get_min_angle_constraint_of_polygon() {
10211029
return meshObject->GetMinAngleConstraintOfPolygon();
10221030
}
10231031

1032+
bool QMeshNode::get_polygon_for_collision_disabled()
1033+
{
1034+
return disablePolygonForCollisions;
1035+
}
1036+
10241037
QBodyNode * QMeshNode::get_owner_body_node(){
10251038
return ownerBodyNode;
10261039
}
@@ -1058,6 +1071,15 @@ QMeshNode *QMeshNode::set_min_angle_constraint_of_polygon(bool value) {
10581071
return this;
10591072
}
10601073

1074+
QMeshNode *QMeshNode::set_polygon_for_collision_disabled(bool value)
1075+
{
1076+
disablePolygonForCollisions=value;
1077+
if ( Engine::get_singleton()->is_editor_hint()==false && meshObject!=nullptr ){
1078+
meshObject->SetPolygonForCollisionsDisabled(value);
1079+
}
1080+
return this;
1081+
}
1082+
10611083
//Particle Operations
10621084
QMeshNode *QMeshNode::add_particle(Ref<QParticleObject> particle_object) {
10631085
if(particle_object.is_valid()==false ){

src/qmesh_node.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class QMeshNode: public Node2D{
5252
bool enableSprings=true;
5353
bool enablePolygons=true;
5454
float particleRadius=0.5f;
55+
bool disablePolygonForCollisions=false;
5556

5657
QMesh *meshObject=nullptr;
5758
QBodyNode *ownerBodyNode=nullptr;
@@ -171,7 +172,10 @@ class QMeshNode: public Node2D{
171172
Array get_matching_particle_positions(TypedArray<QParticleObject> particle_collection,Vector2 target_position,float target_rotation);
172173
float get_min_angle_constraint_of_polygon();
173174

175+
bool get_polygon_for_collision_disabled();
176+
174177
QBodyNode *get_owner_body_node();
178+
175179

176180
//Set Methods
177181
QMeshNode *set_mesh_position(Vector2 value);
@@ -180,6 +184,7 @@ class QMeshNode: public Node2D{
180184
QMeshNode *set_springs_enabled(bool value);
181185
QMeshNode *set_polygons_enabled(bool value);
182186
QMeshNode *set_min_angle_constraint_of_polygon(bool value);
187+
QMeshNode *set_polygon_for_collision_disabled(bool value);
183188

184189

185190
//Particle Operations

0 commit comments

Comments
 (0)