Problematic json export of SphereGeometry

Description of the problem

Consider this code :

let g = new THREE.SphereGeometry(1,2,2)
let t = new THREE.Matrix4().makeTranslation(100,0,0)
g.applyMatrix( t )
let jsg = g.toJSON();

We can see the transformation correctly affects the geometry vertices :

console.log( g.vertices.map( v => v.x ) ) 
//  [ 100, 99, 100.5, 100.5, 100 ]

But if we export as json :

console.log( JSON.stringify( jsg ) )

// {
//   "metadata": {
//     "version": 4.5,
//     "type": "Geometry",
//     "generator": "Geometry.toJSON"
//   },
//   "uuid": "5D17605B-7519-4DED-91AC-255C33AE1A9C",
//   "type": "SphereGeometry",
//   "radius": 1,
//   "widthSegments": 2,
//   "heightSegments": 2
// }

I would expect the transformation to be applied to the geometry when exporting to json ; the geometry would be described as vertices/faces.

I am doing something wrong ?

Thanks.

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

Author: Fantashit

1 thought on “Problematic json export of SphereGeometry

  1. Problematic json export of SphereGeometry

    Once you modify the geometry, it is no longer a SphereGeometry. You will need to modify other properties for consistency. How you choose to do that is up to you.

    Also,

    let t = new THREE.Matrix4().makeTranslation(100,0,0)
    g.applyMatrix( t )

    That is an old code pattern. Instead, use

    geometry.translate( 100, 0, 0 );

Comments are closed.