Files
CavesOfSwift/Sources/JolkEngine/Content/Mesh.swift

87 lines
1.7 KiB
Swift
Raw Normal View History

2024-05-05 17:01:56 +10:00
import OrderedCollections
2024-05-09 20:52:01 +10:00
public struct Model<T: Vertex>: Resource
2024-05-05 17:01:56 +10:00
{
2024-05-09 20:52:01 +10:00
public let meshes: [Mesh<T>]
2024-05-05 17:01:56 +10:00
}
2024-05-09 20:52:01 +10:00
public struct Mesh<T: Vertex>: Resource
2024-05-05 17:01:56 +10:00
{
public typealias Index = UInt16
public struct SubMesh
{
public let start, length: Int
2024-05-09 20:52:01 +10:00
public let material: Int //hack
2024-05-05 17:01:56 +10:00
2024-05-09 20:52:01 +10:00
public init(start: Int, length: Int, material: Int = -1)
2024-05-05 17:01:56 +10:00
{
self.start = start
self.length = length
2024-05-09 20:52:01 +10:00
self.material = material
2024-05-05 17:01:56 +10:00
}
}
2024-05-09 20:52:01 +10:00
public let vertices: [T]
2024-05-05 17:01:56 +10:00
public let indices: [Index]
public let subMeshes: OrderedDictionary<String, SubMesh>
2024-05-09 20:52:01 +10:00
public let materials: [Material] // hack
2024-05-05 17:01:56 +10:00
}
public extension Mesh
{
2024-05-09 20:52:01 +10:00
static var empty: Self { Self(vertices: .init(), indices: .init(), subMeshes: .init(), materials: .init()) }
2024-05-05 17:01:56 +10:00
2024-05-09 20:52:01 +10:00
init(vertices: [T], indices: [Index])
2024-05-05 17:01:56 +10:00
{
self.init(
vertices: vertices,
indices: indices,
2024-05-09 20:52:01 +10:00
subMeshes: .init(),
materials: .init())
}
init(vertices: [T], indices: [Index], subMeshes: OrderedDictionary<String, SubMesh>)
{
self.init(
vertices: vertices,
indices: indices,
subMeshes: subMeshes,
materials: .init())
}
}
public protocol Vertex: Equatable {}
public struct VertexPositionNormalTexcoord: Vertex
{
public let position: Vec3f
public let normal: Vec3f
public let texCoord: Vec2f
public init(position: Vec3f, normal: Vec3f, texCoord: Vec2f)
{
self.position = position
self.normal = normal
self.texCoord = texCoord
}
}
public struct VertexPositionNormalColourTexcoord: Vertex
{
public let position: Vec3f
public let normal: Vec3f
public let colour: Colour
public let texCoord: Vec2f
public init(position: Vec3f, colour: Colour, normal: Vec3f, texCoord: Vec2f)
{
self.position = position
self.colour = colour
self.normal = normal
self.texCoord = texCoord
2024-05-05 17:01:56 +10:00
}
}