Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions include/uipc/constitution/embedded_collision_mesh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once
#include <uipc/geometry/simplicial_complex.h>
#include <uipc/common/dllexport.h>

namespace uipc::constitution
{
// Barycentric embedding of a dense surface mesh onto a coarse tet mesh.
//
// Usage (in IIPCSolver::build_scene):
// EmbeddedCollisionMesh ecm;
// ecm.apply_to(tet_sc, surface_sc);
//
// The surface_sc must be passive (no FEM constitution).
// The tet_sc must already have a FEM constitution applied.
//
// At runtime the CUDA backend reads attributes written here:
// ecm_tet_index (IndexT per surface vertex) — containing tet index
// ecm_bary (Vector4 per surface vertex) — barycentric coords
// ecm_driven (IndexT meta, value=1) — marks the mesh as driven
//
// Reference: SOFA BarycentricMapping — apply() / applyJT()
class UIPC_CONSTITUTION_API EmbeddedCollisionMesh
{
public:
// Build barycentric embedding CPU-side (point-in-tet query).
// Returns false if any surface vertex falls outside all tets (clamped).
bool apply_to(geometry::SimplicialComplex& tet_sc,
geometry::SimplicialComplex& surface_sc) const;
};
}
5 changes: 5 additions & 0 deletions src/backends/cuda/engine/advance_ipc.cu
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ void SimEngine::advance()
step_animation();
m_time_integrator_manager->predict_dof();

// Forward pass: update passive surface positions from tet DOFs
event_before_collision_detection();

// 3. Adaptive Parameter Calculation
detect_dcd_candidates();
compute_adaptive_kappa();
Expand Down Expand Up @@ -340,6 +343,8 @@ void SimEngine::advance()
m_state = SimEngineState::ComputeDyTopoEffect;
compute_dytopo_effect();

// Backward pass: scatter surface contact forces to tet DOFs
event_after_contact_assembly();

// 4) Solve Global Linear System => dx = A^-1 * b
m_state = SimEngineState::SolveGlobalLinearSystem;
Expand Down
12 changes: 12 additions & 0 deletions src/backends/cuda/engine/sim_engine.cu
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ void SimEngine::event_write_scene()
action();
}

void SimEngine::event_before_collision_detection()
{
for(auto& action : m_on_before_collision_detection.view())
action();
}

void SimEngine::event_after_contact_assembly()
{
for(auto& action : m_on_after_contact_assembly.view())
action();
}

void SimEngine::dump_global_surface()
{
BackendPathTool tool{workspace()};
Expand Down
Loading