Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scene Import 1.0 #1034

Merged
merged 40 commits into from Feb 2, 2021
Merged

Conversation

jturner65
Copy link
Contributor

Motivation and Context

This PR replaces the old version found here since much of the old PR was split out into individual PRs that have been merged already.

This PR adds the support for importing scene instances. A scene instance describes a scene layout, using handles to attributes for the various assets used that are specified/defined in a scene dataset configuration file. The scene instance can describe the assets and transformations needed to build instances of a stage, 1 or more objects, a lighting configuration, navmesh and semantic scene descriptor files.

The stage and object instances described in a scene instance include their necessary transformations to align them properly in the scene. For objects, it also includes the motion type the object possesses, and whether or not the position of the placed object should be measured from the COM or from some asset-related origin.

All of Scene Instance Import functionality is driven by data specified in SimulatorConfiguration.

While this functionality is designed as part of the scene dataset configuration functionality that has been added, it is fully backwards compatible with the current scene/stage loading mechanism, and intended to remain so. If the user does not specify an existing scene dataset configuration, the system uses a default that can be modified and expanded (and in the next version of this functionality, saved as well). If the user attempts to load a stage via reconfigure, this functionality will internally construct a scene instance containing that stage and add it to the default dataset.

Future updates to this process are going to include the ability to save stage and object arrangements from within habitat-sim as scene instance configurations, as well as saving scene dataset configurations constructed/modified within habitat.

How Has This Been Tested

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Jan 18, 2021
@jturner65 jturner65 mentioned this pull request Jan 18, 2021
11 tasks
@Skylion007 Skylion007 requested a review from mosra January 19, 2021 02:58
* is created
* @return Whether successful or not
*/
bool createPathfinder(const std::string& navmeshFilename);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, why is the necessary over the existing pathfinder API? shouldn't this be a method on pathfinder? Why should it be its own method. (There are already a lot of duplicate / unused methods on Simulator.h, so we should reuse / refactor when possible.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to support the eventual addition of multiple navmeshes, each of which will require their own pathfinder.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still should remove the amount stat calls to the file system. Doesn't pathfinder already do a file exists check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that fewer OS hits would be a great thing. What you see was the existing mechanism for loading navmesh in reconfigure, which is why I have not modified it.

The loading function does check for file existence, along with multiple other failure conditions, and returns only a boolean success value. By having this test, we can know for certain whether failure is caused by non-existing file, or some other condition, without having to refactor PathFinder::loadNavMesh, which I felt is a bit beyond the scope of this PR.

src/esp/sim/Simulator.cpp Outdated Show resolved Hide resolved
src/esp/sim/Simulator.cpp Outdated Show resolved Hide resolved
@Skylion007
Copy link
Contributor

Do we have any validate JSON functions, currently? I feel like those would be useful.

Copy link
Contributor

@aclegg3 aclegg3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Some questions and suggestions. Would also like to see some tested example scene instances, maybe a test_dataset created from the test_assets directory?

