7 #include "imstkAbstractCellMesh.h" 8 #include "imstkBurnable.h" 9 #include "imstkCellMesh.h" 10 #include "imstkParallelUtils.h" 11 #include "imstkPbdConstraint.h" 12 #include "imstkPbdConstraintContainer.h" 13 #include "imstkPbdModel.h" 14 #include "imstkPbdObject.h" 15 #include "imstkPbdObjectCellRemoval.h" 16 #include "imstkPbdSolver.h" 17 #include "imstkTaskGraph.h" 18 #include "imstkTaskNode.h" 22 Burnable::Burnable(
const std::string& name) :
SceneBehaviour(false, name)
31 CHECK(m_burnableObject !=
nullptr) <<
"Burnable requires a input PBD object," 32 "please add it on creation";
37 m_cellRemover = std::make_shared<PbdObjectCellRemoval>(m_burnableObject, m_updateType);
41 auto cellMesh = std::dynamic_pointer_cast<
AbstractCellMesh>(m_burnableObject->getPhysicsGeometry());
42 int numCells = cellMesh->getNumCells();
44 m_burnDamagePtr = std::make_shared<DataArray<double>>(numCells);
45 m_burnVisualPtr = std::make_shared<DataArray<double>>(numCells);
47 for (
int i = 0; i < numCells; i++)
49 m_burnDamagePtr->at(i) = 0.0;
50 m_burnVisualPtr->at(i) = 0.0;
53 cellMesh->setCellAttribute(
"BurnDamage", m_burnDamagePtr);
54 cellMesh->setCellAttribute(
"BurnVisual", m_burnVisualPtr);
59 Burnable::visualUpdate(
const double& dt)
67 if (m_burnableObject->getPbdBody()->cellConstraintMap.empty())
69 m_burnableObject->computeCellConstraintMap();
73 auto pbdBody = m_burnableObject->getPbdBody();
76 auto cellMesh = std::dynamic_pointer_cast<
AbstractCellMesh>(m_burnableObject->getPhysicsGeometry());
77 auto cellVerts = std::dynamic_pointer_cast<
DataArray<int>>(cellMesh->getAbstractCells());
81 auto burnStatePtr = std::dynamic_pointer_cast<
DataArray<double>>(cellMesh->getCellAttribute(
"BurnDamage"));
86 ParallelUtils::parallelFor(cellMesh->getNumCells(),
89 if (burnState[cellId] >= 1.0)
92 m_cellRemover->removeCellOnApply(cellId);
93 pbdBody->cellConstraintMap.erase(cellId);
94 burnState[cellId] = 0.0;
97 }, cellMesh->getNumCells() > 50);
99 m_cellRemover->apply();
void unlock()
End a thread-safe region.
virtual int getNumberOfComponents() const override
Returns the number of components.
std::weak_ptr< Entity > getEntity() const
Get parent entity.
void lock()
Start a thread-safe region, where only one thread can execute at a time until a call to the unlock fu...
Base class for scene objects that move and/or deform under position based dynamics formulation...
void init() override
Initialize the component, called at a later time after all component construction is complete...
Simple dynamic array implementation that also supports event posting and viewing/facade.
Provides non templated base for cell based meshes.