.toJSON – Extend to include position data?

Description of the problem

I have a group, with several children:

for (i=0; i<objectsToAdd.length; i++) {
      toolpath.add(objectsToAdd[i]); // some Line and Mesh objects
});

I can update the position of one of the children: for example below, and it renders fine.
group.children[4].position.x = 100;

If I export the group using .toJSON

group .toJSON();

then save the JSON out, later, import it again using

var newGroup = loader.parse(jsonstringfromfilereader);

It renders all the objects back to their original positions (ie as its in the Geometry, none of the .position attributes seems to get exported.

Any chance we can get .toJSON() extended to include position data as well? (Suspect I’ll also find Scale, Rotation missing? Going to have to use those soon after this)

Otherwise, a way to update vertices after any position update

// move object with object.position = {x: 10, y:10, z:0 }
// do something to force (traversely) all vertices downward to +10 on X and Y
// reset object.position to 0,0 as the vertices carry the new offset?

Three.js version
  • Dev
  • r92
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS
Hardware Requirements (graphics card, VR Device, …)

Subnote: Did check Stackoverflow, https://stackoverflow.com/questions/37937713/three-js-object3d-tojson-submitted-parameters/37947511 was about the closest, and that says .toJSON doesnt export, therefore my request (:

Thanks again for all your awesome work, really couldnt do any of the cool things i can do with threejs, if it wasnt for you guys and the millions of man hours behind threejs

Author: Fantashit

1 thought on “.toJSON – Extend to include position data?

  1. Sorry for the late response but I don’t think that’s a bug.

    Any chance we can get .toJSON() extended to include position data as well?

    You need to call group.updateMatrixWorld() in your code since only Object3D.matrix is serialized. If it still does not work with the proposed fix, please reopen the issue with a live example that demonstrates the problem.

Comments are closed.