Skip to content

Scene script lib#80

Open
hwandersman wants to merge 10 commits intoaws-samples:mainfrom
hwandersman:scene-sdk
Open

Scene script lib#80
hwandersman wants to merge 10 commits intoaws-samples:mainfrom
hwandersman:scene-sdk

Conversation

@hwandersman
Copy link
Copy Markdown
Contributor

@hwandersman hwandersman commented Sep 16, 2022

Added @iot-twinmaker/scene-utils lib to enable customers to automate scene creation. Sample command line scripts are provided to create the CookieFactory scene, integrate with the Cesium Ion tiling pipeline, and delete scenes.

Issue #, if available:

Description of changes:
Introducing an SDK with command line scripts to automatically manipulate IoT TwinMaker scenes. This library enables customers to manage 3D models that are uploaded to S3 and applied to the scene hierarchy as interactive nodes. A scene node can be a 3D mesh or a built-in augmentation like a tag or motion indicator. You can set the 3D transform of the node and apply a data binding with an entity, component, and property path of a time stream data connector. This SDK also supports adding scene rules to dynamically change an icon or mesh color when data is applied to the scene viewer on your IoT TwinMaker application. Finally, there is an integration with Cesium Ion's REST APIs to compress 3D assets into 3D tiles for consumption in an IoT TwinMaker scene.

Security

This lib uses the AWS JS SDK to connect to IoT TwinMaker and S3. It also has a Cesium client that uses Cesium's REST API to upload 3D models and export 3D tilesets to a customer's S3 bucket.

Customers will use temporary AWS credentials to authenticate into the AWS SDK. To use Cesium customer's must have a Cesium Ion account and an access token with the permissions for writing assets and exports. This access token is used to authenticate into the Cesium REST APIs.

Scripts

Summary of sample command line scripts:

  1. Cookie Factory Sample
    Use the 3D models in this repo's scenes directory to build the CookieFactory.json scene with the SDK.
    This sample is meant as a starting point for users with local 3D models they want to add to a scene with all scene features (tags, motion indicator, data binding, rules, etc.).

  2. Cesium Ion File Upload
    Create an account with Cesium, get an access token, and use it to upload a local file to your Cesium account. Cesium will run its tiling pipeline to generate 3D tiles for your asset. After tiling is complete the tileset will be downloaded into memory and uploaded to your IoT TwinMaker workspace S3 bucket and added to a new scene.

  3. Delete your scene
    Example to clean up nodes in your scene or delete it from your workspace.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…scene creation. Sample command line scripts are provided to create the CookieFactory scene, integrate with the Cesium Ion tiling pipeline, and delete scenes.
twinMakerScene.addRootNodeIfNameNotExist(rootNode);

// Save the changes to the Scene
await factory.save(twinMakerScene);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IIUC the behavior here is to not overwrite the scene if it already exists? If so, we may want to update some of the messages in the sample or adjust to early exit if scene already exists so not making any changes. e.g. I ran and got the following and thought the updated scene was saved to cloud but saw no change there:

Scene already exists, loading scene...
Creating/Editing Cookie Factory scene...
Adding Cookie Lines...
Adding Mixers and WaterTank...
Saving scene scene01...
Scene saved!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looking at save and overrideSave there wasn't any difference in implementation. I will remove overrideSave since save will already override the scene if it already exists. Added a comment to clarify this to save() in scene_factory.ts.

The method loadOrCreateSceneIfNotExists will load an existing scene into memory if it already exists. I don't think it makes sense to have a method to save a scene only if it doesn't exist.

hwandersman and others added 4 commits October 6, 2022 16:10
…ant overrideSave() method from the scene_factory class. Added minor bug fixes and cleaned up client classes.
…irectly to an S3 bucket. Updated README with more instructions for getting started with Cesium.
// IN_PROGRESS
logProgress(`Asset is ${assetMetadata.percentComplete}% complete.`);
}
console.error(`Unrecognized response when requesting the tiling status of asset ${assetId}`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should this output the unrecognized status as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, will edit

// Log progress of Cesium asset export to S3
private async waitForExport(accessToken: string, assetId: string, exportId: string) {
const timeout = 10000; // 10 seconds
let maxChecks = 30; // Will wait for 5 minutes
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just curious: is there an SLA for Cesium? is this something customers may need to be able to adjust depending on asset size?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't know the Cesium SLA, but good idea to make wait times adjustable. Will add the parameters and set it in the sample.

prefix: outputPath,
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
sessionToken: process.env.AWS_SESSION_TOKEN,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will this work for the case where someone is using long-lived credentials? (without SessionToken)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, the API only supports temporary credentials


e. Click “Create”

f. Copy and use this asset token for the `--cesiumAccessToken` parameter in the commands below
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

how "confidential" is the Cesium token? Is it ok for it to be exposed in the command line as an argument or should it be via environment variables like the AWS credentials?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If someone has access to a Cesium token then they will be able to perform any action the token allows in the customer's Cesium account. If it's more secure as an env var then I can enforce the use of an env var for this token.

…the tiles folder is already uploaded to the workspace S3 bucket.
…Split Cesium script into 5 steps to jump into at any step of the conversion/scene upload process.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants