Skip to content

Commit

Permalink
Remove decodeDouble().
Browse files Browse the repository at this point in the history
  • Loading branch information
is0263rf committed Apr 16, 2024
1 parent 9744e0a commit 8a176fc
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 114 deletions.
3 changes: 0 additions & 3 deletions Sources/VRMKit/Extensions/GlobalFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,3 @@ func ???<T>(lhs: T?,
return value
}

func decodeDouble<T: CodingKey>(key: T, container: KeyedDecodingContainer<T>) throws -> Double {
return try (try? container.decode(Double.self, forKey: key)) ?? Double(try container.decode(Int.self, forKey: key))
}
40 changes: 0 additions & 40 deletions Sources/VRMKit/VRM/Material.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,53 +160,13 @@ extension GLTF {
public let scale: Double?
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)
scale = try? decodeDouble(key: .scale, container: container)
extensions = try container.decodeIfPresent(CodableAny.self, forKey: .extensions)
extras = try container.decodeIfPresent(CodableAny.self, forKey: .extras)
}
}

public enum MaterialsMToonOutlineWidthMode: String, Codable {
case none
case worldCoordinates
case screenCoordinates
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
specVersion = try container.decode(String.self, forKey: .specVersion)
transparentWithZWrite = try container.decodeIfPresent(Bool.self, forKey: .transparentWithZWrite)
renderQueueOffsetNumber = try container.decodeIfPresent(Int.self, forKey: .renderQueueOffsetNumber)
shadeColorFactor = try container.decodeIfPresent([Double].self, forKey: .shadeColorFactor)
shadeMultiplyTexture = try container.decodeIfPresent(MaterialsMToonTextureInfo.self, forKey: .shadeMultiplyTexture)
shadingShiftFactor = try? decodeDouble(key: .shadingShiftFactor, container: container)
shadingShiftTexture = try container.decodeIfPresent(MaterialsMToonShadingShiftTexture.self, forKey: .shadingShiftTexture)
shadingToonyFactor = try? decodeDouble(key: .shadingToonyFactor, container: container)
giEqualizationFactor = try? decodeDouble(key: .giEqualizationFactor, container: container)
matcapFactor = try container.decodeIfPresent([Double].self, forKey: .matcapFactor)
matcapTexture = try container.decodeIfPresent(MaterialsMToonTextureInfo.self, forKey: .matcapTexture)
parametricRimColorFactor = try container.decodeIfPresent([Double].self, forKey: .parametricRimColorFactor)
rimMultiplyTexture = try container.decodeIfPresent(MaterialsMToonTextureInfo.self, forKey: .rimMultiplyTexture)
rimLightingMixFactor = try? decodeDouble(key: .rimLightingMixFactor, container: container)
parametricRimFresnelPowerFactor = try? decodeDouble(key: .parametricRimFresnelPowerFactor, container: container)
parametricRimLiftFactor = try? decodeDouble(key: .parametricRimLiftFactor, container: container)
outlineWidthMode = try container.decodeIfPresent(MaterialsMToonOutlineWidthMode.self, forKey: .outlineWidthMode)
outlineWidthFactor = try? decodeDouble(key: .outlineWidthFactor, container: container)
outlineWidthMultiplyTexture = try container.decodeIfPresent(MaterialsMToonTextureInfo.self, forKey: .outlineWidthMultiplyTexture)
outlineColorFactor = try container.decodeIfPresent([Double].self, forKey: .outlineColorFactor)
outlineLightingMixFactor = try? decodeDouble(key: .outlineLightingMixFactor, container: container)
uvAnimationMaskTexture = try container.decodeIfPresent(MaterialsMToonTextureInfo.self, forKey: .uvAnimationMaskTexture)
uvAnimationScrollXSpeedFactor = try? decodeDouble(key: .uvAnimationScrollXSpeedFactor, container: container)
uvAnimationScrollYSpeedFactor = try? decodeDouble(key: .uvAnimationScrollYSpeedFactor, container: container)
uvAnimationRotationSpeedFactor = try? decodeDouble(key: .uvAnimationRotationSpeedFactor, container: container)
extensions = try container.decodeIfPresent(CodableAny.self, forKey: .extensions)
extras = try container.decodeIfPresent(CodableAny.self, forKey: .extras)
}
}
}
}
Expand Down
26 changes: 0 additions & 26 deletions Sources/VRMKit/VRM/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,6 @@ extension GLTF {
case Y
case Z
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
source = try container.decode(Int.self, forKey: .source)
rollAxis = try container.decode(RollAxis.self, forKey: .rollAxis)
weight = try? decodeDouble(key: .weight, container: container)
extensions = try container.decodeIfPresent(CodableAny.self, forKey: .extensions)
extras = try container.decodeIfPresent(CodableAny.self, forKey: .extras)
}
}

public struct AimConstraint: Codable {
Expand All @@ -119,30 +110,13 @@ extension GLTF {
case negativeZ = "NegativeZ"
}
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
source = try container.decode(Int.self, forKey: .source)
aimAxis = try container.decode(AimAxis.self, forKey: .aimAxis)
weight = try? decodeDouble(key: .weight, container: container)
extensions = try container.decodeIfPresent(CodableAny.self, forKey: .extensions)
extras = try container.decodeIfPresent(CodableAny.self, forKey: .extras)
}
}

public struct RotationConstraint: Codable {
public let source: Int
public let weight: Double?
public let extensions: CodableAny?
public let extras: CodableAny?

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
source = try container.decode(Int.self, forKey: .source)
weight = try? decodeDouble(key: .weight, container: container)
extensions = try container.decodeIfPresent(CodableAny.self, forKey: .extensions)
extras = try container.decodeIfPresent(CodableAny.self, forKey: .extras)
}
}
}
}
Expand Down
45 changes: 0 additions & 45 deletions Sources/VRMKit/VRM/VRM1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,26 +199,6 @@ public extension VRM1 {
public let outputScale: Double
public let extensions: CodableAny?
public let extras: CodableAny?

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
inputMaxValue = try decodeDouble(key: .inputMaxValue, container: container)
outputScale = try decodeDouble(key: .outputScale, container: container)
extensions = try container.decodeIfPresent(CodableAny.self, forKey: .extensions)
extras = try container.decodeIfPresent(CodableAny.self, forKey: .extras)
}
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
offsetFromHeadBone = try container.decode([Double].self, forKey: .offsetFromHeadBone)
type = try container.decode(LookAtType.self, forKey: .type)
rangeMapHorizontalInner = try container.decode(LookAtRangeMap.self, forKey: .rangeMapHorizontalInner)
rangeMapHorizontalOuter = try container.decode(LookAtRangeMap.self, forKey: .rangeMapHorizontalOuter)
rangeMapVerticalDown = try container.decode(LookAtRangeMap.self, forKey: .rangeMapVerticalDown)
rangeMapVerticalUp = try container.decode(LookAtRangeMap.self, forKey: .rangeMapVerticalUp)
extensions = try container.decodeIfPresent(CodableAny.self, forKey: .extensions)
extras = try container.decodeIfPresent(CodableAny.self, forKey: .extras)
}
}

Expand Down Expand Up @@ -266,15 +246,6 @@ public extension VRM1 {
public let weight: Double
public let extensions: CodableAny?
public let extras: CodableAny?

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
node = try container.decode(Int.self, forKey: .node)
index = try container.decode(Int.self, forKey: .index)
weight = try decodeDouble(key: .weight, container: container)
extensions = try container.decodeIfPresent(CodableAny.self, forKey: .extensions)
extras = try container.decodeIfPresent(CodableAny.self, forKey: .extras)
}
}

public struct MaterialColorBind: Codable {
Expand Down Expand Up @@ -369,22 +340,6 @@ extension VRM1 {
public let dragForce: Double
public let extensions: CodableAny?
public let extras: CodableAny?

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
node = try container.decode(Int.self, forKey: .node)
hitRadius = try container.decode(Double.self, forKey: .hitRadius)
stiffness = try decodeDouble(key: .stiffness, container: container)
gravityPower = try decodeDouble(key: .gravityPower, container: container)
gravityDir = try container.decode([Double].self, forKey: .gravityDir)
do {
dragForce = try container.decode(Double.self, forKey: .dragForce)
} catch DecodingError.typeMismatch {
dragForce = Double(try container.decode(Int.self, forKey: .dragForce))
}
extensions = try container.decodeIfPresent(CodableAny.self, forKey: .extensions)
extras = try container.decodeIfPresent(CodableAny.self, forKey: .extras)
}
}
}
}
Expand Down

0 comments on commit 8a176fc

Please sign in to comment.