Skip to content

Commit

Permalink
Implement reattaching objects to baked SDF (deletion + attached geom …
Browse files Browse the repository at this point in the history
…+ wraps still broken, #1004)
  • Loading branch information
adamkewley committed Feb 14, 2025
1 parent b765786 commit c5a0d1f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions libopensimcreator/Documents/Model/UndoableModelActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2357,21 +2357,31 @@ bool osc::ActionBakeStationDefinedFrames(IModelStatePair& model)
// - Add the `PhysicalOffsetFrame` into the model in the exact same location + name, so that
// all sockets, associations, etc. work as expected
OpenSim::Model& mutModel = model.updModel();
std::vector<OpenSim::StationDefinedFrame*> sdfsToDelete;
for (auto& sdf : mutModel.updComponentList<OpenSim::StationDefinedFrame>()) {
auto pof = std::make_unique<OpenSim::PhysicalOffsetFrame>();
//static_cast<OpenSim::Object&>(*pof) = sdf;
// TODO: copy component/frame stuff (attached geometry, wrap objects)
// TODO: copy
// - Subcomponents
// - Attached Geometry
// - Wrap Obects
pof->setName(sdf.getName() + "_tmp");
const SimTK::Transform xform = sdf.findTransformInBaseFrame();
pof->set_translation(xform.p());
pof->set_orientation(xform.R().convertRotationToBodyFixedXYZ());
pof->updSocket("parent").setConnecteePath(sdf.findBaseFrame().getAbsolutePathString());
//pof->connectSocket_parent(sdf.findBaseFrame());

// Add it into the model
auto& pofPtr = *pof;
mutModel.updComponent(sdf.getAbsolutePath().getParentPath()).addComponent(pof.release());
// TODO: reassign anything that links to the SDF to instead link to the POF
pofPtr.finalizeConnections(mutModel);
// Reassign anything pointing to the SDF to instead point to the POF
RecursivelyReassignAllSockets(mutModel,sdf, pofPtr);
sdfsToDelete.push_back(&sdf);
}

for (OpenSim::StationDefinedFrame* sdf : sdfsToDelete) {
TryDeleteComponentFromModel(mutModel, *sdf);
}
FinalizeConnections(mutModel);
InitializeModel(mutModel);
InitializeState(mutModel);
model.commit("Bake `StationDefinedFrame`s");
Expand Down

0 comments on commit c5a0d1f

Please sign in to comment.