Changes to vertice information do not seem to propogate into the geometry of a mesh when position, normals and indices are removed

see PG here https://playground.babylonjs.com/#BZTD3P#2

Some context : This code is actually a reduced version of a larger problem i’m solving. I’m actually looking to build a mesh of voxels with the ability to remove a cube (its positions, normals, indices etc)… For the sake of demonstrating the problem I have reduced the code down to faces (3 point vertices) rather than a place or cube which my actual code will use. The final code will pass an index and given I know how many faces a cube has, how many points, indeces it has etc, I can extrapolate an index in the vertice data and slice the arrays and remove the cube essentially. For the purpose of testing I modified the functions to work always remove from the end of the buffer arrays (so i dont have to re-index the indices). The mesh has faces of 3 points per face (not shared intentionally for this test but shared in my code made of planes / cubes!) , the mesh then having 2 faces, with position buffer of 18, normals of 18 and indices of 6

When I remove the first face (first call of my face removel function) I slice 9 of the end of positions, 9 of the normals and 3 of the indices then apdate the vertice data and apply to the mesh… this works at this point and reading the positions, normals and indices arrays shows the correct values. The mesh updates on the screen correctly.

When I then come to remove the second face i get an error

“Invalid typed array length: 18 RangeError: Invalid typed array length: 18
at new Float32Array… etc”

I did a little digging and output the mesh._geometry._totalVertices, and this still reads as the 6 when it should be 3.

Is there something additional I need to do when removing data from a meshesvertices data? I followed examples here Update Vertices - Babylon.js Documentation in terms of how to update a meshes vertice data.

I’ve found if you dont delete data from the positions and normals and only remove indices the code will work and I can ultimately remove all faces from the mesh. But i’d rather not have the point data lying around. I intend or adding and removing positions and normals (plus possibly uvs, color etc) to add and remove voxels to the mesh and dont want to pollute these buffers with unused data.

(note : during testing this i realised that this is why i’d need to re-index the indices then, since i know that all faces in the mesh are going to be the same, i could get away with removing the positions and normals, and slicing off the end of the indices so i dont need to reindex :)… anywa!)

FIx it :slight_smile:

found an article Remove some polygons - Questions & Answers - HTML5 Game Devs Forum… i’d been over this before but hadnt noticed passing the indecis length when setting indices. Code now runs as expected … as i can only share one link i’ll reply again with the new PG

And here is it working https://playground.babylonjs.com/#BZTD3P#3

I’d close this topic if i had permissions.

2 Likes

Lol self answering is the best :slight_smile:
I’ll flag your last post as answer!