Fix T43782: smoke simulation problems with multiple touching colliders.

When the colliders are joined, each cell that touches them only gets
velocity contribution once. When there are multiple objects, velocities
are summed, which causes some cells to get 2x, 3x or more than the actual
object velocity.

Fix this by using the average velocity of all colliders touching a cell.

Reviewers: miikah, lukastoenne

Reviewed By: lukastoenne

Subscribers: dafassi, scorpion81, #physics

Maniphest Tasks: T43782

Differential Revision: https://developer.blender.org/D2112
This commit is contained in:
Alexander Gavrilov 2016-07-17 20:42:06 +03:00
parent f2d5295abf
commit ae9e9700c2
Notes: blender-bot 2023-02-14 09:27:16 +01:00
Referenced by issue #43782, Smoke collision flips out with multiple objects
1 changed files with 18 additions and 4 deletions

View File

@ -707,6 +707,7 @@ typedef struct ObstaclesFromDMData {
bool has_velocity;
float *vert_vel;
float *velocityX, *velocityY, *velocityZ;
int *num_obstacles;
} ObstaclesFromDMData;
static void obstacles_from_derivedmesh_task_cb(void *userdata, const int z)
@ -755,8 +756,10 @@ static void obstacles_from_derivedmesh_task_cb(void *userdata, const int z)
/* tag obstacle cells */
data->obstacle_map[index] = 1;
if (data->has_velocity)
if (data->has_velocity) {
data->obstacle_map[index] |= 8;
data->num_obstacles[index]++;
}
}
}
}
@ -764,7 +767,7 @@ static void obstacles_from_derivedmesh_task_cb(void *userdata, const int z)
static void obstacles_from_derivedmesh(
Object *coll_ob, SmokeDomainSettings *sds, SmokeCollSettings *scs,
unsigned char *obstacle_map, float *velocityX, float *velocityY, float *velocityZ, float dt)
unsigned char *obstacle_map, float *velocityX, float *velocityY, float *velocityZ, int *num_obstacles, float dt)
{
if (!scs->dm) return;
{
@ -835,7 +838,8 @@ static void obstacles_from_derivedmesh(
.sds = sds, .mvert = mvert, .mloop = mloop, .looptri = looptri,
.tree = &treeData, .obstacle_map = obstacle_map,
.has_velocity = has_velocity, .vert_vel = vert_vel,
.velocityX = velocityX, .velocityY = velocityY, .velocityZ = velocityZ
.velocityX = velocityX, .velocityY = velocityY, .velocityZ = velocityZ,
.num_obstacles = num_obstacles
};
BLI_task_parallel_range(
sds->res_min[2], sds->res_max[2], &data, obstacles_from_derivedmesh_task_cb, true);
@ -871,6 +875,8 @@ static void update_obstacles(Scene *scene, Object *ob, SmokeDomainSettings *sds,
float *b = smoke_get_color_b(sds->fluid);
unsigned int z;
int *num_obstacles = MEM_callocN(sizeof(int) * sds->res[0] * sds->res[1] * sds->res[2], "smoke_num_obstacles");
smoke_get_ob_velocity(sds->fluid, &velx, &vely, &velz);
// TODO: delete old obstacle flags
@ -900,7 +906,7 @@ static void update_obstacles(Scene *scene, Object *ob, SmokeDomainSettings *sds,
if ((smd2->type & MOD_SMOKE_TYPE_COLL) && smd2->coll)
{
SmokeCollSettings *scs = smd2->coll;
obstacles_from_derivedmesh(collob, sds, scs, obstacles, velx, vely, velz, dt);
obstacles_from_derivedmesh(collob, sds, scs, obstacles, velx, vely, velz, num_obstacles, dt);
}
}
@ -926,7 +932,15 @@ static void update_obstacles(Scene *scene, Object *ob, SmokeDomainSettings *sds,
b[z] = 0;
}
}
/* average velocities from multiple obstacles in one cell */
if (num_obstacles[z]) {
velx[z] /= num_obstacles[z];
vely[z] /= num_obstacles[z];
velz[z] /= num_obstacles[z];
}
}
MEM_freeN(num_obstacles);
}
/**********************************************************