Collision API
Interface ID 3, version 2.1 (ROCK 1.0.3; 2.1 adds queryWorldSurfaceTriangles at the end of the table). A mod built against these headers needs ROCK 1.0.3 or newer; a mod built against 2.0 keeps working. Include <ROCK/Collision.h>. Namespace rock::api::collision. Permissions: Read (1), Write (2). Hand and body contacts, player collider descriptors, hand collision availability, world raycasts, surface triangles, physics scale and each weapon slot's generated bodies, magazine ejection clearance and object rest watches.
Ejection clearance and object rest, which pre-release SDK builds published as separate EjectionContacts.h and ObjectRest.h headers, are here. External body registration is removed with no replacement.
Entry points
| Function | Permission | Thread | Purpose |
|---|---|---|---|
copySemanticHandContacts | Read | Game | Up to kMaxSemanticContacts (20) contacts of one hand's colliders no older than maxFramesSinceContact. |
copyPlayerColliderDescriptors | Read | Game | Up to kMaxColliderDescriptors (96) hand and body colliders with transforms and shapes. |
copyBodyContacts | Read | Game | Up to kMaxBodyContacts (128) contacts of the player's body colliders. |
getHandCollisionAvailability | Read | Game | Whether a hand's collision bodies exist and may collide, with counts, contact slots and the dynamic collision layer. |
queryWorldRaycast | Read | Game | One world raycast; at most kMaxRaycastsPerOwnerPerFrame (8) per owner per frame. |
getEnvironment | Read | Any | Game-to-Havok scale and each weapon slot's generated bodies. |
requestEjectionClearance | Write | Game | Keeps a dropped reference (an ejected magazine) from colliding with a weapon for one second. |
cancelEjectionClearance | owner | Game | Cancels one clearance, or all of the owner's with reference 0. |
watchObjectRest | Write | Game | Watches a dropped MISC reference until it rests. |
cancelObjectRest | owner | Game | Cancels one watch, or all of the owner's with reference 0. |
getSample | Read | Any | Identity of the current publication. |
queryWorldSurfaceTriangles | Read | Game | 2.1. Up to kMaxSurfaceTriangles (512) collision triangles of visible surfaces within a radius of a point; at most kMaxSurfaceTriangleQueriesPerOwnerPerFrame (2) per owner per frame. |
Copy calls report the total and copy min(capacity, total); a capacity above the limit returns CapacityFull. Follow hand touches through the semantic hand contacts and their contactState (Begin, Continued, End).
World raycast
Casts up to kMaxRaycastDistanceGame (8192) game units. Nonzero generation fields in the request must match ROCK's current ones; the result carries the frame and generations at the time of the cast. request.filter chooses what the cast can hit:
Selection(0, default): the item-picking ray; stops at the first body, actors included.Surfaces(1): sweeps a 1-unit sphere and returns the closest visible solid surface (world geometry, terrain, trees, clutter, props, debris, glass), passing through actors, weapons, projectiles, triggers and invisible collision. The result'shitLayeris then the Fallout 4 collision layer of that surface. Use it for things that land on the scene, such as blood.
WorldRaycastResult: hit, flags (Hit, NormalValid), hitFraction, hitDistanceGame, hitPointGame, hitNormalGame, frameIndex, generations, hitLayer.
Surface triangles (2.1)
queryWorldSurfaceTriangles(owner, request, triangles, capacity, result) returns the collision triangles of the surfaces the Surfaces raycast can hit that lie within request.radiusGame (at most kMaxSurfaceTriangleRadiusGame, 128) of request.centreGame, in game units, as they lie this frame: mesh and compound world geometry, terrain and the hulls of convex clutter (without the rounding of their convex radius). Use it to test many short paths against the scene with one query, for example flying blood, instead of a raycast per path per frame. capacity is 1 to kMaxSurfaceTriangles (512). result.count triangles are written; SurfaceTrianglesFlag::Truncated in result.flags means more lay in the sphere. Each SurfaceTriangle has its corners aGame, bGame, cGame counter-clockwise seen from normalGame, and the Fallout 4 collision layer of its body. Nonzero generation fields guard the request, as for raycasts.
Environment
Environment holds sample, gameToHavokScale, havokToGameScale, physicsScaleRevision and weapons[kMaxWeaponSlots]: for each slot the weaponGenerationKey, bodyCount and bodyIds[8]. Both slots are published; a slot without generated bodies has bodyCount 0.
Ejection clearance
For one second after the reference's bodies become available (up to 1.5 s waiting for them), the reference does not collide with the weapon in weaponSlot; EjectionClearanceFlag::IncludeHands also excludes both hands. The world and other objects still collide; ray queries and grabbing are unaffected. reference (ReferenceKey), expectedBase, weaponFormId and weaponGenerationKey must match the live object and the slot's weapon. Slot 1 returns TargetUnavailable. Repeating the same request observes it without extending it: RequestQueued while waiting, Ok once active or finished. At most kMaxEjectionClearances (8); another owner gets OwnerConflict, a changed request GenerationMismatch.
Object rest
RequestQueued admits a watch (at most kMaxObjectRestWatches, 16); poll with the same request: Ok reports Watching or Resting. Resting completes and frees the watch. Two seconds of supported rest freezes the bodies and saves their pose; grabbing wakes them. Held items cannot rest. Owner, lifecycle or scene loss cancels unfinished watches; submit again after a regrab, drop or load. Retry CapacityFull, NotReady or TargetUnavailable later.
Records
| Record | Fields |
|---|---|
SemanticHandContact | frameIndex, hand, role, finger, segment, handBodyId, targetBodyId, targetFormId, flags (SemanticHandContactFlag), contactState, framesSinceContact, contactSequence, contactPointGame, contactNormalGame, collisionGeneration |
BodyContact | frameIndex, bodyId, targetBodyId, bodyLayer, targetLayer, zone (BodyZoneKind), side, role, descriptorIndex, targetKind (BodyContactTargetKind), inPowerArmor, hasContactPointGame, contactPointGame |
PlayerColliderDescriptor | frameIndex, kind (Hand, Body), hand, bodyId, role, zone, side, descriptorIndex, flags (PlayerColliderFlag), lengthGameUnits, radiusGameUnits, transform, collisionGeneration |
HandCollisionAvailability | frameIndex, hand, flags (HandCollisionAvailabilityFlag), collisionSequence, collisionGeneration, handBodyCount, dynamicTwinCount, generations, otherHandContactSlots, weaponContactSlots, dynamicCollisionLayer, pairSuppressionLeaseCount, collisionEnabledBodyCount, filterKnownBodyCount |
EjectionClearanceRequest | reference, expectedBase, weaponGenerationKey, weaponSlot, weaponFormId, flags |
ObjectRestRequest | reference, expectedBase |
SurfaceTrianglesRequest (2.1) | centreGame, radiusGame, the three guard generations |
SurfaceTriangle (2.1) | aGame, bGame, cGame, normalGame, layer |
SurfaceTrianglesResult (2.1) | count, flags (SurfaceTrianglesFlag: Truncated), frameIndex, the three generations |
BodyZoneKind covers pelvis, spine, chest, neck and head, and shoulder to hand on each side. BodyZoneKind 16-23 (leg and foot zones) and BodyContactTargetKind 1 (Hand), 4 (Body) and 5 (External) are retired and never reused. kNoBody (0x7FFFFFFF) marks a missing body.
Declarations
Complete public declarations: ROCK/Collision.h
#pragma once
#include "Abi.h"
#pragma pack(push, 8)
namespace rock::api::collision {
inline constexpr InterfaceId kInterfaceId = InterfaceId::Collision;
inline constexpr std::uint32_t kMajor = 2;
inline constexpr std::uint32_t kMinor = 1;
inline constexpr std::uint32_t kMaxBodyContacts = 128;
inline constexpr std::uint32_t kMaxSemanticContacts = 20;
inline constexpr std::uint32_t kMaxColliderDescriptors = 96;
inline constexpr std::uint32_t kMaxRaycastsPerOwnerPerFrame = 8;
inline constexpr std::uint32_t kMaxEjectionClearances = 8;
inline constexpr std::uint32_t kMaxObjectRestWatches = 16;
inline constexpr float kMaxRaycastDistanceGame = 8192.0f;
inline constexpr std::uint32_t kNoBody = 0x7FFF'FFFF;
enum class BodyZoneSide : std::uint32_t
{
Center = 0,
Left = 1,
Right = 2,
};
enum class BodyZoneKind : std::uint32_t
{
Unknown = 0,
Pelvis = 1,
SpineLower = 2,
SpineUpper = 3,
Chest = 4,
NeckHead = 5,
LeftShoulder = 6,
LeftUpperArm = 7,
LeftForearmUpper = 8,
LeftForearmLower = 9,
LeftHand = 10,
RightShoulder = 11,
RightUpperArm = 12,
RightForearmUpper = 13,
RightForearmLower = 14,
RightHand = 15,
// 16-23 were the retired leg and foot zones; never reuse them.
};
// 5 (External) is retired with external body registration; 1 (Hand) and
// 4 (Body) are retired because body colliders never touch hands or each
// other. Never reuse them.
enum class BodyContactTargetKind : std::uint32_t
{
Unknown = 0,
Weapon = 2,
HeldObject = 3,
WorldSurface = 6,
DynamicProp = 7,
Actor = 8,
QueryOnly = 9,
};
// ------------------------------------------------------------------
// Hand and body contacts
// ------------------------------------------------------------------
enum class SemanticHandContactFlag : std::uint32_t
{
None = 0,
ContactPointValid = 1u << 0,
ContactNormalValid = 1u << 1,
TargetFormResolved = 1u << 2,
HeldObjectRelation = 1u << 3,
CollisionAvailable = 1u << 4,
TransitionSuppressed = 1u << 5,
};
enum class SemanticContactState : std::uint32_t
{
Begin = 1,
Continued = 2,
End = 3,
};
// One hand collider's contact: role, finger and segment name the part of
// the hand that touched.
struct SemanticHandContact
{
std::uint32_t size{ sizeof(SemanticHandContact) };
std::uint32_t version{ 1 };
std::uint64_t frameIndex{ 0 };
Hand hand{ Hand::None };
std::uint32_t role{ 0 };
std::uint32_t finger{ 0 };
std::uint32_t segment{ 0 };
std::uint32_t handBodyId{ kNoBody };
std::uint32_t targetBodyId{ kNoBody };
std::uint32_t targetFormId{ 0 };
std::uint32_t flags{ 0 };
SemanticContactState contactState{ SemanticContactState::Continued };
std::uint32_t framesSinceContact{ 0 };
std::uint32_t contactSequence{ 0 };
Point3 contactPointGame{};
Point3 contactNormalGame{};
std::uint32_t collisionGeneration{ 0 };
};
// A contact of one of the player's body colliders.
struct BodyContact
{
std::uint32_t size{ sizeof(BodyContact) };
std::uint32_t version{ 1 };
std::uint64_t frameIndex{ 0 };
std::uint32_t bodyId{ kNoBody };
std::uint32_t targetBodyId{ kNoBody };
std::uint32_t bodyLayer{ 0xFFFF'FFFF };
std::uint32_t targetLayer{ 0xFFFF'FFFF };
BodyZoneKind zone{ BodyZoneKind::Unknown };
BodyZoneSide side{ BodyZoneSide::Center };
std::uint32_t role{ 0 };
std::uint32_t descriptorIndex{ 0 };
BodyContactTargetKind targetKind{ BodyContactTargetKind::Unknown };
std::uint32_t inPowerArmor{ 0 };
std::uint32_t hasContactPointGame{ 0 };
Point3 contactPointGame{};
};
// ------------------------------------------------------------------
// Player colliders
// ------------------------------------------------------------------
enum class PlayerColliderKind : std::uint32_t
{
Hand = 1,
Body = 2,
};
enum class PlayerColliderFlag : std::uint32_t
{
None = 0,
Valid = 1u << 0,
Enabled = 1u << 1,
PrimaryPalmAnchor = 1u << 2,
TransformValid = 1u << 3,
InPowerArmor = 1u << 4,
LifecycleAllowed = 1u << 5,
FilterKnown = 1u << 6,
CollisionSuppressed = 1u << 7,
};
struct PlayerColliderDescriptor
{
std::uint32_t size{ sizeof(PlayerColliderDescriptor) };
std::uint32_t version{ 1 };
std::uint64_t frameIndex{ 0 };
PlayerColliderKind kind{ PlayerColliderKind::Hand };
Hand hand{ Hand::None };
std::uint32_t bodyId{ kNoBody };
std::uint32_t role{ 0 };
BodyZoneKind zone{ BodyZoneKind::Unknown };
BodyZoneSide side{ BodyZoneSide::Center };
std::uint32_t descriptorIndex{ 0 };
std::uint32_t flags{ 0 };
float lengthGameUnits{ 0.0f };
float radiusGameUnits{ 0.0f };
Transform transform{};
std::uint32_t collisionGeneration{ 0 };
};
enum class HandCollisionAvailabilityFlag : std::uint32_t
{
None = 0,
BodiesReady = 1u << 0,
DynamicTwinsReady = 1u << 1,
PhysicsWritesAllowed = 1u << 2,
CollisionAvailable = 1u << 3,
TransitionSuppressed = 1u << 4,
MenuSuppressed = 1u << 5,
HandDisabled = 1u << 6,
DynamicInteractionsEnabled = 1u << 7,
DynamicOtherHandContact = 1u << 8,
DynamicWeaponContact = 1u << 9,
DynamicWeaponPairSuppressed = 1u << 10,
DynamicPairFilterReady = 1u << 11,
FilterKnown = 1u << 12,
CollisionSuppressed = 1u << 13,
};
struct HandCollisionAvailability
{
std::uint32_t size{ sizeof(HandCollisionAvailability) };
std::uint32_t version{ 1 };
std::uint64_t frameIndex{ 0 };
Hand hand{ Hand::None };
std::uint32_t flags{ 0 };
std::uint64_t collisionSequence{ 0 };
std::uint32_t collisionGeneration{ 0 };
std::uint32_t handBodyCount{ 0 };
std::uint32_t dynamicTwinCount{ 0 };
std::uint32_t worldGeneration{ 0 };
std::uint32_t skeletonGeneration{ 0 };
std::uint32_t providerGeneration{ 0 };
std::uint32_t otherHandContactSlots{ 0 };
std::uint32_t weaponContactSlots{ 0 };
std::uint32_t dynamicCollisionLayer{ 0 };
std::uint32_t pairSuppressionLeaseCount{ 0 };
std::uint32_t collisionEnabledBodyCount{ 0 };
std::uint32_t filterKnownBodyCount{ 0 };
};
// ------------------------------------------------------------------
// World raycast
// ------------------------------------------------------------------
enum class WorldRaycastResultFlag : std::uint32_t
{
None = 0,
Hit = 1u << 0,
NormalValid = 1u << 1,
};
// What a world raycast can hit.
enum class WorldRaycastFilter : std::uint32_t
{
// The item-picking ray: world geometry, objects and actor bodies.
Selection = 0,
// Visible solid surfaces only (static and animated world geometry,
// terrain, trees, clutter, props, debris, glass); never actors,
// weapons, projectiles, triggers or invisible collision. For things
// that land on the scene, such as blood. Costs a small sweep.
Surfaces = 1,
};
// Nonzero generation fields guard the request.
struct WorldRaycastRequest
{
std::uint32_t size{ sizeof(WorldRaycastRequest) };
std::uint32_t version{ 1 };
Point3 startGame{};
Point3 directionGame{};
float maxDistanceGame{ 0.0f };
std::uint32_t worldGeneration{ 0 };
std::uint32_t skeletonGeneration{ 0 };
std::uint32_t providerGeneration{ 0 };
WorldRaycastFilter filter{ WorldRaycastFilter::Selection };
};
// frameIndex and the generations are those at the time of the cast.
// hitLayer is the Fallout 4 collision layer of the hit body for the
// Surfaces filter; 0 without a hit and for Selection.
struct WorldRaycastResult
{
std::uint32_t size{ sizeof(WorldRaycastResult) };
std::uint32_t version{ 1 };
std::uint32_t hit{ 0 };
std::uint32_t flags{ 0 };
float hitFraction{ 1.0f };
float hitDistanceGame{ 0.0f };
Point3 hitPointGame{};
Point3 hitNormalGame{};
std::uint64_t frameIndex{ 0 };
std::uint32_t worldGeneration{ 0 };
std::uint32_t skeletonGeneration{ 0 };
std::uint32_t providerGeneration{ 0 };
std::uint32_t hitLayer{ 0 };
};
// ------------------------------------------------------------------
// Surface triangles (2.1)
// ------------------------------------------------------------------
inline constexpr float kMaxSurfaceTriangleRadiusGame = 128.0f;
inline constexpr std::uint32_t kMaxSurfaceTriangles = 512;
inline constexpr std::uint32_t kMaxSurfaceTriangleQueriesPerOwnerPerFrame = 2;
/*
* 2.1. The collision triangles of the surfaces queryWorldRaycast's Surfaces
* filter can hit (visible solid world geometry, terrain, clutter; never
* actors, weapons, projectiles, triggers or invisible collision) within
* radiusGame of centreGame, in game units, as they lie this frame. For
* code that tests many short paths against the scene, such as flying blood,
* with one query instead of a raycast per path per frame. Convex bodies
* are their hulls, without the rounding of their convex radius. Nonzero
* generation fields guard the request.
*/
struct SurfaceTrianglesRequest
{
std::uint32_t size{ sizeof(SurfaceTrianglesRequest) };
std::uint32_t version{ 1 };
Point3 centreGame{};
float radiusGame{ 0.0f };
std::uint32_t worldGeneration{ 0 };
std::uint32_t skeletonGeneration{ 0 };
std::uint32_t providerGeneration{ 0 };
};
// a, b, c wind counter-clockwise seen from the side normalGame faces.
// layer is the Fallout 4 collision layer of the body it belongs to.
struct SurfaceTriangle
{
Point3 aGame{};
Point3 bGame{};
Point3 cGame{};
Point3 normalGame{};
std::uint32_t layer{ 0 };
std::uint32_t reserved{ 0 };
};
enum class SurfaceTrianglesFlag : std::uint32_t
{
// More triangles lay in the sphere than capacity or ROCK's own limit.
Truncated = 1u << 0,
};
// frameIndex and the generations are those at the time of the query.
struct SurfaceTrianglesResult
{
std::uint32_t size{ sizeof(SurfaceTrianglesResult) };
std::uint32_t version{ 1 };
std::uint32_t count{ 0 };
std::uint32_t flags{ 0 };
std::uint64_t frameIndex{ 0 };
std::uint32_t worldGeneration{ 0 };
std::uint32_t skeletonGeneration{ 0 };
std::uint32_t providerGeneration{ 0 };
std::uint32_t reserved{ 0 };
};
// ------------------------------------------------------------------
// Environment
// ------------------------------------------------------------------
// The generated bodies of one weapon slot (bodyCount 0 without one).
struct WeaponBodies
{
std::uint64_t weaponGenerationKey{ 0 };
std::uint32_t bodyCount{ 0 };
std::uint32_t bodyIds[8]{};
};
// Physics scale and each weapon slot's generated bodies for the
// publication named by sample. Both slots are published; a slot without
// generated bodies has bodyCount 0.
struct Environment
{
std::uint32_t size{ sizeof(Environment) };
std::uint32_t version{ 1 };
Sample sample{};
float gameToHavokScale{ 0.0f };
float havokToGameScale{ 0.0f };
std::uint32_t physicsScaleRevision{ 0 };
WeaponBodies weapons[kMaxWeaponSlots]{};
};
// ------------------------------------------------------------------
// Ejection clearance
// ------------------------------------------------------------------
enum class EjectionClearanceFlag : std::uint32_t
{
// Also exclude the object's contacts with both physical hands.
IncludeHands = 1u << 0,
};
/*
* For one second after the reference's bodies become available (up to
* 1.5 s waiting for them to load), the reference does not collide with
* the weapon in weaponSlot, nor with the hands under IncludeHands. World
* and other objects still collide; ray queries and grabbing are
* unaffected. reference names the object; expectedBase its base form;
* weaponFormId and weaponGenerationKey witness the slot's weapon. Repeating the same request
* observes it and never extends the deadline: RequestQueued while waiting,
* Ok once active or completed. At most kMaxEjectionClearances references;
* owner, generation or weapon changes revoke a clearance.
*/
struct EjectionClearanceRequest
{
std::uint32_t size{ sizeof(EjectionClearanceRequest) };
std::uint32_t version{ 1 };
ReferenceKey reference{};
std::uint32_t expectedBase{ 0 };
std::uint64_t weaponGenerationKey{ 0 };
std::uint32_t weaponSlot{ 0 };
std::uint32_t weaponFormId{ 0 };
std::uint32_t flags{ 0 };
};
// ------------------------------------------------------------------
// Object rest
// ------------------------------------------------------------------
enum class ObjectRestState : std::uint32_t { Waiting, Watching, Resting };
/*
* Watches a dropped MISC reference until it rests. RequestQueued admits a
* watch (at most kMaxObjectRestWatches); poll with the same request: Ok
* reports Watching or Resting. Resting acknowledges completion and frees
* the watch. Retry CapacityFull, NotReady or TargetUnavailable later. Held
* items cannot rest. Two seconds of supported rest freezes the native
* bodies and saves their final pose; ordinary grabbing wakes them. Owner,
* lifecycle or scene loss cancels unfinished watches; submit again after a
* regrab, drop or load. A completed placement is not undone.
*/
struct ObjectRestRequest
{
std::uint32_t size{ sizeof(ObjectRestRequest) };
std::uint32_t version{ 1 };
ReferenceKey reference{};
std::uint32_t expectedBase{ 0 };
};
// Permission bits are local to this interface major. Discovery grants none.
enum class Permission : std::uint32_t { Read = 1, Write = 2 };
inline constexpr std::uint32_t kSupportedPermissions = 3;
struct Api
{
static constexpr InterfaceId interfaceId = kInterfaceId;
static constexpr std::uint32_t majorVersion = kMajor;
static constexpr std::uint32_t minorVersion = kMinor;
// Game thread (Read). Contacts no older than maxFramesSinceContact.
Status(ROCK_CALL* copySemanticHandContacts)(OwnerToken owner, Hand hand, std::uint32_t maxFramesSinceContact, SemanticHandContact* outContacts, std::uint32_t capacity, std::uint32_t* outCount) noexcept;
Status(ROCK_CALL* copyPlayerColliderDescriptors)(OwnerToken owner, PlayerColliderDescriptor* outDescriptors, std::uint32_t capacity, std::uint32_t* outCount) noexcept;
Status(ROCK_CALL* copyBodyContacts)(OwnerToken owner, BodyContact* outContacts, std::uint32_t capacity, std::uint32_t* outCount) noexcept;
Status(ROCK_CALL* getHandCollisionAvailability)(OwnerToken owner, Hand hand, HandCollisionAvailability* outState) noexcept;
// Game thread (Read); at most kMaxRaycastsPerOwnerPerFrame per frame.
Status(ROCK_CALL* queryWorldRaycast)(OwnerToken owner, const WorldRaycastRequest* request, WorldRaycastResult* outResult) noexcept;
// Any thread (Read).
Status(ROCK_CALL* getEnvironment)(OwnerToken owner, Environment* outEnvironment) noexcept;
// Game thread; Write to request, owner only to cancel. reference 0
// cancels all of the owner's clearances or watches.
Status(ROCK_CALL* requestEjectionClearance)(OwnerToken owner, const EjectionClearanceRequest* request) noexcept;
Status(ROCK_CALL* cancelEjectionClearance)(OwnerToken owner, std::uint32_t referenceFormId) noexcept;
Status(ROCK_CALL* watchObjectRest)(OwnerToken owner, const ObjectRestRequest* request, ObjectRestState* outState) noexcept;
Status(ROCK_CALL* cancelObjectRest)(OwnerToken owner, std::uint32_t referenceFormId) noexcept;
// Any thread. Identity of the current publication.
Status(ROCK_CALL* getSample)(OwnerToken owner, Sample* outSample) noexcept;
// 2.1. Game thread (Read); at most
// kMaxSurfaceTriangleQueriesPerOwnerPerFrame per frame. capacity is at
// most kMaxSurfaceTriangles; outResult->count triangles are written.
Status(ROCK_CALL* queryWorldSurfaceTriangles)(OwnerToken owner, const SurfaceTrianglesRequest* request,
SurfaceTriangle* outTriangles, std::uint32_t capacity, SurfaceTrianglesResult* outResult) noexcept;
};
}
#pragma pack(pop)