Skip to content

Commit eb7f252

Browse files
committed
Clean code
1 parent 23e41cd commit eb7f252

File tree

15 files changed

+99
-117
lines changed

15 files changed

+99
-117
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import simd
2+
3+
package struct BlendShapeBinding<Mesh> {
4+
package let mesh: Mesh
5+
package let index: Int
6+
package let weight: Double
7+
8+
package init(mesh: Mesh, index: Int, weight: Double) {
9+
self.mesh = mesh
10+
self.index = index
11+
self.weight = weight
12+
}
13+
}
14+
15+
package struct BlendShapeClip<Mesh> {
16+
package let name: String
17+
package let preset: BlendShapePreset
18+
package let values: [BlendShapeBinding<Mesh>]
19+
package let isBinary: Bool
20+
21+
package var key: BlendShapeKey {
22+
return preset == .unknown ? .custom(name) : .preset(preset)
23+
}
24+
25+
package init(name: String,
26+
preset: BlendShapePreset,
27+
values: [BlendShapeBinding<Mesh>],
28+
isBinary: Bool) {
29+
self.name = name
30+
self.preset = preset
31+
self.values = values
32+
self.isBinary = isBinary
33+
}
34+
}
35+
36+
package struct MaterialValueBinding {
37+
package let materialName: String
38+
package let valueName: String
39+
package let targetValue: SIMD4<Float>
40+
package let baseValue: SIMD4<Float>
41+
42+
package init(materialName: String,
43+
valueName: String,
44+
targetValue: SIMD4<Float>,
45+
baseValue: SIMD4<Float>) {
46+
self.materialName = materialName
47+
self.valueName = valueName
48+
self.targetValue = targetValue
49+
self.baseValue = baseValue
50+
}
51+
}

Sources/VRMKitRuntime/BlendShapeTypes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public enum BlendShapePreset: String {
3131
case blinkL = "blink_l"
3232
case blinkR = "blink_r"
3333

34-
package init(name: String) {
34+
public init(name: String) {
3535
self = BlendShapePreset(rawValue: name.lowercased()) ?? .unknown
3636
}
3737
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22

33
extension Collection {
4-
subscript(safe index: Index) -> Element? {
4+
package subscript(safe index: Index) -> Element? {
55
return startIndex <= index && index < endIndex ? self[index] : nil
66
}
77
}

Sources/VRMKitRuntime/SIMD+Runtime.swift

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import simd
22

3-
public extension SIMD3 where Scalar == Float {
3+
package extension SIMD3 where Scalar == Float {
44
var normalized: SIMD3 {
55
simd_normalize(self)
66
}
@@ -18,20 +18,34 @@ public extension SIMD3 where Scalar == Float {
1818
}
1919
}
2020

21-
public extension simd_quatf {
21+
package extension simd_quatf {
2222
static func * (_ left: simd_quatf, _ right: SIMD3<Float>) -> SIMD3<Float> {
2323
simd_act(left, right)
2424
}
2525
}
2626

27-
public let quat_identity_float = simd_quatf(matrix_identity_float4x4)
27+
package let quat_identity_float = simd_quatf(matrix_identity_float4x4)
2828

29-
public func cross(_ left: SIMD3<Float>, _ right: SIMD3<Float>) -> SIMD3<Float> {
29+
package func cross(_ left: SIMD3<Float>, _ right: SIMD3<Float>) -> SIMD3<Float> {
3030
simd_cross(left, right)
3131
}
3232

33-
public func normal(_ v0: SIMD3<Float>, _ v1: SIMD3<Float>, _ v2: SIMD3<Float>) -> SIMD3<Float> {
33+
package func normal(_ v0: SIMD3<Float>, _ v1: SIMD3<Float>, _ v2: SIMD3<Float>) -> SIMD3<Float> {
3434
let e1 = v1 - v0
3535
let e2 = v2 - v0
3636
return simd_normalize(simd_cross(e1, e2))
3737
}
38+
39+
package extension simd_float4x4 {
40+
var translation: SIMD3<Float> {
41+
SIMD3<Float>(columns.3.x, columns.3.y, columns.3.z)
42+
}
43+
44+
func multiplyPoint(_ v: SIMD3<Float>) -> SIMD3<Float> {
45+
let result = simd_mul(self, SIMD4<Float>(v.x, v.y, v.z, 1))
46+
guard result.w != 0 else {
47+
return SIMD3<Float>(result.x, result.y, result.z)
48+
}
49+
return SIMD3<Float>(result.x / result.w, result.y / result.w, result.z / result.w)
50+
}
51+
}

Sources/VRMKitRuntime/UnityTransform.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
public protocol UnityTransformCompatible {
1+
package protocol UnityTransformCompatible {
22
associatedtype CompatibleType
33
var utx: CompatibleType { get }
44
}
55

6-
public final class UnityTransform<Base> {
6+
package final class UnityTransform<Base> {
77
package let base: Base
88

9-
public init(_ base: Base) {
9+
package init(_ base: Base) {
1010
self.base = base
1111
}
1212
}
1313

14-
public extension UnityTransformCompatible {
14+
package extension UnityTransformCompatible {
1515
var utx: UnityTransform<Self> {
1616
UnityTransform(self)
1717
}

Sources/VRMRealityKit/CustomType/BlendShape.swift

Lines changed: 0 additions & 27 deletions
This file was deleted.

Sources/VRMRealityKit/CustomType/Humanoid.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#if canImport(RealityKit)
22
import VRMKit
3+
import VRMKitRuntime
34
import RealityKit
45

56
public final class Humanoid {

Sources/VRMRealityKit/Extensions/Collection+.swift

Lines changed: 0 additions & 7 deletions
This file was deleted.

Sources/VRMRealityKit/Extensions/Simd+.swift

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
11
@_exported import VRMKitRuntime
2+
3+
#if canImport(RealityKit)
4+
import RealityKit
5+
6+
// MARK: - BlendShapeBindings
7+
8+
typealias BlendShapeBinding = VRMKitRuntime.BlendShapeBinding<Entity>
9+
typealias BlendShapeClip = VRMKitRuntime.BlendShapeClip<Entity>
10+
typealias MaterialValueBinding = VRMKitRuntime.MaterialValueBinding
11+
#endif

0 commit comments

Comments
 (0)