Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions Example/Example/RealityKitViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class RealityKitViewController: UIViewController, UIGestureRecognizerDeleg
private var orbitPitch: Float = -0.1
private var orbitDistance: Float = 2
private var orbitTarget = SIMD3<Float>(0, 0.8, 0)
private var currentExpression: RKExpression = .neutral
private var currentExpression: Expression = .neutral

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -52,7 +52,7 @@ final class RealityKitViewController: UIViewController, UIGestureRecognizerDeleg
segmentedControl.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(segmentedControl)

let expressionItems = RKExpression.allCases.map { $0.displayName }
let expressionItems = Expression.allCases.map { $0.displayName }
let expressionSegmentedControl = UISegmentedControl(items: expressionItems)
expressionSegmentedControl.selectedSegmentIndex = 0
expressionSegmentedControl.addTarget(self, action: #selector(expressionSegmentChanged(_:)), for: .valueChanged)
Expand All @@ -73,7 +73,7 @@ final class RealityKitViewController: UIViewController, UIGestureRecognizerDeleg
}

@objc private func expressionSegmentChanged(_ sender: UISegmentedControl) {
let expression = RKExpression.allCases[sender.selectedSegmentIndex]
let expression = Expression.allCases[sender.selectedSegmentIndex]
loadedEntity?.setBlendShape(value: 0.0, for: .preset(currentExpression.preset))
currentExpression = expression
loadedEntity?.setBlendShape(value: 1.0, for: .preset(currentExpression.preset))
Expand Down Expand Up @@ -249,22 +249,3 @@ final class RealityKitViewController: UIViewController, UIGestureRecognizerDeleg
return true
}
}

