VR-Engage  2.3
Loading...
Searching...
No Matches
vortexCollisionDynamicsExtension.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2026 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vortexCollisionDynamicsExtension.h
7//! \brief Extension for Processing Vortex Collisions
8//! \ingroup vreVrfVortex
9
10#pragma once
11
12#include <vreVrfVortex/export.h>
13
16
18
19#include <deque>
20#include <map>
21#include <memory>
22#include <mutex>
23#include <string>
24#include <vector>
25
26#include <Vx/VxDynamicsExtension.h>
27#include <Vx/VxUniverse.h>
28#include <Vx/VxUniverseObserver.h>
29#include <Vx/VxCollisionGeometry.h>
30#include <Vx/VxCompositeCollisionGeometry.h>
31#include <Vx/VxCollisionGeometryPair.h>
32#include <Vx/VxIntersectResult.h>
33
34namespace Vx
35{
36class VxUniverse;
37class VxUniverseObserver;
38} // namespace Vx
39
40class DtSimObject;
41
42namespace makVre
43{
47
48//! \brief Recursively iterates over a collision geometry and its children, invoking a callback for each.
49//!
50//! Traverses `VxCompositeCollisionGeometry` nodes into their child geometries, invoking `fn` on
51//! the composite node itself and on every descendant.
52//!
53//! \param geo Collision geometry to iterate.
54//! \param fn Callback invoked for each visited geometry. Signature should be `void(Vx::VxCollisionGeometry*)`.
55template <typename Fn>
56inline void forEachGeometryNode(Vx::VxCollisionGeometry* geo, Fn&& fn)
57{
58 if (!geo)
59 {
60 return;
61 }
62 fn(geo);
63 if (auto* composite = dynamic_cast<Vx::VxCompositeCollisionGeometry*>(geo))
64 {
65 for (auto* child : composite->getCollisionGeometries())
66 {
67 forEachGeometryNode(child, fn);
68 }
69 }
70}
71
72//! \brief Universe observer that removes cached part-to-UUID mappings when parts are deleted.
73class DtVortexUniverseObserver final : public Vx::VxUniverseObserver
74{
75public:
76 //! \brief Constructor.
77 //!
78 //! \param ext Owning collision dynamics extension.
80 //! \brief Destructor.
81 ~DtVortexUniverseObserver() override = default;
82 //! \brief Copy construction is disabled.
84 //! \brief Copy assignment is disabled.
86 //! \brief Move construction is disabled.
88 //! \brief Move assignment is disabled.
90
91 //! \brief Callback invoked when a Vortex part is removed from the universe.
92 //!
93 //! \param part Removed part pointer.
94 void onPartRemoved(Vx::VxPart* part);
95
96protected:
97 //! \brief Owning extension used to forward part-removal notifications.
99};
100
101//! \brief Handles Vortex collision collection, message exchange, and impulse application.
102//!
103//! \details The Vortex Collision Dynamics Extension classifies local parts, collects detected collisions between them,
104//! computes impulses to apply to remote proxies, and sends/receives those remote impulse messages.
105//!
106//! This class extends Vortex's VxDynamicsExtension, and utilizes extensions of Vortex's IntersectSubscriber and UniverseObserver
107//!
108//! This extension has three classifications of parts, these are assigned using the tagGeometryAs... methods for each type.
109//! Proxy: Inactive parts that either are not currently, or are unable to be simulated by Vortex.
110//! These can include fallback boxes. These have the proxy response type, which is used as a flag to configure the intersect subscriber
111//! Vortex: Active parts that are simulated by Vortex, on the local sim engine.
112//! These have the rigid body response type, which is used as a flag to configure the intersect subscriber
113//! Sensor: Active parts that are simulated by Vortex, but are not simulated on the local.
114//! These have the contact sensor response type, and do not have the rigid body response model
115//!
116//! These three classifications are used in two pairs: Proxy <-> Vortex, and Sensor <-> Vortex. Each pair has its own intersect subscriber,
117//! which is used to collect contacts between the two classifications.
118//!
119//! The PROXY subscriber will simply collect and store contacts, which are only used for CollisionEvents.
120//! The SENSOR subscriber will collect contacts, pass them into Vortex for local impulse, and calculate a remote impulse to send and apply.
121//!
122class VREVRFVORTEX_DLL DtVortexCollisionDynamicsExtension : public Vx::VxDynamicsExtension
123{
124public:
125 struct ContactData; // Forward declaration for ContactData struct
126 //! \brief Constructor.
128 //! \brief Destructor.
130
131 //! \brief Detaches this extension's observer and clears its user dynamics contacts from \p universe.
132 //! \param universe Universe currently owning this extension.
133 void detachFromUniverse(Vx::VxUniverse* universe);
134
135 //! \brief Copy construction is disabled.
137 //! \brief Copy assignment is disabled.
139 //! \brief Move construction is disabled.
141 //! \brief Move assignment is disabled.
143
144 //! \brief Clears per-step contact state before simulation advances.
145 virtual void preStep() override;
146
147 //! \brief Initializes the extension on demand and processes queued remote collision messages.
148 virtual void step() override;
149
150 //! \brief Sends or applies collision impulses for contacts collected during the step.
151 virtual void postStep() override;
152
153 //! \brief Registers proxy collision geometry with this extension.
154 //!
155 //! If the universe is not yet available, the geometry is queued for deferred assignment once the universe is initialized.
156 //!
157 //! \param geo Geometry to configure for proxy-vs-Vortex collision collection.
158 virtual void tagGeometryAsProxy(Vx::VxCollisionGeometry* geo);
159
160 //! \brief Registers Vortex collision geometry with this extension.
161 //!
162 //! If the universe is not yet available, the geometry is queued for deferred assignment once the universe is initialized.
163 //!
164 //! \param geo Geometry to configure for Vortex collision collection.
165 virtual void tagGeometryAsVortex(Vx::VxCollisionGeometry* geo);
166
167 //! \brief Registers Vortex collision geometry and associates its part with a simulation UUID.
168 //!
169 //! If the universe is not yet available, the geometry is queued for deferred assignment once the universe is initialized.
170 //!
171 //! \param geo Geometry to configure for Vortex collision collection.
172 //! \param uuid UUID of the owning simulation object.
173 virtual void tagGeometryAsVortex(Vx::VxCollisionGeometry* geo, DtUUID uuid);
174
175 //! \brief Registers sensor collision geometry with this extension, and associates its part with a simulation UUID.
176 //!
177 //! If the universe is not yet available, the geometry is queued for deferred assignment once the universe is initialized.
178 //!
179 //! \param geo Geometry to configure for sensor collision collection.
180 //! \param uuid UUID of the owning simulation object.
181 virtual void tagGeometryAsSensor(Vx::VxCollisionGeometry* geo, DtUUID uuid);
182
183 //! \brief Registers sensor collision geometry with this extension.
184 //!
185 //! If the universe is not yet available, the geometry is queued for deferred assignment once the universe is initialized.
186 //!
187 //! \param geo Geometry to configure for sensor collision collection.
188 virtual void tagGeometryAsSensor(Vx::VxCollisionGeometry* geo);
189
190 //! \brief Removes a cached Vortex part-to-UUID mapping.
191 //!
192 //! \param part Part to remove from the mapping table.
193 virtual void removeVortexPart(Vx::VxPart* part);
194
195 //! \brief Handles an incoming collision message from the message manager.
196 //!
197 //! \param message Incoming message payload.
198 //! \return `HANDLED` when accepted for deferred processing; `IGNORED` otherwise.
200
201 //! \brief Creates and queues a collision message from a Vortex contact.
202 //!
203 //! \param data ContactData used to build the outgoing message.
204 virtual void sendCollisionMessage(const ContactData& data);
205
206 //! \brief Returns proxy-vs-Vortex contacts collected for the current step.
207 //!
208 //! \return Non-owning reference to the current proxy contact list.
209 const std::vector<ContactData>& getProxyContacts() const;
210
211 //! \brief Returns Vortex-vs-Vortex contacts collected for the current step.
212 //!
213 //! \return Non-owning reference to the current Vortex contact list.
214 const std::vector<ContactData>& getSensorContacts() const;
215
216 //! \brief Gets the response type used for proxy geometries.
217 //!
218 //! \return Vortex response type ID assigned to proxy geometries.
219 Vx::ResponseType getProxyResponseType();
220
221 //! \brief Gets the response type used for Vortex geometries.
222 //!
223 //! \return Vortex response type ID assigned to Vortex geometries.
224 Vx::ResponseType getVortexResponseType();
225
226 //! \brief Gets the response type used for sensor (remotely active Vortex vehicle) geometries.
227 //!
228 //! \return Vortex response type ID assigned to sensor geometries
229 Vx::ResponseType getSensorResponseType();
230
231 //! \brief Gets the Vortex Physical World singleton used by this extension.
232 //! \return Pointer to the Vortex Physical World singleton.
234
235 //! \brief Returns whether networked collision messages are enabled.
236 //! \return True if networked collision messages are enabled, false otherwise.
238
239 //! \brief Renders ImGui controls for tuning collision physics parameters.
241
242 //! \brief Looks up the simulation UUID mapped to a Vortex part.
243 //!
244 //! \param part Part whose UUID is requested.
245 //! \return Mapped UUID, or `DtUUID::nullUUID()` when no mapping exists.
246 DtUUID getVortexUUIDFromPart(Vx::VxPart* part);
247
248 //! \brief Resolves the owning VxPart for a collision geometry, falling back
249 //! to the geometry->part map populated during tagging when the geometry is
250 //! a leaf child of a `VxCompositeCollisionGeometry` and its own `getPart()`
251 //! returns null.
252 //!
253 //! \note Diagnostic helper only
254 //!
255 //! \param geo Collision geometry to resolve.
256 //! \return Owning part, or nullptr when no part can be resolved.
257 Vx::VxPart* resolvePartForGeometry(Vx::VxCollisionGeometry* geo);
258
259 //! \brief Logs the assigned response IDs for every collision geometry on a
260 //! part, recursing into composite geometries. Intended for debugging tagging
261 //! and subscription issues; compares each ID against `proxyResponseType`,
262 //! `vortexResponseType`, and `kResponseSensorContact` and annotates matches.
263 //!
264 //! \note Diagnostic helper only
265 //!
266 //! \param part Part whose geometries should be logged.
267 //! \param label Optional label prefixed to each log line.
268 void logResponseIDsForPart(Vx::VxPart* part, const char* label = "");
269
270 //! \brief Struct for storing VxDynamicsContacts and related info to handle them correctly.
272 {
273 //! \brief Pointer to the VxDynamicsContact
274 Vx::VxDynamicsContact* contact = nullptr;
275 //! \brief Total number of contacts between the same part pair as this one. Proxy contacts have -1
276 int contactCount = -1;
277 };
278
279protected:
280 //! \brief Initializes response models, subscribers, and requests once a universe is available.
281 //!
282 //! \return True when initialization is complete.
284
285 //! \brief Applies response/request IDs to geometries queued before initialization completed.
287
288 //! \brief Tags a geometry tree with the given response ID, deferring until initialization completes.
289 //!
290 //! \param geo Root collision geometry to tag.
291 //! \param responseType Response ID to assign to each leaf geometry.
292 //! \param deferredList List to queue the geometry on when the universe is not yet available.
294 Vx::VxCollisionGeometry* geo, Vx::ResponseType responseType, std::vector<Vx::VxCollisionGeometry*>& deferredList);
295
296 //! \brief Maps a geometry's owning part to a simulation UUID under both part lookup maps.
297 //!
298 //! \param geo Geometry whose owning part should be registered.
299 //! \param uuid Simulation UUID to associate with the part.
300 void registerPartUuidForGeometry(Vx::VxCollisionGeometry* geo, const DtUUID& uuid);
301
302 //! \brief Drains queued received messages and applies their impulses to mapped local parts.
304
305 //! \brief Applies an impulse to a local Vortex part identified by UUID and part name.
306 //!
307 //! Used to apply impulses for both received and locally generated collisions.
308 //!
309 //! \param impulse Impulse vector in Vortex world frame (NWU).
310 //! \param position Contact position expressed as the offset from the target
311 //! entity's origin, in Vortex world axes (NOT rotated into any
312 //! part's body frame). Must match the packing done by
313 //! sendCollisionMessage().
314 //! \param uuid UUID of the target part's simulation object.
315 //! \param partName Name of the target part.
317 const DtVector& impulse, const DtVector& position, const DtUUID& uuid, const std::string& partName);
318
319 //! \brief Looks up a Vortex part by simulation UUID and part name.
320 //!
321 //! \param uuid Simulation UUID of the owning object.
322 //! \param partName Name of the part to find.
323 //! \param entity Non-null owning simulation object whose published VortexArtPartMap supplies
324 //! the fallback chassis part name when the requested part is not mapped.
325 //! \return Non-owning pointer to the requested part or fallback chassis part, or nullptr if neither is mapped.
326 Vx::VxPart* findPartForApplication(const DtUUID& uuid, const std::string& partName, const DtSimObject* entity);
327
328 //! \brief Computes an impulse vector from a Vortex contact for a designated local part.
329 //!
330 //! The impulse magnitude is based on the local part's mass only, so the result is
331 //! independent of the sensor proxy mass (which is unreliable for remote Vortex vehicles).
332 //! The caller is responsible for negating the result to obtain the reaction impulse for
333 //! the remote side.
334 //!
335 //! \param data Source contact inside ContactData struct.
336 //! \param localPart Part that should receive the resulting impulse direction/sign convention.
337 //! \return Impulse vector in world coordinates, scaled by the local part's mass.
338 DtVector calculateImpulseFromContact(const ContactData& data, Vx::VxPart* localPart);
339
340 //! \brief Calculates the reduced mass for physics calculation of a collision between two parts.
341 //!
342 //! \param remotePart Pointer to the remote Vortex part involved in the collision.
343 //! \param localPart Pointer to the local Vortex part involved in the collision.
344 //! \param normal Collision normal vector.
345 //! \param position Collision position vector.
346 //! \return Reduced mass value for the collision
348 Vx::VxPart* remotePart, Vx::VxPart* localPart, Vx::VxVector3 normal, Vx::VxVector3 position);
349
350 //! \brief Sets message UUID fields and identifies which part is remote for message application.
351 //!
352 //! \param part0 First part in the contact pair.
353 //! \param part1 Second part in the contact pair.
354 //! \param message Message to populate.
355 //! \return `0` when `part0` is remote, `1` when `part1` is remote, or `-1` on error.
356 int handlePartUUIDsForMessage(Vx::VxPart* part0, Vx::VxPart* part1, VortexCollisionMessage* message);
357
358 //! \brief Inverts a 3x3 matrix, returning false if the determinant is too small.
359 //!
360 //! \param m Input matrix to invert.
361 //! \param invOut Output matrix to receive the inverse.
362 //! \param eps Threshold for determinant magnitude below which the matrix is considered singular.
363 static bool invertVxReal33(const Vx::VxReal33& m, Vx::VxReal33& invOut, double eps = 1e-12);
364
365 //! \brief Converts a world position to the Vortex frame, accounting for coordinate system differences.
366 //!
367 //! \param worldPos Position in the world frame
368 //! \param vortexPosOut Output position in the Vortex frame
369 void worldPosToVortexFrame(const DtVector& worldPos, DtVector& vortexPosOut);
370
371 //! \brief Converts a world position to a Vortex coordinate frame, entity centered, format
372 //!
373 //! Converts a position in Vortex world coordinates (worldPos), to an entity centered position in the world frame (outpos), which is still in vortex coordinates
374 //!
375 //! \param part Pointer to the Vortex part whose frame is used for the relative position.
376 //! \param outpos Output position in the world frame, relative to the part's origin.
377 //! \param worldPos Position in the Vortex frame to be converted (eg. of the collision)
378 //! \return True if the conversion was successful, false if the part is null or has no transform.
379 bool getPosEntityRelativeVortex(Vx::VxPart* part, DtVector& outpos, Vx::VxVector3& worldPos);
380
381
382 //! \brief True once response models, requests, and subscribers have been initialized.
384
385 //! \brief Back-pointer to the global Vortex physical world singleton.
387
388 //! \brief Response ID for box-proxy geometries (non-Vortex vehicles).
389 //! Produces real dynamics contacts against Vortex vehicles.
390 Vx::ResponseType myProxyResponseType;
391
392 //! \brief Response ID for local Vortex-vehicle geometries.
393 //! Pairs with myProxyResponseType (solver contacts) and mySensorResponseType
394 //! (sensor contacts for remote Vortex peers, resolved via message exchange).
395 Vx::ResponseType myVortexResponseType;
396
397 //! \brief Response ID for local proxies of vehicles that actively simulated on a remote sim engine
398 //! Used to filter intersect detections against remote proxies
399 Vx::ResponseType mySensorResponseType;
400
401 //! \brief Universe collision request ID shared by proxy and Vortex geometries.
403
404 //! \name Physics tuning parameters
405 //! These fields are all configurable in vortexConfig.lua, to allow for tuning the physics reactions
406 //! The three fields related to impulse generation (BaumgarteFraction, BaumgarteSquared, Restitution) are all adjustable per sim-engine from the remote debugger, however, those values do not persist.
407 //! When tuning, if needed, the most important number is myBaumgarteFraction, tune it first until collisions are decent.
408 //! Increase myBaumgarteSquared if the entities are still penetrating too far/resolution is slow.
409 //! Increase myRestitution to make the collisions more elastic
410 //! Decrease myMaxSeparationVelocityForApplication if the entities are being flung too far apart, and if impulses continue to be applied after separation.
411 //! myWarmStartFraction is probably the least significant parameter, but increasing it should make collisions smoother/prolong their effects.
412 //!@{
413
414 //! \brief Fraction of penetration depth to resolve per step (Baumgarte linear term).
415 double myBaumgarteFraction = 0.75;
416 //! \brief Coefficient for quadratic penetration correction term.
417 double myBaumgarteSquared = 1.0;
418 //! \brief Coefficient of restitution (0 = inelastic, 1 = elastic).
419 double myRestitution = 0.1;
420
421 //! \brief Fraction of previous impulse applied as warm start; smooths out impulse application.
423 0.8; // fraction of previous impulse to apply as warm start. This smooths out impulse application
424
425 //! \brief Maximum separation velocity for which impulses will be applied.
426 //! Prevents applying impulses to parts that are separating too fast.
428 2; // maximum separation velocity for which impulses will be applied. This prevents applying impulses to parts that are separating too fast
429
430 //! \brief Whether collision impulses are exchanged over the network.
432 //!@}
433
434 //! \brief Subscriber for proxy-vs-Vortex contact events.
435 std::unique_ptr<DtVortexIntersectSubscriber> myProxyIntersectSubscriber;
436 //! \brief Subscriber for Vortex-vs-Vortex contact events.
437 std::unique_ptr<DtVortexIntersectSubscriber> mySensorIntersectSubscriber;
438
439 //! \brief Contacts collected for proxy-vs-Vortex collisions this step.
440 std::vector<ContactData> myProxyContacts;
441 //! \brief Contacts collected for Vortex-vs-Vortex collisions this step.
442 std::vector<ContactData> mySensorContacts;
443
444 //! \brief Universe observer used to clean up part mappings on part removal.
446
447 //! \brief Proxy geometries queued before initialization.
448 std::vector<Vx::VxCollisionGeometry*> myDeferredProxyGeometries;
449 //! \brief Vortex geometries queued before initialization.
450 std::vector<Vx::VxCollisionGeometry*> myDeferredVortexGeometries;
451 //! \brief Sensor geometries queued before initialization.
452 std::vector<Vx::VxCollisionGeometry*> myDeferredSensorGeometries;
453
454 //! \brief Mapping from Vortex part pointer to simulation UUID.
455 std::unordered_map<Vx::VxPart*, DtUUID> myVortexPartUUIDMap;
456 //! \brief Reverse mapping from (UUID, partName) to Vortex part pointer.
457 std::map<std::pair<DtUUID, std::string>, Vx::VxPart*> myUUIDPartMap; // Reverse Map (UUID, partName) -> VxPart
458 //! \brief Mapping from a leaf collision geometry (typically a child of a
459 //! VxCompositeCollisionGeometry, whose getPart() returns null) to the
460 //! owning VxPart. Populated when geometries are tagged for the collision
461 //! subscriber so that contact reports referencing composite child geoms can
462 //! still be resolved back to a part.
463 std::unordered_map<Vx::VxCollisionGeometry*, Vx::VxPart*> myGeometryPartMap;
464 //! \brief Mutex protecting `myVortexPartUUIDMap`.
466
467 //! \brief Last known collision simulation time for each UUID.
468 std::unordered_map<DtUUID, double> myLastCollisionTimeMap;
469
470 //! \brief Max age (seconds) of an incoming remote collision message before discard.
471 //! Overridable via `vortexSettings.collisionProxy.maxCollisionImpulseLatency`.
473
474 //! \brief Deferred received-collision payload stored until simulation step processing.
476 {
477 //! \brief UUID1 field from the collision message.
478 DtUUID uuid1;
479 //! \brief UUID2 field from the collision message.
480 DtUUID uuid2;
481 //! \brief Part name associated with the collision target.
482 std::string partName;
483 //! \brief Impulse vector from the message.
484 DtVector impulse;
485 //! \brief Contact position from the message.
486 DtVector position;
487 };
488
489 //! \brief Warm-start impulse cache keyed by UUID/part for the current frame.
490 std::map<std::pair<DtUUID, std::string>, VxMath::Vector3> myCachedImpulses;
491 //! \brief Warm-start impulse cache built for use on the next frame.
492 std::map<std::pair<DtUUID, std::string>, VxMath::Vector3> myCachedImpulsesNextFrame;
493
494 //! \brief Queue of received messages waiting to be processed in `step()`.
495 std::deque<ReceivedMessage> myReceivedMessages;
496 //! \brief Mutex protecting `myReceivedMessages`.
498
499 //! \brief Indicates whether the universe observer is registered.
501};
502
503//! \brief Intersect subscriber that converts Vortex intersect callbacks into contact lists.
504class DtVortexIntersectSubscriber : public Vx::VxUniverse::IntersectSubscriber
505{
506public:
507 //! \brief Contact collection mode.
509 {
510 PROXY = 0, //!< Collect proxy-vs-Vortex contacts.
511 SENSOR = 1, //!< Collect Vortex-vs-Vortex contacts.
512 };
513
514 //! \brief Constructor.
515 //!
516 //! \param ext Owning collision dynamics extension.
517 //! \param mode Contact collection mode.
518 //! \param contacts Output list where generated user contacts are stored.
520 SubscriberMode mode,
521 std::vector<DtVortexCollisionDynamicsExtension::ContactData>* contacts);
522 //! \brief Destructor.
524 //! \brief Copy construction is disabled.
526 //! \brief Copy assignment is disabled.
528 //! \brief Move construction is disabled.
530 //! \brief Move assignment is disabled.
532
533 //! \brief Unused disjoint callback.
534 virtual void notifyDisjoint(Vx::VxUniverse::eIntersectEventType type, Vx::VxIntersectResult* res) override {}
535
536 //! \brief Handles intersect events and stores generated user contacts.
537 //!
538 //! \param type Intersect event type.
539 //! \param ires Intersect result containing geometry/contact information.
540 //! \param dres Dynamics response input for the intersect pair.
541 virtual void notifyIntersect(Vx::VxUniverse::eIntersectEventType type,
542 Vx::VxIntersectResult* ires,
543 Vx::VxDynamicsResponseInput* dres) override;
544
545protected:
546 //! \brief Owning collision extension.
548 //! \brief Contact list managed by the extension for this subscriber mode.
549 std::vector<DtVortexCollisionDynamicsExtension::ContactData>* myCollectedContacts;
550 //! \brief Subscriber operating mode.
552 //! \brief EventType to subscribe to
553 const Vx::VxUniverse::eIntersectEventType mySubscribedEventType = Vx::VxUniverse::kEventActive;
554};
555
556} // namespace makVre
Handles Vortex collision collection, message exchange, and impulse application.
Definition vortexCollisionDynamicsExtension.h:123
DtVortexCollisionDynamicsExtension(const DtVortexCollisionDynamicsExtension &)=delete
Copy construction is disabled.
std::vector< Vx::VxCollisionGeometry * > myDeferredProxyGeometries
Proxy geometries queued before initialization.
Definition vortexCollisionDynamicsExtension.h:448
std::unordered_map< Vx::VxCollisionGeometry *, Vx::VxPart * > myGeometryPartMap
Mapping from a leaf collision geometry (typically a child of a VxCompositeCollisionGeometry,...
Definition vortexCollisionDynamicsExtension.h:463
Vx::VxPart * resolvePartForGeometry(Vx::VxCollisionGeometry *geo)
Resolves the owning VxPart for a collision geometry, falling back to the geometry->part map populated...
void worldPosToVortexFrame(const DtVector &worldPos, DtVector &vortexPosOut)
Converts a world position to the Vortex frame, accounting for coordinate system differences.
virtual void sendCollisionMessage(const ContactData &data)
Creates and queues a collision message from a Vortex contact.
std::map< std::pair< DtUUID, std::string >, VxMath::Vector3 > myCachedImpulsesNextFrame
Warm-start impulse cache built for use on the next frame.
Definition vortexCollisionDynamicsExtension.h:492
virtual void tagGeometryAsVortex(Vx::VxCollisionGeometry *geo)
Registers Vortex collision geometry with this extension.
int handlePartUUIDsForMessage(Vx::VxPart *part0, Vx::VxPart *part1, VortexCollisionMessage *message)
Sets message UUID fields and identifies which part is remote for message application.
double calculateReducedMass(Vx::VxPart *remotePart, Vx::VxPart *localPart, Vx::VxVector3 normal, Vx::VxVector3 position)
Calculates the reduced mass for physics calculation of a collision between two parts.
double myBaumgarteFraction
Fraction of penetration depth to resolve per step (Baumgarte linear term).
Definition vortexCollisionDynamicsExtension.h:415
DtVortexPhysicalWorld * getVortexPhysicalWorld()
Gets the Vortex Physical World singleton used by this extension.
DtUUID getVortexUUIDFromPart(Vx::VxPart *part)
Looks up the simulation UUID mapped to a Vortex part.
void renderImgui()
Renders ImGui controls for tuning collision physics parameters.
virtual void removeVortexPart(Vx::VxPart *part)
Removes a cached Vortex part-to-UUID mapping.
std::map< std::pair< DtUUID, std::string >, VxMath::Vector3 > myCachedImpulses
Warm-start impulse cache keyed by UUID/part for the current frame.
Definition vortexCollisionDynamicsExtension.h:490
static bool invertVxReal33(const Vx::VxReal33 &m, Vx::VxReal33 &invOut, double eps=1e-12)
Inverts a 3x3 matrix, returning false if the determinant is too small.
void applyImpulse(const DtVector &impulse, const DtVector &position, const DtUUID &uuid, const std::string &partName)
Applies an impulse to a local Vortex part identified by UUID and part name.
const std::vector< ContactData > & getSensorContacts() const
Returns Vortex-vs-Vortex contacts collected for the current step.
DtVortexCollisionDynamicsExtension & operator=(DtVortexCollisionDynamicsExtension &&)=delete
Move assignment is disabled.
double myRestitution
Coefficient of restitution (0 = inelastic, 1 = elastic).
Definition vortexCollisionDynamicsExtension.h:419
void registerPartUuidForGeometry(Vx::VxCollisionGeometry *geo, const DtUUID &uuid)
Maps a geometry's owning part to a simulation UUID under both part lookup maps.
virtual void postStep() override
Sends or applies collision impulses for contacts collected during the step.
std::map< std::pair< DtUUID, std::string >, Vx::VxPart * > myUUIDPartMap
Reverse mapping from (UUID, partName) to Vortex part pointer.
Definition vortexCollisionDynamicsExtension.h:457
Vx::VxPart * findPartForApplication(const DtUUID &uuid, const std::string &partName, const DtSimObject *entity)
Looks up a Vortex part by simulation UUID and part name.
bool getPosEntityRelativeVortex(Vx::VxPart *part, DtVector &outpos, Vx::VxVector3 &worldPos)
Converts a world position to a Vortex coordinate frame, entity centered, format.
double myMaxSeparationVelocityForApplication
Maximum separation velocity for which impulses will be applied. Prevents applying impulses to parts t...
Definition vortexCollisionDynamicsExtension.h:427
bool myUniverseObserverRegistered
Indicates whether the universe observer is registered.
Definition vortexCollisionDynamicsExtension.h:500
bool myEnableNetworkedCollisions
Whether collision impulses are exchanged over the network.
Definition vortexCollisionDynamicsExtension.h:431
DtVortexPhysicalWorld * myVortexPhysicalWorld
Back-pointer to the global Vortex physical world singleton.
Definition vortexCollisionDynamicsExtension.h:386
void flushDeferredGeometryAssignments()
Applies response/request IDs to geometries queued before initialization completed.
bool networkCollisionEnabled()
Returns whether networked collision messages are enabled.
Definition vortexCollisionDynamicsExtension.h:237
virtual void tagGeometryAsSensor(Vx::VxCollisionGeometry *geo, DtUUID uuid)
Registers sensor collision geometry with this extension, and associates its part with a simulation UU...
virtual void preStep() override
Clears per-step contact state before simulation advances.
virtual void step() override
Initializes the extension on demand and processes queued remote collision messages.
Vx::ResponseType mySensorResponseType
Response ID for local proxies of vehicles that actively simulated on a remote sim engine Used to filt...
Definition vortexCollisionDynamicsExtension.h:399
std::unordered_map< Vx::VxPart *, DtUUID > myVortexPartUUIDMap
Mapping from Vortex part pointer to simulation UUID.
Definition vortexCollisionDynamicsExtension.h:455
std::vector< Vx::VxCollisionGeometry * > myDeferredSensorGeometries
Sensor geometries queued before initialization.
Definition vortexCollisionDynamicsExtension.h:452
DtVector calculateImpulseFromContact(const ContactData &data, Vx::VxPart *localPart)
Computes an impulse vector from a Vortex contact for a designated local part.
virtual void tagGeometryAsVortex(Vx::VxCollisionGeometry *geo, DtUUID uuid)
Registers Vortex collision geometry and associates its part with a simulation UUID.
std::unique_ptr< DtVortexIntersectSubscriber > myProxyIntersectSubscriber
Subscriber for proxy-vs-Vortex contact events.
Definition vortexCollisionDynamicsExtension.h:435
std::vector< ContactData > mySensorContacts
Contacts collected for Vortex-vs-Vortex collisions this step.
Definition vortexCollisionDynamicsExtension.h:442
Vx::ResponseType myProxyResponseType
Response ID for box-proxy geometries (non-Vortex vehicles). Produces real dynamics contacts against V...
Definition vortexCollisionDynamicsExtension.h:390
void logResponseIDsForPart(Vx::VxPart *part, const char *label="")
Logs the assigned response IDs for every collision geometry on a part, recursing into composite geome...
DtVortexCollisionDynamicsExtension(DtVortexCollisionDynamicsExtension &&)=delete
Move construction is disabled.
std::unique_ptr< DtVortexIntersectSubscriber > mySensorIntersectSubscriber
Subscriber for Vortex-vs-Vortex contact events.
Definition vortexCollisionDynamicsExtension.h:437
std::vector< ContactData > myProxyContacts
Contacts collected for proxy-vs-Vortex collisions this step.
Definition vortexCollisionDynamicsExtension.h:440
std::mutex myVortexPartUUIDMapMutex
Mutex protecting myVortexPartUUIDMap.
Definition vortexCollisionDynamicsExtension.h:465
Vx::ResponseType getProxyResponseType()
Gets the response type used for proxy geometries.
std::mutex myReceivedMessagesMutex
Mutex protecting myReceivedMessages.
Definition vortexCollisionDynamicsExtension.h:497
double myWarmStartFraction
Fraction of previous impulse applied as warm start; smooths out impulse application.
Definition vortexCollisionDynamicsExtension.h:422
virtual DtVreMessageResult handleReceivedCollision(DtVreMessage *message)
Handles an incoming collision message from the message manager.
std::unordered_map< DtUUID, double > myLastCollisionTimeMap
Last known collision simulation time for each UUID.
Definition vortexCollisionDynamicsExtension.h:468
std::vector< Vx::VxCollisionGeometry * > myDeferredVortexGeometries
Vortex geometries queued before initialization.
Definition vortexCollisionDynamicsExtension.h:450
virtual void tagGeometryAsProxy(Vx::VxCollisionGeometry *geo)
Registers proxy collision geometry with this extension.
bool myInitialized
True once response models, requests, and subscribers have been initialized.
Definition vortexCollisionDynamicsExtension.h:383
DtVortexCollisionDynamicsExtension & operator=(const DtVortexCollisionDynamicsExtension &)=delete
Copy assignment is disabled.
Vx::ResponseType myVortexResponseType
Response ID for local Vortex-vehicle geometries. Pairs with myProxyResponseType (solver contacts) and...
Definition vortexCollisionDynamicsExtension.h:395
void detachFromUniverse(Vx::VxUniverse *universe)
Detaches this extension's observer and clears its user dynamics contacts from universe.
double myBaumgarteSquared
Coefficient for quadratic penetration correction term.
Definition vortexCollisionDynamicsExtension.h:417
std::deque< ReceivedMessage > myReceivedMessages
Queue of received messages waiting to be processed in step().
Definition vortexCollisionDynamicsExtension.h:495
Vx::ResponseType getVortexResponseType()
Gets the response type used for Vortex geometries.
virtual void tagGeometryAsSensor(Vx::VxCollisionGeometry *geo)
Registers sensor collision geometry with this extension.
double myMaxCollisionLatency
Max age (seconds) of an incoming remote collision message before discard. Overridable via vortexSetti...
Definition vortexCollisionDynamicsExtension.h:472
DtVortexUniverseObserver myUniverseObserver
Universe observer used to clean up part mappings on part removal.
Definition vortexCollisionDynamicsExtension.h:445
Vx::ResponseType getSensorResponseType()
Gets the response type used for sensor (remotely active Vortex vehicle) geometries.
void processReceivedMessages()
Drains queued received messages and applies their impulses to mapped local parts.
const std::vector< ContactData > & getProxyContacts() const
Returns proxy-vs-Vortex contacts collected for the current step.
void tagGeometryWithResponse(Vx::VxCollisionGeometry *geo, Vx::ResponseType responseType, std::vector< Vx::VxCollisionGeometry * > &deferredList)
Tags a geometry tree with the given response ID, deferring until initialization completes.
int myRequestId
Universe collision request ID shared by proxy and Vortex geometries.
Definition vortexCollisionDynamicsExtension.h:402
bool initializeIfPossible()
Initializes response models, subscribers, and requests once a universe is available.
Intersect subscriber that converts Vortex intersect callbacks into contact lists.
Definition vortexCollisionDynamicsExtension.h:505
SubscriberMode
Contact collection mode.
Definition vortexCollisionDynamicsExtension.h:509
@ PROXY
Collect proxy-vs-Vortex contacts.
Definition vortexCollisionDynamicsExtension.h:510
@ SENSOR
Collect Vortex-vs-Vortex contacts.
Definition vortexCollisionDynamicsExtension.h:511
DtVortexIntersectSubscriber(DtVortexIntersectSubscriber &&)=delete
Move construction is disabled.
DtVortexIntersectSubscriber & operator=(const DtVortexIntersectSubscriber &)=delete
Copy assignment is disabled.
SubscriberMode myMode
Subscriber operating mode.
Definition vortexCollisionDynamicsExtension.h:551
virtual void notifyDisjoint(Vx::VxUniverse::eIntersectEventType type, Vx::VxIntersectResult *res) override
Unused disjoint callback.
Definition vortexCollisionDynamicsExtension.h:534
virtual void notifyIntersect(Vx::VxUniverse::eIntersectEventType type, Vx::VxIntersectResult *ires, Vx::VxDynamicsResponseInput *dres) override
Handles intersect events and stores generated user contacts.
DtVortexIntersectSubscriber(DtVortexCollisionDynamicsExtension *ext, SubscriberMode mode, std::vector< DtVortexCollisionDynamicsExtension::ContactData > *contacts)
Constructor.
DtVortexIntersectSubscriber(const DtVortexIntersectSubscriber &)=delete
Copy construction is disabled.
DtVortexIntersectSubscriber & operator=(DtVortexIntersectSubscriber &&)=delete
Move assignment is disabled.
const Vx::VxUniverse::eIntersectEventType mySubscribedEventType
EventType to subscribe to.
Definition vortexCollisionDynamicsExtension.h:553
std::vector< DtVortexCollisionDynamicsExtension::ContactData > * myCollectedContacts
Contact list managed by the extension for this subscriber mode.
Definition vortexCollisionDynamicsExtension.h:549
DtVortexCollisionDynamicsExtension * myCollisionExtension
Owning collision extension.
Definition vortexCollisionDynamicsExtension.h:547
Main class responsible for managing the Vortex physics simulation environment.
Definition vortexPhysicalWorld.h:65
Universe observer that removes cached part-to-UUID mappings when parts are deleted.
Definition vortexCollisionDynamicsExtension.h:74
~DtVortexUniverseObserver() override=default
Destructor.
DtVortexUniverseObserver & operator=(const DtVortexUniverseObserver &)=delete
Copy assignment is disabled.
DtVortexUniverseObserver(DtVortexCollisionDynamicsExtension *ext)
Constructor.
DtVortexUniverseObserver(const DtVortexUniverseObserver &)=delete
Copy construction is disabled.
DtVortexUniverseObserver & operator=(DtVortexUniverseObserver &&)=delete
Move assignment is disabled.
void onPartRemoved(Vx::VxPart *part)
Callback invoked when a Vortex part is removed from the universe.
DtVortexUniverseObserver(DtVortexUniverseObserver &&)=delete
Move construction is disabled.
DtVortexCollisionDynamicsExtension * myExtension
Owning extension used to forward part-removal notifications.
Definition vortexCollisionDynamicsExtension.h:98
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Used to report collisions between Vortex entities.
Definition vortexCollision.h:34
Export macros for the VR-Forces Vortex extension library.
#define VREVRFVORTEX_DLL
Export macro for non-Windows platforms.
Definition export.h:30
Wheel articulated part IDs used in the system.
Definition surfaceToVxMaterialMapper.h:20
!
Definition glsVreMessageUtil.h:50
void forEachGeometryNode(Vx::VxCollisionGeometry *geo, Fn &&fn)
Recursively iterates over a collision geometry and its children, invoking a callback for each.
Definition vortexCollisionDynamicsExtension.h:56
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Struct for storing VxDynamicsContacts and related info to handle them correctly.
Definition vortexCollisionDynamicsExtension.h:272
Vx::VxDynamicsContact * contact
Pointer to the VxDynamicsContact.
Definition vortexCollisionDynamicsExtension.h:274
int contactCount
Total number of contacts between the same part pair as this one. Proxy contacts have -1.
Definition vortexCollisionDynamicsExtension.h:276
Deferred received-collision payload stored until simulation step processing.
Definition vortexCollisionDynamicsExtension.h:476
DtVector impulse
Impulse vector from the message.
Definition vortexCollisionDynamicsExtension.h:484
DtUUID uuid1
UUID1 field from the collision message.
Definition vortexCollisionDynamicsExtension.h:478
DtUUID uuid2
UUID2 field from the collision message.
Definition vortexCollisionDynamicsExtension.h:480
std::string partName
Part name associated with the collision target.
Definition vortexCollisionDynamicsExtension.h:482
DtVector position
Contact position from the message.
Definition vortexCollisionDynamicsExtension.h:486
Defines the central message manager for the VREngage messaging system.
Defines the base class for all VREngage messages.