assume i want to serialize a model and the direct parts inside of it.
would i:
save the model’s pivot cframe and scale and save the part relative cframe to the model and the part’s size, with math performed on them so it was as if the model was at default scale?
or can i save the part’s size and relative cframe as-is, and then set the model’s scale and then apply part properties when deserializing
i know these options work, but i want to know what the cleanest or most standard method would be
There are no such standards.
Both approaches have place: some apps keep everything in global coordinates, others in relative to parents coordinates.
It could be defined by underlying system.
For example, in Roblox children natively have global coordinates, so its somewhat easier to serialize using global coordinates; well, because it does not require mappings from/to parent’s space.
First approach is generally cleaner if you want to properly preserve the model’s canonical scale.
Save the model’s pivot + scale, and store the parts relative CFrames and sizes normalized as if the model was at scale 1. On deserialize you rebuild the parts at scale 1, set the pivot, then call Model:ScaleTo(savedScale). This properly preserves the model’s canonical scale (which the engine uses for animations, joints, etc) and avoids any double scaling or floating-point issues
-- serialize
local scale = model:GetScale()
local relCF = model:GetPivot():ToObjectSpace(part.CFrame)
local size1 = part.Size / scale
thank you for your response! i am already doing something like this, i misworded my question a little badly. my intent is to allow players in my building game to be able to individually resize and move parts in a model, but the model still serves as the center pivot for both cframe and scale. just wanted to make sure i wasn’t breaking some unspoken mathematical rule haha