-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
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
Serialization of ParametricGeometry, ParametricBufferGeometry contains unserializable function #17381
Comments
Some classes in I guess we can solve this issue by implementing toJSON() {
var data = super.toJSON();
data.func = this.parameters.func.toString();
return data;
} Deserializing in var func = new Function( 'return ' + data.func )(); We consider the parametric functions as self-contained (like ParametricGeometries.klein) so this approach should work. Better suggestions? |
@Mugen87 that should work if the function contains only local variables and globals (e.g. |
As mentioned by @mrdoob in the linked PR, the proposed code is not safe enough since malicious code could be injected into 3D scenes. |
Description of the problem
The parametric function in a ParametricBufferGeometry ultimately gets serialized as
{ func }
on the geometry, and since it is a function, the object representation is no longer serializable, at least in terms of the web's structured clone algorithm. In the context of other serialization issues (#17328, #16816, #16764), maybe this issue would be better framed as, "What is the serialization strategy for three.js objects?"The text was updated successfully, but these errors were encountered: