Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/physics/rigidbody_object.c
| Context not available. | |||||
| * | * | ||||
| * The Original Code is: all of this file. | * The Original Code is: all of this file. | ||||
| * | * | ||||
| * Contributor(s): Joshua Leung, Sergej Reich | * Contributor(s): Joshua Leung, Sergej Reich, Martin Felke | ||||
| * | * | ||||
| * ***** END GPL LICENSE BLOCK ***** | * ***** END GPL LICENSE BLOCK ***** | ||||
| */ | */ | ||||
| Context not available. | |||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "BKE_rigidbody.h" | #include "BKE_rigidbody.h" | ||||
| #include "BKE_DerivedMesh.h" | |||||
| #include "BKE_cdderivedmesh.h" | |||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "RNA_define.h" | #include "RNA_define.h" | ||||
| Context not available. | |||||
| { | { | ||||
| if (ob->rigidbody_object) { | if (ob->rigidbody_object) { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| DerivedMesh* dm_ob; | |||||
| float volume; /* m^3 */ | float volume; /* m^3 */ | ||||
| float mass; /* kg */ | float mass; /* kg */ | ||||
| Context not available. | |||||
| /* mass is calculated from the approximate volume of the object, | /* mass is calculated from the approximate volume of the object, | ||||
| * and the density of the material we're simulating | * and the density of the material we're simulating | ||||
| */ | */ | ||||
| BKE_rigidbody_calc_volume(ob, &volume); | |||||
| if (ob->type == OB_MESH) { | |||||
aligorith: Ugh! This conditional here smells of leaking implementation detail all over the show.
If you… | |||||
Not Done Inline ActionsI need to distinguish here between Mesh and Non-Mesh types, because the Fracture modifier can directly operate on Curves, Surfaces and Font objects as well, it internally converts them to derivedmesh and cleans that a bit up. scorpion81: I need to distinguish here between Mesh and Non-Mesh types, because the Fracture modifier can… | |||||
| /* if we have a mesh, determine its volume */ | |||||
| dm_ob = CDDM_from_mesh(ob->data); | |||||
Not Done Inline Actions
sergey: - You don't free the DM.
- I'm not even sure why you need to create DM here. | |||||
| volume = BKE_rigidbody_calc_volume(dm_ob, ob->rigidbody_object); | |||||
| } | |||||
| else { | |||||
| float dim[3]; | |||||
| /* else get object boundbox as last resort, | |||||
| * because fracture modifier can operate on non-mesh objects too | |||||
| * and there we need a fallback volume of the "whole" object as well*/ | |||||
| BKE_object_dimensions_get(ob, dim); | |||||
| volume = dim[0] * dim[1] * dim[2]; | |||||
| } | |||||
| mass = volume * density; | mass = volume * density; | ||||
| /* use RNA-system to change the property and perform all necessary changes */ | /* use RNA-system to change the property and perform all necessary changes */ | ||||
| Context not available. | |||||
Ugh! This conditional here smells of leaking implementation detail all over the show.
If you must retain the ability to directly pass a mesh + rigidbody in (for the shards), I'd rather have a method for that named BKE_reigidbody_calc_mesh_volume(). BKE_rigidbody_calc_volume() would then still take its current args,