How to loop through vertices of a sphere

vars.sphere = MeshBuilder.CreateSphere("sphere", { diameter: 4, segments: 10 }, vars.scene);

// I was expecting, but vertices dont exist
for (let i = 0; i < vars.sphere.vertices.length; i++) {
        let vert = vars.sphere.vertices[i];
}

// Then tried
log(vars.sphere.getVerticesData()); // results in null

Any ideas?

Thanks

D

getVerticesData requires a kind parameter
https://doc.babylonjs.com/how_to/updating_vertices#vertex-data

Got it…

// 1 find out what data is in the thing
log(vars.sphere.getVerticesDataKinds());

// 2. get the data (documentation states strings from constants such as 
// VertexBuffer.PositionKind, these all return NULL, use string found from no1 above
log(vars.sphere.getVerticesData("position",true));
// Note doesnt return arrays of x,y,z but a single array so you will need to parse it in 3s.