ReadFaces iterates over all the vertices and calls the specified callback function with face-forming vertex triples. The callback function returns false to continue or true to break.
(cb func(vA, vB, vC math32.Vector3) bool)
| 273 | // the specified callback function with face-forming vertex triples. |
| 274 | // The callback function returns false to continue or true to break. |
| 275 | func (g *Geometry) ReadFaces(cb func(vA, vB, vC math32.Vector3) bool) { |
| 276 | |
| 277 | // Get buffer with position vertices |
| 278 | vbo := g.VBO(gls.VertexPosition) |
| 279 | if vbo == nil { |
| 280 | return |
| 281 | } |
| 282 | |
| 283 | // If geometry has indexed vertices need to loop over indexes |
| 284 | if g.Indexed() { |
| 285 | var vA, vB, vC math32.Vector3 |
| 286 | positions := vbo.Buffer() |
| 287 | for i := 0; i < g.indices.Size(); i += 3 { |
| 288 | // Get face vertices |
| 289 | positions.GetVector3(int(3*g.indices[i]), &vA) |
| 290 | positions.GetVector3(int(3*g.indices[i+1]), &vB) |
| 291 | positions.GetVector3(int(3*g.indices[i+2]), &vC) |
| 292 | // Call callback with face vertices |
| 293 | brk := cb(vA, vB, vC) |
| 294 | if brk { |
| 295 | break |
| 296 | } |
| 297 | } |
| 298 | } else { |
| 299 | // Geometry does NOT have indexed vertices - can read vertices in sequence |
| 300 | vbo.ReadTripleVectors3(gls.VertexPosition, cb) |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | // TODO Read and Operate on Texcoords, Faces, Edges, FaceNormals, etc... |
| 305 |
no test coverage detected