The Skung Cave commit
This commit is contained in:
@ -1,54 +1,86 @@
|
||||
import OrderedCollections
|
||||
|
||||
|
||||
public struct Model: Resource
|
||||
public struct Model<T: Vertex>: Resource
|
||||
{
|
||||
public let meshes: [Mesh]
|
||||
public let meshes: [Mesh<T>]
|
||||
}
|
||||
|
||||
public struct Mesh: Resource
|
||||
public struct Mesh<T: Vertex>: Resource
|
||||
{
|
||||
public typealias Index = UInt16
|
||||
|
||||
public struct Vertex: Equatable
|
||||
{
|
||||
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 SubMesh
|
||||
{
|
||||
public let start, length: Int
|
||||
public let material: Int //hack
|
||||
|
||||
public init(start: Int, length: Int)
|
||||
public init(start: Int, length: Int, material: Int = -1)
|
||||
{
|
||||
self.start = start
|
||||
self.length = length
|
||||
self.material = material
|
||||
}
|
||||
}
|
||||
|
||||
public let vertices: [Vertex]
|
||||
public let vertices: [T]
|
||||
public let indices: [Index]
|
||||
public let subMeshes: OrderedDictionary<String, SubMesh>
|
||||
public let materials: [Material] // hack
|
||||
}
|
||||
|
||||
public extension Mesh
|
||||
{
|
||||
static let empty = Self(vertices: .init(), indices: .init(), subMeshes: .init())
|
||||
static var empty: Self { Self(vertices: .init(), indices: .init(), subMeshes: .init(), materials: .init()) }
|
||||
|
||||
init(vertices: [Vertex], indices: [Index])
|
||||
init(vertices: [T], indices: [Index])
|
||||
{
|
||||
self.init(
|
||||
vertices: vertices,
|
||||
indices: indices,
|
||||
subMeshes: .init())
|
||||
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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user