Particle-body contact reads a command-time held list; LIMB attachments skip the attached body's whole limb tree
held_by's scan of every attachment is replaced by held_start/held_count/held_body, derived in rederive_topology; limb_body names the body of a particle's lowest LIMB attachment and body_contacts skips every body sharing that body's limb-tree root (the proxy root is the parent lane followed to its end). No ABI change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
620af79161
commit
92d390c0a3
5 changed files with 60 additions and 12 deletions
|
|
@ -132,7 +132,7 @@ separate native object (`ymir_box3d_soa.c`, ABI 16) so the Aetheria session's co
|
|||
component`. The phase word: bits 0-19 are the group, bit 20 `SELF_COLLIDE`, bit 21 `SELF_FILTER`, bit 22 `FLUID`, bit 23 `NO_PARTICLE_CONTACT` (refused together with `FLUID`); any other bit is refused.
|
||||
Distance lanes: two particles, rest length, compliance (m/N), `tension` (sensor). Bend lanes: two distances that share one
|
||||
particle (and so the three particles a, b, c), rest and limit offsets, compliance. Attachment lanes: kind (body, static,
|
||||
removed), flags (`TETHER`), particle, body, point, compliance, `force` (sensor). Tether lanes (derived): attachment,
|
||||
removed), flags (`TETHER`; `LIMB`, Body only: the particle is flesh of the body's limb tree, so contact skips every body whose limb-tree root, the `parent` lane followed to its end, is the attached body's), particle, body, point, compliance, `force` (sensor). Held lanes (derived, command time): per particle the list of bodies its live Body attachments name, which contact skips, and `limb_body`, the body of its lowest live `LIMB` attachment or -1. Tether lanes (derived): attachment,
|
||||
particle, bound, parent tether, edge, other attachment. Material table: friction, XSPH viscosity, wet friction and the caller's material id. Handles are
|
||||
(lane, generation).
|
||||
- Commands, each refused whole before anything changes: `create_particles(n, desc{position, velocity, rest, mass, radius,
|
||||
|
|
|
|||
|
|
@ -1466,6 +1466,12 @@ static void ymir_soa_gather_proxies(ymir_box3d_soa_world* world)
|
|||
{
|
||||
b->size[k] = world->size[(size_t)k * (size_t)world->capacity + (size_t)i];
|
||||
}
|
||||
int root = i;
|
||||
for (int hops = 0; hops < world->count && world->parent[root] >= 0; ++hops)
|
||||
{
|
||||
root = world->parent[root]; // the limb tree's root: parents are earlier lanes, so the walk ends
|
||||
}
|
||||
b->root = root;
|
||||
b->position[0] = p.x; b->position[1] = p.y; b->position[2] = p.z;
|
||||
b->rotation[0] = q.v.x; b->rotation[1] = q.v.y; b->rotation[2] = q.v.z; b->rotation[3] = q.s;
|
||||
b->velocity[0] = v.x; b->velocity[1] = v.y; b->velocity[2] = v.z;
|
||||
|
|
|
|||
|
|
@ -108,6 +108,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(held_start, int32_t, np); CARVE(held_count, int32_t, np); CARVE(limb_body, int32_t, np); CARVE(held_body, int32_t, na);
|
||||
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(wet_body, int32_t, nw); CARVE(wet_particle, int32_t, nw); CARVE(wet_x, float, nw); CARVE(wet_y, float, nw); CARVE(wet_z, float, nw);
|
||||
|
|
@ -616,7 +617,8 @@ static int has_pair(const ymir_particles* p, int32_t a, const int32_t* label)
|
|||
// refused with every lane as it was.
|
||||
// ISOLATED is for a command that changed no distance and no attachment, only which lanes are live: the graph, so every
|
||||
// tether and every other lane's component, is as it was. It writes the component of the `n` lanes in `lanes` (each
|
||||
// just created, which is its own component, or just destroyed, which reads 0) and returns.
|
||||
// just created, which is its own component, or just destroyed, which reads 0), their held list (empty) and limb body (-1),
|
||||
// and returns.
|
||||
enum
|
||||
{
|
||||
TOPO_FULL = 0,
|
||||
|
|
@ -630,6 +632,8 @@ static int32_t rederive_topology(ymir_particles* p, int mode, const int32_t* lan
|
|||
for (int32_t k = 0; k < n; ++k)
|
||||
{
|
||||
p->component[lanes[k]] = p->particle_live[lanes[k]] ? lanes[k] : 0;
|
||||
p->held_count[lanes[k]] = 0;
|
||||
p->limb_body[lanes[k]] = -1;
|
||||
}
|
||||
return YMIR_PARTICLES_OK;
|
||||
}
|
||||
|
|
@ -793,6 +797,34 @@ static int32_t rederive_topology(ymir_particles* p, int mode, const int32_t* lan
|
|||
for (int32_t i = 0; i < np; ++i)
|
||||
{
|
||||
p->component[i] = p->tether_of[i] >= 0 ? p->tether_of[i] : 0;
|
||||
p->held_count[i] = 0;
|
||||
p->limb_body[i] = -1;
|
||||
}
|
||||
// The held lists: held_start first holds each particle's slice end, then the attachments are walked from the highest
|
||||
// lane down, each taking the slot below, so a slice ends up in ascending attachment lane order and starts at held_start.
|
||||
for (int32_t a = 0; a < p->attachment_count; ++a)
|
||||
{
|
||||
if (p->att_kind[a] == YMIR_ATTACH_BODY)
|
||||
{
|
||||
p->held_count[p->att_particle[a]]++;
|
||||
}
|
||||
}
|
||||
for (int32_t i = 0, end = 0; i < np; ++i)
|
||||
{
|
||||
end += p->held_count[i];
|
||||
p->held_start[i] = end;
|
||||
}
|
||||
for (int32_t a = p->attachment_count - 1; a >= 0; --a)
|
||||
{
|
||||
if (p->att_kind[a] == YMIR_ATTACH_BODY)
|
||||
{
|
||||
int32_t i = p->att_particle[a];
|
||||
p->held_body[--p->held_start[i]] = p->att_body[a];
|
||||
if (p->att_flags[a] & YMIR_ATTACH_FLAG_LIMB)
|
||||
{
|
||||
p->limb_body[i] = p->att_body[a]; // descending: the lowest lane's body is the last written
|
||||
}
|
||||
}
|
||||
}
|
||||
int32_t nt = 0;
|
||||
for (int32_t a = 0; a < p->attachment_count; ++a)
|
||||
|
|
@ -1131,7 +1163,8 @@ int32_t ymir_particles_create_bends(ymir_particles* p, int32_t n, const ymir_ben
|
|||
int32_t ymir_particles_attach(ymir_particles* p, const ymir_attachment_desc* d, int32_t body_count, uint64_t step_count, ymir_handle* out)
|
||||
{
|
||||
if (p == NULL || d == NULL || (d->kind != YMIR_ATTACH_BODY && d->kind != YMIR_ATTACH_STATIC) ||
|
||||
(d->flags & ~(uint32_t)YMIR_ATTACH_FLAG_TETHER) != 0 || !particle_ok(p, d->particle.lane, d->particle.generation) ||
|
||||
(d->flags & ~(uint32_t)(YMIR_ATTACH_FLAG_TETHER | YMIR_ATTACH_FLAG_LIMB)) != 0 ||
|
||||
(d->kind == YMIR_ATTACH_STATIC && (d->flags & YMIR_ATTACH_FLAG_LIMB) != 0) || !particle_ok(p, d->particle.lane, d->particle.generation) ||
|
||||
!finite3(d->point) || !isfinite(d->compliance) || d->compliance < 0.0f ||
|
||||
(p->phase[d->particle.lane] & YMIR_PHASE_FLUID) != 0) // fluid holds no constraint
|
||||
{
|
||||
|
|
@ -1994,11 +2027,12 @@ static float proxy_reach(const ymir_particle_proxy* b)
|
|||
}
|
||||
|
||||
// 1 when particle i is held to body k by an attachment: such a particle is the body's own point, so contact skips that body.
|
||||
// Reads the list rederive_topology wrote at the last command.
|
||||
static int held_by(const ymir_particles* p, int32_t i, int32_t k)
|
||||
{
|
||||
for (int32_t a = 0; a < p->attachment_count; ++a)
|
||||
for (int32_t s = p->held_start[i], e = s + p->held_count[i]; s < e; ++s)
|
||||
{
|
||||
if (p->att_kind[a] == YMIR_ATTACH_BODY && p->att_particle[a] == i && p->att_body[a] == k)
|
||||
if (p->held_body[s] == k)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -2008,7 +2042,8 @@ static int held_by(const ymir_particles* p, int32_t i, int32_t k)
|
|||
|
||||
// Each particle against each shaped body in ascending lane order. The correction is split by inverse mass between
|
||||
// the particle and the body at the contact point; Coulomb friction removes the tangential slip up to mu times the
|
||||
// push. Every body the particle is attached to is skipped: the attachment already ties them.
|
||||
// push. Every body the particle is attached to is skipped: the attachment already ties them. A LIMB attachment skips the
|
||||
// attached body's whole limb tree: flesh does not meet the bones of its own limb.
|
||||
static void body_contacts(phase* f)
|
||||
{
|
||||
ymir_particles* p = f->p;
|
||||
|
|
@ -2037,9 +2072,9 @@ static void body_contacts(phase* f)
|
|||
{
|
||||
continue;
|
||||
}
|
||||
if (held_by(p, i, k))
|
||||
if ((p->limb_body[i] >= 0 && b->root == p->proxies[p->limb_body[i]].root) || held_by(p, i, k))
|
||||
{
|
||||
continue;
|
||||
continue; // the particle is flesh of this body's limb tree, or attached to this body
|
||||
}
|
||||
v3 n, s;
|
||||
float d = proxy_distance(b, x, &n, &s);
|
||||
|
|
|
|||
|
|
@ -67,7 +67,8 @@ enum
|
|||
|
||||
enum
|
||||
{
|
||||
YMIR_ATTACH_FLAG_TETHER = 1u // bounds each particle by the rest path to the nearest point of its two nearest islands of tether attachments
|
||||
YMIR_ATTACH_FLAG_TETHER = 1u, // bounds each particle by the rest path to the nearest point of its two nearest islands of tether attachments
|
||||
YMIR_ATTACH_FLAG_LIMB = 2u // the particle is flesh of its body's limb tree: contact skips every body whose limb-tree root is the attached body's root; refused on a STATIC attachment
|
||||
};
|
||||
|
||||
enum
|
||||
|
|
@ -166,6 +167,7 @@ typedef struct ymir_particle_proxy
|
|||
float angular_impulse[3];
|
||||
float sub_impulse[3]; // N s: this substep's, applied by the caller before the body's positions integrate
|
||||
float sub_angular[3];
|
||||
int32_t root; // the lane of the body's limb-tree root (the body itself when it has no parent); filled by the caller each step
|
||||
} ymir_particle_proxy;
|
||||
|
||||
typedef struct ymir_particles
|
||||
|
|
@ -189,6 +191,9 @@ typedef struct ymir_particles
|
|||
uint32_t *phase, *material, *particle_live, *particle_generation;
|
||||
uint64_t* particle_removed_at;
|
||||
int32_t* component; // derived: the lowest lane of the particle's distance-connected component
|
||||
int32_t *held_start, *held_count; // derived (rederive_topology): the slice of held_body that lists the bodies particle i is attached to (BODY attachments), contact skips them
|
||||
int32_t* held_body; // derived, attachment capacity: the live BODY attachments' bodies grouped by particle, in attachment lane order
|
||||
int32_t* limb_body; // derived: the body of the particle's lowest live LIMB attachment, -1 for none; contact skips every body in that body's limb tree
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1280,16 +1280,18 @@ public sealed class Box3DSoaWorld : IDisposable
|
|||
/// <summary>
|
||||
/// Ties <paramref name="particle"/> to a body point (kind Body: <paramref name="target"/> is the body lane, <paramref name="point"/> in
|
||||
/// its frame) or a world point (Static). With <paramref name="tether"/> the point also bounds every particle of the component by
|
||||
/// the rest path. <paramref name="compliance"/> is m/N, 0 for rigid. Attach where the particle already is.
|
||||
/// the rest path. With <paramref name="limb"/> (Body only) the particle is flesh of the body's limb tree: contact skips every body
|
||||
/// that shares the attached body's limb-tree root, not just the attached body. <paramref name="compliance"/> is m/N, 0 for rigid.
|
||||
/// Attach where the particle already is.
|
||||
/// </summary>
|
||||
public Box3DSoaConstraintHandle Attach(
|
||||
Box3DSoaAttachKind kind, Box3DSoaParticleHandle particle, int target = -1, (float X, float Y, float Z) point = default,
|
||||
float compliance = 0f, bool tether = false)
|
||||
float compliance = 0f, bool tether = false, bool limb = false)
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_handle == 0, this);
|
||||
var desc = new Box3DSoaAttachmentDesc
|
||||
{
|
||||
Kind = (uint)kind, Flags = tether ? 1u : 0u, Particle = particle, Body = target,
|
||||
Kind = (uint)kind, Flags = (tether ? 1u : 0u) | (limb ? 2u : 0u), Particle = particle, Body = target,
|
||||
PointX = point.X, PointY = point.Y, PointZ = point.Z, Compliance = compliance,
|
||||
};
|
||||
Check(Box3DSoaNative.ymir_box3d_soa_attach(_handle, desc, out var handle));
|
||||
|
|
|
|||
Loading…
Reference in a new issue