Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c8d5da7
vrm1.0 support
tatsuya-ogawa Jan 26, 2026
6c880bd
Update Example/VisionExample/VisionExampleApp.swift
tatsuya-ogawa Jan 31, 2026
85a140f
displayName
tatsuya-ogawa Jan 31, 2026
b6a0b7f
displayName
tatsuya-ogawa Jan 31, 2026
04b327f
Update Example/VisionExample/ContentView.swift
tatsuya-ogawa Jan 31, 2026
7e8607f
materialName
tatsuya-ogawa Jan 31, 2026
0ea686a
SpringBone
tatsuya-ogawa Jan 31, 2026
445e5f6
revert Sources/VRMKit/VRM/Node.swift
tatsuya-ogawa Jan 31, 2026
b66fe1c
revert Sources/VRMKit/VRM/VRM1.swift
tatsuya-ogawa Jan 31, 2026
6371170
Revert "revert Sources/VRMKit/VRM/VRM1.swift"
tatsuya-ogawa Jan 31, 2026
51d4ff6
Revert "revert Sources/VRMKit/VRM/Node.swift"
tatsuya-ogawa Jan 31, 2026
4b5e8fd
fix test
tatsuya-ogawa Jan 31, 2026
58c01fa
fix BlendShape
tatsuya-ogawa Feb 1, 2026
c058dd8
Merge branch 'main' of github.com:tatsuya-ogawa/VRMKit into feature/v…
tatsuya-ogawa Feb 2, 2026
d8b23bd
fix comment
tatsuya-ogawa Feb 2, 2026
8b9b966
remove comments
tatsuya-ogawa Feb 2, 2026
d1cb5f3
fix comment
tatsuya-ogawa Feb 2, 2026
9451a52
mac example
tatsuya-ogawa Feb 2, 2026
dee4292
add testcase
tatsuya-ogawa Feb 2, 2026
e51ea67
remove unnecessary comment
tatsuya-ogawa Feb 2, 2026
84d9113
SwiftTesting
tatsuya-ogawa Feb 3, 2026
6abaf87
revert VRM1Tests.swift
tatsuya-ogawa Feb 3, 2026
9dd2db8
Revert "revert VRM1Tests.swift"
tatsuya-ogawa Feb 3, 2026
9876270
refactor testcase
tatsuya-ogawa Feb 3, 2026
4e407c4
allowedUserName
tatsuya-ogawa Feb 3, 2026
775d164
texture transform
tatsuya-ogawa Feb 3, 2026
cfb1b65
fix build error
tatsuya-ogawa Feb 3, 2026
141fb79
add example build pipeline
tatsuya-ogawa Feb 3, 2026
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
Prev Previous commit
Next Next commit
SpringBone
  • Loading branch information
tatsuya-ogawa committed Jan 31, 2026
commit 0ea686a0c0f71800c4b41adca33e44910a169e77
93 changes: 66 additions & 27 deletions Sources/VRMKit/VRM/VRMMigration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,26 +218,13 @@
}
}

