JSON structure changes

Hi,

The structure of the JSON made with version 2.2.0.15 is quite different as that from previous versions. Some information seem to be missing now.

For ModelShell:

  • The id of the mesh node is missing in the mesh of the shells.

  • The id of the mesh element is missing.

For LineJoints in the Joints part:

  • The type, position, yDir and zDir are missing.

Besides could it be possible to write the karamba version to the json? So it is better predictable how the JSON will look like.

Hi Knut,
I was not aware of these changes. I will have a look.
Adding the version number to the JSON file is a great idea - thanks for the hint!
– Clemens

Hi Clemens,

Thanks for the response!

I have found two files where I can show you an important difference in the Mesh object in the json
On the left you see the old structure (which we like), and on the right you see the new structure. I can’t tell you for certain from exactly which version this started occurring, but it could be from 2.2.0.15.
I have also attached these two jsons.

old_structure.json (652.2 KB)
new_structure.json (3.6 MB)

Hi Knut,
yes, the serialization of Mesh3-objects changed in the latest build of Karamba3D to make it more performant. Instead of lists arrays are used to read and write data. Here the constructor for reading from Json:

private Mesh3(
SerializationInfo info,
StreamingContext context)
{
_guid = (Guid)info.GetValue(“Guid”, typeof(Guid));
_vertices = Point3.PointsFromArray((double [ ])info.GetValue(“VertexComponents”, typeof(double[ ])));
_vertexColors = SerializationUtils.ColorsFromArray((int[ ])info.GetValue(“VertexColors”, typeof(int[ ])));
_faces = Face3.FacesFromArray((int[ ])info.GetValue(“FaceNodeInds”, typeof(int[ ])));
}

The corresponding constructor for JointLine looks like this:

protected JointLine(SerializationInfo info, StreamingContext context)
: base(info, context)
{
this.dAlpha = (double)info.GetValue(“dAlpha”, typeof(double));
this.position = (IBuilderElementPosition)info.GetValue(“position”, typeof(IBuilderElementPosition));
this.vicinityPointsToCurve = (IVicinityPointsToCurve)info.GetValue(“vicinityPointsToCurve”, typeof(IVicinityPointsToCurve));
this.yDir = (Vector3)info.GetValue(“yDir”, typeof(Vector3));
this.zDir = (Vector3)info.GetValue(“zDir”, typeof(Vector3));
}

Both routines can be found in KarambaCommon.dll using e.g. ILSpy.

– Clemens

In the upcoming service release of Karamba3D V 2.3. the Json data of models contains the entry “Version”. The corresponding string is the version of Karamba3D with which the Json file was generated.
– Clemens

Hi Clemens,

Okay thank you! We will adapt our conversion then to work with this new structure. And thanks for the tip about ILSpy! Very useful!

Do you expect there to be more changes to the JSON serialization after 2.3?
And do you know roughly when 2.3 will be released?

Best,
Knut

Hi Knut,
in the future I plan to remove all references to .NET-classes in the JSON-file if possible, so that it is easier to import/export a K3D model in Python or Java.
There will be a prerelease of Karamba3D 3.0 in the coming weeks on Github (see here)
– Clemens

1 Like