PBF notes for hector
Use const if you aren’t going to reassign the variable value (especially for functions)
72: for (let i = 0; i <trianglesOnVoxels.length; i ++) tInV.push(trianglesOnVoxels[i].length);
Can be rewritten with map (faster for https://jsperf.com/map-vs-for-loop-performance/6)
tInV = trianglesOnVoxels.map((i) => i.length);
Division is slow. Can you do *.33333
?
86: let u = tInV[i] / 3;
102: tTriangles
, tNormals
, tVoxeslOffset
are all the same values, can these be one shared texture? Is there a faster way to clone textures over webGL2createTexture2D
?
Your loop length gets evaluated on each iteration, save as var for faster loops...
123: for (let i = 0, l =Math.ceil(Math.log(_expandedTextureSize) / Math.log(2)); i < l; i++) {
instead of
123: for (let i = 0; i < Math.ceil(Math.log(_expandedTextureSize) / Math.log(2)); i++) {
array length over push (if your really need it) https://jsperf.com/ereioeriuoerwiouewjfkfsjkdjhroweuryw
in createTexture2D, can you use multiplication or bitshifting instead of division for generating m
?