// Convert Springs (BoneGroups)
// Convert Springs (BoneGroups)
var boneGroups: [BoneGroup] = []
if let springs = sb.springs {
for spring in springs {
// VRM 1.0 Spring joints -> VRM 0.x bones
// VRM 1.0: joints: [{node, stiffness, ...}, ...]
// VRM 0.x: bones: [Int] (indices of root bones)
// VRM 0.x assumes uniform physics parameters for the group.
// VRM 1.0 has per-joint parameters.
// Migration: Take average or first joint's parameters?

guard let firstJoint = spring.joints.first else { continue }

let bones = spring.joints.map { $0.node }

// Map VRM 1.0 colliderGroups (indices) to OUR generated vrm0ColliderGroups (indices)?
// This is hard. VRM 1.0 spring refers to VRM 1.0 collider groups.
// VRM 0.x spring refers to VRM 0.x collider groups (which we just synthesized by Node).
// If we want exact collision logic, we need to find which nodes are involved in the VRM 1.0 collider groups referenced by this spring.

// Determine `colliderGroups` valid for this Spring.
// These are shared for all split groups derived from this Spring.
var referencedNodeIndices: Set<Int> = []
if let groupIndices = spring.colliderGroups, let vrm1Groups = sb.colliderGroups {
for groupIdx in groupIndices {
Expand All @@ -258,17 +245,69 @@
return referencedNodeIndices.contains(group.node) ? index : nil
}

boneGroups.append(BoneGroup(
bones: bones,
center: spring.center ?? -1,
colliderGroups: vrm0ColliderGroupIndices,
comment: spring.name,
dragForce: firstJoint.dragForce ?? 0.5,
gravityDir: VRM.Vector3(x: firstJoint.gravityDir?[0] ?? 0, y: firstJoint.gravityDir?[1] ?? -1, z: firstJoint.gravityDir?[2] ?? 0),
gravityPower: firstJoint.gravityPower ?? 0,
hitRadius: firstJoint.hitRadius ?? 0.02,
stiffiness: firstJoint.stiffness ?? 1.0
))
// VRM 1.0 joints can have varying parameters.
// We split them into multiple VRM 0.x BoneGroups if parameters change.

struct PhysicsParams: Equatable {
let dragForce: Double
let gravityDir: [Double]
let gravityPower: Double
let hitRadius: Double
let stiffness: Double
}

var currentJoints: [Int] = []
var currentParams: PhysicsParams?

for joint in spring.joints {
let params = PhysicsParams(
dragForce: joint.dragForce ?? 0.5,
gravityDir: joint.gravityDir ?? [0, -1, 0],
gravityPower: joint.gravityPower ?? 0,
hitRadius: joint.hitRadius ?? 0.02,
stiffness: joint.stiffness ?? 1.0
)

if let current = currentParams, current == params {
// Same parameters, add to current group.
currentJoints.append(joint.node)
} else {
// Parameters changed or first joint.
if let current = currentParams, !currentJoints.isEmpty {
// Close previous group
boneGroups.append(BoneGroup(
bones: currentJoints,
center: spring.center ?? -1,
colliderGroups: vrm0ColliderGroupIndices,
comment: spring.name,
dragForce: current.dragForce,
gravityDir: VRM.Vector3(x: current.gravityDir[0], y: current.gravityDir[1], z: current.gravityDir[2]),
gravityPower: current.gravityPower,
hitRadius: current.hitRadius,
stiffiness: current.stiffness
))
}

// Start new group
currentParams = params
currentJoints = [joint.node]
}
}

// Close the last group
if let current = currentParams, !currentJoints.isEmpty {
boneGroups.append(BoneGroup(
bones: currentJoints,
center: spring.center ?? -1,
colliderGroups: vrm0ColliderGroupIndices,
comment: spring.name,
dragForce: current.dragForce,
gravityDir: VRM.Vector3(x: current.gravityDir[0], y: current.gravityDir[1], z: current.gravityDir[2]),
gravityPower: current.gravityPower,
hitRadius: current.hitRadius,
stiffiness: current.stiffness
))
}
}
}

Expand All @@ -294,7 +333,7 @@

// Map MToon parameters to VRM 0.x MaterialProperty
var floatProperties: [String: Double] = [:]
var keywordMap: [String: Bool] = [:]

Check warning on line 336 in Sources/VRMKit/VRM/VRMMigration.swift

View workflow job for this annotation

GitHub Actions / Test package (iOS)

variable 'keywordMap' was never mutated; consider changing to 'let' constant

Check warning on line 336 in Sources/VRMKit/VRM/VRMMigration.swift

View workflow job for this annotation

GitHub Actions / Test package (xrOS)

variable 'keywordMap' was never mutated; consider changing to 'let' constant

Check warning on line 336 in Sources/VRMKit/VRM/VRMMigration.swift

View workflow job for this annotation

GitHub Actions / Test package (watchOS)

variable 'keywordMap' was never mutated; consider changing to 'let' constant
var textureProperties: [String: Int] = [:]
var vectorProperties: [String: [Double]] = [:] // VRM0.x expects [Double] (array of 4)

Expand Down
Loading