Comment on lines +332 to +335
// make sure that all stage, object and lighting attributes referenced in
// scene attributes are loaded in dataset, as well as the scene attributes
// itself.
datasetAttr->addNewSceneInstanceToDataset(sceneAttributes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This says make sure, so can it fail? Should the process proceed if something fails to load here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what the function does. If it does not find named attributes within the dataset corresponding to those specified in the scene instance, it attempts to create them. This process will not "fail" per se, but empty results/unfound attributes may not be what the user wishes for. Or, it may be, depending on the source of the scene instance attributes that has been created.

@@ -18,10 +18,28 @@ const std::map<std::string, esp::physics::MotionType>
SceneObjectInstanceAttributes::SceneObjectInstanceAttributes(
const std::string& handle)
: AbstractAttributes("SceneObjectInstanceAttributes", handle) {
setMotionType(-1); // defaults to unknown
// defaults to unknown/undefined
setMotionType(static_cast<int>(esp::physics::MotionType::UNDEFINED));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you instance an object with "esp::physics::MotionType::UNDEFINED"? Does it just get the default of the current simulator implementation?

Copy link
Contributor Author

@jturner65 jturner65 Jan 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This value in the scene object instance attributes is only used to override the default setting already in place. So this comes into play in the following code from Simulator.cpp (466) :

    const physics::MotionType attrObjMotionType =
        static_cast<physics::MotionType>(objInst->getMotionType());
    const physics::MotionType objMotionType =
        physicsManager_->getObjectMotionType(objID);

    if ((attrObjMotionType != objMotionType) &&
        (attrObjMotionType != physics::MotionType::UNDEFINED)) {
      physicsManager_->setObjectMotionType(objID, attrObjMotionType);
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..which has been changed heh. Now it will only attempt to change the value if the object instance motion type value is not undefined.

    // set object's motion type if different than set value
    const physics::MotionType attrObjMotionType =
        static_cast<physics::MotionType>(objInst->getMotionType());
    if (attrObjMotionType != physics::MotionType::UNDEFINED) {
      physicsManager_->setObjectMotionType(objID, attrObjMotionType);
    }

src/esp/metadata/attributes/SceneDatasetAttributes.cpp Outdated Show resolved Hide resolved
src/esp/metadata/attributes/SceneDatasetAttributes.cpp Outdated Show resolved Hide resolved
src/esp/metadata/managers/SceneAttributesManager.h Outdated Show resolved Hide resolved
src/esp/metadata/managers/SceneAttributesManager.h Outdated Show resolved Hide resolved
src/esp/metadata/managers/SceneAttributesManager.h Outdated Show resolved Hide resolved
src/esp/sim/Simulator.cpp Outdated Show resolved Hide resolved
auto stageAttributes = metadataMediator_->getNamedStageAttributesCopy(
curSceneInstanceAttributes->getStageInstance()->getHandle());
if (stageAttributes != nullptr) {
// assetType of stage is used to specify semanctic scene descriptor format
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no way to directly load what I configured without checking against the stage? If I specify a particular file in my Scene (e.g. a ".house") which does not correspond to the stage type defaults (e.g. an AssetType::INSTANCE_MESH stage which defaults to "info_semantic.json"), does this loading fail? I understand using the stage type when we are searching for the file initially during a back-compat phase, but if we specify the file in the configs we should just be able to load it, even if it isn't a typical type combination, right?

Use case: maybe I like a particular semantic scene format and manually make my own configs for object classes in that format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to come up with a better/expanded design for handling this, I agree. I would also prefer not to be tethered to the stage attributes for this - SSD loading should be completely independent of stage and stage type.

We could modify the check to use the file name given for the ssd, and if that fails to yield a usable type, then fall back on the scene instance. -shrug-.

Copy link
Contributor Author

@jturner65 jturner65 Jan 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mechanism has been modified somewhat. If an ssd filename is specified in the scene instance attributes, this is first checked for existence, and if it does exist, it is attempted to be loaded (currently loading is determined by its name). If what is specified does not load properly or is not found, then the previous implementation (pivoting on stageAttributes type) is executed. This is not the ideal mechanism, but is a reasonable compromise between the existing mechanism and leveraging the expanded capabilities of the scene instance.

We still need a mechanism by which the user can specify the format for the ssd file, or, better yet, develop a mechanism to intelligently load the appropriate file type using (meta)data in the file itself.

src/esp/sim/Simulator.cpp Outdated Show resolved Hide resolved
@jturner65 jturner65 force-pushed the MM_LoadSceneInstance_1.0 branch 6 times, most recently from 6839496 to f54916c Compare January 26, 2021 19:00
@jturner65 jturner65 force-pushed the MM_LoadSceneInstance_1.0 branch 5 times, most recently from a7c5f1e to f0efa36 Compare January 28, 2021 15:54
…ade.

If a scene instance is composed in blender, no notion of the COM will exist and any translations will need to be corrected by COM offset.  However, in the future we plan on supporting the saving of existing, composed scenes to scene instance attributes, and the locations of objects will be already corrected for their COM offset.  So this introduces a mechanism to differentiate between the two processes.
Remove the ability to set a stage attributes lighting key via json (this functionality has been supplanted by scene instances); Bypass misleading error on stage instancing.
Copy link
Contributor

@aclegg3 aclegg3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we're ready. 👍

"template_name":"dataset_test_object2",
"translation":[0.3,0.4,0.5]
}
],
"default_lighting":"modified_test_lights",
"frustum_culling":true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we decided to remove this from config system and instead just keep SimulatorConfiguration as the entry point.

@jturner65 jturner65 merged commit ae2faa8 into facebookresearch:master Feb 2, 2021
@jturner65 jturner65 deleted the MM_LoadSceneInstance_1.0 branch February 2, 2021 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants