[Bf-blender-cvs] [38d5aa3a58d] fracture_modifier: expose rigidbody apply_force and apply_torque to python via rna function

Martin Felke noreply at git.blender.org
Fri Jan 25 18:12:30 CET 2019


Commit: 38d5aa3a58d780a1e76e5fd373d1da1bc6bac900
Author: Martin Felke
Date:   Fri Jan 25 18:11:57 2019 +0100
Branches: fracture_modifier
https://developer.blender.org/rB38d5aa3a58d780a1e76e5fd373d1da1bc6bac900

expose rigidbody apply_force and apply_torque to python via rna function

===================================================================

M	intern/rigidbody/RBI_api.h
M	intern/rigidbody/rb_bullet_api.cpp
M	source/blender/makesrna/intern/rna_rigidbody.c

===================================================================

diff --git a/intern/rigidbody/RBI_api.h b/intern/rigidbody/RBI_api.h
index a73faf4d87c..00b88439fe4 100644
--- a/intern/rigidbody/RBI_api.h
+++ b/intern/rigidbody/RBI_api.h
@@ -237,6 +237,7 @@ void RB_body_apply_central_force(rbRigidBody *body, const float v_in[3]);
 
 void RB_body_apply_impulse(rbRigidBody* object, const float impulse[3], const float pos[3]);
 void RB_body_apply_force(rbRigidBody* object, const float force[3], const float pos[3]);
+void RB_body_apply_torque(rbRigidBody* object, const float torque[3]);
 
 /* ********************************** */
 /* Collision Shape Methods */
diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp
index 7c8933cc29c..c5785fb69fa 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -1614,6 +1614,14 @@ void RB_body_apply_force(rbRigidBody* object, const float force[3], const float
 	body->applyForce(btVector3(force[0], force[1], force[2]), btVector3(pos[0], pos[1], pos[2]));
 }
 
+void RB_body_apply_torque(rbRigidBody* object, const float torque[3])
+{
+	btRigidBody *body = object->body;
+
+	body->applyTorque(btVector3(torque[0], torque[1], torque[2]));
+}
+
+
 /* ********************************** */
 /* Collision Shape Methods */
 
diff --git a/source/blender/makesrna/intern/rna_rigidbody.c b/source/blender/makesrna/intern/rna_rigidbody.c
index ff62e3f4597..14529559f9c 100644
--- a/source/blender/makesrna/intern/rna_rigidbody.c
+++ b/source/blender/makesrna/intern/rna_rigidbody.c
@@ -126,6 +126,25 @@ static int rna_RigidBodyCon_is_intact(RigidBodyCon *con)
 	return 0;
 }
 
+static void rna_RigidBodyOb_force_apply(RigidBodyOb* rbo, float force[3], float position[3])
+{
+#ifdef WITH_BULLET
+	if (rbo && rbo->physics_object) {
+			RB_body_apply_force(rbo->physics_object, force, position);
+	}
+#endif
+}
+
+
+static void rna_RigidBodyOb_torque_apply(RigidBodyOb* rbo, float torque[3])
+{
+#ifdef WITH_BULLET
+	if (rbo && rbo->physics_object) {
+		RB_body_apply_torque(rbo->physics_object, torque);
+	}
+#endif
+}
+
 /* ******************************** */
 
 static void rna_RigidBodyWorld_reset(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
@@ -1651,7 +1670,8 @@ static void rna_def_rigidbody_world(BlenderRNA *brna)
 static void rna_def_rigidbody_object(BlenderRNA *brna)
 {
 	StructRNA *srna;
-	PropertyRNA *prop;
+	PropertyRNA *prop, *parm;
+	FunctionRNA *func;
 	
 	
 	srna = RNA_def_struct(brna, "RigidBodyObject", NULL);
@@ -1875,6 +1895,22 @@ static void rna_def_rigidbody_object(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Randomize Margin",
 	                         "Randomize the custom collision margin for better packing when shapes stack up");
 	RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_shape_reset");
+
+
+	//expose force and torque application as RNA functions
+	func = RNA_def_function(srna, "apply_force", "rna_RigidBodyOb_force_apply");
+	parm = RNA_def_float_vector_xyz(func, "force", 3, NULL, -FLT_MAX, FLT_MAX,
+	                                "Applied Force", "The currently applied force on this rigid body",
+	                                -FLT_MIN, FLT_MAX);
+
+	parm = RNA_def_float_vector_xyz(func, "position", 3, NULL, -FLT_MAX, FLT_MAX,
+	                                "Position", "The position of the applied force on this rigid body",
+	                                -FLT_MIN, FLT_MAX);
+
+	func = RNA_def_function(srna, "apply_torque", "rna_RigidBodyOb_torque_apply");
+	parm = RNA_def_float_vector_xyz(func, "torque", 3, NULL, -FLT_MAX, FLT_MAX,
+	                                "Applied Torque", "The currently applied torque on this rigid body",
+	                                -FLT_MIN, FLT_MAX);
 }
 
 static void rna_def_rigidbody_constraint(BlenderRNA *brna)



More information about the Bf-blender-cvs mailing list