Support lanes: what each fluid particle touched in the last substep
ABI 13. support_body (the highest body lane touched) and support_particle (the first listed solid that touches) are cleared to -1 for each live fluid lane after prediction and written by body_contacts and the fluid-solid contact pass; create and destroy write -1. Resting on fluid alone reads -1 on both. The step writes them and no pass reads them: the pins (Abi8, Pile, Fluid) do not move. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c6365d4d85
commit
888117dc5c
7 changed files with 158 additions and 17 deletions
|
|
@ -8,11 +8,11 @@ Box3D decides every physical outcome; Ymir creates bodies, steps the world and e
|
|||
`ymir_box3d_session_*` (`ymir_box3d.c`) is the planar Aetheria session: gravity is zero, Y is locked,
|
||||
only yaw rotates (`motionLocks.linearY/angularX/angularZ`), and state leaves by `copy_bodies` into an
|
||||
array of structs. A body cannot fall or tumble there, and every read is a copy. The SoA world is a
|
||||
separate native object (`ymir_box3d_soa.c`, ABI 12) so the Aetheria session's contract is untouched.
|
||||
separate native object (`ymir_box3d_soa.c`, ABI 13) so the Aetheria session's contract is untouched.
|
||||
|
||||
## Contract
|
||||
|
||||
- Native (ABI 12): `ymir_box3d_soa_create(capacity, joint_capacity, gravity, fact_capacity, hit_threshold, particle_capacities*) /
|
||||
- Native (ABI 13): `ymir_box3d_soa_create(capacity, joint_capacity, gravity, fact_capacity, hit_threshold, particle_capacities*) /
|
||||
create_particles / destroy_particles / create_distances / create_bends / attach / remove / set_material / free_slots /
|
||||
add_body / add_joint / step / get_view / get_facts / set_anchor_target / destroy_joint / free_joint_slots / apply_impulse / cast_ray_closest / destroy`. `add_body` takes one descriptor (sphere, capsule, box, static box, anchor; position,
|
||||
rotation, velocity, size, density, friction, restitution, rolling resistance, material id, parent, limb). Capacities are fixed at creation,
|
||||
|
|
@ -197,10 +197,17 @@ separate native object (`ymir_box3d_soa.c`, ABI 12) so the Aetheria session's co
|
|||
materials' `viscosity`, split by inverse mass the same way, and only when some material has a viscosity above 0 (one scan of the material lanes a substep). A pair that
|
||||
entered reach since pass A is missed by XSPH (smoothing, not a constraint). Lists, copies and the fluid grid are per-substep scratch, carved once at create: 28 bytes a particle lane
|
||||
(`nbr_start`, `nbr_count`, `sx sy sz sw sphase`; h1's per-lane lists were 388) and 384 a unit of fluid capacity. A world with no live fluid steps byte-identically to
|
||||
one before fluid (no pass runs: `live_fluid` counts the live fluid particles, written by create and destroy only). Cost on the 16 x 16 sheet scene at 4 substeps, increment over the same scene without fluid (Release, three runs):
|
||||
one before fluid (no pass runs: `live_fluid` counts the live fluid particles, written by create and destroy only). Cost on the 16 x 16 sheet scene at 4 substeps, increment over the same scene without fluid (Release, three runs; the cost line in `Box3DSoaCouplingTests` now prints the median of nine interleaved with-and-without pairs and its interquartile range):
|
||||
512 fluid +0.76 to +0.84 ms a tick at viscosity 0 and +0.86 to +1.01 at 0.01; 2000 fluid +4.1 to +4.4 at both, against a target of 1.0 ms at 512 (h1: +3.0 to +3.4 and +13.1 to +13.9). The probe behind the design
|
||||
(a standalone replica of the pass) read 7 ns a cell visit in the 125-cell walk: the cost was per cell, not arithmetic, so the cell is now the kernel reach and the copies and the branchless filter keep the 27 buckets cheap. Two counting sorts a substep run with fluid live.
|
||||
sensor lane `particle_density` reads `n_i / n0` (1 at rest, 0 for a solid) in the last substep the particle ran.
|
||||
Support lanes `particle_support_body` and `particle_support_particle` (ABI 13; `SupportBody`, `SupportParticle` in the binding) name what a fluid particle touched in the
|
||||
last substep it ran. Both are cleared to -1 for each live fluid lane at the start of the substep, after prediction, and written by the substep's contacts: body contact
|
||||
sets `support_body` to the lane of each shaped body whose surface comes within the particle's radius, bodies ascending, so the highest lane touched wins; the fluid-solid
|
||||
contact pass sets `support_particle` to the first solid listed in the particle's row that touches it (pass 1 of the walk, the solid's lane). A fluid particle resting only
|
||||
on fluid reads -1 on both, so the bottom of a deep pool is supported and the interior is not; a solid lane, a free lane and a lane after create or destroy read -1 too.
|
||||
The lanes name contact, not rest: the caller judges speed. They are notification only, written by the step and read by no pass; a world with no settled liquid
|
||||
steps byte-identically to ABI 12.
|
||||
Fluid holds no constraint: `create_distances` and `attach` refuse a fluid particle, so `create_bends` (over distances) can
|
||||
never name one; a thing that holds liquid is cloth around free fluid (a balloon), as in Flex sec. 8. Every `create_particles`
|
||||
and every `destroy_particles` of particles that held no distance derives only the isolated lanes
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ enum
|
|||
YMIR_SOA_JOINT_REMOVED = 4 // a destroyed joint's lane: never accepted by add_joint
|
||||
};
|
||||
|
||||
#define YMIR_SOA_ABI_VERSION 12u
|
||||
#define YMIR_SOA_ABI_VERSION 13u
|
||||
|
||||
// A body to create. `size` by kind: sphere {radius}, capsule {radius, half_length} (segment along
|
||||
// local Y), box and static box {half_x, half_y, half_z}. `parent` is the lane index of an earlier body
|
||||
|
|
@ -205,7 +205,7 @@ typedef struct ymir_box3d_soa_view
|
|||
const float* particle_impulse_y;
|
||||
const float* particle_impulse_z;
|
||||
// Particle lanes (read-only; only `step` and the particle and constraint commands change them), indexed by lane
|
||||
// up to the set's count (a high-water mark). A dead lane reads live 0 and every other lane 0 except generation
|
||||
// up to the set's count (a high-water mark). A dead lane reads live 0 and every other lane 0 (the support lanes -1) except generation
|
||||
// and removed_at. Handles are (lane, generation); a lane is reused once a step has passed since its removal.
|
||||
const float* particle_x;
|
||||
const float* particle_y;
|
||||
|
|
@ -276,6 +276,10 @@ typedef struct ymir_box3d_soa_view
|
|||
const float* material_friction;
|
||||
const uint64_t* material_id_lane;
|
||||
const float* material_viscosity;
|
||||
// A fluid particle's support in the last substep it ran: the highest body lane it touched, and the first solid particle lane its
|
||||
// row listed touching it; -1 for none, and -1 for a solid or free lane. Contact, not rest: the caller judges speed. Notification only.
|
||||
const int32_t* particle_support_body;
|
||||
const int32_t* particle_support_particle;
|
||||
} ymir_box3d_soa_view;
|
||||
|
||||
// A begin or end of touch between two bodies: their lane indices and the shapes' stable ids.
|
||||
|
|
@ -1572,6 +1576,8 @@ YMIR_EXPORT int32_t YMIR_CALL ymir_box3d_soa_get_view(const ymir_box3d_soa_world
|
|||
view->material_friction = pt->mat_friction;
|
||||
view->material_id_lane = pt->mat_id;
|
||||
view->material_viscosity = pt->mat_viscosity;
|
||||
view->particle_support_body = pt->support_body;
|
||||
view->particle_support_particle = pt->support_particle;
|
||||
}
|
||||
return YMIR_SOA_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ static size_t layout(ymir_particles* p, unsigned char* base)
|
|||
CARVE(rest_x, float, np); CARVE(rest_y, float, np); CARVE(rest_z, float, np);
|
||||
CARVE(phase, uint32_t, np); CARVE(material, uint32_t, np); CARVE(particle_live, uint32_t, np);
|
||||
CARVE(particle_generation, uint32_t, np); CARVE(particle_removed_at, uint64_t, np); CARVE(component, int32_t, np);
|
||||
CARVE(density, float, np);
|
||||
CARVE(density, float, np); CARVE(support_body, int32_t, np); CARVE(support_particle, int32_t, np);
|
||||
CARVE(nbr, int32_t, (int64_t)p->fluid_capacity * YMIR_FLUID_NEIGHBOURS); CARVE(nbr_start, int32_t, np); CARVE(nbr_count, int32_t, np);
|
||||
CARVE(dist_a, int32_t, nd); CARVE(dist_b, int32_t, nd); CARVE(dist_rest, float, nd); CARVE(dist_compliance, float, nd);
|
||||
CARVE(dist_tension, float, nd); CARVE(dist_live, uint32_t, nd); CARVE(dist_generation, uint32_t, nd);
|
||||
|
|
@ -779,6 +779,7 @@ int32_t ymir_particles_create_particles(ymir_particles* p, int32_t n, const ymir
|
|||
p->inv_mass[i] = d[k].mass > 0.0f ? 1.0f / d[k].mass : 0.0f;
|
||||
p->phase[i] = d[k].phase;
|
||||
p->material[i] = d[k].material;
|
||||
p->support_body[i] = p->support_particle[i] = -1;
|
||||
p->particle_live[i] = 1;
|
||||
p->live_particles++;
|
||||
p->live_fluid += (d[k].phase & YMIR_PHASE_FLUID) != 0;
|
||||
|
|
@ -843,6 +844,7 @@ int32_t ymir_particles_destroy_particles(ymir_particles* p, int32_t n, const ymi
|
|||
p->radius[i] = p->inv_mass[i] = 0.0f;
|
||||
p->phase[i] = p->material[i] = 0;
|
||||
p->density[i] = p->lambda[i] = 0.0f;
|
||||
p->support_body[i] = p->support_particle[i] = -1;
|
||||
p->particle_live[i] = 0;
|
||||
p->particle_generation[i] += 1;
|
||||
p->particle_removed_at[i] = step_count;
|
||||
|
|
@ -1271,7 +1273,7 @@ static int touching(const ymir_particles* p, int32_t i, int32_t j, v3 xi, v3* d,
|
|||
#define YMIR_INLINE static inline __attribute__((always_inline))
|
||||
#endif
|
||||
|
||||
typedef void (*pair_fn)(ymir_particles* p, void* ctx, int32_t i, int32_t j);
|
||||
typedef int (*pair_fn)(ymir_particles* p, void* ctx, int32_t i, int32_t j);
|
||||
|
||||
YMIR_INLINE void walk_half(ymir_particles* p, pair_fn fn, void* ctx)
|
||||
{
|
||||
|
|
@ -1300,19 +1302,19 @@ YMIR_INLINE void walk_half(ymir_particles* p, pair_fn fn, void* ctx)
|
|||
}
|
||||
|
||||
// One pass of the contact walk: pass 0 counts every particle's overlaps, pass 1 moves both ends of each pair.
|
||||
static void contact_pair(ymir_particles* p, void* ctx, int32_t i, int32_t j)
|
||||
static int contact_pair(ymir_particles* p, void* ctx, int32_t i, int32_t j) // 1 when the pair touches
|
||||
{
|
||||
v3 d;
|
||||
float r2, md, wsum;
|
||||
if (!touching(p, i, j, P(p, p->pp_x, p->pp_y, p->pp_z, i), &d, &r2, &md, &wsum))
|
||||
{
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
if (*(int*)ctx == 0)
|
||||
{
|
||||
p->contacts[i]++;
|
||||
p->contacts[j]++;
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
float rr = sqrtf(r2), depth = (md - rr) / rr;
|
||||
float weight = 1.0f / (float)(p->contacts[i] > p->contacts[j] ? p->contacts[i] : p->contacts[j]);
|
||||
|
|
@ -1320,6 +1322,7 @@ static void contact_pair(ymir_particles* p, void* ctx, int32_t i, int32_t j)
|
|||
v3 dj = vmul(d, weight * (p->inv_mass[j] / wsum) * depth);
|
||||
p->dp_x[i] += di.x; p->dp_y[i] += di.y; p->dp_z[i] += di.z;
|
||||
p->dp_x[j] -= dj.x; p->dp_y[j] -= dj.y; p->dp_z[j] -= dj.z;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Overlapping pairs push each other apart, split by inverse mass (Macklin 2014). Each pair is found once, by walking
|
||||
|
|
@ -1560,9 +1563,9 @@ static void fluid_density(ymir_particles* p)
|
|||
const int32_t* list = p->nbr + p->nbr_start[i];
|
||||
for (int32_t k = 0; k < p->nbr_count[i]; ++k)
|
||||
{
|
||||
if (!(p->phase[list[k]] & YMIR_PHASE_FLUID))
|
||||
if (!(p->phase[list[k]] & YMIR_PHASE_FLUID) && contact_pair(p, &pass, i, list[k]) && pass == 1 && p->support_particle[i] < 0)
|
||||
{
|
||||
contact_pair(p, &pass, i, list[k]);
|
||||
p->support_particle[i] = list[k]; // the first listed solid that touches: what the particle rests on
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1762,6 +1765,10 @@ static void body_contacts(phase* f)
|
|||
{
|
||||
continue;
|
||||
}
|
||||
if (p->phase[i] & YMIR_PHASE_FLUID)
|
||||
{
|
||||
p->support_body[i] = k; // bodies ascend: the highest lane touched wins
|
||||
}
|
||||
float depth = r - d;
|
||||
float wb = proxy_w(b, s, n);
|
||||
float w = wi + wb;
|
||||
|
|
@ -2069,6 +2076,10 @@ void ymir_particles_substep(ymir_particles* p, float h, float gx, float gy, floa
|
|||
{
|
||||
continue;
|
||||
}
|
||||
if (p->phase[i] & YMIR_PHASE_FLUID)
|
||||
{
|
||||
p->support_body[i] = p->support_particle[i] = -1; // this substep's contacts write them again
|
||||
}
|
||||
v3 x = P(p, p->pos_x, p->pos_y, p->pos_z, i);
|
||||
if (p->inv_mass[i] > 0.0f)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -172,6 +172,7 @@ typedef struct ymir_particles
|
|||
uint64_t* particle_removed_at;
|
||||
int32_t* component; // derived: the lowest lane of the particle's distance-connected component
|
||||
int32_t *nbr, *nbr_start, *nbr_count; // scratch: the fluid rows' kernel neighbours in walk order, packed (CSR) in an arena of fluid_capacity * YMIR_FLUID_NEIGHBOURS; row i holds nbr_count[i] from nbr_start[i], this substep's
|
||||
int32_t *support_body, *support_particle; // sensor: what a fluid particle touched in the last substep, the highest body lane / the first solid lane its row listed touching it; -1 for none, and always -1 for a solid or free lane
|
||||
float* density; // sensor: a fluid particle's number density over its rest density n_i / n0 in the last substep it ran, else 0
|
||||
|
||||
// distance lanes
|
||||
|
|
|
|||
|
|
@ -342,6 +342,8 @@ internal unsafe struct Box3DSoaViewNative
|
|||
public float* MaterialFriction;
|
||||
public ulong* MaterialTableId;
|
||||
public float* MaterialViscosity;
|
||||
public int* SupportBody;
|
||||
public int* SupportParticle;
|
||||
}
|
||||
|
||||
/// <summary>Native layout of <c>ymir_box3d_soa_facts</c>: counts, dropped counters, then three pointers.</summary>
|
||||
|
|
@ -737,6 +739,10 @@ public readonly unsafe struct Box3DSoaView
|
|||
public ReadOnlySpan<ulong> MaterialTableId => Lane(_v.MaterialTableId, MaterialCapacity);
|
||||
/// <summary>The XSPH coefficient of each material (a fluid pair relaxes its velocities by the mean of the two).</summary>
|
||||
public ReadOnlySpan<float> MaterialViscosity => Lane(_v.MaterialViscosity, MaterialCapacity);
|
||||
/// <summary>A fluid particle's support in the last substep it ran: the highest body lane it touched, else -1; -1 for a solid or free lane. Contact, not rest: the caller judges speed. Notification only.</summary>
|
||||
public ReadOnlySpan<int> SupportBody => Lane(_v.SupportBody, ParticleCount);
|
||||
/// <summary>A fluid particle's support in the last substep it ran: the first solid particle lane its row listed touching it, else -1 (resting on fluid alone reads -1); -1 for a solid or free lane.</summary>
|
||||
public ReadOnlySpan<int> SupportParticle => Lane(_v.SupportParticle, ParticleCount);
|
||||
|
||||
/// <summary>N s, world: the impulse the particle phase delivered to each body over the last step (0 for a body it did not touch). Box3D has already applied it; this is notification only.</summary>
|
||||
public ReadOnlySpan<float> ParticleImpulseX => Lane(_v.ParticleImpulseX, Count);
|
||||
|
|
@ -755,7 +761,7 @@ public readonly unsafe struct Box3DSoaView
|
|||
/// </summary>
|
||||
public sealed class Box3DSoaWorld : IDisposable
|
||||
{
|
||||
private const uint ExpectedAbi = 12;
|
||||
private const uint ExpectedAbi = 13;
|
||||
private nint _handle;
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -458,6 +458,116 @@ public sealed class Box3DSoaFluidTests
|
|||
Assert.True(below <= FloorThrough, line + $": more than {FloorThrough} through");
|
||||
}
|
||||
|
||||
// The support lanes name contact in the last substep, not rest: the step writes them and nothing reads them, so these tests read them.
|
||||
private static void ReadSupport(string scene, Box3DSoaView v, Box3DSoaParticleHandle[] fluid)
|
||||
{
|
||||
var body = fluid.Count(h => v.SupportBody[h.Lane] >= 0);
|
||||
var particle = fluid.Count(h => v.SupportParticle[h.Lane] >= 0);
|
||||
Readings.Add($"SUPPORT {scene}: {fluid.Length} fluid particles, {body} read a body, {particle} read a solid particle");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Support_lanes_name_what_fluid_rests_on()
|
||||
{
|
||||
// Static floor and walls: a 4 x 4 x 4 pool in a well. Whoever touches the floor or a wall (the highest lane wins) reads that body; a particle
|
||||
// resting only on other fluid reads -1 on both lanes, as does a drop in flight. A drop pinched between the floor (lane 0) and a slab 1.9 r above
|
||||
// it (lane 5) touches both: the slab, the higher lane.
|
||||
{
|
||||
using var world = FluidWorld(128, gravityY: -9.81f);
|
||||
Well(world, 0.05f);
|
||||
var slab = world.AddStaticBox(6, (1f, 1.9f * R + 0.05f, 0f), (0.1f, 0.05f, 0.1f));
|
||||
var pool = Graph.Block(world, (-0.0375f, R + 0.005f, -0.0375f), 4, 4, 4, R, FluidMass, FluidPhase);
|
||||
var pinched = new Box3DSoaParticleHandle[1];
|
||||
world.CreateParticles([Fluid((1f, R, 0f))], pinched);
|
||||
var flight = new Box3DSoaParticleHandle[1];
|
||||
world.CreateParticles([Fluid((-1f, 40f, 0f))], flight);
|
||||
var thrown = new Box3DSoaParticleHandle[1];
|
||||
world.CreateParticles([Fluid((-1f, 0.5f * R, 1f), velocity: (0f, 1f, 0f))], thrown); // inside the floor, moving up
|
||||
Assert.Equal(5, slab);
|
||||
var view = world.View;
|
||||
Assert.Equal(-1, view.SupportBody[pool[0].Lane]);
|
||||
world.Step(1f / 240f, 1); // one substep: the thrown drop touches the floor in it
|
||||
Assert.Equal(0, world.View.SupportBody[thrown[0].Lane]);
|
||||
world.Step(1f / 60f, Sub); // four more: it is in flight in each, so a lane the step did not clear would still read the floor
|
||||
Assert.Equal(-1, world.View.SupportBody[thrown[0].Lane]);
|
||||
for (var tick = 0; tick < 119; tick++) world.Step(1f / 60f, Sub);
|
||||
view = world.View;
|
||||
var floor = 0; var resting = 0;
|
||||
foreach (var h in pool)
|
||||
{
|
||||
// A particle a contact pushed out ends at distance r from the face, as one that never touched may: only gravity presses the floor layer every
|
||||
// substep, so that layer must read; a particle clear of every face by 5% must read -1; one within 5% of a wall may read either.
|
||||
var (x, y, z) = (view.ParticleX[h.Lane], view.ParticleY[h.Lane], view.ParticleZ[h.Lane]);
|
||||
var nearWall = MathF.Abs(x) >= 0.05f - 1.05f * R || MathF.Abs(z) >= 0.05f - 1.05f * R;
|
||||
var body = view.SupportBody[h.Lane];
|
||||
if (y <= 1.001f * R) { floor++; Assert.True(body >= 0 && body <= 4, $"x {x:F5} y {y:F5} z {z:F5} body {body}"); }
|
||||
else if (y > 1.05f * R && !nearWall) { resting++; Assert.Equal(-1, body); }
|
||||
else if (body >= 0) Assert.True(nearWall || y <= 1.05f * R, $"x {x:F5} y {y:F5} z {z:F5} body {body}");
|
||||
Assert.Equal(-1, view.SupportParticle[h.Lane]);
|
||||
}
|
||||
Assert.True(floor >= 8 && resting >= 2, $"{floor} on the floor, {resting} resting on fluid");
|
||||
Assert.Equal(5, view.SupportBody[pinched[0].Lane]);
|
||||
Assert.Equal(-1, view.SupportParticle[pinched[0].Lane]);
|
||||
Assert.Equal(-1, view.SupportBody[flight[0].Lane]);
|
||||
Assert.Equal(-1, view.SupportParticle[flight[0].Lane]);
|
||||
ReadSupport("well", view, pool);
|
||||
}
|
||||
// A free box on the floor, a pool on the box: the box's lane for the layer that touches it, -1 above, never the floor's.
|
||||
{
|
||||
using var world = FluidWorld(128, gravityY: -9.81f);
|
||||
world.AddStaticBox(1, (0f, -0.5f, 0f), (2f, 0.5f, 2f), friction: 0.3f);
|
||||
var box = world.AddBox(2, (0f, 0.1f, 0f), (0.1f, 0.1f, 0.1f), 5000f, friction: 0.3f);
|
||||
var pool = Graph.Block(world, (-0.025f, 0.2f + R + 0.005f, -0.025f), 3, 7, 3, R, FluidMass, FluidPhase);
|
||||
for (var tick = 0; tick < 12; tick++) world.Step(1f / 60f, Sub);
|
||||
var view = world.View;
|
||||
var top = view.PositionY[box] + 0.1f;
|
||||
var touching = 0; var resting = 0;
|
||||
foreach (var h in pool)
|
||||
{
|
||||
var y = view.ParticleY[h.Lane];
|
||||
if (MathF.Abs(view.ParticleX[h.Lane] - view.PositionX[box]) > 0.1f - R || MathF.Abs(view.ParticleZ[h.Lane] - view.PositionZ[box]) > 0.1f - R) continue; // spilled over the edge
|
||||
if (y <= top + 1.001f * R) { touching++; Assert.Equal(box, view.SupportBody[h.Lane]); }
|
||||
else if (y > top + 1.5f * R) { resting++; Assert.Equal(-1, view.SupportBody[h.Lane]); }
|
||||
Assert.Equal(-1, view.SupportParticle[h.Lane]);
|
||||
}
|
||||
Assert.True(touching >= 4 && resting >= 4, $"{touching} touch the box, {resting} above them");
|
||||
ReadSupport("free box", view, pool);
|
||||
}
|
||||
// A sheet pinned along two opposite edges (one edge alone swings down like a curtain; a corner-pinned tarp sieves, lodur:ruling:ymir-sheet-sieve-at-budget-substeps) under a few drops: each reads a
|
||||
// sheet particle that touches it; a drop high above reads -1 on both.
|
||||
{
|
||||
using var world = new Box3DSoaWorld(4, gravityY: -9.81f, particles: new Box3DSoaParticleCapacities(256, 160, 140, 16, 1024, 2, 16));
|
||||
world.AddStaticBox(1, (0f, -50f, 0f), (1f, 1f, 1f));
|
||||
var sheet = Graph.Sheet(world, (0f, 0.6f, 0f), (0.04f, 0f, 0f), (0f, 0f, 0.04f), 8, 8, 0.02f, 0.02f, Box3DSoaPhase.Of(4, true, true));
|
||||
for (var j = 0; j < 8; j++)
|
||||
for (var i = 0; i < 8; i += 7)
|
||||
world.Attach(Box3DSoaAttachKind.Static, sheet.Particles[j * 8 + i], point: (0.04f * i, 0.6f, 0.04f * j));
|
||||
var drops = new Box3DSoaParticleHandle[4];
|
||||
world.CreateParticles([Fluid((0.12f, 0.64f, 0.12f)), Fluid((0.16f, 0.64f, 0.16f)), Fluid((0.13f, 0.7f, 0.14f)), Fluid((0.15f, 60f, 0.14f))], drops);
|
||||
world.Step(1f / 60f, Sub);
|
||||
// a drop 4 cm above a sheet particle sits inside the kernel reach and so in its row's list, and does not touch (4 cm against 3.25): no support
|
||||
Assert.Equal(-1, world.View.SupportParticle[drops[0].Lane]);
|
||||
Assert.Equal(-1, world.View.SupportParticle[drops[1].Lane]);
|
||||
for (var tick = 1; tick < 20; tick++) world.Step(1f / 60f, Sub);
|
||||
var view = world.View;
|
||||
var onSheet = new HashSet<int>(sheet.Particles.Select(h => h.Lane));
|
||||
var read = 0;
|
||||
foreach (var h in drops.Take(3))
|
||||
{
|
||||
var s = view.SupportParticle[h.Lane];
|
||||
Assert.Equal(-1, view.SupportBody[h.Lane]);
|
||||
if (s < 0) continue;
|
||||
read++;
|
||||
Assert.Contains(s, onSheet);
|
||||
Assert.True(Graph.Dist(view, h.Lane, s) <= 1.05f * (view.ParticleRadius[h.Lane] + view.ParticleRadius[s]), "the named particle does not touch");
|
||||
}
|
||||
Assert.True(read >= 2, $"{read} of 3 drops read a sheet particle");
|
||||
Assert.Equal(-1, view.SupportParticle[drops[3].Lane]);
|
||||
Assert.Equal(-1, view.SupportBody[drops[3].Lane]);
|
||||
ReadSupport("sheet", view, drops);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Fluid_pushes_a_body()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -167,10 +167,10 @@ public sealed class Box3DSoaGrabTests
|
|||
[Fact]
|
||||
public void The_managed_side_refuses_a_native_library_of_another_abi_in_either_direction()
|
||||
{
|
||||
Assert.Equal(12u, Box3DSoaNative.ymir_box3d_soa_get_abi_version());
|
||||
Box3DSoaWorld.RequireNativeAbi(12);
|
||||
Assert.Throws<InvalidOperationException>(() => Box3DSoaWorld.RequireNativeAbi(11)); // an older native under this managed build
|
||||
Assert.Throws<InvalidOperationException>(() => Box3DSoaWorld.RequireNativeAbi(13)); // a newer one
|
||||
Assert.Equal(13u, Box3DSoaNative.ymir_box3d_soa_get_abi_version());
|
||||
Box3DSoaWorld.RequireNativeAbi(13);
|
||||
Assert.Throws<InvalidOperationException>(() => Box3DSoaWorld.RequireNativeAbi(12)); // an older native under this managed build
|
||||
Assert.Throws<InvalidOperationException>(() => Box3DSoaWorld.RequireNativeAbi(14)); // a newer one
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
Loading…
Reference in a new issue