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

Added method to pack the models as a byte array to be sent over the network and received on the client side #6

Closed
wants to merge 1 commit into from

Conversation

PotatoPeeler3000
Copy link
Contributor

@PotatoPeeler3000 PotatoPeeler3000 commented Mar 25, 2024

Allows for sending the byte[] with metadata that contains information about how the models should be split back into their original components

@@ -42,6 +42,41 @@ public DefaultLogModelProvider(Class<T> modelLoader,
System.arraycopy(topLevelResourceDirectories, 0, this.topLevelResourceDirectories, 0, topLevelResourceDirectories.length);
}

/**
* Returns the byte array of the combined InputStreams to be sent over the network
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even if we have one model, this still works, meta data will be added so on the receiving side that needs to be accounted for

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The receiving side is in the SCS2 so this PR handles that: ihmcrobotics/simulation-construction-set-2#172

@@ -30,7 +30,7 @@ public DefaultLogModelProvider(Class<T> modelLoader,

try
{
this.model = IOUtils.toByteArray(modelFileAsStream);
this.model = packModels(modelsAsStreams);
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 like this way of doing things, where we add the meta data regardless. The other option is to check the size of the modelsAsStream and if its not greater then 1, send that over with IOUtils.toByteArray(modelsAsStream) without any meta data.

Copy link
Contributor Author

@PotatoPeeler3000 PotatoPeeler3000 Mar 25, 2024

Choose a reason for hiding this comment

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

Only thing with this is if clients are not accounting for this on the receiving side then the metadata in the new logs will mess them up, an acompanying PR for SCS2 implements the receiving side to account for the new meta data.

@PotatoPeeler3000 PotatoPeeler3000 self-assigned this Mar 25, 2024
@PotatoPeeler3000 PotatoPeeler3000 added the new feature New feature or request label Mar 25, 2024
@PotatoPeeler3000
Copy link
Contributor Author

PotatoPeeler3000 commented Mar 26, 2024

The only thing with this is the model.sdf file in a log will have some incorrect tags. Since its being composed, it will have one complete URDF and the next one will be appended below it, so however many files your URDF is it, you will have
<robot>... <junkkkkkkk> </robot> <robot> <second URDF> </robot> <robot> <third URDF> </robot>

Which means it can't be loaded into SCS2 without manual formatting, however all the data is there and its pretty easy to remove those tags manually.

@PotatoPeeler3000
Copy link
Contributor Author

The only thing with this is the model.sdf file in a log will have some incorrect tags. Since its being composed, it will have one complete URDF and the next one will be appended below it, so however many files your URDF is it, you will have <robot>... <junkkkkkkk> </robot> <robot> <second URDF> </robot> <robot> <third URDF> </robot>

Which means it can't be loaded into SCS2 without manual formatting, however all the data is there and its pretty easy to remove those tags manually.

Also I'm not sure we even use that file, all the models for the URDF are in the log anyways

@PotatoPeeler3000
Copy link
Contributor Author

I did look into sending multiple models that get stored in a directory, but that would require a lot of code changes so I thought it was better to add all the models to the byte[] with metadata so it could be split back up.

private static byte[] packModels(Collection<InputStream> models) throws IOException
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

Copy link
Member

Choose a reason for hiding this comment

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

Instead of doing this let's combine the models into a single one and ship that. You can use URDFTools,saveURDFModel() to write a URDFModel into a output stream

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that's awesome. Now nothing inside DefaultLogModelViewer has to change so we don't need this PR 🤯 😲

@PotatoPeeler3000 PotatoPeeler3000 deleted the feature/combined-urdfs branch April 2, 2024 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants