ThreeJS does not update scene after children update

51 views Asked by At

I am woking on: ThreeJS Editor. And I want to force update scene after I change children props in the scene
Now I have some Box(get by Scene) and I want to add some SphereGeometry to this Box:

buildSceneGeometry() {
   const objects = this.scene.children;
   // Generate connecting points
   const connectionPoints = [
     { x: -0.5, y: 0, z: 0 },
     { x: 0.5, y: 0, z: 0 },
     { x: 0, y: 0, z: 0.25 },
   ]
   objects.forEach((data: any) => {
     connectionPoints.forEach((point) => {
       const sphereGeometry = new THREE.SphereGeometry(0.1)
       const sphereMaterial = new THREE.MeshBasicMaterial({ color: '#ff0000' })
       const sphere = new THREE.Mesh(sphereGeometry, sphereMaterial)
       sphere.name = NAME_SNAP
       sphere.position.set(point.x, point.y, point.z)
       data.children = [...data.children, sphere]
     })
   })
   // force update scene here...

}

My expected: My expected

But, after I run buildSceneGeometry, it likes: enter image description here

After refreshing by F5 press. It's working, but I want to force update it.
And, I'm using three npm: ^0.158.0,
Thank all

0

There are 0 answers