Skip to content

Commit 9e82ce2

Browse files
committed
Clean code
1 parent eb7f252 commit 9e82ce2

File tree

12 files changed

+46
-139
lines changed

12 files changed

+46
-139
lines changed
File renamed without changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Foundation
2+
import VRMKit
3+
4+
package extension VRMImage {
5+
static func from(_ image: GLTF.Image,
6+
relativeTo rootDirectory: URL?,
7+
bufferView: (Int) throws -> Data) throws -> VRMImage {
8+
let data: Data
9+
if let uri = image.uri {
10+
data = try Data(gltfUrlString: uri, relativeTo: rootDirectory)
11+
} else if let bufferViewIndex = image.bufferView {
12+
data = try bufferView(bufferViewIndex)
13+
} else {
14+
throw VRMError._dataInconsistent("failed to load image: both uri and bufferView are nil")
15+
}
16+
17+
return try VRMImage(data: data) ??? ._dataInconsistent("failed to create image from data")
18+
}
19+
}

Sources/VRMSceneKit/Extensions/SCNVector3+.swift renamed to Sources/VRMKitRuntime/Extensions/Vector3+SIMD.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import VRMKit
2-
import SceneKit
32

4-
extension VRM0.Vector3 {
3+
package extension VRM0.Vector3 {
54
var simd: SIMD3<Float> {
65
SIMD3<Float>(x: Float(x), y: Float(y), z: Float(z))
76
}

Sources/VRMRealityKit/CustomType/Humanoid.swift renamed to Sources/VRMKitRuntime/Humanoid.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
#if canImport(RealityKit)
21
import VRMKit
3-
import VRMKitRuntime
4-
import RealityKit
52

6-
public final class Humanoid {
7-
var bones: [Bones: Entity] = [:]
3+
public final class Humanoid<Node> {
4+
package var bones: [Bones: Node] = [:]
85

9-
func setUp(humanoid: VRM0.Humanoid, nodes: [Entity?]) {
6+
public init() {}
7+
8+
package func setUp(humanoid: VRM0.Humanoid, nodes: [Node?]) {
109
bones = humanoid.humanBones.reduce(into: [:]) { result, humanBone in
11-
guard let bone = Bones(rawValue: humanBone.bone),
12-
let node = nodes[safe: humanBone.node] else { return }
10+
guard let bone = Bones(rawValue: humanBone.bone) else { return }
11+
guard nodes.indices.contains(humanBone.node),
12+
let node = nodes[humanBone.node] else { return }
1313
result[bone] = node
1414
}
1515
}
1616

17-
public func node(for bone: Bones) -> Entity? {
17+
public func node(for bone: Bones) -> Node? {
1818
return bones[bone]
1919
}
2020

@@ -75,4 +75,3 @@ public final class Humanoid {
7575
case upperChest
7676
}
7777
}
78-
#endif

Sources/VRMRealityKit/GLTF2RealityKit/UIImage+GLTF.swift

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

Sources/VRMRealityKit/RuntimeExports.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ import RealityKit
88
typealias BlendShapeBinding = VRMKitRuntime.BlendShapeBinding<Entity>
99
typealias BlendShapeClip = VRMKitRuntime.BlendShapeClip<Entity>
1010
typealias MaterialValueBinding = VRMKitRuntime.MaterialValueBinding
11+
12+
// MARK: - Humanoid
13+
14+
public typealias Humanoid = VRMKitRuntime.Humanoid<Entity>
1115
#endif

Sources/VRMRealityKit/VRMEntityLoader.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,9 @@ open class VRMEntityLoader {
613613
func image(withImageIndex index: Int) throws -> VRMImage {
614614
if let cache = try entityData.load(\.images, index: index) { return cache }
615615
let gltfImage = try gltf.load(\.images)[index]
616-
let image = try VRMImage.from(gltfImage, relativeTo: rootDirectory, loader: self)
616+
let image = try VRMImage.from(gltfImage, relativeTo: rootDirectory) { index in
617+
try self.bufferView(withBufferViewIndex: index).bufferView
618+
}
617619
entityData.images[index] = image
618620
return image
619621
}

Sources/VRMSceneKit/CustomType/Humanoid.swift

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

Sources/VRMSceneKit/CustomType/VRMSpringBoneColliderGroup.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import VRMKit
2+
import VRMKitRuntime
23
import SceneKit
34

45
@available(*, deprecated, message: "Deprecated. Use VRMRealityKit instead.")

Sources/VRMSceneKit/GLTF2SCN/UIImage+GLTF.swift

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

0 commit comments

Comments
 (0)