joostn / OpenJsCad

3D solid CAD using only Javascript
315 stars 128 forks source link

WebGL 64k vertex limit #21

Closed risacher closed 11 years ago

risacher commented 11 years ago

WebGL can apparently only handle 16-bit indexes into the Vertex array, so if you try to draw something with more than 64k vertices, it doesn't work. This can be worked around by splitting the draw call up so not all the polygons get drawn at once.

Would be cool if OpenJsCad could separate the mesh somehow to work around this limitation.

risacher commented 11 years ago

Interestingly, Chrome's WebGL implementation displays a partial mesh, while Firefox displays nothing.

risacher commented 11 years ago

As it turns out, the CSG that I'm trying to model actually only has about 22k vertices, but in csgToMesh() [around openjscad.js:291] each vertex is copied into the mesh vertex list separately for each polygon it is in - which multiplies my vertex count to 130k - well above the WebGL 16bit-index limit. If I set smoothlighting = true, then the vertexes are not copied multiple times, but the normals get interpolated and it no longer looks like the real shape.

Perhaps a different shader would solve the problem? I don't know anything about WebGL shaders yet.

risacher commented 11 years ago

Rather than mess with the shaders, I implemented splitting a CSG into multiple meshes.

risacher commented 11 years ago

Close with Pull Request #23