nickdesaulniers / prims

3D Geometry Primitives for WebGL
Other
42 stars 5 forks source link

polygon offset #10

Open nickdesaulniers opened 10 years ago

nickdesaulniers commented 10 years ago

walter: so you need [6:01pm] walter: gl.polygonOffset(1, 1) on the TRIANGLES call [6:01pm] walter: and then [6:01pm] walter: gl.polygonOffset(0, 0) on the line call [6:01pm] walter: and gl.enable(POLYGON_OFFSET_FILL) [6:01pm] walter: at the top

waltermoz commented 10 years ago

Extra notes: polygonOffset() only needs to be done once, because triangles = fill and lines are not, so the offset won't be applied to the line call.

Also the line loop trick only works for meshes with their triangles in a special order. For example it'll have extraneous lines going all over the place for something like the menger spong:

lines

nickdesaulniers commented 10 years ago

Wouldn't this be indicative of something wrong in the mesh?

waltermoz commented 10 years ago

No, think about how line loop operates. It creates a line between two consecutive vertices and then connects the last vertex with the first vertex. For example, above, whenever you move from one finished box to the next (which may be on the other side of the mesh) there will be a line from the last vertex of that box to the first vertex of the other box. The mesh is perfectly fine.

You can try to put the vertices into the buffer in such a way that it works out (like the torus), but I don't think it works for arbitrary meshes. There may be other ways, (other than a duplicate mesh), but I haven't looked.