I am creating a decal then saving its position and normal.
But when i recreate the decal from saved json the texture applied is rotated on some angles.
I found that if pickedinfo normals are (-0,1,-0) and due to serialization process in server it is converted to (0,1,0) and both (0,1,0) and (-0,1,-0) have different texture rotation when reloaded.
The problem here is effectively that CreateDecal projects the normal vector onto the x/z plane and so when that normal is up (e.g. a perfectly horizontal surface like a floor/ceiling or top/bottom of a cube) we don’t really have a reference point from which to apply the decal rotation. This combined with JSON.stringify(-0) being 0 results in the behavior seen in the PG.
I think the only real solution here would be to update the CreateDecal function to optionally take an explicit reference vector for the rotation, which needs to not be colinear with the normal that is passed in. Without this additional info, then I don’t think there is really anything we can do to improve the current behavior, so from that standpoint I would say the behavior is “expected/supposed to happen,” but we could change the API to allow the additional needed info to be passed in to avoid this situation.
Alternatively if you just want consistent behavior in your specific use case, you might be able to get away with just converting those -0s to 0s, but this may not be robust as any internal calculations potentially could turn very small numbers into -0/0 due to floating point limitations.
Its a custom serialization/deserialization which saves the scene into a json. I ended up saving the normal vectors as string and deserialize “-0” as -0.