-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Curves: Added serialization/ deserialization #12797
Conversation
This PR directly addresses #8007 since |
Hmm... It's kind of tempting to move |
Okay, I've changed the code so shapes are stored in their own group. Updated Demo: https://jsfiddle.net/ht3zuzkr/2/ |
@mrdoob Is the PR now okay like this? 😊 |
Checking! |
src/core/BufferGeometry.js
Outdated
@@ -923,6 +923,32 @@ Object.assign( BufferGeometry.prototype, EventDispatcher.prototype, { | |||
|
|||
} | |||
|
|||
// ShapeBufferGeometry | |||
|
|||
if ( data.type === 'ShapeBufferGeometry' ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding this in ShapeBufferGeometry
's own toJSON()
?
ShapeBufferGeometry.prototype.toJSON = function () {
var data = BufferGeometry.prototype.toJSON.call( this );
data.shapes = [];
if ( Array.isArray( shapes ) ) {
for ( var i = 0, l = shapes.length; i < l; i ++ ) {
var shape = shapes[ i ];
data.shapes.push( shape.uuid );
}
} else {
data.shapes.push( shapes.uuid );
}
return data;
}
I think that should work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Indeed, it's better to place this code not in Geometry
or BufferGeometry
but in ShapeGeometry
.
src/core/Geometry.js
Outdated
@@ -1009,6 +1009,32 @@ Object.assign( Geometry.prototype, EventDispatcher.prototype, { | |||
|
|||
} | |||
|
|||
// ShapeGeometry | |||
|
|||
if ( data.type === 'ShapeGeometry' ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here...
Apart from these two. It's looking good to me! 👌 |
Done! Updated Demo https://jsfiddle.net/ht3zuzkr/2/ The PR performs no changes to |
src/core/Object3D.js
Outdated
if ( parameters !== undefined && parameters.shapes !== undefined ) { | ||
|
||
var shapes = parameters.shapes; | ||
var uuids = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this array for? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this is a remnant of a previous solution. I'll remove it...
Beautiful! 😊 |
Thanks! |
This PR adds serialization/ deserialization for all curve entities. It's now possible to store and load
ShapeGeometry
andShapeBufferGeometry
.The implementation allows to perform serialization/ deserialization on all hierarchy levels (
Curve
,CurvePath
,Path
,Shape
) with.toJSON()
and.fromJSON()
methods.I'll consider
ExtrudeGeometry
in a separate PR.Demo: https://jsfiddle.net/ht3zuzkr/2/