'Position not changing for mesh in animate() in THREE.js

I'm trying to get a mesh's position to change constantly so that it moves at a constant velocity. The console shows that the position Vector3 is changing, but the actual scene shows all of the meshes remaining static. This is the code I tried:

let ball = new THREE.Mesh();
let equator = new THREE.Mesh()

for (let i = 1; i <= 12; i++) {

    let scale = Math.floor(Math.random() * 3) + 1

    let pos_x = Math.floor(Math.random() * 10) * 5 - 25
    let pos_y = Math.floor(Math.random() * 10) * 5 - 25
    let pos_z = Math.floor(Math.random() * 10) * 5 - 25
    pos = new THREE.Vector3(pos_x, pos_y, pos_z)

    loader.load( './ball.gltf', function ( gltf ) { //load sphere
        gltf.scene.traverse(function(model) {
            if (model.isMesh) {
            model.castShadow = true;
            model.material = sphereMaterial;
            pos_arr.push(model)
            }
        });
        ball = gltf.scene
        ball.position.set(pos_x, pos_y, pos_z)
        ball.scale.set(scale, scale, scale)
        scene.add( ball );
        
    }, undefined, function ( error ) {
        console.error( error );
    } );    

    loader.load( './equator.gltf', function ( gltf2 ) {
        gltf2.scene.traverse(function(model) { //for gltf shadows!
            if (model.isMesh) {
              model.castShadow = true
              model.material = equatorMaterial
            }
        });
        equator = gltf2.scene
        equator.position.set(pos_x, pos_y, pos_z)
        equator.scale.set(scale, scale, scale)
        scene.add( equator )
        
    }, undefined, function ( error ) {
        console.error( error )
    } );
    pos_arr.push([ball, equator, pos])
}

//light
const light = new THREE.AmbientLight( 0xffffff );
scene.add( light );


let y_axis_dist = []
for (let j = 0; j < pos_arr.length; j++) {
    y_axis_dist.push(pos_arr[j][2].distanceTo(new THREE.Vector3(0, pos_arr[j][2].y , 0)))
}

//render

console.log(pos_arr)
function animate() {
    requestAnimationFrame( animate );

    pos_arr[0][1].position.x += 0.1
    console.log(pos_arr[0][1].position)
    
    renderer.render( scene, camera );
}
animate()

enter image description here

If anyone knows what I'm doing wrong, I will appreciate it a lot.



Solution 1:[1]

It's a little hard to parse your question, but I think what you are asking for is the mean GROSSAREA per each YEARBUILD. If that's not the correct understanding then please edit your question and add an example set of data with the desired output.

If I'm correct then you want to use groupby.

import pandas as pd

df = pd.DataFrame({'YEARBUILT': [1999, 1999, 2000, 2000], 'GROSSAREA': [10, 20, 50, 60]})

df.groupby(by='YEARBUILT').mean()
           GROSSAREA
YEARBUILT           
1999              15
2000              55

That will give you the mean per each group of YEARBUILT.

I think of groupby like merging cells in a spreadsheet.

# Your original dataframe:
  YEARBUILT  GROSSAREA
       1999         10
       1999         20
       2000         50
       2000         60

# Your dataframe after df.groupby(by='YEARBUILT')
  YEARBUILT  GROSSAREA
       1999         10
                    20
       2000         50
                    60

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1