@available(iOS 18.0, *)
private enum RKExpression: String, CaseIterable {
case neutral, joy, angry, sorrow, fun

var preset: BlendShapePreset {
switch self {
case .neutral: return .neutral
case .joy: return .joy
case .angry: return .angry
case .sorrow: return .sorrow
case .fun: return .fun
}
}

var displayName: String {
return rawValue.capitalized
}
}
8 changes: 6 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ let package = Package(
targets: [
.target(name: "VRMKit"),
.target(
name: "VRMSceneKit",
name: "VRMKitRuntime",
dependencies: ["VRMKit"]
),
.target(
name: "VRMSceneKit",
dependencies: ["VRMKit", "VRMKitRuntime"]
),
.target(
name: "VRMRealityKit",
dependencies: ["VRMKit"]
dependencies: ["VRMKit", "VRMKitRuntime"]
),

.testTarget(
Expand Down
37 changes: 37 additions & 0 deletions Sources/VRMKitRuntime/BlendShapeTypes.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
public enum BlendShapeKey: Hashable {
case preset(BlendShapePreset)
case custom(String)

public var isPreset: Bool {
switch self {
case .preset: return true
case .custom: return false
}
}
}

/// VRM 0.x Blend Shape Preset
public enum BlendShapePreset: String {
case unknown
case neutral
case a
case i
case u
case e
case o
case blink
case joy
case angry
case sorrow
case fun
case lookUp = "lookup"
case lookDown = "lookdown"
case lookLeft = "lookleft"
case lookRight = "lookright"
case blinkL = "blink_l"
case blinkR = "blink_r"

package init(name: String) {
self = BlendShapePreset(rawValue: name.lowercased()) ?? .unknown
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import VRMKit

protocol GLTFTextureInfoProtocol {
package protocol GLTFTextureInfoProtocol {
var index: Int { get }
var texCoord: Int { get }
}
Expand Down
37 changes: 37 additions & 0 deletions Sources/VRMKitRuntime/SIMD+Runtime.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import simd

public extension SIMD3 where Scalar == Float {
var normalized: SIMD3 {
simd_normalize(self)
}

var length: Scalar {
simd_length(self)
}

var length_squared: Scalar {
simd_length_squared(self)
}

mutating func normalize() {
self = normalized
}
}

public extension simd_quatf {
static func * (_ left: simd_quatf, _ right: SIMD3<Float>) -> SIMD3<Float> {
simd_act(left, right)
}
}

public let quat_identity_float = simd_quatf(matrix_identity_float4x4)

public func cross(_ left: SIMD3<Float>, _ right: SIMD3<Float>) -> SIMD3<Float> {
simd_cross(left, right)
}

public func normal(_ v0: SIMD3<Float>, _ v1: SIMD3<Float>, _ v2: SIMD3<Float>) -> SIMD3<Float> {
let e1 = v1 - v0
let e2 = v2 - v0
return simd_normalize(simd_cross(e1, e2))
}
18 changes: 18 additions & 0 deletions Sources/VRMKitRuntime/UnityTransform.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public protocol UnityTransformCompatible {
associatedtype CompatibleType
var utx: CompatibleType { get }
}

public final class UnityTransform<Base> {
package let base: Base

public init(_ base: Base) {
self.base = base
}
}

public extension UnityTransformCompatible {
var utx: UnityTransform<Self> {
UnityTransform(self)
}
}
37 changes: 1 addition & 36 deletions Sources/VRMRealityKit/CustomType/BlendShape.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if canImport(RealityKit)
import RealityKit
import VRMKitRuntime

struct BlendShapeClip {
let name: String
Expand All @@ -23,40 +24,4 @@ struct MaterialValueBinding {
let targetValue: SIMD4<Float>
let baseValue: SIMD4<Float>
}

public enum BlendShapeKey: Hashable {
case preset(BlendShapePreset)
case custom(String)
var isPreset: Bool {
switch self {
case .preset: return true
case .custom: return false
}
}
}

public enum BlendShapePreset: String {
case unknown
case neutral
case a
case i
case u
case e
case o
case blink
case joy
case angry
case sorrow
case fun
case lookUp = "lookup"
case lookDown = "lookdown"
case lookLeft = "lookleft"
case lookRight = "lookright"
case blinkL = "blink_l"
case blinkR = "blink_r"

init(name: String) {
self = BlendShapePreset(rawValue: name.lowercased()) ?? .unknown
}
}
#endif
2 changes: 1 addition & 1 deletion Sources/VRMRealityKit/CustomType/VRMEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import CoreGraphics
import Foundation
import RealityKit
import VRMKit
import VRMKitRuntime

@available(iOS 18.0, macOS 15.0, visionOS 2.0, *)
struct BlendShapeNormalTangentComponent: Component {
Expand Down Expand Up @@ -360,4 +361,3 @@ public final class VRMEntity {
}
}
#endif

1 change: 1 addition & 0 deletions Sources/VRMRealityKit/CustomType/VRMEntitySpringBone.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if canImport(RealityKit)
import RealityKit
import VRMKit
import VRMKitRuntime
import Foundation

@available(iOS 18.0, macOS 15.0, visionOS 2.0, *)
Expand Down
19 changes: 1 addition & 18 deletions Sources/VRMRealityKit/Extensions/Entity+UnityTransform.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
#if canImport(RealityKit)
import RealityKit
import simd

public protocol UnityTransformCompatible {
associatedtype CompatibleType
var utx: CompatibleType { get }
}

public final class UnityTransform<Base> {
private let base: Base
public init(_ base: Base) {
self.base = base
}
}

public extension UnityTransformCompatible {
var utx: UnityTransform<Self> {
UnityTransform(self)
}
}
import VRMKitRuntime

extension Entity: UnityTransformCompatible {}

Expand Down
36 changes: 0 additions & 36 deletions Sources/VRMRealityKit/Extensions/Simd+.swift
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
import simd

extension SIMD3 where Scalar == Float {
var normalized: SIMD3 {
simd_normalize(self)
}

var length: Scalar {
simd_length(self)
}

var length_squared: Scalar {
simd_length_squared(self)
}

mutating func normalize() {
self = normalized
}
}

extension simd_float4x4 {
var translation: SIMD3<Float> {
SIMD3<Float>(columns.3.x, columns.3.y, columns.3.z)
Expand All @@ -31,21 +13,3 @@ extension simd_float4x4 {
return SIMD3<Float>(result.x / result.w, result.y / result.w, result.z / result.w)
}
}

extension simd_quatf {
static func * (_ left: simd_quatf, _ right: SIMD3<Float>) -> SIMD3<Float> {
simd_act(left, right)
}
}

let quat_identity_float = simd_quatf(matrix_identity_float4x4)

func cross(_ left: SIMD3<Float>, _ right: SIMD3<Float>) -> SIMD3<Float> {
simd_cross(left, right)
}

func normal(_ v0: SIMD3<Float>, _ v1: SIMD3<Float>, _ v2: SIMD3<Float>) -> SIMD3<Float> {
let e1 = v1 - v0
let e2 = v2 - v0
return simd_normalize(simd_cross(e1, e2))
}
1 change: 1 addition & 0 deletions Sources/VRMRealityKit/RuntimeExports.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@_exported import VRMKitRuntime
1 change: 1 addition & 0 deletions Sources/VRMRealityKit/VRMEntityLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import CoreGraphics
import RealityKit
import Metal
import VRMKit
import VRMKitRuntime

@available(iOS 18.0, macOS 15.0, visionOS 2.0, *)
@MainActor
Expand Down
39 changes: 1 addition & 38 deletions Sources/VRMSceneKit/CustomType/BlendShape.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SceneKit
import VRMKitRuntime

@available(*, deprecated, message: "Deprecated. Use VRMRealityKit instead.")
struct BlendShapeClip {
Expand Down Expand Up @@ -26,41 +27,3 @@ struct MaterialValueBinding {
let targetValue: SCNVector4
let baseValue: SCNVector4
}

@available(*, deprecated, message: "Deprecated. Use VRMRealityKit instead.")
public enum BlendShapeKey: Hashable {
case preset(BlendShapePreset)
case custom(String)
var isPreset: Bool {
switch self {
case .preset: return true
case .custom: return false
}
}
}

@available(*, deprecated, message: "Deprecated. Use VRMRealityKit instead.")
public enum BlendShapePreset: String {
case unknown
case neutral
case a
case i
case u
case e
case o
case blink
case joy
case angry
case sorrow
case fun
case lookUp = "lookup"
case lookDown = "lookdown"
case lookLeft = "lookleft"
case lookRight = "lookright"
case blinkL = "blink_l"
case blinkR = "blink_r"

init(name: String) {
self = BlendShapePreset(rawValue: name.lowercased()) ?? .unknown
}
}
1 change: 1 addition & 0 deletions Sources/VRMSceneKit/CustomType/VRMNode.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SceneKit
import VRMKit
import VRMKitRuntime

@available(*, deprecated, message: "Deprecated. Use VRMRealityKit instead.")
open class VRMNode: SCNNode {
Expand Down
1 change: 1 addition & 0 deletions Sources/VRMSceneKit/CustomType/VRMSpringBone.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import SceneKit
import GameKit
import VRMKit
import VRMKitRuntime

@available(*, deprecated, message: "Deprecated. Use VRMRealityKit instead.")
final class VRMSpringBone {
Expand Down
11 changes: 0 additions & 11 deletions Sources/VRMSceneKit/Extensions/GLTF+.swift

This file was deleted.

Loading
Loading