Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/rigidbody.c
| Show First 20 Lines • Show All 1,895 Lines • ▼ Show 20 Lines | static void rigidbody_update_simulation_post_step(Depsgraph *depsgraph, RigidBodyWorld *rbw) | ||||
| FOREACH_COLLECTION_OBJECT_RECURSIVE_END; | FOREACH_COLLECTION_OBJECT_RECURSIVE_END; | ||||
| } | } | ||||
| bool BKE_rigidbody_check_sim_running(RigidBodyWorld *rbw, float ctime) | bool BKE_rigidbody_check_sim_running(RigidBodyWorld *rbw, float ctime) | ||||
| { | { | ||||
| return (rbw && (rbw->flag & RBW_FLAG_MUTED) == 0 && ctime > rbw->shared->pointcache->startframe); | return (rbw && (rbw->flag & RBW_FLAG_MUTED) == 0 && ctime > rbw->shared->pointcache->startframe); | ||||
| } | } | ||||
| /* Sync rigid body and object transformations */ | bool BKE_rigidbody_is_affected_by_simulation(Object *ob) | ||||
| void BKE_rigidbody_sync_transforms(RigidBodyWorld *rbw, Object *ob, float ctime) | |||||
| { | { | ||||
| RigidBodyOb *rbo = ob->rigidbody_object; | /* Check if the object will have its transform changed by the rigidbody simulation. */ | ||||
| /* True if the shape of this object's parent is of type compound */ | /* True if the shape of this object's parent is of type compound */ | ||||
| bool obCompoundParent = (ob->parent != NULL && ob->parent->rigidbody_object != NULL && | bool obCompoundParent = (ob->parent != NULL && ob->parent->rigidbody_object != NULL && | ||||
| ob->parent->rigidbody_object->shape == RB_SHAPE_COMPOUND); | ob->parent->rigidbody_object->shape == RB_SHAPE_COMPOUND); | ||||
| /* keep original transform for kinematic and passive objects */ | RigidBodyOb *rbo = ob->rigidbody_object; | ||||
| if (ELEM(NULL, rbw, rbo) || rbo->flag & RBO_FLAG_KINEMATIC || rbo->type == RBO_TYPE_PASSIVE || | if (rbo == NULL || rbo->flag & RBO_FLAG_KINEMATIC || rbo->type == RBO_TYPE_PASSIVE || | ||||
| obCompoundParent) { | obCompoundParent) { | ||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | |||||
| /* Sync rigid body and object transformations */ | |||||
| void BKE_rigidbody_sync_transforms(RigidBodyWorld *rbw, Object *ob, float ctime) | |||||
| { | |||||
| if (!BKE_rigidbody_is_affected_by_simulation(ob)) { | |||||
| /* Don't sync transforms for objects that are not affected/changed by the simulation. */ | |||||
| return; | return; | ||||
| } | } | ||||
| RigidBodyOb *rbo = ob->rigidbody_object; | |||||
| /* use rigid body transform after cache start frame if objects is not being transformed */ | /* use rigid body transform after cache start frame if objects is not being transformed */ | ||||
| if (BKE_rigidbody_check_sim_running(rbw, ctime) && | if (BKE_rigidbody_check_sim_running(rbw, ctime) && | ||||
| !(ob->base_flag & BASE_SELECTED && G.moving & G_TRANSFORM_OBJ)) { | !(ob->base_flag & BASE_SELECTED && G.moving & G_TRANSFORM_OBJ)) { | ||||
| float mat[4][4], size_mat[4][4], size[3]; | float mat[4][4], size_mat[4][4], size[3]; | ||||
| normalize_qt(rbo->orn); // RB_TODO investigate why quaternion isn't normalized at this point | normalize_qt(rbo->orn); // RB_TODO investigate why quaternion isn't normalized at this point | ||||
| quat_to_mat4(mat, rbo->orn); | quat_to_mat4(mat, rbo->orn); | ||||
| copy_v3_v3(mat[3], rbo->pos); | copy_v3_v3(mat[3], rbo->pos); | ||||
| Show All 9 Lines | else { | ||||
| mat4_to_loc_quat(rbo->pos, rbo->orn, ob->obmat); | mat4_to_loc_quat(rbo->pos, rbo->orn, ob->obmat); | ||||
| } | } | ||||
| } | } | ||||
| /* Used when canceling transforms - return rigidbody and object to initial states */ | /* Used when canceling transforms - return rigidbody and object to initial states */ | ||||
| void BKE_rigidbody_aftertrans_update( | void BKE_rigidbody_aftertrans_update( | ||||
| Object *ob, float loc[3], float rot[3], float quat[4], float rotAxis[3], float rotAngle) | Object *ob, float loc[3], float rot[3], float quat[4], float rotAxis[3], float rotAngle) | ||||
| { | { | ||||
| bool correct_delta = BKE_rigidbody_is_affected_by_simulation(ob); | |||||
| RigidBodyOb *rbo = ob->rigidbody_object; | RigidBodyOb *rbo = ob->rigidbody_object; | ||||
| bool correct_delta = !(rbo->flag & RBO_FLAG_KINEMATIC || rbo->type == RBO_TYPE_PASSIVE); | |||||
| /* return rigid body and object to their initial states */ | /* return rigid body and object to their initial states */ | ||||
| copy_v3_v3(rbo->pos, ob->loc); | copy_v3_v3(rbo->pos, ob->loc); | ||||
| copy_v3_v3(ob->loc, loc); | copy_v3_v3(ob->loc, loc); | ||||
| if (correct_delta) { | if (correct_delta) { | ||||
| add_v3_v3(rbo->pos, ob->dloc); | add_v3_v3(rbo->pos, ob->dloc); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 320 Lines • Show Last 20 Lines | |||||