Skip to content

Instantly share code, notes, and snippets.

@ynagatomo
Created April 29, 2024 11:48
Show Gist options
  • Save ynagatomo/282486fd5ea71ac455bfe952c851cf04 to your computer and use it in GitHub Desktop.
Save ynagatomo/282486fd5ea71ac455bfe952c851cf04 to your computer and use it in GitHub Desktop.
An extension of ModelComponent, to dump its MeshResource.Model such as positions and normals.
extension ModelComponent {
/// Dump the MeshResource.Model
func dumpMeshResourceModel() {
let printSIMD3Float = { (value: SIMD3<Float>) in
print("(\(value.x), \(value.y), \(value.z)), ", terminator: "")
}
let printSIMD2Float = { (value: SIMD2<Float>) in
print("(\(value.x), \(value.y)), ", terminator: "")
}
print("MeshResource.Models (count = \(mesh.contents.models.count))")
for meshResModel in mesh.contents.models {
print(" MeshResource.Model:")
print(" +- id: \(meshResModel.id)")
print(" +- Parts (count = \(meshResModel.parts.count)):")
for part in meshResModel.parts {
print(" +- Part:")
// [MeshResource.Part properties]
print(" +- id: \(part.id)")
print(" +- materialIndex: \(part.materialIndex)")
print(" +- skeletonID: \(part.skeletonID ?? "nil")")
print(" +- jointInfluences (count = \(part.jointInfluences?.influences.count ?? -1))")
print(" +- triangleIndices (count = \(part.triangleIndices?.count ?? -1)) : ",
terminator: "")
if let triangleIndices = part.triangleIndices {
for triangleIndex in triangleIndices {
print("\(triangleIndex), ", terminator: "")
}
}
print("")
// [MeshBufferContainer protocol's properties]
// [positions]
print(" +- positions (count = \(part.positions.count)): ", terminator: "")
for position in part.positions {
printSIMD3Float(position)
}
print("")
// [normals]
if let normals = part.normals {
print(" +- normals (count = \(normals.count)): ", terminator: "")
for normal in normals {
printSIMD3Float(normal)
}
print("")
}
// [tangents]
if let tangents = part.tangents {
print(" +- tangents (count = \(tangents.count)): ", terminator: "")
for tangent in tangents {
printSIMD3Float(tangent)
}
print("")
}
// [bitangents]
if let bitangents = part.bitangents {
print(" +- bitangents (count = \(bitangents.count)): ", terminator: "")
for bitangent in bitangents {
printSIMD3Float(bitangent)
}
print("")
}
// [textureCoordinates]
if let textureCoordinates = part.textureCoordinates {
print(" +- textureCoordinates (count = \(textureCoordinates.count)): ",
terminator: "")
for textureCoordinate in textureCoordinates {
printSIMD2Float(textureCoordinate)
}
print("")
}
// [MeshResource.Part properties]
// [buffers]
print(" +- buffers: (count = \(part.buffers.count))")
for (id, partBuffer) in part.buffers {
print(" +- buffer")
print(" +- id: \(id.description) (name: \(id.name))")
print(" +- anyMeshBuffer")
print(" +- count: \(partBuffer.count)")
print(" +- elementType: \(partBuffer.elementType)")
print(" +- id: \(partBuffer.id.description)")
print(" +- rate: \(partBuffer.rate)")
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment