Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VRM 1.0 parsing support #29

Merged
merged 28 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f3db791
Change VRMLoader to prepare for VRM 1.0
is0263rf Apr 4, 2024
572700e
Copy VRM.swift to VRM1.swift
is0263rf Apr 4, 2024
b69844a
Load VRM extension and parse specVersion.
is0263rf Apr 4, 2024
439fc49
Add parsing meta of VRM 1.0
is0263rf Apr 5, 2024
3e01a6f
Add parsing firstPerson of VRM 1.0
is0263rf Apr 5, 2024
08be216
Add parsing lookAt of VRM 1.0
is0263rf Apr 5, 2024
95213ec
Add parsing humanoid of VRM 1.0
is0263rf Apr 5, 2024
8301ab6
Add parsing expressions of VRM 1.0
is0263rf Apr 5, 2024
1f24a04
Remove unnecessary code.
is0263rf Apr 5, 2024
c7b25da
Restore load() functions for compatibility.
is0263rf Apr 5, 2024
6d3ff1e
Add Tests and asset for VRM 1.0
is0263rf Apr 5, 2024
168879a
Remove type annotations.
is0263rf Apr 5, 2024
bb554ba
Add parsing VRMC_springBone
is0263rf Apr 10, 2024
223a386
Rename IntOrDouble to Either<Int, Double>.
is0263rf Apr 11, 2024
dde5142
Add parsing VRMC_materials_mtoon.
is0263rf Apr 12, 2024
f638a38
Add parsing VRMC_node_constraint.
is0263rf Apr 12, 2024
c50da81
Add key for extensions and extras.
is0263rf Apr 12, 2024
98479bf
Use symbolic link in Asset directory.
is0263rf Apr 12, 2024
481da32
Fix typing of shadingShiftTextureInfo.index and shadingShiftTextureIn…
is0263rf Apr 16, 2024
614301e
Rename VRMFileProtocol to VRMFile.
is0263rf Apr 16, 2024
f1549eb
Split VRMTests into 2 files.
is0263rf Apr 16, 2024
f2a097e
fix load() interface to accept Type in argument.
is0263rf Apr 16, 2024
867c283
Fix type of textureInfo.schema.json.
is0263rf Apr 16, 2024
fcae4b9
Merge remote-tracking branch 'upstream/main' into support-vrm1
is0263rf Apr 16, 2024
9744e0a
Remove Either<Int, Double>.
is0263rf Apr 16, 2024
8a176fc
Remove decodeDouble().
is0263rf Apr 16, 2024
3d8d21c
Remove init() in MaterialsMToonTextureInfo.
is0263rf Apr 17, 2024
cd2213d
Fix RollAxis, change upper case to lower case.
is0263rf Apr 17, 2024
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
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ let package = Package(
.testTarget(
name: "VRMKitTests",
dependencies: ["VRMKit"],
resources: [.copy("Assets/AliciaSolid.vrm")]
resources: [.copy("Assets/AliciaSolid.vrm"), .copy("Assets/Seed-san.vrm")]
),
.testTarget(
name: "VRMSceneKitTests",
dependencies: ["VRMSceneKit"],
resources: [.copy("Assets/AliciaSolid.vrm")]
resources: [.copy("Assets/AliciaSolid.vrm"), .copy("Assets/Seed-san.vrm")]
),
]
)
1 change: 1 addition & 0 deletions Sources/VRMKit/Extensions/GlobalFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ func ???<T>(lhs: T?,
guard let value = lhs else { throw error() }
return value
}

69 changes: 68 additions & 1 deletion Sources/VRMKit/VRM/Material.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Foundation
extension GLTF {
public struct Material: Codable {
public let name: String?
public let extensions: CodableAny?
public let extensions: MaterialExtensions?
public let extras: CodableAny?
public let pbrMetallicRoughness: PbrMetallicRoughness?
public let normalTexture: NormalTextureInfo?
Expand Down Expand Up @@ -102,5 +102,72 @@ extension GLTF {
case MASK
case BLEND
}

public struct MaterialExtensions: Codable {
public let materialsMToon: MaterialsMToon?

private enum CodingKeys: String, CodingKey {
case materialsMToon = "VRMC_materials_mtoon"
}

public struct MaterialsMToon: Codable {
public let specVersion: String
public let transparentWithZWrite: Bool?
public let renderQueueOffsetNumber: Int?
public let shadeColorFactor: [Double]?
public let shadeMultiplyTexture: MaterialsMToonTextureInfo?
public let shadingShiftFactor: Double?
public let shadingShiftTexture: MaterialsMToonShadingShiftTexture?
public let shadingToonyFactor: Double?
public let giEqualizationFactor: Double?
public let matcapFactor: [Double]?
public let matcapTexture: MaterialsMToonTextureInfo?
public let parametricRimColorFactor: [Double]?
public let rimMultiplyTexture: MaterialsMToonTextureInfo?
public let rimLightingMixFactor: Double?
public let parametricRimFresnelPowerFactor: Double?
public let parametricRimLiftFactor: Double?
public let outlineWidthMode: MaterialsMToonOutlineWidthMode?
public let outlineWidthFactor: Double?
public let outlineWidthMultiplyTexture: MaterialsMToonTextureInfo?
public let outlineColorFactor: [Double]?
public let outlineLightingMixFactor: Double?
public let uvAnimationMaskTexture: MaterialsMToonTextureInfo?
public let uvAnimationScrollXSpeedFactor: Double?
public let uvAnimationScrollYSpeedFactor: Double?
public let uvAnimationRotationSpeedFactor: Double?
public let extensions: CodableAny?
public let extras: CodableAny?

public struct MaterialsMToonTextureInfo: Codable {
public let index: Int
public let texCoord: Int?
public let extensions: CodableAny?
public let extras: CodableAny?

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
index = try container.decode(Int.self, forKey: .index)
texCoord = try container.decodeIfPresent(Int.self, forKey: .texCoord)
extensions = try container.decodeIfPresent(CodableAny.self, forKey: .extensions)
extras = try container.decodeIfPresent(CodableAny.self, forKey: .extras)
}
tattn marked this conversation as resolved.
Show resolved Hide resolved
}

public struct MaterialsMToonShadingShiftTexture: Codable {
public let index: Int
public let texCoord: Int?
public let scale: Double?
public let extensions: CodableAny?
public let extras: CodableAny?
}

public enum MaterialsMToonOutlineWidthMode: String, Codable {
case none
case worldCoordinates
case screenCoordinates
}
}
}
}
}
72 changes: 71 additions & 1 deletion Sources/VRMKit/VRM/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension GLTF {
}
public let weights: [Float]?
public let name: String?
public let extensions: CodableAny?
public let extensions: NodeExtensions?
public let extras: CodableAny?

private enum CodingKeys: String, CodingKey {
Expand All @@ -51,5 +51,75 @@ extension GLTF {
case extensions
case extras
}

public struct NodeExtensions: Codable {
public let nodeConstraint: NodeConstraint?

private enum CodingKeys: String, CodingKey {
case nodeConstraint = "VRMC_node_constraint"
}

public struct NodeConstraint: Codable {
public let specVersion: String
public let constraint: Constraint
public let extensions: CodableAny?
public let extras: CodableAny?

public struct Constraint: Codable {
public let roll: RollConstraint?
public let aim: AimConstraint?
public let rotation: RotationConstraint?
public let extensions: CodableAny?
public let extras: CodableAny?

public struct RollConstraint: Codable {
public let source: Int
public let rollAxis: RollAxis
public let weight: Double?
public let extensions: CodableAny?
public let extras: CodableAny?

public enum RollAxis: String, Codable {
case X
case Y
case Z
tattn marked this conversation as resolved.
Show resolved Hide resolved
}
}

public struct AimConstraint: Codable {
public let source: Int
public let aimAxis: AimAxis
public let weight: Double?
public let extensions: CodableAny?
public let extras: CodableAny?

public enum AimAxis: String, Codable {
case positiveX
case negativeX
case positiveY
case negativeY
case positiveZ
case negativeZ

private enum CodingKeys: String, CodingKey {
case positiveX = "PositiveX"
case negativeX = "NegativeX"
case positiveY = "PositiveY"
case negativeY = "NegativeY"
case positiveZ = "PositiveZ"
case negativeZ = "NegativeZ"
}
}
}

public struct RotationConstraint: Codable {
public let source: Int
public let weight: Double?
public let extensions: CodableAny?
public let extras: CodableAny?
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion Sources/VRMKit/VRM/VRM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public struct VRM {
public struct VRM: VRMFile {
public let gltf: BinaryGLTF
public let meta: Meta
public let version: String?
Expand Down
Loading
Loading