|
| 1 | +package Primitives |
| 2 | + |
| 3 | +import Types "github.com/Patch2PDF/GDTF-Mesh-Reader/pkg/MeshTypes" |
| 4 | + |
| 5 | +func NewCube() Types.Mesh { |
| 6 | + v := []Types.Vector{ |
| 7 | + {X: -1, Y: 1, Z: -1}, {X: -1, Y: 1, Z: 1}, {X: 1, Y: 1, Z: 1}, {X: 1, Y: 1, Z: -1}, |
| 8 | + {X: -1, Y: -1, Z: -1}, {X: -1, Y: -1, Z: 1}, {X: 1, Y: -1, Z: 1}, {X: 1, Y: -1, Z: -1}, |
| 9 | + } |
| 10 | + mesh := Types.Mesh{ |
| 11 | + Triangles: []*Types.Triangle{ |
| 12 | + // top |
| 13 | + { |
| 14 | + V0: &Types.Vertex{Position: v[1], Normal: nil}, |
| 15 | + V1: &Types.Vertex{Position: v[2], Normal: nil}, |
| 16 | + V2: &Types.Vertex{Position: v[3], Normal: nil}, |
| 17 | + }, |
| 18 | + { |
| 19 | + V0: &Types.Vertex{Position: v[0], Normal: nil}, |
| 20 | + V1: &Types.Vertex{Position: v[1], Normal: nil}, |
| 21 | + V2: &Types.Vertex{Position: v[3], Normal: nil}, |
| 22 | + }, |
| 23 | + // left |
| 24 | + { |
| 25 | + V0: &Types.Vertex{Position: v[4], Normal: nil}, |
| 26 | + V1: &Types.Vertex{Position: v[1], Normal: nil}, |
| 27 | + V2: &Types.Vertex{Position: v[0], Normal: nil}, |
| 28 | + }, |
| 29 | + { |
| 30 | + V0: &Types.Vertex{Position: v[4], Normal: nil}, |
| 31 | + V1: &Types.Vertex{Position: v[5], Normal: nil}, |
| 32 | + V2: &Types.Vertex{Position: v[1], Normal: nil}, |
| 33 | + }, |
| 34 | + // front |
| 35 | + { |
| 36 | + V0: &Types.Vertex{Position: v[5], Normal: nil}, |
| 37 | + V1: &Types.Vertex{Position: v[2], Normal: nil}, |
| 38 | + V2: &Types.Vertex{Position: v[1], Normal: nil}, |
| 39 | + }, |
| 40 | + { |
| 41 | + V0: &Types.Vertex{Position: v[5], Normal: nil}, |
| 42 | + V1: &Types.Vertex{Position: v[6], Normal: nil}, |
| 43 | + V2: &Types.Vertex{Position: v[2], Normal: nil}, |
| 44 | + }, |
| 45 | + // right |
| 46 | + { |
| 47 | + V0: &Types.Vertex{Position: v[7], Normal: nil}, |
| 48 | + V1: &Types.Vertex{Position: v[3], Normal: nil}, |
| 49 | + V2: &Types.Vertex{Position: v[2], Normal: nil}, |
| 50 | + }, |
| 51 | + { |
| 52 | + V0: &Types.Vertex{Position: v[7], Normal: nil}, |
| 53 | + V1: &Types.Vertex{Position: v[2], Normal: nil}, |
| 54 | + V2: &Types.Vertex{Position: v[6], Normal: nil}, |
| 55 | + }, |
| 56 | + // back |
| 57 | + { |
| 58 | + V0: &Types.Vertex{Position: v[0], Normal: nil}, |
| 59 | + V1: &Types.Vertex{Position: v[3], Normal: nil}, |
| 60 | + V2: &Types.Vertex{Position: v[4], Normal: nil}, |
| 61 | + }, |
| 62 | + { |
| 63 | + V0: &Types.Vertex{Position: v[7], Normal: nil}, |
| 64 | + V1: &Types.Vertex{Position: v[4], Normal: nil}, |
| 65 | + V2: &Types.Vertex{Position: v[3], Normal: nil}, |
| 66 | + }, |
| 67 | + // bottom |
| 68 | + { |
| 69 | + V0: &Types.Vertex{Position: v[6], Normal: nil}, |
| 70 | + V1: &Types.Vertex{Position: v[5], Normal: nil}, |
| 71 | + V2: &Types.Vertex{Position: v[4], Normal: nil}, |
| 72 | + }, |
| 73 | + { |
| 74 | + V0: &Types.Vertex{Position: v[7], Normal: nil}, |
| 75 | + V1: &Types.Vertex{Position: v[6], Normal: nil}, |
| 76 | + V2: &Types.Vertex{Position: v[4], Normal: nil}, |
| 77 | + }, |
| 78 | + }, |
| 79 | + } |
| 80 | + return mesh |
| 81 | +} |
0 commit comments