Files
CavesOfSwift/Sources/JolkEngine/Content/Mesh.swift
2024-05-09 20:52:01 +10:00

87 lines
1.7 KiB
Swift

import OrderedCollections
public struct Model<T: Vertex>: Resource
{
public let meshes: [Mesh<T>]
}
public struct Mesh<T: Vertex>: Resource
{
public typealias Index = UInt16
public struct SubMesh
{
public let start, length: Int
public let material: Int //hack
public init(start: Int, length: Int, material: Int = -1)
{
self.start = start
self.length = length
self.material = material
}
}
public let vertices: [T]
public let indices: [Index]
public let subMeshes: OrderedDictionary<String, SubMesh>
public let materials: [Material] // hack
}
public extension Mesh
{
static var empty: Self { Self(vertices: .init(), indices: .init(), subMeshes: .init(), materials: .init()) }
init(vertices: [T], indices: [Index])
{
self.init(
vertices: vertices,
indices: indices,
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
}
}