-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
56f0260
to
08b12e8
Compare
@@ -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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 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 |
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(); | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 🤯 😲
Allows for sending the byte[] with metadata that contains information about how the models should be split back into their original components