Notifications
Clear all

[Closed] Please give some advice on serialization of max objects

I want to save/load max object with xml format.

Let’s say I want to save renderer parameters as xml.
Boolean or number type would be easy.
But, there can be an array of max objects as a parameter.
Or… it could be selection set name.

What would be your approach?

12 Replies

first of all you have to decide what scenes you want to serialize: custom (specially) organized or any (every).
for example a scene can have nodes with same names, selection sets with the same names, selection sets can share nodes, etc.
if your scene specially organized you can follow same rules. in this case the scene is easier for serialization. for example use layers which names are always unique.

if you have nodes with same names there’s pretty well-known solution – store node full-path (incluging all ancestors) instead of just a name

1 Reply
 lo1
(@lo1)
Joined: 11 months ago

Posts: 0

How is it a solution? Two nodes can also share the same ancestral path. The only guaranteed unique value is the node handle, and per session, the anim handle.

I want to serialize generic scene(no specific rules).
But, not the entire scene, just certain data.

For node array. I use bitarray of inode handle.
So… writing bitarray into xml is easy.
My main question is what would be the best way to get original data back as max value in generic way.

My brute force(?) solution was tagging data type when I write.
Something like this…

<property name=“NodeToRender” value=”#{ 1, 5, 7…22}” type=“nodebitarray”>
<property name=“MotionBlur” value=“true” type=“booleanclass”>

 lo1

I’m not sure about bitarray for the node handles. The numbers are not guaranteed to be low, what if the node handle is 2000000000? you’ll be allocating 2 Gb of memory for every read and write. A regular array might be a bit more verbose in most cases but will avoid extreme situations with large numbers.

1 Reply
(@gandhics)
Joined: 11 months ago

Posts: 0

Hmm… I never thought about memory.
But, I think it is still make sense to use bitarray for node list.
Because…

  1. Even in your extreme case, that’s only 270MB.
    Our workstation has at least 64GB, many of them has 128GB.
    I also may read/write with bitarray, but most time I probably convert to array to work

  2. It is a lot easier to do Boolean operation with bitarray.

  3. When I write xml, birarray string would be a lot shorter than array string.

handler is ULONG in sdk … or 18,446,744,073,709,551,615 is maximum available handle
but for version compatibility only 32 bits used as i know. which makes 4294967295…
mxs doesn’t have unsigned integer, so it’s technically possible that a handle be negative and can’t be put in mxs bitarray

i can be wrong about it, but i agree with lo that a bitarray with large numbers can cause an issue.

 lo1

ULONG is a typedef for unsigned long – 32bit.
Changsoo does make some good points in favor of bitarray though, I guess it requres real world observations of what the largest handle in typical scenes is.

I am still waiting for an advice for my original question…

if you are storing node data as their handles it means you need it for specific file. do you want to restore anything that not exists anymore using the stored data?
it’s only the case that makes sense for me. in any other case it’s easier to save data with a file

Yes, it is for a specific file.
I’ll generate xml and store it in root node appdata.
If I need to read/write between two scenes, I can just rely on name.

I think my example kinda made a confusion.
Node list was just an example.
My question is how should I serialize max specific class with xml in generic way.

How about serializing all vray parameters as xml?

Page 1 / 2