Skip to content

Commit 0620632

Browse files
committed
--[Bugfix] - Scene Reset Redundancy (#2470)
* --modify reset() to not perform redundant object re-placement After successful scene creation, reset is called, but the objects have all already been placed in their initial positions. * --fix bindings Don't expose the boolean in reset to python, should only be consumed from Simulator::reconfigure
1 parent 79d507a commit 0620632

File tree

5 files changed

+30
-19
lines changed

5 files changed

+30
-19
lines changed

src/esp/bindings/SimBindings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void initSimBindings(py::module& m) {
164164
R"(Use gfx_replay_manager for replay recording and playback.)")
165165
.def("seed", &Simulator::seed, "new_seed"_a)
166166
.def("reconfigure", &Simulator::reconfigure, "configuration"_a)
167-
.def("reset", &Simulator::reset)
167+
.def("reset", [](Simulator& self) { self.reset(false); })
168168
.def(
169169
"close", &Simulator::close, "destroy"_a = true,
170170
R"(Free all loaded assets and GPU contexts. Use destroy=true except where noted in tutorials/async_rendering.py.)")

src/esp/physics/PhysicsManager.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,24 @@ class PhysicsManager : public std::enable_shared_from_this<PhysicsManager> {
264264

265265
/**
266266
* @brief Reset the simulation and physical world.
267-
* Sets the @ref worldTime_ to 0.0, changes the physical state of all objects back to their initial states. Only changes motion_type when scene_instance specified a motion type.
268-
*/
269-
virtual void reset() {
267+
* Sets the @ref worldTime_ to 0.0, changes the physical
268+
* state of all objects back to their initial states.
269+
* Only changes motion_type when scene_instance specified a motion type.
270+
* @param calledAfterSceneCreate If this is true, this is being called
271+
* directly after a new scene was created and all the objects were placed
272+
* appropriately, so bypass object placement reset code.
273+
*/
274+
virtual void reset(bool calledAfterSceneCreate) {
270275
// reset object states from initial values (e.g. from scene instance)
271276
worldTime_ = 0.0;
272-
for (const auto& bro : existingObjects_) {
273-
bro.second->resetStateFromSceneInstanceAttr();
274-
}
275-
for (const auto& bao : existingArticulatedObjects_) {
276-
bao.second->resetStateFromSceneInstanceAttr();
277+
if (!calledAfterSceneCreate) {
278+
// No need to re-place objects after scene creation
279+
for (const auto& bro : existingObjects_) {
280+
bro.second->resetStateFromSceneInstanceAttr();
281+
}
282+
for (const auto& bao : existingArticulatedObjects_) {
283+
bao.second->resetStateFromSceneInstanceAttr();
284+
}
277285
}
278286
}
279287

src/esp/sim/Simulator.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,9 @@ bool Simulator::createSceneInstance(const std::string& activeSceneName) {
426426
success = instanceArticulatedObjectsForSceneAttributes(
427427
curSceneInstanceAttributes_);
428428
if (success) {
429-
// TODO : reset may eventually have all the scene instantiation code so
430-
// that scenes can be reset
431-
reset();
429+
// Pass true so that the object/AO placement code is bypassed in
430+
// physicsManager_->reset
431+
reset(true);
432432
}
433433
}
434434
}
@@ -670,20 +670,20 @@ bool Simulator::instanceArticulatedObjectsForSceneAttributes(
670670
return true;
671671
} // Simulator::instanceArticulatedObjectsForSceneAttributes
672672

673-
void Simulator::reset() {
673+
void Simulator::reset(bool calledAfterSceneCreate) {
674674
if (physicsManager_ != nullptr) {
675675
// Note: resets time to 0 and all existing objects set back to initial
676676
// states. Does not add back deleted objects or delete added objects. Does
677677
// not break ManagedObject pointers.
678-
physicsManager_->reset();
678+
physicsManager_->reset(calledAfterSceneCreate);
679679
}
680680

681681
for (auto& agent : agents_) {
682682
agent->reset();
683683
}
684684
getActiveSceneGraph().getRootNode().computeCumulativeBB();
685685
resourceManager_->setLightSetup(gfx::getDefaultLights());
686-
} // Simulator::reset()
686+
} // Simulator::reset
687687

688688
metadata::attributes::SceneInstanceAttributes::ptr
689689
Simulator::buildCurrentStateSceneAttributes() const {

src/esp/sim/Simulator.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ class Simulator {
7575
* Does not invalidate existing ManagedObject wrappers.
7676
* Does not add or remove object instances.
7777
* Only changes motion_type when scene_instance specified a motion type.
78+
* @param calledAfterSceneCreate Whether this reset is being called after a
79+
* new scene has been created in reconfigure. If so we con't want to
80+
* redundantly re-place the newly-placed object positions.
7881
*/
79-
void reset();
82+
void reset(bool calledAfterSceneCreate = false);
8083

8184
void seed(uint32_t newSeed);
8285

src/tests/PhysicsTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ void PhysicsTest::testJoinCompound() {
224224
objectTemplate->setJoinCollisionMeshes(true);
225225
}
226226
objectAttributesManager->registerObject(objectTemplate);
227-
physicsManager_->reset();
227+
physicsManager_->reset(false);
228228

229229
// add and simulate objects
230230
int num_objects = 7;
@@ -302,7 +302,7 @@ void PhysicsTest::testCollisionBoundingBox() {
302302
objectTemplate->setBoundingBoxCollisions(true);
303303
}
304304
objectAttributesManager->registerObject(objectTemplate);
305-
physicsManager_->reset();
305+
physicsManager_->reset(false);
306306

307307
auto objectWrapper = makeObjectGetWrapper(
308308
objectFile, &sceneManager_->getSceneGraph(sceneID_).getDrawables());
@@ -612,7 +612,7 @@ void PhysicsTest::testMotionTypes() {
612612

613613
// reset the scene
614614
rigidObjectManager_->removeAllObjects();
615-
physicsManager_->reset(); // time=0
615+
physicsManager_->reset(false); // time=0
616616
}
617617
}
618618
} // PhysicsTest::testMotionTypes

0 commit comments

Comments
 (0)