(box Box, anchor Vector)
| 58 | } |
| 59 | |
| 60 | func (m *Mesh) FitInside(box Box, anchor Vector) { |
| 61 | scale := box.Size().Div(m.BoundingBox().Size()).MinComponent() |
| 62 | extra := box.Size().Sub(m.BoundingBox().Size().MulScalar(scale)) |
| 63 | matrix := Identity() |
| 64 | matrix = matrix.Translate(m.BoundingBox().Min.MulScalar(-1)) |
| 65 | matrix = matrix.Scale(Vector{scale, scale, scale}) |
| 66 | matrix = matrix.Translate(box.Min.Add(extra.Mul(anchor))) |
| 67 | m.Transform(matrix) |
| 68 | } |
| 69 | |
| 70 | func (m *Mesh) Transform(matrix Matrix) { |
| 71 | for _, t := range m.Triangles { |