mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
102.57k stars 35.37k forks source link

Geometries are not de-serialized in all cases #16340

Open Temdog007 opened 5 years ago

Temdog007 commented 5 years ago
Description of the problem

Currently, there are geometries in THREE JS src that are not de-serializable.

There are 2 main reasons for this issue.

Based on @Mugen87's comment, it sounds like increasing the complexity of ObjectLoader is undesirable. However, these geometries are currently serialized in a way where they can't be de-serialized.

My suggestion would be one of the following:

  1. Make these geometries serialize as normal BufferGeometry and send a warning saying such.

    
    EdgesBufferGeometry.prototype.toJSON = function () {
    
    console.warn("EdgesBufferGeometry is not serializable. It will be serialized as BufferGeometry.");
    var parameters = this.parameters;
    this.parameters = undefined;
    var data = BufferGeometry.prototype.toJSON.call( this );
    this.parameters = parameters;
    
    return data;

};


2. Make these geometries not serializable and send a error saying such.
#### Example
```javascript
EdgesBufferGeometry.prototype.toJSON = function () {

    console.error("EdgesBufferGeometry is not serializable. Convert this geometry to BufferGeometry and call .toJSON() on that");

};
  1. Make ObjectLoader handle these geometries

Related #16026, #16087, #14357

Three.js version
Browser
OS
Mugen87 commented 5 years ago

I vote for suggestion 3 since I still think it's the most consistent approach. ObjectLoader can exactly restore the geometry objects which were previously part of your scene. From my point of view, this is the most expected result of a serialization/deserialization workflow.

spade69 commented 5 years ago

a vote for suggestion 3. what else can i expect if i 'd like to serialize edgesGeometry in worker?

StratusBase commented 1 year ago

Any updates on this...? I am still seeing the following error when attempting to import EdgesGeometry in latest version (0.146.0)

"TypeError: Geometries[data.type].fromJSON is not a function"

Mugen87 commented 1 year ago

I've mentioned this elsewhere but I believe it was a mistake to introduce EdgesGeometry and WireframeGeometry. Both are actually helpers (since they visualize other geometry data) and should be EdgesHelper and WireframeHelper.

The support for helpers in ObjectLoader is tracked in #15714. You essentially need similar logic for EdgesGeometry and WireframeGeometry like for camera or light helpers since you have to deserialization other objects first before you can process helpers.