forked from nicklockwood/ShapeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaterial.swift
More file actions
52 lines (43 loc) · 1.08 KB
/
Material.swift
File metadata and controls
52 lines (43 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// Material.swift
// ShapeScript
//
// Created by Nick Lockwood on 16/01/2019.
// Copyright © 2019 Nick Lockwood. All rights reserved.
//
import Euclid
import Foundation
public typealias Color = Euclid.Color
public enum Texture: Hashable {
case file(name: String, url: URL)
case data(Data)
}
public enum MaterialProperty: Hashable {
case color(Color)
case texture(Texture)
init?(_ value: Any) {
switch value {
case let color as Color:
self = .color(color)
case let texture as Texture:
self = .texture(texture)
default:
return nil
}
}
}
public struct Material: Hashable {
public var opacity = 1.0
public var texture: Texture?
public var color: Color? {
// Color and texture are mutually exclusive
didSet { texture = (color != nil) ? nil : texture }
}
public var isOpaque: Bool {
opacity > 0.999 && (color?.a ?? 1) > 0.999
}
public static let `default` = Material()
public init(color: Color? = nil) {
self.color = color
}
}