1    type MeshFormat =
2        | Regular
3        | Skinned
4    
5    type Vertex = struct
6        position : Vector3
7        normal : Vector3
8        color : Vector3
9        uv0 : Vector2
10   
11   type SkinnedVertex = struct
12       position : Vector3
13       normal : Vector3
14       color : Vector3
15       uv0 : Vector2
16       joints : ByteVector4
17       weights : Vector4
18   
19   type MeshMemory =
20       val format : MeshFormat
21       val vertices : Array<u8>
22       val indices : Array<u32>
23   
24       def equals (other : MeshMemory) =
25           format == other.format
26           && vertices.equals other.vertices && indices.equals other.indices
27   
28       def discard =
29           vertices.discard
30           indices.discard
31   
32       is Discard
33   
34       def min_max : (Vector3, Vector3) =
35           let positions = List.new
36           case format of
37               MeshFormat/Regular ->
38                   let vertex_array = vertices.bytes_as<Vertex>
39                   for vertex in vertex_array do
40                       positions.add vertex.position
41   
42               MeshFormat/Skinned ->
43                   let vertex_array = vertices.bytes_as<SkinnedVertex>
44                   for vertex in vertex_array do
45                       positions.add vertex.position
46   
47           let mut min_x = f32.max
48           let mut min_y = f32.max
49           let mut min_z = f32.max
50           let mut max_x = f32.min
51           let mut max_y = f32.min
52           let mut max_z = f32.min
53           for position in positions do
54               min_x = min_x.min position.x
55               min_y = min_y.min position.y
56               min_z = min_z.min position.z
57               max_x = max_x.max position.x
58               max_y = max_y.max position.y
59               max_z = max_z.max position.z
60   
61           (Vector3 min_x min_y min_z, Vector3 max_x max_y max_z)
62