Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/rigidbody.c
| Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_library_query.h" | #include "BKE_library_query.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_pointcache.h" | #include "BKE_pointcache.h" | ||||
| #include "BKE_rigidbody.h" | #include "BKE_rigidbody.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "DEG_depsgraph_query.h" | |||||
| /* ************************************** */ | /* ************************************** */ | ||||
| /* Memory Management */ | /* Memory Management */ | ||||
| /* Freeing Methods --------------------- */ | /* Freeing Methods --------------------- */ | ||||
| #ifndef WITH_BULLET | #ifndef WITH_BULLET | ||||
| ▲ Show 20 Lines • Show All 912 Lines • ▼ Show 20 Lines | if (rbw->objects) { | ||||
| int i; | int i; | ||||
| for (i = 0; i < rbw->numbodies; i++) { | for (i = 0; i < rbw->numbodies; i++) { | ||||
| func(rbw, (ID **)&rbw->objects[i], userdata, IDWALK_CB_NOP); | func(rbw, (ID **)&rbw->objects[i], userdata, IDWALK_CB_NOP); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Add rigid body settings to the specified object */ | /* Add rigid body settings to the specified object */ | ||||
| RigidBodyOb *BKE_rigidbody_create_object(Scene *scene, Object *ob, short type) | RigidBodyOb *BKE_rigidbody_create_object(Depsgraph *depsgraph, Scene *scene, Object *ob, short type) | ||||
| { | { | ||||
| RigidBodyOb *rbo; | RigidBodyOb *rbo; | ||||
| RigidBodyWorld *rbw = scene->rigidbody_world; | RigidBodyWorld *rbw = scene->rigidbody_world; | ||||
| /* sanity checks | /* sanity checks | ||||
| * - rigidbody world must exist | * - rigidbody world must exist | ||||
| * - object must exist | * - object must exist | ||||
| * - cannot add rigid body if it already exists | * - cannot add rigid body if it already exists | ||||
| */ | */ | ||||
| if (ob == NULL || (ob->rigidbody_object != NULL)) | if (ob == NULL || (ob->rigidbody_object != NULL)) | ||||
| return NULL; | return NULL; | ||||
| const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | |||||
| /* create new settings data, and link it up */ | /* create new settings data, and link it up */ | ||||
| rbo = MEM_callocN(sizeof(RigidBodyOb), "RigidBodyOb"); | rbo = MEM_callocN(sizeof(RigidBodyOb), "RigidBodyOb"); | ||||
| /* set default settings */ | /* set default settings */ | ||||
| rbo->type = type; | rbo->type = type; | ||||
| rbo->mass = 1.0f; | rbo->mass = 1.0f; | ||||
| Show All 17 Lines | RigidBodyOb *BKE_rigidbody_create_object(Depsgraph *depsgraph, Scene *scene, Object *ob, short type) | ||||
| if (type == RBO_TYPE_ACTIVE) | if (type == RBO_TYPE_ACTIVE) | ||||
| rbo->shape = RB_SHAPE_CONVEXH; | rbo->shape = RB_SHAPE_CONVEXH; | ||||
| else | else | ||||
| rbo->shape = RB_SHAPE_TRIMESH; | rbo->shape = RB_SHAPE_TRIMESH; | ||||
| rbo->mesh_source = RBO_MESH_DEFORM; | rbo->mesh_source = RBO_MESH_DEFORM; | ||||
| /* set initial transform */ | /* set initial transform */ | ||||
| mat4_to_loc_quat(rbo->pos, rbo->orn, ob->obmat); | mat4_to_loc_quat(rbo->pos, rbo->orn, ob_eval->obmat); | ||||
| /* flag cache as outdated */ | /* flag cache as outdated */ | ||||
| BKE_rigidbody_cache_reset(rbw); | BKE_rigidbody_cache_reset(rbw); | ||||
| /* return this object */ | /* return this object */ | ||||
| return rbo; | return rbo; | ||||
| } | } | ||||
| /* Add rigid body constraint to the specified object */ | /* Add rigid body constraint to the specified object */ | ||||
| RigidBodyCon *BKE_rigidbody_create_constraint(Scene *scene, Object *ob, short type) | RigidBodyCon *BKE_rigidbody_create_constraint(Depsgraph *UNUSED(depsgraph), Scene *scene, Object *ob, short type) | ||||
| { | { | ||||
| RigidBodyCon *rbc; | RigidBodyCon *rbc; | ||||
| RigidBodyWorld *rbw = scene->rigidbody_world; | RigidBodyWorld *rbw = scene->rigidbody_world; | ||||
| /* sanity checks | /* sanity checks | ||||
| * - rigidbody world must exist | * - rigidbody world must exist | ||||
| * - object must exist | * - object must exist | ||||
| * - cannot add constraint if it already exists | * - cannot add constraint if it already exists | ||||
| ▲ Show 20 Lines • Show All 299 Lines • ▼ Show 20 Lines | if (ob->type == OB_MESH) { | ||||
| /* update transformation matrix of the object so we don't get a frame of lag for simple animations */ | /* update transformation matrix of the object so we don't get a frame of lag for simple animations */ | ||||
| BKE_object_where_is_calc(depsgraph, scene, ob); | BKE_object_where_is_calc(depsgraph, scene, ob); | ||||
| if (rbo == NULL) { | if (rbo == NULL) { | ||||
| /* Since this object is included in the sim group but doesn't have | /* Since this object is included in the sim group but doesn't have | ||||
| * rigid body settings (perhaps it was added manually), add! | * rigid body settings (perhaps it was added manually), add! | ||||
| * - assume object to be active? That is the default for newly added settings... | * - assume object to be active? That is the default for newly added settings... | ||||
| */ | */ | ||||
| ob->rigidbody_object = BKE_rigidbody_create_object(scene, ob, RBO_TYPE_ACTIVE); | ob->rigidbody_object = BKE_rigidbody_create_object(depsgraph, scene, ob, RBO_TYPE_ACTIVE); | ||||
| rigidbody_validate_sim_object(rbw, ob, true); | rigidbody_validate_sim_object(rbw, ob, true); | ||||
| rbo = ob->rigidbody_object; | rbo = ob->rigidbody_object; | ||||
| } | } | ||||
| else { | else { | ||||
| /* perform simulation data updates as tagged */ | /* perform simulation data updates as tagged */ | ||||
| /* refresh object... */ | /* refresh object... */ | ||||
| if (rebuild) { | if (rebuild) { | ||||
| Show All 30 Lines | FOREACH_GROUP_OBJECT_BEGIN(rbw->constraints, ob) | ||||
| RigidBodyCon *rbc = ob->rigidbody_constraint; | RigidBodyCon *rbc = ob->rigidbody_constraint; | ||||
| /* update transformation matrix of the object so we don't get a frame of lag for simple animations */ | /* update transformation matrix of the object so we don't get a frame of lag for simple animations */ | ||||
| BKE_object_where_is_calc(depsgraph, scene, ob); | BKE_object_where_is_calc(depsgraph, scene, ob); | ||||
| if (rbc == NULL) { | if (rbc == NULL) { | ||||
| /* Since this object is included in the group but doesn't have | /* Since this object is included in the group but doesn't have | ||||
| * constraint settings (perhaps it was added manually), add! | * constraint settings (perhaps it was added manually), add! | ||||
| */ | */ | ||||
| ob->rigidbody_constraint = BKE_rigidbody_create_constraint(scene, ob, RBC_TYPE_FIXED); | ob->rigidbody_constraint = BKE_rigidbody_create_constraint(depsgraph, scene, ob, RBC_TYPE_FIXED); | ||||
| rigidbody_validate_sim_constraint(rbw, ob, true); | rigidbody_validate_sim_constraint(rbw, ob, true); | ||||
| rbc = ob->rigidbody_constraint; | rbc = ob->rigidbody_constraint; | ||||
| } | } | ||||
| else { | else { | ||||
| /* perform simulation data updates as tagged */ | /* perform simulation data updates as tagged */ | ||||
| if (rebuild) { | if (rebuild) { | ||||
| /* World has been rebuilt so rebuild constraint */ | /* World has been rebuilt so rebuild constraint */ | ||||
| ▲ Show 20 Lines • Show All 241 Lines • ▼ Show 20 Lines | |||||
| struct RigidBodyCon *BKE_rigidbody_copy_constraint(const Object *ob, const int flag) { return NULL; } | struct RigidBodyCon *BKE_rigidbody_copy_constraint(const Object *ob, const int flag) { return NULL; } | ||||
| void BKE_rigidbody_validate_sim_world(Scene *scene, RigidBodyWorld *rbw, bool rebuild) {} | void BKE_rigidbody_validate_sim_world(Scene *scene, RigidBodyWorld *rbw, bool rebuild) {} | ||||
| void BKE_rigidbody_calc_volume(Object *ob, float *r_vol) { if (r_vol) *r_vol = 0.0f; } | void BKE_rigidbody_calc_volume(Object *ob, float *r_vol) { if (r_vol) *r_vol = 0.0f; } | ||||
| void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_center[3]) { zero_v3(r_center); } | void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_center[3]) { zero_v3(r_center); } | ||||
| struct RigidBodyWorld *BKE_rigidbody_create_world(Scene *scene) { return NULL; } | struct RigidBodyWorld *BKE_rigidbody_create_world(Scene *scene) { return NULL; } | ||||
| struct RigidBodyWorld *BKE_rigidbody_world_copy(RigidBodyWorld *rbw, const int flag) { return NULL; } | struct RigidBodyWorld *BKE_rigidbody_world_copy(RigidBodyWorld *rbw, const int flag) { return NULL; } | ||||
| void BKE_rigidbody_world_groups_relink(struct RigidBodyWorld *rbw) {} | void BKE_rigidbody_world_groups_relink(struct RigidBodyWorld *rbw) {} | ||||
| void BKE_rigidbody_world_id_loop(struct RigidBodyWorld *rbw, RigidbodyWorldIDFunc func, void *userdata) {} | void BKE_rigidbody_world_id_loop(struct RigidBodyWorld *rbw, RigidbodyWorldIDFunc func, void *userdata) {} | ||||
| struct RigidBodyOb *BKE_rigidbody_create_object(Scene *scene, Object *ob, short type) { return NULL; } | struct RigidBodyOb *BKE_rigidbody_create_object(Depsgraph *depsgraph, Scene *scene, Object *ob, short type) { return NULL; } | ||||
| struct RigidBodyCon *BKE_rigidbody_create_constraint(Scene *scene, Object *ob, short type) { return NULL; } | struct RigidBodyCon *BKE_rigidbody_create_constraint(Depsgraph *depsgraph, Scene *scene, Object *ob, short type) { return NULL; } | ||||
| struct RigidBodyWorld *BKE_rigidbody_get_world(Scene *scene) { return NULL; } | struct RigidBodyWorld *BKE_rigidbody_get_world(Scene *scene) { return NULL; } | ||||
| void BKE_rigidbody_remove_object(Scene *scene, Object *ob) {} | void BKE_rigidbody_remove_object(Scene *scene, Object *ob) {} | ||||
| void BKE_rigidbody_remove_constraint(Scene *scene, Object *ob) {} | void BKE_rigidbody_remove_constraint(Scene *scene, Object *ob) {} | ||||
| void BKE_rigidbody_sync_transforms(RigidBodyWorld *rbw, Object *ob, float ctime) {} | void BKE_rigidbody_sync_transforms(RigidBodyWorld *rbw, Object *ob, float ctime) {} | ||||
| void BKE_rigidbody_aftertrans_update(Object *ob, float loc[3], float rot[3], float quat[4], float rotAxis[3], float rotAngle) {} | void BKE_rigidbody_aftertrans_update(Object *ob, float loc[3], float rot[3], float quat[4], float rotAxis[3], float rotAngle) {} | ||||
| bool BKE_rigidbody_check_sim_running(RigidBodyWorld *rbw, float ctime) { return false; } | bool BKE_rigidbody_check_sim_running(RigidBodyWorld *rbw, float ctime) { return false; } | ||||
| void BKE_rigidbody_cache_reset(RigidBodyWorld *rbw) {} | void BKE_rigidbody_cache_reset(RigidBodyWorld *rbw) {} | ||||
| void BKE_rigidbody_rebuild_world(struct Depsgraph *depsgraph, Scene *scene, float ctime) {} | void BKE_rigidbody_rebuild_world(struct Depsgraph *depsgraph, Scene *scene, float ctime) {} | ||||
| ▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines | |||||