Skip to content

Commit a85cc6d

Browse files
authored
Merge pull request #8 from XiaoFFGe/blender-v4.5-release
Blender v4.5 release
2 parents 2da9738 + 7410337 commit a85cc6d

5 files changed

Lines changed: 47 additions & 2 deletions

File tree

locale/po/zh_HANS.po

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ msgid "Change the speed of the simulation for this rigid body"
149149
msgstr "更改此刚体的模拟速度"
150150

151151

152+
msgid "Influence of global gravity on this rigid body (0 = no gravity, 1 = full gravity)"
153+
msgstr "局重力对该刚体的影响(0 = 无重力,1 = 完全重力)"
154+
155+
152156
msgctxt "Operator"
153157
msgid "Selected Build Collision Mask"
154158
msgstr "从选择构建遮罩"

scripts/startup/bl_ui/properties_physics_rigidbody.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,10 @@ def draw(self, context):
376376
# XXX: settings such as activate on collision/etc.
377377

378378
col = flow.column()
379-
col.prop(rbo, "time_scale", text="Time Scale")
379+
col.prop(rbo, "time_scale", text="Speed")
380+
381+
col = flow.column()
382+
col.prop(rbo, "gravity", text="Gravity")
380383

381384
col = flow.column()
382385
col.prop(rbo, "linear_damping", text="Damping Translation")

source/blender/blenkernel/intern/rigidbody.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,8 @@ RigidBodyOb *BKE_rigidbody_create_object(Scene *scene, Object *ob, short type)
12731273
rbo->lin_damping = 0.04f;
12741274
rbo->ang_damping = 0.1f;
12751275

1276+
rbo->gravity = 1.0f; /* full gravity influence by default */
1277+
12761278
rbo->col_groups = 0;
12771279

12781280
/* use triangle meshes for passive objects
@@ -2014,13 +2016,38 @@ static void rigidbody_update_external_forces(Depsgraph *depsgraph,
20142016
Scene *scene,
20152017
RigidBodyWorld *rbw)
20162018
{
2019+
/* get world gravity */
2020+
float world_gravity[3];
2021+
if (rbw->shared->runtime->physics_world) {
2022+
RB_dworld_get_gravity(rbw->shared->runtime->physics_world, world_gravity);
2023+
}
2024+
else {
2025+
zero_v3(world_gravity);
2026+
}
2027+
20172028
FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (rbw->group, ob) {
20182029
/* only update if rigid body exists */
20192030
RigidBodyOb *rbo = ob->rigidbody_object;
20202031
if (ob->type != OB_MESH || rbo->shared->physics_object == nullptr) {
20212032
continue;
20222033
}
20232034

2035+
/* Apply per-body gravity weight */
2036+
if (rbo->type == RBO_TYPE_ACTIVE && (rbo->flag & RBO_FLAG_DISABLED) == 0 &&
2037+
rbo->gravity != 1.0f && !is_zero_v3(world_gravity))
2038+
{
2039+
float gravity_force[3];
2040+
float mass = RB_body_get_mass(static_cast<rbRigidBody *>(rbo->shared->physics_object));
2041+
/* Calculate the additional gravity force needed to achieve the desired gravity influence */
2042+
/* If gravity < 1.0, we need to reduce the effective gravity */
2043+
/* If gravity > 1.0, we need to increase the effective gravity */
2044+
float gravity_factor = rbo->gravity - 1.0f;
2045+
copy_v3_v3(gravity_force, world_gravity);
2046+
mul_v3_fl(gravity_force, gravity_factor * mass);
2047+
RB_body_apply_central_force(static_cast<rbRigidBody *>(rbo->shared->physics_object),
2048+
gravity_force);
2049+
}
2050+
20242051
/* update influence of effectors - but don't do it on an effector */
20252052
/* only dynamic bodies need effector update */
20262053
if (rbo->type == RBO_TYPE_ACTIVE &&

source/blender/makesdna/DNA_rigidbody_types.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ typedef struct RigidBodyOb {
161161
/** Damping for angular velocities. */
162162
float ang_damping;
163163

164+
/** Gravity influence for this rigid body (0.0 - 1.0). */
165+
float gravity;
166+
164167
/** Deactivation threshold for linear velocities. */
165168
float lin_sleep_thresh;
166169
/** Deactivation threshold for angular velocities. */
@@ -172,7 +175,7 @@ typedef struct RigidBodyOb {
172175
float pos[3];
173176
char _pad1[4];
174177

175-
char _pad2[12]; /* 为将来使用保留的填充字节 */
178+
char _pad2[8]; /* 为将来使用保留的填充字节 */
176179

177180
/** This pointer is shared between all evaluated copies. */
178181
struct RigidBodyOb_Shared *shared;

source/blender/makesrna/intern/rna_rigidbody.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,14 @@ static void rna_def_rigidbody_object(BlenderRNA *brna)
12791279
prop, "Angular Damping", "Amount of angular velocity that is lost over time");
12801280
RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
12811281

1282+
prop = RNA_def_property(srna, "gravity", PROP_FLOAT, PROP_FACTOR);
1283+
RNA_def_property_float_sdna(prop, nullptr, "gravity");
1284+
RNA_def_property_range(prop, 0.0f, 1.0f);
1285+
RNA_def_property_float_default(prop, 1.0f);
1286+
RNA_def_property_ui_text(
1287+
prop, "Gravity", "Influence of global gravity on this rigid body (0 = no gravity, 1 = full gravity)");
1288+
RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
1289+
12821290
/* Collision Parameters - Surface Parameters */
12831291
prop = RNA_def_property(srna, "friction", PROP_FLOAT, PROP_FACTOR);
12841292
RNA_def_property_float_sdna(prop, nullptr, "friction");

0 commit comments

Comments
 (0)