Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: Introduce VRMKitRuntime for common implementation
  • Loading branch information
tattn committed Feb 3, 2026
commit 220b20495163045c5f16872816acec4fb50e98f1
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 {
public 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)
}
Comment thread
tattn marked this conversation as resolved.

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))
}
Comment thread
tattn marked this conversation as resolved.
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
Comment thread
tattn marked this conversation as resolved.
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.

21 changes: 1 addition & 20 deletions Sources/VRMSceneKit/Extensions/SCNNode+UnityTransform.swift
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
import SceneKit

public protocol UnityTransformCompatible {
associatedtype CompatibleType

var utx: CompatibleType { get }
}

@available(*, deprecated, message: "Deprecated. Use VRMRealityKit instead.")
public final class UnityTransform<Base> {
private let base: Base
public init(_ base: Base) {
self.base = base
}
}
import VRMKitRuntime

@available(*, deprecated, message: "Deprecated. Use VRMRealityKit instead.")
public extension UnityTransformCompatible {
var utx: UnityTransform<Self> {
return UnityTransform(self)
}
}

extension SCNNode: UnityTransformCompatible {}

@available(*, deprecated, message: "Deprecated. Use VRMRealityKit instead.")
Expand Down
Loading
Loading