loadAttributes loads the provided list of vertex attributes as VBO(s) into the specified geometry.
(geom *geometry.Geometry, attributes map[string]int, indices math32.ArrayU32)
| 544 | |
| 545 | // loadAttributes loads the provided list of vertex attributes as VBO(s) into the specified geometry. |
| 546 | func (g *GLTF) loadAttributes(geom *geometry.Geometry, attributes map[string]int, indices math32.ArrayU32) error { |
| 547 | |
| 548 | // Indices of buffer views |
| 549 | interleavedVBOs := make(map[int]*gls.VBO, 0) |
| 550 | |
| 551 | // Load primitive attributes |
| 552 | for name, aci := range attributes { |
| 553 | accessor := g.Accessors[aci] |
| 554 | |
| 555 | // Validate that accessor is compatible with attribute |
| 556 | err := g.validateAccessorAttribute(accessor, name) |
| 557 | if err != nil { |
| 558 | return err |
| 559 | } |
| 560 | |
| 561 | // Load data and add it to geometry's VBO |
| 562 | if g.isInterleaved(accessor) { |
| 563 | bvIdx := *accessor.BufferView |
| 564 | // Check if we already loaded this buffer view |
| 565 | vbo, ok := interleavedVBOs[bvIdx] |
| 566 | if ok { |
| 567 | // Already created VBO for this buffer view |
| 568 | // Add attribute with correct byteOffset |
| 569 | g.addAttributeToVBO(vbo, name, uint32(*accessor.ByteOffset)) |
| 570 | } else { |
| 571 | // Load data and create vbo |
| 572 | buf, err := g.loadBufferView(bvIdx) |
| 573 | if err != nil { |
| 574 | return err |
| 575 | } |
| 576 | // |
| 577 | // TODO: BUG HERE |
| 578 | // If buffer view has accessors with different component type then this will have a read alignment problem! |
| 579 | // |
| 580 | data, err := g.bytesToArrayF32(buf, accessor.ComponentType, accessor.Count*TypeSizes[accessor.Type]) |
| 581 | if err != nil { |
| 582 | return err |
| 583 | } |
| 584 | vbo := gls.NewVBO(data) |
| 585 | g.addAttributeToVBO(vbo, name, 0) |
| 586 | // Save reference to VBO keyed by index of the buffer view |
| 587 | interleavedVBOs[bvIdx] = vbo |
| 588 | // Add VBO to geometry |
| 589 | geom.AddVBO(vbo) |
| 590 | } |
| 591 | } else { |
| 592 | buf, err := g.loadAccessorBytes(accessor) |
| 593 | if err != nil { |
| 594 | return err |
| 595 | } |
| 596 | data, err := g.bytesToArrayF32(buf, accessor.ComponentType, accessor.Count*TypeSizes[accessor.Type]) |
| 597 | if err != nil { |
| 598 | return err |
| 599 | } |
| 600 | vbo := gls.NewVBO(data) |
| 601 | g.addAttributeToVBO(vbo, name, 0) |
| 602 | // Add VBO to geometry |
| 603 | geom.AddVBO(vbo) |
no test coverage detected